How do I get the target position after a turn?

0 favourites
  • 4 posts
From the Asset Store
A well commented RPG game template to learn from or use as a base for your own game!
  • 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 ). 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Ehm...it appears I miss completely the syntax of the expression

    Now it works perfectly.

    Thank you so much for your help.

    Massimo

  • My pleasure

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)