Jump to content

rotating sprite in direction of drag


KonMos
 Share

Recommended Posts

Hi there,

I want to implement a car which can be dragged and is able to turn around corners while being draged

so far I only found a posibility to turn in direction of the pointer (eg mouse) but than the car turns before it is even (pixelperfect)clicked too

any sugguesstions or helpfull links?

 

thanks:)

 

Link to comment
Share on other sites

You can update car rotation only if button is pressed. To smooth the rotation I would calculate angle between objects ( http://phaser.io/docs/2.6.2/Phaser.Math.html#angleBetweenPoints ) and slowly correct it toward 0 if it's bigger than some small value. I would never target 0 value as it will make car vibrating. Pseudo code would look something like this:

if buttonPressed {
  if angleBetween(car, pointer) > 0.2 {
    car.rotation += (or -=) 0.1
  }
}

You need to experiment wit the values and check if this works for you.

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

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