We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm making a tank game and I need to be able to rotate the tanks with the arrow keys and then if I press forward, they will move towards the direction that they are facing. I managed to rotate them, but I can't figure out how to move them forwards according to their rotation. Here is my code:
void draw() {
if (keys[2]) {
tankRotate1-=tankRSpeed1;
}
if(keys[3]) {
tankRotate1+=tankRSpeed1;
}
imageMode(CENTER);
pushMatrix();
translate(tankX1, tankY1);
rotate(radians(tankRotate1));
image(redTnak, 0, 0);
popMatrix();
}
Let me know if more code is needed. I appreciate any help that I can get!
Answers
You need to update your tanks position based on it's rotation in addition to which keys are pressed:
THANK YOU SO MUCH! I've been looking everywhere for something like that!
Actually, when I tried playing your code, in some directions, it behaves strangely (if you press up sometimes, it will go sideways and others, it will behave normally) how would I fix that?
When you press up, it goes in the direction the triangle points.