- Home /
Pinball Flipper using Quaternion.Lerp?
Greetings. I am attempting to make a pinball flipper. I use a cylinder shape as a hinge with a cuboid as it's child. I would like to know how to rotate the hinge FROM 40° TO -40° on the y-axis in 0.5 seconds, and back to its original position (40°) when the key is no longer pressed. Using C#, I understand Quaternion.Lerp is involved, however the tutorial requires rotating from one object to another, which is inconvenient. I'd appreciate the help :)
capture.jpg
(269.0 kB)
Comment
Answer by YasinJavaid_ · Feb 16, 2018 at 12:28 PM
Transform from = this.transform;
Transform to = this.transform;
if(Input.keyDown){
to.eulerAngles = new Vector3 (to.eulerAngles.x, to.eulerAngles.y + 40, to.eulerAngles.z);
transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * 10);
}
// minus same with some delay of 0.5 seconds.