Having trouble with projectile firing from player. Rotation is and force is not correct.

I am have a player that rotates around using a or d. This is the Tank controls from unity. You hold a until you have lined up your target then you shoot. The projectile shoots out to the left and right and force is added but when i shoot in other rotations the bullet continues to come out the sides and goes slower. I have tried to look through the forum for an answer but having trouble finding one. Any help would be much appreciated.

85759-untitled.png

    private void Fire()
    {
        // Set the fired flag so only Fire is only called once.
        m_Fired = true;

        // Create an instance of the shell and store a reference to it's rigidbody.
        Rigidbody shellInstance = Instantiate(m_Shell, m_FireTransform.position, this.transform.rotation) as Rigidbody;
        shellInstance.transform.rotation = this.transform.rotation;
        Physics.IgnoreCollision(shellInstance.GetComponent<Collider>(), GetComponent<Collider>());

        // Set the shell's velocity to the launch force in the fire position's forward direction.
        shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward; ;

        // Reset the launch force.  This is a precaution in case of missing button events.
        m_CurrentLaunchForce = m_MinLaunchForce;
    }

Thank you!

1 Answer

1

velocity property is in World Space.
Use AddRelatviveForce () instead.