Firing Projectile on path,Firing Rockets on path
I'm making a 2D space shooter game and I'm trying to animate a rocket being fired from the player ship, outward and then up the screen. I've made the animation clip and it's being triggered successfully, but the animation seems to be overriding the position and it spawns at (0,0,0)
This is the script for launching the rockets public class RocketLauncher : MonoBehaviour { public GameObject rocket;
private PlayerController playerController;
private Vector3 rocketLauncher;
void Start(){
playerController = GameObject.FindWithTag("Player").GetComponent<PlayerController>();
}
void Update(){
Vector3 rocketLauncher = playerController.transform.position;
this.transform.position = playerController.transform.position;
}
//Rocket /Sound/ and Spawn
void RocketFireR(){
GameObject rocketR = Instantiate(rocket, rocketLauncher, Quaternion.identity) as GameObject;
}
public void RocketFire(){
RocketFireR();
}
}
Followed by the script for the rockets themselves, which handle the animation.
public class Rocket : MonoBehaviour {
public AnimationClip fire;
private Animation anim;
void Start () {
anim = GetComponent<Animation>();
FireAnimation();
anim.clip = fire;
}
void FireAnimation(){
anim.Play();
}
}
I can't figure out how to get the animation to spawn from the player ship position rather than the values in the animation itself (I'm quite new at this)
Your answer
Follow this Question
Related Questions
How would you make a dust trail with a 2d sprite animation? 0 Answers
2D Character rotates on collision 0 Answers
transform.localScal not flipping 0 Answers