- Home /
Mouse look alteration?
Is there any way to change the default mouse look script so that if its attached to my gun it moves my gun around but it smoothly glides back to its starting position instead of moving and staying in the new position, Im trying to make my gun have sort of a sway movement when you look around. (its very common in modern shooters), if anyone could help me I would be very great full.
Answer by Berenger · Jun 01, 2012 at 04:27 PM
First, you need to lerp between the current rotation and the default rotation. Use Time.deltaTime and a speed as t parameter.
Then, you need to decide when this is performed. I'd say when those two rotation are different which means the player moved the mouse, but with a timer reset every time the player actually move. It would look like that :
function Update()
{
if( Mouse move )
timer = WAIT_BEFORE_CENTER_WEAPON;
if( timer > 0 )
transform.rotation = Quaternion.Lerp( transform.rotation, defaultRotation, Time.deltaTime * speed );
timer -= Time.deltaTime;
}
Your answer
Follow this Question
Related Questions
Gun Muzzle Flash 2 Answers
A node in a childnode? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Animation On Mouse Click 1 Answer
Bullet Script Help 3 Answers