I have a FPS gun model that I modeled and animated in blender.
It has this script attached to it in unity:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class characteranim : MonoBehaviour
{
private Animator anim;
public float fireRate = 15f;
private float nextTimeToFire = 0;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
{
anim.SetBool("isRunning", true);
}
else
{
anim.SetBool("isRunning", false);
}
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire && AMMOscript.ammoValue > 0)
{
anim.SetTrigger("shoot");
nextTimeToFire = Time.time + 1f / fireRate;
}
}
}
I have all the animations working well enough in the animator except in the game after an animation plays the whole object moves down or up after every time the animation plays (making it go lower and lower (or higher and higher)) until it is barely visible. I’ve been looking for a fix for days now, I’ve even remodeled the gun and reanimated it but still nothing is working. I’ll also note that I am using Unity’s standard asset FPScontroller which the model is a child of.
Thanks in advance.
Edit: I think that the issue might be that after each time the animation transitions to another it rotates the object down (or up) on its center point.
Also the object spawn in game at a slightly different position to where it is in the Scene editor, I don’t know why this is either.