- Home /
How do I use addforce relative to a parent's rotation
I'm using Instantiate to shoot a bullet, my problem is that i can't seem to get the bullet to actually shoot where the barrel is facing, i've tried using a set velocity rb.AddForce (0, bulletVelo, 0);
and transform.forward, but using the latter doesn't make the bullet move at all. Here are my two scripts i'm using to shoot/spawn the bullet and to make the bullet move
using UnityEngine; using System.Collections; public class fire : MonoBehaviour { public GameObject bullet; public Transform muzzle; void Update () { if (Input.GetButtonDown ("Fire1")) { Instantiate (bullet, muzzle.position, Quaternion.identity); } } }
and bullet velocity
using System.Collections; using UnityEngine; public class flyFool : MonoBehaviour { private Rigidbody rb; public float destroyTime = 2.5f; public float bulletStartVelo = 5000f; public GameObject muzzle; void Awake () { muzzle = GetComponent<Transform>(); rb = GetComponent<Rigidbody>(); } void Start() { rb.AddForce (transform.forward * bulletStartVelo); Destroy (gameObject, destroyTime); } }
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Rotation based on Velocity returning 0,0,0 rotation 1 Answer
Transferring velocity from kinematic to a rigid body 0 Answers
2d kinematic projectile velocity problem 0 Answers