I was wondering how i could simulate tank like movement.
What i was planing on doing is changing the rotation using left and right keys (Already using a library for input) then moving the tank with both the up and down keys. Usually movements pretty easy as in if the right button is pressed then increase the x coord but i wouldnt know how to do that with rotation. Sorry, its kind of hard for me to explain.
Tank heading += TurningRate * LeftKeyPressed
Tank heading -= TurningRate * RightKeyPressed
Tank X Position += cos(Tank heading) + MovementRate * FwdKeyPressed
Tank X Position -= cos(Tank heading) + MovementRate * AftKeyPressed
Tank Y Position += sin(Tank heading) + MovementRate * FwdKeyPressed
Tank Y Position -= sin(Tank heading) + MovementRate * AftKeyPressed
Tank is the bitmap im drawing, both 32s are the x and y values of the middle of the bitmap, the next to arguments are the screen coords im drawing to, and the next is the angle to rotate by
Well for converting from deg to rad I would use a name instead of the actual number or an inlined function might be even better. It also seems everything is a global variable, why not make a class call it, vec2 use that for position instead, then make a class for tank or entity to hold the position etc...
It's a simple mathematical equation you learn in highschool. 0.017blahblah is just PI / 180. It really is simple when you think about it. 2PI is a complete circle in degrees it is 360, so 2PI/360 is rad per degree (can be simplified to PI/180) that multiplied by any degree will get you the radians, which is what all the mathematical functions use.
Why start a bad habit ? Save it now by removing all the globals before it's too late.
Oh thats why i dont know that, im still in highschool - My teacher only briefly mentioned sin cos and tang so i dont really know what its used for.
So what i have is
But its still not working as expected, it rotates fine and smooth but it doesnt move as it should. Thanks for your help so far though.
And ehh i know globals are bad. Ill fix it right now