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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

My character is falling through the floor

Discussion in 'Getting Started' started by justKinro, Jan 31, 2021.

  1. justKinro

    justKinro

    Joined:
    Jan 31, 2021
    Posts:
    2
    Hey I watched a tutorial about player movement, so i copied the code but my character is falling endless.
    Here is the code, I hope someone can help me.

    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public float MovementSpeed = 1;
    private void Start()
    {

    }


    private void Update()
    {
    var movement = Input.GetAxis("Horizontal");
    transform.position += new Vector3(movement, 0, 0) * Time.DeltaTime * MovementSpeed;
    }
    }
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,847
    If your character is falling, with this code, then it means you have physics on your character.

    Look for a Rigidbody or Rigidbody2D component on the GameObject that represents the player, and remove it.
     
    justKinro likes this.
  3. justKinro

    justKinro

    Joined:
    Jan 31, 2021
    Posts:
    2
    Thank you!!!