KonMos

rotating sprite in direction of drag

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:)

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

thanks for all the suggestions. the car now turns only when the input eg mouse is clicked but does not update contionously when the pointer is moving around.

any suggestions how to update?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.