Could I move animated game objects as I want?

I make a game object and I add an animation to it. This animation has position (0,0,0) on 0 second, and (0,2,0) on 0.5 second and (0,0,0) on 1seocnd. (up and down animation)

I add an script to this game object that has code as follows.

this.GetComponent ().velocity =  new Vector2 (-1*moveSpeed, 0);

I want to move my object toward -X axis and also I want my game object to move as it was animated.

As a result, my object doesn’t move toward -X axis, and just follow as it was animated.

Is there any solution that can move animated game objects(which I animate its position) as I want?

It would be really glad if you help me. Have a nice day.

Good day.

First, you are doing GetComponent () without specify what component you want to get… Get component is to reach one of the components of the object… the animator maybe?


And then, you want to change the speed of the animation? not the velocity? velocity is a vector, speed is a integrer.

I think you are missunderstanding things. You should watch some tutorial about Animation.