An easy maths question
Blitz3D Forums/Blitz3D Beginners Area/An easy maths question
| ||
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. |
| ||
finalx = currentx + (sin(angle)*distancetomove) finalz = currentz + (cos(angle)*distancetomove) |
| ||
or just use MoveEntity(entity, distancetomove). Then you don't need to bother with the x, z values... |
| ||
Nah I'm using tokamak so it's not relative to orientation. Thanks Rob, that seems to be what I'm looking for. |
| ||
I think you need to swap the sin & cos in that, Rob. ;) |
| ||
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) |
| ||
Yeah it worked a treat, cheers :) It brought memories flooding back of my TCP-scented PGCE maths teacher from high school. |
| ||
OK, I thought you wanted to move using 'world coords', where zero degrees would be along the +x axis. i.e. "absolute positioning" |