Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Jumping or rather raycasting in general

Discussion in 'Physics for ECS' started by andynayrb, Jan 16, 2020.

  1. andynayrb


    Feb 28, 2019
    Okay so I am attempting to make my object jump. I use a ray to see if he is on the ground. If I am standing still it works just fine. If I am moving forward it does not. So clearly there is something wrong. Here is the current code for the ray to check to see if I am on the ground. The floor is flat. Oh, I am using physics to move the character.

    var from = translation.Value - new float3(x: 0f, y: 1/2f, z: 0f);
    var to = translation.Value - new float3(x: 0f, y: 1/2f + 0.1f, z: 0f);
    var input = new RaycastInput()
    End = to,
    Filter = filter,
    Start = from
    var hit = collisionWorld.CastRay(input);
    return hit;

    It is my assumption that there is a better way to get the from and to for this. I have a feeling that using the translation to get this is not a good idea. Not sure what the proper way would be.

    Second question, related to the first question. If I hit the jump button fast enough, he will jump again and again, ignoring the fact that he has not landed. Again I assume the translation is affecting this.

    This leads to another related question, or maybe the same question. If I hold the forward button down and run into a wall, I bounce off most of the time. Sometimes eventually I just go right through the wall. Is this just physics engine not being able to keep up?
  2. SebLazyWizard


    Jun 15, 2018
    Is your ray's starting position always above- and the end position below the ground when your object is on it?
    Make sure that you exclude your object from the ray collision filter and make the ray start from within the object and it's end position to like 0.1 meter below the object.