How do I get the target position after a turn?

Just started using Construct 2? Post your questions here

Post » Fri Feb 06, 2015 7:05 am

Hi everyone,
perfect noob here... in English language too (sorry!).
My, very basic, question is: in a top-down game I have an AI Car (with "Car" behaviour, guided by events) pursuing other vehicles in a large arena (Car Wars style :D). The Car may easily figure out if a target is in front of it by "LOS" behaviour; when the target exits the LOS cone (I keep it quite narrow), the Car knows it turned left or right. This is the point: left or right? how can the car to obtain this info? I tried the formula "angle(Car.x,target.x,Car.y,target.y)", supposing that when it returns 180 or less is a right turn and viceversa, but the returned values are useless (zero or -90) - probably I did not understand the correct use of that expression.
Any suggestion for a quick way to know where the target is relatively to the AI Car? thx in advance!

Massimo
B
26
S
3
G
1
Posts: 31
Reputation: 1,513

Post » Fri Feb 06, 2015 2:43 pm

1. it should be targetAngle = angle(car.x, car.y, target.x, target.y)
2. you should compare that angle to the angle of car, so if targetAngle < car.angle it turned right, else it turned left.

But also there is problem with angle 0 where 0 becomes 360, so it should be:
if targetAngle < car.angle = right
or
if targetAngle > car.angle + 180 = right

else = left

Hope it helps, if you give capx maybe I could help more.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Fri Feb 06, 2015 4:31 pm

Ehm...it appears I miss completely the syntax of the expression :oops:
Now it works perfectly.
Thank you so much for your help.

Massimo
B
26
S
3
G
1
Posts: 31
Reputation: 1,513

Post » Fri Feb 06, 2015 4:56 pm

My pleasure ;)
B
12
S
6
G
2
Posts: 99
Reputation: 1,727


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests