5
$\begingroup$

I'm making a first person shooter game and I want to make it so when the right mouse button is being held down the, the player looks down the sights, and when the right button is released it returns to the normal view. So this is the normal view from the camera: normal view

And this is what I want it to look like when the player is holding the right mouse button (The gun moved to the left an backwards a bit:) zoomed view

Another problem I encountered while trying to do this was that I already have a shoot animation, so how do I have different actions on one object?

$\endgroup$
14
+200
$\begingroup$

It is actually rather easy to do this.

First, you need a cool gun, You already have on of those, so then next step is to make it my favorite color blue - 1BC8F7.

You can skip that step if you want, but the gun looks so much nicer blue :-)

I assume you are giving the gun recoil with logic like this.

enter image description here

To make your gun be able to aim from the sights, parent the gun to an empty.

enter image description here

The empty should be parented to the camera.

enter image description here

Now, if we move the camera, everything should move with it.

enter image description here

This is good. Now, your recoil animation can play on the gun, but it will not move into place yet.

enter image description here

We can fix this by animating the empty to move into place when the mouse is clicked, and then move back out of place when the mouse is released.

enter image description here

Believe it or not, we can do this with one animation. I am going to be using the right mouse button to aim the gun to the center, because it makes funner gameplay, however, it is just a simple to do it with the left mouse..

enter image description here

This is using the right mouse to aim the gun into place.

enter image description here

It works- Yay!

Now for the left mouse.

You only need to change a few things to your existing logic on the empty, to get this setup.

enter image description here

I added a simply ground plane to see the gun's movement better.

enter image description here

Now we need to add a Mouse Look actuator

enter image description here

Now, we can test it.

enter image description here

I'm not happy with that quite yet, so I'm going to add a slow parent to the empty.

enter image description here

Now we can test it.

enter image description here

That looks much better! You could, of course, tweak the settings to make it exactly how you want your gun. I think bullets and muzzle flashes would seriously help - but they have nothing to do with this answer :-(

$\endgroup$
  • $\begingroup$ This works, thanks! But, maybe I've done something wrong, right click toggles aiming down the iron sight. Is there a way so that it's looking down the iron sight when I'm holding right mouse button then when I release the button it goes back to hip-fire? @X-27 $\endgroup$ – Jacob_ Aug 29 '15 at 20:54
  • $\begingroup$ If I'm reading your question correctly, try using the second method (the one using left click to aim down the sights) - then change the mouse sensor from left click to right click. $\endgroup$ – X-27 the fluffy unicorn Aug 29 '15 at 21:08
  • 2
    $\begingroup$ Another classic X-27 overkill answer :D +1 $\endgroup$ – GiantCowFilms Aug 29 '15 at 22:18
  • $\begingroup$ I sound like this guy! (no it's excitement not overkill) $\endgroup$ – Pro Blaster Nov 27 '16 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.