- Home /
How to make a script for "jetpack" boost animation
Hi, im fairly new to unity and scripting, and need help in making a script for my spaceships boost animation to play when i hold down Left mouse button and go back to "idle" animation when LMB is released. At the moment i dont have anything else in my script except movement. Farthest i've gotten with it is gettin it to change the animation to boost but it blinked the boost on and off and wouldn't go back to idle.
Game is 2D
if someone could make me clear instructions on how this is done.
Here's my script for the spaceship.
using UnityEngine; using System.Collections;
public class ufocontrols : MonoBehaviour {
public float jetpackForce = 75.0f;
public float forwardMovementSpeed = 3.0f;
Animator animator;
// Use this for initialization
void Start () {
animator = this.GetComponent<Animator> ();
}
void Update ()
{
}
// Update is called once per frame
void FixedUpdate ()
{
bool jetpackActive = Input.GetButton("Fire1");
if (jetpackActive) {
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, jetpackForce));
}
Vector2 newVelocity = GetComponent<Rigidbody2D>().velocity;
newVelocity.x = forwardMovementSpeed;
GetComponent<Rigidbody2D>().velocity = newVelocity;
}
}
Have you tried ins$$anonymous$$d of animating your jetpack through script to add parameters to the animator transitions there can be ? Example your in idle and go to boost if parameter "speed" is more than 20.0 . if not, go back to idle?
Answer by Eosray · May 07, 2015 at 02:23 PM
no but i found out that i was using animator wrong since they included "Entry and Exit" in the animator and i wasnt using them at all, i just made transitions between the animations not from entry to animation to exit. and that fixed my problem.
but thanks anyways and i will certainly try that out if it would work better !!
Your answer
Follow this Question
Related Questions
How to make an animation play after releasing key? 1 Answer
Animation not at correct position W/Video 0 Answers
ui button animation finish 0 Answers
Animation Not Playing - VideoExplanation 2 Answers