bartk Posted September 24, 2015 Share Posted September 24, 2015 Hello folks, I have here a code to rotate my car object://turnSpeed is a fraction of the car's current speed so that the car can't rotate without moving forwardturnSpeed = speed / 6000; //these conditionals are true when the buttons on the screen are touched if (rightArrowLeftIsPressed) { playerCar.rotation += turnSpeed; } if (leftArrowLeftIsPressed) { playerCar.rotation -= turnSpeed; }//if no button is pressed, the car should snap to a wind direction if it's already close to one else { if (playerCar.rotation < 0.15 && playerCar.rotation > -0.15) { playerCar.rotation = 0; } if (playerCar.rotation > (Math.PI - 0.15) || playerCar.rotation < (-Math.PI + 0.15)) { playerCar.rotation = Math.PI; } if (playerCar.rotation > -Math.PI / 2 - 0.15 && playerCar.rotation < -Math.PI / 2 + 0.15) { playerCar.rotation = -Math.PI / 2; } if (playerCar.rotation > Math.PI / 2 - 0.15 && playerCar.rotation < Math.PI / 2 + 0.15) { playerCar.rotation = Math.PI / 2; } }For some reason, pressing the rightArrowLeft button works only until the car reaches a rotation of 0, 90, 180 or 270. Then, it snaps to that direction without rotating further.The leftArrowLeft button, to rotate counterclockwise, works without any problems.Anyone have any idea why this would happen? Thanks Link to comment Share on other sites More sharing options...
Recommended Posts