Search Unity

Angled Walls Allow Clipping/ Jitter

Discussion in 'Physics' started by beanie4now, Feb 4, 2019.

  1. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    As displayed in the following video when I set up walls at angles and collide into them (player movement excerpt)
    Code (CSharp):
    1. float h = Input.GetAxis("Horizontal")/drag;
    2.         float v = Input.GetAxis("Vertical")/drag;
    3.         transform.Translate(h,0,v);
    I am able to clip right through.
    Do i need to revert to a velocity driven system?


     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    Modifying the player's transform overrides any physics or collisions. I'm not expert here, but I think you should use the available components and scripts in Unity for controlling the character.
     
  3. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    That means you bypass the physics engine and "teleport" the object from its viewpoint.

    You need MovePosition() instead. https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html

    Also check if your objects even have colliders as well as rigidbodies. (colliders are definitely needed, rigidbody depends on what you actually want to do)
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    Rigidbody.MovePosition also bypass the physics engine. The difference with modifying transform.position is that MovePosition applies interpolation for displaying intermediate steps.

    Without having experience here, it seems that using a CharacterController component and its Move or SimpleMove methods is a better approach for this case. From:
    https://docs.unity3d.com/ScriptReference/CharacterController.html

    "A CharacterController allows you to easily do movement constrained by collisions without having to deal with a rigidbody."