hello!
i have been fooling around with the idea of making a top down racing game (seems like a few ppl are doing that) but anyway… ive been having some trouble with the motion of the car.
so far ive got it “driving” around the screen, no track or any boundaries it just goes. i sortof got the turning down, but then it i have a bit of a problem that i dont know how to solve yet which is slowing down when turning aswell. when i take my finger off the accelerator button, but i turn aswell, it does follow the path of the turning thing, it just goes in the last direction it was when the accelerator goes. i tried several approaches to this problem, mostly involving moving around the place where i calculated the angle it should be moving, because thats what i figured i should do, but it didnt really work, at all…
so this is the current part of my code with the accelerating and angle stuff:
if (keys[KeyEvent.VK_LEFT]) {
pcar[T]-=5;
}
if (keys[KeyEvent.VK_RIGHT]) {
pcar[T]+=5;
}
if (keys[KeyEvent.VK_UP]){
pcar[VX] += Math.sin(Math.toRadians(pcar[T])) * 1.0;
pcar[VY] += -Math.cos(Math.toRadians(pcar[T])) * 1.0;
}
if (keys[KeyEvent.VK_DOWN]) {
pcar[VX] += -Math.sin(Math.toRadians(pcar[T])) * 1.0;
pcar[VY] += Math.cos(Math.toRadians(pcar[T])) * 1.0;
}
pcar[VX] *= 0.9;
pcar[VY] *= 0.9;
pcar[DX] += pcar[VX];
pcar[DY] += pcar[VY];
dx/y is the cars position, vx/y is the velocity in that direction and T is the angle at which the car is currently rotated. this code here just has the car deccelerate in the direction it was last traveling with the accelerator pushed.
i also had the Math.sin, and Math.cos calculations in with the “friction” thing (pcar[vx] *= Math.sin(Math.toRadians(pcar[T])) * 0.9) but that didnt work.
so what im looking for is any info regarding car physics, and anything on this trigonometry stuff in general
thanks alot