Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Lock Rotation to Ground

Discussion in '2D' started by Socks1301, Mar 2, 2023.

  1. Socks1301

    Socks1301

    Joined:
    Aug 13, 2020
    Posts:
    3
    Hi,
    I am making a platformer game with a circle as the character. I would like the circle to roll while moving so I unlocked the Rigidbody 2D Z rotation. The bad thing is that the ground check rotates with it so the player is only able to jump when the ground check is on the ground. How do I fix this?

    Thanks
     
  2. Socks1301

    Socks1301

    Joined:
    Aug 13, 2020
    Posts:
    3
    To fix the issue, I removed the ground check from the player and used the enclosed script to set the position of ground check to follow the player so it doesn't follow the rotation.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GroundCheck : MonoBehaviour
    6. {
    7.     public Transform groundCheckPos;
    8.     public Transform player;
    9.  
    10.     void Update()
    11.     {
    12.         groundCheckPos.position = player.transform.position;
    13.     }
    14. }
    15.  
    Thanks