- Home /
How to scale the changes done to a transform in an Animation on various objects?
So I have multiple objects that rock back and forth using an animation, only changes done are to the transform. However they all rock in at the exact same "intensity". How can I scale the changes done to transforms in the animation keyframes for each individual object? For example the default is each object rocks back and forth 15 degrees, but I want some to have twice the intensity and thus rock back and forth 30 degrees.
I want to have it so that there is a script on these objects that determines the rock intensity via a public float, and if this was speed this would be an easy change (using animation.speed) but I don't want the speed to change, just the intensity of what the animation does. I don't want to make a separate animation for each object, because there are 100+ objects in the scene and each one could have a unique intensity. Adjust a single float "animationIntensity" in the inspector would be a whole lot easier.
Answer by Distant-Object · Jan 11, 2016 at 09:36 PM
I think I figured out an alright solution, just multiply the changes by the intensity var in LateUpdate:
public void LateUpdate()
{
transform.eulerAngles = new Vector3(0.0f, 0.0f, transform.eulerAngles.z * animationIntensity);
}