An easy maths question

Blitz3D Forums/Blitz3D Beginners Area/An easy maths question

Caff(Posted 2005) [#1]
Say I want to move 20 units in a particular direction (ie. the direction the character is facing) - only using the X and Z axis. (I think this is called 'absolute' positioning?) How do I calculate the necessary X and Z values based on the angle alone?

I'm sure trigonometry has something to do with this, but years of alcohol abuse has ruined my memory.


Rob Farley(Posted 2005) [#2]
finalx = currentx + (sin(angle)*distancetomove)
finalz = currentz + (cos(angle)*distancetomove)


WolRon(Posted 2005) [#3]
or just use MoveEntity(entity, distancetomove).
Then you don't need to bother with the x, z values...


Caff(Posted 2005) [#4]
Nah I'm using tokamak so it's not relative to orientation.

Thanks Rob, that seems to be what I'm looking for.


big10p(Posted 2005) [#5]
I think you need to swap the sin & cos in that, Rob. ;)


Rob Farley(Posted 2005) [#6]
I don't.

Angle of 0 (forwards)
Sin(0) = 0
Cos(0) = 1

therefore I'm saying x=x+(0*20) z=z+(1*20)

Angle of 90 (move right)
sin(90) = 1
cos(90) = 0

therefore x=x+(1*20) z=z+(0*20)


Caff(Posted 2005) [#7]
Yeah it worked a treat, cheers :)

It brought memories flooding back of my TCP-scented PGCE maths teacher from high school.


big10p(Posted 2005) [#8]
OK, I thought you wanted to move using 'world coords', where zero degrees would be along the +x axis. i.e. "absolute positioning"