Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Character Clipping through Enclosed Mesh

Discussion in 'Physics' started by Lhurgoyf, May 13, 2018.

  1. Lhurgoyf

    Lhurgoyf

    Joined:
    May 5, 2018
    Posts:
    1
    5.6.3p2 Personal on a 2015 MacBook (usable for editing simple stuff in Unity, amazingly)
    Using C#
    Hello, Unity World. I am a somewhat good programmer and have been figuring out how to use Unity over the past several months. So, recently I set up a *very* basic scene. It consists of a capsule collider for the player, a camera parented to the capsule, the default lights, and a map (an FBX exported from Unity.) The Player script uses a **very** basic top-down controller (changed a bit from a tutorial on YouTube.) My problem is clipping. The player controller moves up, down, left, and right with WASD, but when it collides with the map for long enough, it clips through the walls as shown in the video linked to on Google Drive below.

    TL;DR I am using a basic RigidBody capsule character controller that has worked in the past that now clips through the map of my scene, which uses a mesh collider. What may be causing the clipping, and how might I be able to fix it?


    Thank you so much for your help.

    ZIP with project along with video of the problem

    //The top-down character controller.
    using UnityEngine;
    using System.Collections;

    public class TopDownController : MonoBehaviour
    {

    public float speed = 10.0F; //How fast the character moves


    // Use this for initialization
    void Start()
    {
    Cursor.lockState = CursorLockMode.Locked; //The cursor can't move

    }

    // Update is called once per frame
    void Update()
    {

    float translation = Input.GetAxis("Vertical") * speed;
    float strafe = Input.GetAxis("Horizontal") * speed;
    translation *= Time.deltaTime;
    strafe *= Time.deltaTime;

    transform.Translate(strafe, 0, translation);

    if (Input.GetKeyDown("escape")) {
    /*Holding escape makes the cursor
    * able to move outside of the game*/
    Cursor.lockState = CursorLockMode.None;
    }

    }
    }