2
votes

I'm pretty new to Unity so please bear with me.

What I want to do:

I want my simple game object to have a linear speed on Z axis (white path on the screenshot) and perform a simple animation while this object is moving

So I have attached rigidbody to my green game object and attach a script to it and get the required component and set velocity to 10f.

myRigidBody = GetComponent<Rigidbody> ();
myRigidBody.velocity = new Vector3 (0,0,10f);

This works and the object starts moving when I hit "play" in Unity editor.

enter image description here

The problem:

If "Animator" component on this game object is checked, the player won't move (but it will perform animation). When I uncheck this component the game object will start to move.

In the animation itself, I'm changing the position of game object (Y axis - jump), and rotation (will flip).

The question:

Why my game object won't move (even that I've given it a linear velocity), when the animator component is checked (in action)?

I want this game object to be moving and on click perform an animation.

This is basically it. Any help highly appreciated.

EDIT: Animation values:

enter image description here

1
Did you checked if animation does not overrides rigidbody's properties?Mateusz
Please see my edit. Any chance there Is something wrong with values?rootpanthera
So you're changing it's position in animation. That's why rigidbody cannot "push" your object.Mateusz
Yes because I want to "jump". Or am I approaching this the wrong way?rootpanthera
If you want to just "jump" then do not change X and Z values in the animation. You should change only the Y value.Mateusz

1 Answers

1
votes

You can overcome the fact that Unity overrides the Rigidbody when an Animator is attached by creating a new empty GameObject and making it the parent of the existing (animating) GameObject.

I found this information on the Unity forum.