Jump to content

Sprite move with angle


siemacieslak
 Share

Recommended Posts

Hello.

 

I'm new to game coding. For my first project i'm creating small car game in bird's eye view.

I want to make other sprites that will move across the map in specified routes.

 

Game is using P2 physics.

 

I'd like to make car spawn every 2 seconds, make it drive to the specified direction and than delete it.

I want to make car run towards his actual angle (like in moveForward() method).

 

Green circle on picture shows spawn point, blue one is the cars and red line is direction line.

 

I've tried to use timeout functions and tweens but i could'nt achieve my target.

 

 

This is how my controllable sprite movement in game looks like:

    if (cursors.up.isDown)    {        car.body.moveForward(150);            if (cursors.left.isDown)            {                car.body.rotateLeft(60);            }            else if (cursors.right.isDown)            {                car.body.rotateRight(60);            }            else            {                car.body.setZeroRotation();            }    }

Could someone give me a solution to solve this please?

post-8076-0-27505800-1397041374.jpg

Link to comment
Share on other sites

I would create a custom Sprite that has a path to follow. This could be a series of markers and events at each marker. I.e. 'turn towards marker 1, then drive at this speed' and so on. There is nothing built-in to handle this for you, you're going to have to code it yourself, but I don't think it would be that much work. Just a series of coordinates and use a Timer event to get them to trigger when you need them.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...