0
\$\begingroup\$

I have the following structure of my Turret:

enter image description here

The Body rotates by Y and Head rotating by X via script to a target, I have created simple Idle animation for turret which rotate Body and Head. The problem when the animation is added to an Animator, tower is stacked in static position, if i make translation to a Idle animation it's playing normally, but don't return back to a default state. I tried to create a buffer State without Idle Motion turret is rotating fine, I tried add conditions with bool value.

The questis is:

  1. How to play animation in different rotations? (If object changes his Transform, and then play animation, the animation shout start not from 0,0,0 but from 90,0,0 for example)

  2. How to switch default behaviour of targeting Enemies, maybee I should may animation for a Targeting or smth like this?

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

To solve it, I used parent object to have such structure:

enter image description here

I am rotating Body and Head via script, and create animation for an BodyAnimRotator, I have added reference to a BodyAnimRotator and Animator. When target is out of range I am enabling Animator if no, disabling.

To save current rotation of the body, we are rotating BodyAnimRotator in Animation, so position of the body stays the same.

\$\endgroup\$
0
\$\begingroup\$

When one of the animation states of an Animator changes a certain property of an object, then the Animator thinks that it "owns" that property. It will reset it to the default value each frame even when in a state where that property isn't a part of the Action.

However, you can override the results of the animator to implement the LateUpdate event. LateUpdate gets executed after the Animator, so you can use it to overwrite its results with something else.

This means that you can have an idle animation defined as an animation, and then when the turret has a target, overwrite the rotations in LateUpdate with your target tracking code.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .