- Home /
FPS Weapon and animation
Hello there, I've begun on creating a FPS game, and I have a few questions. I currently have a weapon model + arms attached to my main camera on my character controller. I was wondering if there is a way to give it an idle animation, like if you just sitting around, the gun and hands and arms move slowly up and down. Also, I have tried to make it so the weapon does not clip though other stuff such as walls. I tried adding a mesh collider, but it only makes it so I cannot jump and can't want when looking down or straight. I know in many FPS game if you hold up your gun to person's head, your weapon appears tiny and does not go though walls and other stuff. Is the viewmodel actually tiny? My weapon is actually equal to the size of a player's head, but looks fine looking around normally. What is an appropriate way to fix this problem?
Answer by HamCoder404 · Aug 13, 2013 at 04:20 PM
Part I:
Create an animations script. I have a default code here, remember to create your animations:
function Update() {
if(Input.GetAxis("Vertical")){
// If you go forward or backward...
if(Input.GetKeyDown(KeyCode.LeftShift)){
// If you put down left shift...
animation.CrossFade("Run", 0.1);
// Crossfade the animation "Run"...
}
else
// If you are not holding left shift...
{
animation.CrossFade("Walk", 0.1);
// Crossfade the animation "Walk"
}
}
else
// If your not pressing anything
{
animation.CrossFade("Idle", 0.1);
// Crosssfade the animation Idle...
}
}
Crossfade means to merge the animations so they have a smooth flow...
Part II:
I have done this before. Basically, what you need to do is duplicate the camera you are using, and rename it "Gun Cam". On the toolbar click Edit>Project Settings>NavMeshSettings and then add a layer called "Gun". Select your gun and hands and and set the layer to "Gun". Now go click on your main camera and under "Culling Mask" unselect "Gun", and on your Gun Cam Select Only "Guns". Make sure Main camera has a near of 0.2, while you Gun Cam has a near of 0.1! Try it out.
Your answer
Follow this Question
Related Questions
Switch Weapon Script Not taking effect HELP!! 2 Answers
Hot to use walking animation while aiming! 0 Answers
Multiple Weapon Animation Help 0 Answers
problem with weapon animation -.- 0 Answers
Weapon Switch Animations 1 Answer