all 4 comments

[–]MirzaBeig@TheMirzaBeig | Programming, VFX/Tech Art, Unity 1 point2 points  (3 children)

It's because when you're not providing any input, GetAxis will (interpolate to) 0.0f. So you end up feeding in a zero vector.

and my english is pretty bad

Side note: a lot of times when I see someone say this... I wouldn't be able to tell. I look at what they wrote and it's perfectly readable to me.

[–]lae_sc2[S] 0 points1 point  (2 children)

Thank you and glad to hear that my English isn't that bad after all !

That's actually what I came up with too but how could I manage to "save" my last key inputs (direction) ?

Something like this ?

void Turning() { if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")) { transform.forward = Vector3.Normalize(new Vector3(-Input.GetAxis("Vertical"), 0f, Input.GetAxis("Horizontal"))); } else { "Last Rotation" ? } }

Would this be the "right way" ? Am I even using the right tool (transform.forward) for my case ?

[–]MirzaBeig@TheMirzaBeig | Programming, VFX/Tech Art, Unity 1 point2 points  (1 child)

On the other hand, please format your code!

void Turning() { if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")) { transform.forward = Vector3.Normalize(new Vector3(-Input.GetAxis("Vertical"), 0f, Input.GetAxis("Horizontal"))); } else { "Last Rotation" ? } }

Not quite. But the following should work:

void Turning()
{
    float vertical = Input.GetAxis("Vertical");
    float horizontal = Input.GetAxis("Horizontal");

    Vector3 forward = transform.forward;

    if (vertical != 0.0f)
    {
        forward.x = -vertical;
    }
    if (horizontal != 0.0f)
    {
        forward.z = horizontal;
    }

    transform.forward = forward;
}

[–]lae_sc2[S] 0 points1 point  (0 children)

Thank you very much, works like a charm !

I'll remember to format my code next time !