Gun script is shooting wrong direction,Script is shooting wrong direction
Hi, i have problem with script. When i type transform.forward
the bullet only drops from the gun and if i type transform.right
it shoots backward Here is the script
var Bullet : Transform;
var Spawn : Transform;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
function Shoot()
{
var pel = Instantiate(Bullet, Spawn.position, Spawn.rotation);
pel.GetComponent.<Rigidbody>().AddForce(transform.right * 2000);
}
I went ahead and formatted your post for you; in the future, please format the code in your post so that its easier to look at. The button that looks like binary is the code formatting button - select your code in edit mode and click the button to format your code.
Answer by magarcan · Mar 28, 2017 at 04:17 PM
Here is my code. It's c# but I think you can use it as a referecence:
Rigidbody2D clone;
clone = Instantiate(Projectile, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection (Vector2.up * ProjectileSpeed);
Your answer

Follow this Question
Related Questions
transform.forward problem 2 Answers
How to make a NavMeshAgent move in the direction it is looking? 4 Answers
transform.forward giving unwanted movement 1 Answer
transform.localPosition += transform.forward moves object toward (0, 0, 0) 2 Answers
How do you maintain gravity using transform.forward and transform.right? 0 Answers