Player object to rotate on keydown

Hello, I’m needing my player object ( a ball ) to rotate continuously on keydown when moving right or left. I currently have my left and right movements bound to “a” and “d” respectively. My movement is working but if, for instance, I add into my movement conditional this.ball.setRotation() it only rotates a single time and then doesn’t rotate again.

So again, I’m wanting my player object (ball) to rotate continuously when keydown. Should this be an animation and then this.ball.play() ?

You could use the Update function in your gameobject, and check if “a” or “d” is pressed once per frame.

I’ll give that a try and let you know. Thanks!

Hey Ben,
So if your movement is working, it sounds like you are running the movement method every frame “a” or “d” is pressed. However, the setRotation method sets the value, it does not increment it.

As a solution you could probably do one of the following things:

this.ball.setRotation(this.ball.rotation + rotationSpeed);

or

this.ball.rotation += rotationSpeed;

Note: rotation uses radians. If you want to use degrees, use angle ex: this.ball.angle += rotationSpeed;

2 Likes

@Jake.Caron This worked beautifully! Thank you very much.