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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Jumping or rather raycasting in general

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

  1. andynayrb

    andynayrb

    Joined:
    Feb 28, 2019
    Posts:
    25
    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

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    208
    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.