Hi,
I am currently trying to make a physically accurate firearm system. The only problem is that I cannot get my bullet facing the direction it is currently going.
Ray ray = new Ray();
ray.origin = playerCamera.transform.position;
ray.direction = playerCamera.transform.forward;
direction = (ray.GetPoint(69) - firePoint.position).normalized;
GameObject bulletInstance = Instantiate(bullet, firePoint.position, Quaternion.identity);
bulletInstance.transform.forward = direction;
Vector3 bulletForce = direction * bulletVelocity;
bulletInstance.GetComponent<Rigidbody>().AddForce(bulletForce, ForceMode.Impulse);
Whatever I try to do, I cannot get the bullets to face in the direction they are going, they always point up.
What you could do is add a script to your bullet GameObject, so that you’re rotating the bullet to be looking at the same direction of the velocity vector. Using something like : Quaternion.LookRotation(rigidbody.velocity);
Should get you the correct rotation. Set the rotation of the rigidbody to change the bullet rotation using the physics engine.