I’m making a mobile game with ping pong style mechanics. I managed to get the paddle to follow the players finger, but I’m having some issues with rotating it. I want the paddle to slightly rotate in the direction swiped and return to the original rotation once they stop swiping. I tried a few different things but none of them seemed to work or I just don’t know how to apply them.
Sounds like maybe you need a currentRotation and a desiredRotation to control the paddle angle, and to:
set desiredRotation according to whatever swipe is going on
tween currentRotation smoothly to the desiredRotation so the paddle doesn’t jerk.
#1 above is up to you: usually you compare position this frame to the position last frame to decide motion of a given finger, and from that value decide what desiredAngle you want.
I tried this out, but I’m still not quite sure how I’m supposed to apply all of this. The paddle should gradually rotate to a maximum of 45 degrees from its original orientation in whatever direction the movement or swipe occurs. Once the player stops swiping, the paddle should return to its original orientation. I’m quite new to coding and Quaternions/rotations are still very alien to me (as you probably noticed lol). I know I’m asking for a lot, but could you give me an example that I could apply to my code on implementing this?
After playing around with the different rotation methods, I managed to get it working with these 2 lines of code. I have no idea if this is the ideal way to go about, but it works so I’ll take it
I do not have such an example handy but the pastebin tweening code I posted above can easily be adapted. You would use the currentQuantity to drive a rotation:
var TheObjectTransform.rotation = Quaternion.Euler( 0, 0, currentQuantity);
That will rotate it around the Z axis. If you’re going to programmatically do rotations, understanding at least how to create rotations out of the Quaternion.Euler() factory function is not really optional.
Well that’s awesome… ship it out to the customer now then!