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

How to stop player character from phasing temporarily into objects? (not Min Penet. for Penalty...?)

Discussion in '2D' started by JohnFromMath, Feb 24, 2015.

  1. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    I've found a description online of a common issue that sounds quite like the one I'm having - however, when I edit the project's Physics (not Physics2D, because no such variable seems to exist there) and lower Min Penetration for Penalty from 0.01 to 0.0001... nothing happens.

    This is a 2D game. Essentially, the issue I'm having is that my character will rapidly phase into and out of objects she touches horizontally, including diagonal slopes (although it's most pronounced with 90-degree angles). As a note, she does not use whatever standard speed variables come with Unity2D (because I don't know how to implement those with characters, if they even exist *hangs head*); rather, I have her movement (and the camera's) controlled by a script that rapidly transforms them by a small amount at a time, complete with ac/de-celeration. Everything works fine, except for this weird clipping issue... and jumping (but that's a story for another day). What could be the cause here? I can provide the script if needed; I'm doing everything in one script.
     
  2. justJack

    justJack

    Joined:
    Feb 5, 2015
    Posts:
    22
    The problem is that you are handling your movement inside the Update function, directly changing your transform, which is wrong as you have a Rigidbody2D attached. Am I wrong?

    Check "Is Kinematic" on the Rigidbody2D component, or remove the Update code and handle your movement inside the FixedUpdate function, like this:

    Code (JavaScript):
    1. var speed : float;
    2.  
    3. function FixedUpdate () {
    4.    var h : float = Input.GetAxis ("Horizontal");
    5.    rigidbody2D.velocity.x = h * speed;
    6. }
    Good luck.
     
    JohnFromMath likes this.
  3. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    Checking "Is Kinematic" does make the movement non-jerky, but now the character doesn't fall (she can only jump) or collide with anything; she just moves right through it. The code's in C#, by the way.