Skip to main content
April 2, 2013
Answered

Car game help: Moving forward relative to the direction changes.

  • April 2, 2013
  • 1 reply
  • 1161 views

Hey,

Just wondering how I can determine what coordinates my car needs to when I press up on my keyboard relative to the directions the car steers to.

Basically, when I steering the car I want it to still go forward after I've steered.

Here's the function I have prepared already:



public function actions(event:Event):void {



if (upKeyDown) {








}



if (rightKeyDown) {




this.rotation+=steering;



}



if (leftKeyDown) {




this.rotation-=steering;



}


}
This topic has been closed for replies.
Correct answer moccamaximum

Look for the line where its says:

velocityX = Math.sin (this.rotation * Math.PI / 180) * speed;

this velocityX (and velocityY) is used in the enter_frame function to set the cars position on stage

1 reply

Inspiring
April 2, 2013
April 2, 2013

I've already been to that website, my problem was I don't understand where those variables were being used on the car x and y coordinates. I can only see them being set and not used. Care to explain how they are being used on the car object?

Thanks for the reply.

moccamaximumCorrect answer
Inspiring
April 2, 2013

Look for the line where its says:

velocityX = Math.sin (this.rotation * Math.PI / 180) * speed;

this velocityX (and velocityY) is used in the enter_frame function to set the cars position on stage