- Home /
How to get smooth object rotation??
Hi, im working on a fps game and i want the camera to smoothly & slightly rotate up when Fire() is called and then smoothly back to start rotation again. The code i have works but not exactly how i want. Can someone please help me? Update() { if(rotationProgress < 1 && rotationProgress >= 0) { rotationProgress += Time.deltaTime * 5; Camera.main.tranform.Rotate = (-rotationProgress,0,0); } } Fire() { rotationProgress = 0; }
How can "if (rotationProgress < 1 && rotationProgress >= 0)" ever be true? You can't both be less than 1 and also greater than 0? I would recommend a lerp function, but you would need to know your destination and how fast you want to get there, but I'm not sure if that is something you know or not. If you clarify this, I can help further!
I dont know lol but somehow it works, the "1" also limits the recoil, if i set it like rotationProgress < 5 then the recoil is much more. But i gave up and just made recoil a animation and its working just the way i want. Thank you for the reply
@agray427... Well 0.5 is greater than 0 and less than 1....
@PZ4_Bailey : Why don't you use an animation to do so? Or an animation curve like this:
public AnimationCurve recoilAnimation ;
private float fireTime ;
Update()
{
if( Time.time - fireTime < recoilAnimation.keys[recoilAnimation.length -1].time )
{
float angle = recoilAnimation.Evaluate( Time.time - fireTime ) ;
Camera.main.tranform.Rotate(-angle,0,0);
}
// ...
}
public void Fire()
{
fireTime = Time.time ;
//...
}
Your answer
Follow this Question
Related Questions
Rotating wrong 0 Answers
Clamp Quaternions Rotation for camera 1 Answer
Gun tilting in the direction you look towards 1 Answer
Gun not rotating with the camera? 1 Answer
Storing camera angles for a FPS -1 Answers