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. Dismiss Notice

Half of player falling through the ground

Discussion in 'Scripting' started by SamsonSmith, Dec 16, 2020.

  1. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, I am quite new to unity and have a problem with one of my game. Basically when I click on the play button to test the game, the player starts to fall through the ground but stops roughly half way (You can still move whilst half of the player is in the ground). The floor does have a box collider on it and so does the player (which is a square). The weight of the player is coded in the movement script so I don't have a ridged body on my character. Please help!

    Thanks
     
  2. Tiernan98

    Tiernan98

    Joined:
    Jul 11, 2017
    Posts:
    42
    There isn't enough information without your movement script or the dimensions of the red box, or even where the local origin of it is, etc...

    Possible causes:
    • Capsule is too small and the bottom is halfway up the player.
    • Capsule is not centred correctly
    • Something wrong in the movement script
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Something is off about this statement to me. If your player object is using a CharacterController then your character has a capsule shaped collider automatically (The CharacterController is a capsule shaped collider). I'm not sure what would happen with any other colliders you may attach to it.
     
    Last edited: Dec 16, 2020
  4. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, my player does have a CharacterController on it, and it also automatically had a collider on it. i was just saying that both the player and the floor has a collider.
     
  5. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, here is the movement script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Movement : MonoBehaviour
    {
    public CharacterController controller;
    public float speed = 12f;
    public float gravity = -9.81f;
    Vector3 velocity;
    // Update is called once per frame
    void Update()
    {
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");
    Vector3 move = transform.right * x + transform.forward * z;
    controller.Move(move * speed * Time.deltaTime);
    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);
    }
    }
     
  6. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    306
    I'm not next to the computer to check but shouldn't that player have a rigid body and collider on it directly?

    But either way, once you find your colliders click "edit collider", on the component and make sure they are shaped right. My first thought would be colliders shape is wrong
     
  7. Tuliyev

    Tuliyev

    Joined:
    Mar 30, 2019
    Posts:
    2
    I think Treecrotch is right. Box collider's center should be set up to (0, 0, 0). Its size need to increased by "y" vector.
     
  8. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, the collider is shaped correctly and i've messed around with it but got the exact same result of half the player falling through the floor.
     
  9. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Ok, let me check
     
  10. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, what do you mean by the size needs to be increased by "y" vector?
     
  11. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    306
    Your picture of Player doesn't have a box collider.
    The cube you call player does. So the cube is inside the player?

    The nesting is prob offset, or put the collider on the parent "player" game object.

    And check your ground objects collider
     
  12. Tuliyev

    Tuliyev

    Joined:
    Mar 30, 2019
    Posts:
    2
    Now box collider's size is equal to 1.449... lets try to change it to 2 or 3
     
  13. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, the problem has been fixed. Thanks for the help!
     
  14. SamsonSmith

    SamsonSmith

    Joined:
    Nov 3, 2020
    Posts:
    18
    Hello, the problem has been fixed. Thanks for your help!
     
    tree_arb likes this.