Need help to trigger animation on input

I’m very new to Unity, but I need a script that can trigger an animation when a UI joystick is moved in a particular direction. The joystick is from the UJoystick package.
When the joystick is moved to the right, I need the object (in this case the helicopter) to tilt slightly to the right. And so on for the other directions.
I would really appreciate some help on this.

Since I already have a script for movement, it would be best if this rotation script could be to tilt the helicopter in the direction that it moves. So I don’t have to use too many animations for every possible direction.

1 Like

I sincerely recommend starting by opening Unity Learn > Pathways.

“Junior Programmer” course answers all your questions.

Wonderful! I’m sure this will help alot. I’ve just started looking around for something like that!

I’m actually using Unity to make mods for an existing game. This question is for a mod I’m currently working on, and this is the last final piece to the puzzle to finish off my project. Are you able to help me out here? I need something to make the helicopter tilt in whatever direction it moves, to make the aircraft’s movement look smooth.

1 Like

The 2nd Module of Mission 1 in Junior Programmer literally leads you to what you need.

I’ve been working through the course, and finished unit 1. One question, how do I make a value have a maximum? I have the code to allow the helicopter to move to the right, and code to make it tilt (rotate) to the right as well, but the helicopter just keeps on tilting (as long as I press the right arrow key) and eventually rolls over. I need it to have a maximum amount of tilt before it stops, so that it can keep on moving to the right without rolling over.

1 Like

For such cases, often Mathf.Clamp() is used.

Ah thanks, i’ll research on how to use that.

What about if I want the rotation to revert back to 0 when the right key is released? I need the helicopter to tilt to the right for as long as its moving to the right, but automatically go back to neutral again when it stops moving.

1 Like

When the key is not pressed, use Quaternion.Lerp to revert the rotation to the default state.

Great, this will set me up for a while.

I really must thank you for showing me the course, it is extremely helpful.

1 Like