Search Unity

Can an object/target be moved as close to a new point without "clipping" a collider?

Discussion in 'Scripting' started by glom1envisage0, Nov 13, 2011.

  1. glom1envisage0

    glom1envisage0

    Joined:
    Apr 3, 2011
    Posts:
    167
    I've found a way to make a character "jump" to the position of the ground directly below using raycast, and even though I get very close, I can't prevent the character from sometimes going through the ground or being slightly above it, making him unable to jump. Because of the curve of the controller's capsule, I can't pin down what normal angle should translate to how much re-positioning of the Y coordinate of the character. If the controller was a box I could always place him at the correct spot but since that's not the case I'm wondering if you could have an object move from one location to another in one frame without going through a collider that is between them; instead stopping at that point rather.
    On second thought, a box wouldn't work either, because the point directly below the center of the controller would be different from a point directly below the left-center of the controller.
     
    Last edited: Nov 13, 2011
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    ok, sounds a bit complicated..

    You are trying to pinpoint a "jump" from one place to another, in one frame? Aside that this is called a "teleport" Which has no effect on physics at all. Just restate his position to the new position. Now if this involves the character's center being above the current bottom of the character, you will need to add that amount to the hit point of your selection process. So hit.point + Vector3.up + controller.height / 2 + 0.1;

    Why add 0.1... because if you don't the collider could simply drop through the floor because there is no physics tolerances there.