Shooting sideways?
When i shoot my projectile, it shoots sideways! But i want it to shoot forward, here's my shoot script. please help, thanks!
using UnityEngine;
using System.Collections;
public class Shooting : MonoBehaviour
{
public Rigidbody projectile;
public float speed = 20;
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
Rigidbody instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(1, 1,speed));
}
}
}
Answer by EvilSam · Dec 30, 2015 at 04:53 AM
in line 15 i believe you meant to write new Vector3(0, 0,speed)
instead of new Vector3(1, 1,speed)
.
but anyway, you should replace line 15 with the following 2 lines:
instantiatedProjectile.velocity = transform.forward * speed;
instantiatedProjectile.transform.forward = transform.forward;
i think you accidentally deleted my comment, i updated the answer.
my projectile's rotation is still sideways
$$anonymous$$aybe you should change the rotation of the projectile prefab appropriately so it's not side ways.
Your answer
Follow this Question
Related Questions
How to make a bullet delay? 0 Answers
Reading a var from variable parents 1 Answer
making a boomerang effect in a 2D enviorment 1 Answer
How to get bullet hole to wrap around corners of objects? 0 Answers