KonMos Posted December 29, 2017 Share Posted December 29, 2017 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 More sharing options...
in mono Posted December 29, 2017 Share Posted December 29, 2017 Collect a statistic of the last few points the car has been at and use them to smooth the rotation. Link to comment Share on other sites More sharing options...
Odk Posted December 29, 2017 Share Posted December 29, 2017 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 More sharing options...
KonMos Posted January 3, 2018 Author Share Posted January 3, 2018 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? Link to comment Share on other sites More sharing options...
KonMos Posted January 3, 2018 Author Share Posted January 3, 2018 oh and it needs to be a pixelperfect drag with rotation too Link to comment Share on other sites More sharing options...
KonMos Posted January 15, 2018 Author Share Posted January 15, 2018 anyone? Link to comment Share on other sites More sharing options...
Recommended Posts