transform.forward always returns the z axis

Im trying to program shooting and have done this multiple times by now, however this time Unity is nto feeling it and returns the z axis when casting a ray.

void Update()
{
    if(isLocalPlayer)
    {
        if(Input.GetKeyDown(KeyCode.Mouse0))
        {
            Shoot(transform.forward);
        }
    }
}

[Command]
void Shoot(Vector dir)
{
    DamagePlayer(dir);
}

[ClientRpc]
void DamagePlayer(Vector3 dir)
{
    RaycastHit hit;

    if (Physics.Raycast(transform.position, dir, out hit))
    {
        if (hit.transform.gameObject.tag == "Player")
        {
            hit.transform.GetComponent<Player>().health -= 10;
        }
    }
}

Well, the first question would be if you’re even rotating your character at any point. Is this a first person shooter? Maybe you have this script on the character, but you’re only rotation the camera, so the character’s forward never changes?

1 Like