2

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

5
  • Did you checked if animation does not overrides rigidbody's properties? Commented Apr 12, 2017 at 11:30
  • Please see my edit. Any chance there Is something wrong with values? Commented Apr 12, 2017 at 11:37
  • So you're changing it's position in animation. That's why rigidbody cannot "push" your object. Commented Apr 12, 2017 at 11:59
  • Yes because I want to "jump". Or am I approaching this the wrong way? Commented Apr 12, 2017 at 12:20
  • If you want to just "jump" then do not change X and Z values in the animation. You should change only the Y value. Commented Apr 12, 2017 at 12:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.