x


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.

more ▼

asked May 31 '12 at 03:35 PM

Dreave gravatar image

Dreave
122 82 94 96

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
}
more ▼

answered Jun 01 '12 at 04:27 PM

Berenger gravatar image

Berenger
11k 12 19 53

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5092
x3747
x446
x25
x25

asked: May 31 '12 at 03:35 PM

Seen: 442 times

Last Updated: Jun 03 '12 at 10:32 AM