Search Unity

Rotating character while it is moving.

Discussion in '2D' started by Darkhalo45, May 22, 2016.

  1. Darkhalo45

    Darkhalo45

    Joined:
    May 7, 2016
    Posts:
    18
    I am making a game, where the player is a ball. When the players body starts to move, I want it to rotate, so it would look like a rolling ball. Apparently,I tried doing so and it didn't work.

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

    Movement(horizontal, vertical);

    }

    void Movement(float horizontal, float vertical) {
    PlayerRigidBody.velocity = new Vector2(horizontal * movementSpeed, PlayerRigidBody.velocity.y);
    transform.localRotation = new Vector2(transform.rotation.x + 1, 0); // Here is where I get an error.
    }
    }
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807