Home > Net >  How can I make the player flip when it touches ground
How can I make the player flip when it touches ground

Time:04-12

I have a gravity thing and when they touch the ceiling I want the player to flip, my code doesn't work and I wonder if there is a better way to do this. I'd also like to know how to make the player not rotate to those exact coordinates and just where the player is already facing.

IEnumerator GravitySwitch()
{
    if (Input.GetMouseButtonDown(1) && grounded)
    {
        Physics.gravity = new Vector3(0, 10.0f, 0);
        yield return new WaitForSeconds(0.2f);
        if (grounded)
        transform.localEulerAngles = new Vector3(0, 0, 180);

    }
    if (Input.GetMouseButtonDown(0) && grounded)
    {
        Physics.gravity = new Vector3(0, -10.0f, 0);
        yield return new WaitForSeconds(0.2f);
        if (grounded)
        transform.localEulerAngles = new Vector3(0, 0, 0);


    }
}

CodePudding user response:

You could multiply the scale of your player's scale vector by:

new Vector3(1, -1, 1);

CodePudding user response:

can try

transform.Rotate(0.0f, 0.0f, 180.0f, Space.Self);

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html

  • Related