Hi folks, been a while
, quite a while actually, a few years I'd say
... life got in the way of programming what can I say..
. Anyway I came across an old unfinished project, a 2d topdown car game I was building... remembering a few of my topics http://www.java-gaming.org/topics/car-rotation-problem-in-top-down/23817/60/view.html
, and well I must say that now I have been wanting to get a move on with the project; that is now that I have some free time on my hands! (work isn't being as invasive
So I wanted to come back and solve the issue of movement once and for all... with all that I have learnt and read through, should be a piece of cake one would have thought...
, seems it isn't the case. Having rummaged through my old thread, I remembered and found a link http://stackoverflow.com/questions/7312773/mathematical-vectors-and-rotations-topdown-java-game-dev-physics-problem
which explains how I wanted acceleration to act as a 2D vector.
Moving on to the fact that the answer lies in the last post; that is having two vectors totaling to the acceleration vector (as i recalled being told a few times in my earlier posts on JGO), I am now faced with a simple yet unanswerable problem with the code I have used. The problem lies in the fact that considering an angle of 0 and 360 degrees both pointing north respectively, I cannot for the life of me figure out why moving up will not keep the angle constant to 0. (apart from the fact that this angle is given through Math.toDegrees(Math.atan2(y, x)))
If we take this code for example ( a direct result of the last thread on stackoverflow )
double secondsElapsed = deltaTime / 1000.0;
double forwardDirection = velocity.angle() + 90;
double leftDirection = forwardDirection + 90;
double forwardAccel = 0;
forwardAccel = 100;
forwardAccel = -100;
double leftAccel = 0;
leftAccel = 100;
leftAccel = -100;
double fDir = Math.toRadians(forwardDirection - 90);
double lDir = Math.toRadians(leftDirection - 90);
Vector2D forwardUnitVector = new Vector2D (Math.cos(fDir), Math.sin(fDir));
Vector2D leftUnitVector = new Vector2D (Math.cos(lDir), Math.sin(lDir));
Vector2D acceleration = forwardUnitVector.scale(forwardAccel);
Vector2D deltaV = acceleration.scale(secondsElapsed);
angle = velocity.angle() + 90;
the angle and motion with the upwards press is set to give acceleration on the x axis (which is fine considering my angle is 90 degrees pointing east). Now realizing that we want a forwardUnitVector of (0,-1) (to get me poiting to the north) I was thinking something along the lines of a resulting degree of 270 (Math.sin(Math.toRadians(270)) = -1 which would be used along the y axis to create motion in the top direction. However, having set the forwardDirection to 360 which would give me a result of forwardUnitVector(0, -1) I am given a velocity and an angle which acts as a rotation and not a simple magnitude.
Can anyone please exaplin to me why my concept of having motion towards the north is flawed?
Thanks for bearing with me through this post!
and if any other information is required let me know!