Animated Projectile

Hey, possibly a newb question.

I’ve made a projectile following the Brick Shooter tutorial. Mine is a shark, and I want to give it a swimming animation. I can animate the shark model, but when I apply the animation to the rigidbody shark, it doesn’t respond to the force input. It just sits there and swims in place. Is there something obvious I’m missing here?

The animations I’m using are imported from Blender. The script to trigger animation is connected to the rigid body and is as follows:

using UnityEngine;
using System.Collections;

public class ShrkSwm : MonoBehaviour
{

		protected Animator animator;
		
		void Start ()
		{
			animator = GetComponent<Animator> ();
			animator.SetBool ("Swimming", true);
		}

}	

This is the script for the launching behavior, attached to the camera:

using UnityEngine;
using System.Collections;

public class Sharkapult : MonoBehaviour {
	
	public Rigidbody projectile;
	public Transform shotPos;
	public float shotForce = 1000f;
	public float moveSpeed = 10f;
	public float spiralForce = 0f;
	public float horSpinForce = 0f;
	public float verSpinForce = 0f;
	
	void Update () {
		
		float h = Input.GetAxis ("Horizontal") * Time.deltaTime * moveSpeed;
		float v = Input.GetAxis ("Vertical") * Time.deltaTime * moveSpeed;
		
		transform.Translate(new Vector3(h,v,0));


		if(Input.GetButtonUp("Fire1")) {
			Rigidbody shot = Instantiate(projectile, shotPos.position, shotPos.rotation) as Rigidbody;
			shot.transform.Rotate(new Vector3(0,90,0));
			shot.AddForce(shotPos.forward * shotForce);
			shot.AddTorque(new Vector3(spiralForce,horSpinForce,verSpinForce));

		}
	}
}

Any insight here would be very appreciated. Thanks!

Can you give more information? What is the script you're using, and what type of animation are you using?

Yup, thank you. Let me know if there's any more info you could use!

1 Answer

1

The animation is most likely overriding the position changes from the rigidbody. Try putting your Shark object into an empty parent GameObject. Then control the parent with a rigidbody instead while the animation plays on the Shark.

That did it, thank you!