Shooting an instantiated missile the way a object is facing.
Hi! I am trying to make a 2D Tank game. I want to create a new missile using Instantiate. This works perfect but I can't add a velocity to it, and I don't know the way the missile will go. This is my code:
public GameObject MissileOriginal;
public Transform MissileLaunchPosition;
GameObject newMissile;
public float missilespeed;
public void ShootMissile()
{
newMissile = Instantiate(MissileOriginal, MissileLaunchPosition.position, MissileLaunchPosition.rotation);
newMissile.AddComponent<Rigidbody2D>();
newMissile.GetComponent<Rigidbody2D>().gravityScale = 0;
newMissile.GetComponent<Rigidbody2D>().velocity = missilespeed * MissileLaunchPosition.forward;
}
If you could help me that would be great! I am very new to coding and Unity so every tip/ trick would be great! Thanks in advance!
Comment
Your answer
Follow this Question
Related Questions
How does one instantiate a prefab with velocity? 1 Answer
Firing to a mouse position 0 Answers
Instantiate GameObject with Velocity 1 Answer
Destroying game object 0 Answers