Constrain actor in front of another actor (need cos and sin help pls)
Hi, I have a car in a top down game, i want to constrain another actor directly in front of that car no matter which way the car is facing.
Anyone got a simple cos and sin formula to help me get started please?
Anyone got a simple cos and sin formula to help me get started please?
Comments
Then take the Half of the size in x and y , you have to use Cos for x and Sen for Y
Constrain actor pos x to Car pos x +cos angle *Half size car in that axis
in the object which has to follow the front of the car , make a constrain attribute like this
constrain position x to Carx +(cos(angle)*HSX)
Where carx is the x position of the car, angle is the current rotation angle of the car and HSX is half the size on the x axis
Then the same for the Y, but using sin
constrain position y to Cary +(sin(angle)*HSY)
where Hsy is half size on the Y
HSY is that carposx / 2, or half the size of the car itself?
if your car is 32x16 then
Hsx 16
hsy 8
Tank Rotate
see:- http://en.wikipedia.org/wiki/Pythagorean_trigonometric_identity for theory
thanx!
@};- MH
There are some real gems in that demo:
1) extremely easy to follow positioning formulas
2) intuitive rotation of the two constrained objects
3) a really great forward/backward direction control system I'd never even dreamed of! (I will be extremely embarrassed if everyone knew how to do that but me.)
Thanks for sharing it!
RThurman
I finally worked it out using bits and pieces from everyone's solutions, here are the final formulae I used to constrain an actor in front of a car
The rules for the constrained actor
constrain self.pos.x -> Car.Pos.X +(cos(Car.Rotation+90)*150)
constrain self.pos.y -> Car.Pos.Y+(sin(Car.Rotation+90)*150)
the Car rotation=90 was added because initially the actor is constrained to the right of the car (if the car is pointing up) so added the +90 and it constrains in front of the car. The 150 at the end you can change to any number, it just moves the actor closer or further away but 150 seems to work well about 1/3 of a scree in front of the car.
Thanks again to everyone that helped out!