# How do I trigonometrizzle this?

Get help using Construct 2

### » Sun Jun 26, 2016 7:12 pm

Hi,

(edit:) tl;dr: I want to create a position on a circle, found a formula for it, but am not sure what the highlighted part means (below)

Quick context:
My enemies are supposed to circle the player (roughly) when getting within a certain distance of him.
I want to use pathfinding, so I simply want to create a position within said distance and have pf resolve movement.

Now i found this online and it looks just like what i need; but I have trouble reading one particular line.

a = (r02 - r12 + d2 ) / (2d)

h = r0 sinP0 ((or) r1 sinP1)

P2 = P0 + a ( P1 - P0 ) / d
i.e.,
x2 = x0 + a (x1 - x0) / d
y2 = y0 + a (y1 - y0) / d

x3 = x2 ± h ( y1 - y0 ) / d

y3 = y2 ± h ( x1 - x0 ) / d

So this translates nicely to my setup, my only trouble is that black line:
what is "r0 sinP0"?
sinus of a position vector, multiplied by the radius? is that what it's saying? how do i take sinus of a vector?
Last edited by facecrime on Sun Jun 26, 2016 7:49 pm, edited 2 times in total.
B
17
S
8
Posts: 263
Reputation: 2,213

### » Sun Jun 26, 2016 7:16 pm

And while I'm here posting, can anyone suggest a better approach?
I previously achieved this using a bullet behaviour and moving the enemy orthogonally while looking at the player.
But using pathfinding just prevents collision issues with environment better.
B
17
S
8
Posts: 263
Reputation: 2,213

### » Sun Jun 26, 2016 7:20 pm

Take a look at the line of sight behavior.
B
175
S
50
G
199
Posts: 8,624
Reputation: 124,024

### » Sun Jun 26, 2016 7:46 pm

Why, does that have some way of providing a position for my enemy to move to that I've been missing so far?
B
17
S
8
Posts: 263
Reputation: 2,213

### » Sun Jun 26, 2016 7:54 pm

That doesn't make sense. What in particular are you looking to solve with that diagram?

Is P0 the player and P1 the enemy and you want to find p3?
B
97
S
36
G
131
Posts: 5,513
Reputation: 83,464

### » Sun Jun 26, 2016 8:07 pm

First one is my trying to visualize what I want the resulting behaviour to look like instead of long text.

Second one is what i found online, some bloke determining the intersection point of two circles (P3)
For my situation that translates to:
P0 is the player
P1 is the enemy
r0 being the circling range
r1 being the destination distance
and yes, P3 is what I want to find
B
17
S
8
Posts: 263
Reputation: 2,213

### » Sun Jun 26, 2016 9:05 pm

https://dl.dropboxusercontent.com/u/542 ... rsect.capx

dist = distance between centers
ang = angle from one center to the other

Then from the first center you move r0 pixels at angle ang+acos((r0^2 -r1^2 +dist^2)/(2*dist*r0)) to get to the left intersection point. You can also use -acos to get the right intersection point.
B
97
S
36
G
131
Posts: 5,513
Reputation: 83,464

### » Mon Jun 27, 2016 12:52 am

facecrime wrote:Why, does that have some way of providing a position for my enemy to move to that I've been missing so far?

That's what it does.

The problem with the pathfinding behavior is that it makes the object turn to the angle of motion before it moves.
So basically you would have to split up a circle, and find a path to each point of the circumference.
That's not hard, but it's incredibly wasteful.
B
175
S
50
G
199
Posts: 8,624
Reputation: 124,024

### » Mon Jun 27, 2016 8:22 pm

@R0J0hound thank you for your example, and thanks for your ongoing patience and support for that matter!

@newt I'm aware that I'm losing the circluar route this way, but that's fine.
I don't understand how you think I should use LoS to improve this. Can I get you to point me there?
B
17
S
8
Posts: 263
Reputation: 2,213

### » Mon Jun 27, 2016 9:15 pm

When the ai has los to the object you trigger an event that creates a point, or points on a circle. There are two ways to do it.
Create a list of points to follow, while its still has los, meaning you have to restart the list at some point.
Or pick a single point on a circle, move it, then find another point of that circle, while it still has los.
B
175
S
50
G
199
Posts: 8,624
Reputation: 124,024

Next