- Home /
Question by
Haugen · Jul 13, 2018 at 01:23 AM ·
rotationinstantiateprogramming
Why is my projectile firing "off" after rotation
I have a simple 3D object inside of a nulll object. The null object has a script to instatiate and launch/fire a projectile. It's a placeholder space fighter while I test.
When pointing forward at game load, I can fire straight forward without issues, but if I rotate to a side, the origin of the projectiles turns quicker than the craft.
Code
void Fire()
{
GameObject projectileInstance = Instantiate(Projectile, transform.position, transform.rotation);
projectileInstance.GetComponent<Rigidbody>().AddRelativeForce(transform.forward * SpeedMultiplier, ForceMode.VelocityChange);
}
I want to fire the objects straight ahead at all times
Comment
Answer by bennett_apps · Jul 23, 2018 at 11:46 PM
To fire forward? Simply turn the bullet to the same as the player and use transform.forward to move it.