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

Clipping through walls, no clue what to do

Discussion in 'Physics' started by SlinkyBanana, May 11, 2018.

  1. SlinkyBanana

    SlinkyBanana

    Joined:
    Sep 17, 2017
    Posts:
    6
    I am currently trying to make a very simple game. I have a simple environment set up as a placeholder, and simple movement controls (I am not that great at coding.) Anyways, my character was moving through walls that were 1 unit thick, which I did not want to happen. I made them thicker, and they would no longer just move through. However, the player (a capsule for a placeholder) is slightly pushing into them. While it does work, it 1) Looks shoddy and sloppy and 2) worries me that it might cause problems with other physics that I add into the game. I attached an image to this thread of what happens when I am moving towards the wall, and here is the movement script, if it is helpful: Screen Shot 2018-05-10 at 9.11.28 PM.png
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMove : MonoBehaviour {
    6.  
    7.     public Rigidbody Player;
    8.     public float MoveSpeed = 50f;
    9.     public bool jumpStat;
    10.  
    11.     void Start(){
    12.    
    13.         jumpStat = true;
    14.         Player = gameObject.GetComponent<Rigidbody>();
    15.     }
    16.  
    17.     void FixedUpdate(){
    18.  
    19.         Player.MovePosition(transform.position + (transform.forward * Input.GetAxis("Vertical") * MoveSpeed) + (transform.right * Input.GetAxis("Horizontal") * MoveSpeed));
    20.  
    21.         if (Input.GetKeyDown("space")){
    22.             if (jumpStat == true){
    23.                 Player.AddForce (0, 400, 0);
    24.                 jumpStat = false;  
    25.             }
    26.  
    27.         }
    28.     }
    29.  
    30.     void OnCollisionEnter (Collision collider){
    31.  
    32.         if(collider.gameObject.tag == "Floor"){
    33.             jumpStat = true;
    34.    
    35.         }
    36.     }
    37. }
     
  2. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    981
    Okay.
    What type of collider, do you have on the wall?

    And, do you have a capsule collider, on your capsule object?
    If so, is the capsule collider, approximately the same size, as your capsule object?
     
    Last edited: May 11, 2018
  3. SlinkyBanana

    SlinkyBanana

    Joined:
    Sep 17, 2017
    Posts:
    6
    There is a box collider on the wall and a capsule collider on the player, and they are both the same size as their respective Gameobjects.
     
  4. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    981
    Okay. Thanks for that info.
    Is it possible, to post a screenshot, of the rigidbody/collider
    options/settings panels?

    eg. The panels normally located, on the right side of the workscreen,
    with options like: Drag, Use gravity, Is Kinematic etc.
     
  5. SlinkyBanana

    SlinkyBanana

    Joined:
    Sep 17, 2017
    Posts:
    6
    This is the wall: Screen Shot 2018-05-15 at 11.25.30 AM.png
    And this is the player: Screen Shot 2018-05-15 at 11.25.41 AM.png
     
  6. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    981
  7. SlinkyBanana

    SlinkyBanana

    Joined:
    Sep 17, 2017
    Posts:
    6
  8. IgnisIncendio

    IgnisIncendio

    Joined:
    Aug 16, 2017
    Posts:
    90
    Is the player's capsule collider the same size as the player?
     
  9. SlinkyBanana

    SlinkyBanana

    Joined:
    Sep 17, 2017
    Posts:
    6
    Yep