Search Unity

Get move distance from rigidbody

Discussion in 'Physics' started by phoenix0330, Dec 14, 2018.

  1. phoenix0330

    phoenix0330

    Joined:
    Dec 4, 2010
    Posts:
    65
    hi, im trying to get the move distance from the rigidbody before it applies it to the gameobject, is this posible?
    im trying to move an object but first, check if there is something between the current position and the position is going to move.
    thnks
     
  2. Isn't that velocity * fixedDeltaTime?
     
    SparrowGS likes this.
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Are we talking dynamic rigidbodies that move via forces(IE Collisions/AddForce() ), or what?

    Please elaborate more on your situation, what are you trying to check against?
     
  4. phoenix0330

    phoenix0330

    Joined:
    Dec 4, 2010
    Posts:
    65
    im trying to make a bullet hit prediction, to avoid fast bullets jump some collisions because of high move values.

    i instantiate an object (bullet) with rigidbody with 2 velocity (example) no AddForce, i need to know how much the object is going to move to check if there is something between the current position and the next position with a raycast before its moved by the rigidbody.
    with transform i only need the moveSpeed value and then tell the gameobject to add that move, but with rigidbody i only tell the veolcity to be 2 but if im not wrong thats 2 units per second, not move 2 units. i need the units that the object is going to move.
    i dont know if thats a bit clear.

    i got a solution thats its kind of working, intead of checking how much is going to move, i check after it moves, get the distance traveled and then check with the raycast if there was something between the last position and the current position, and if there was, i move the object to the hitpoint. this works but when i move the object to the hitpoint, it jumps from the current position to the hitpoint like a werid reverse jump.
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Avoid using bullets with rigidbodies if possible (for fast moving ones).
    Do a raycast checks (or any other shape-cast) instead when moving, and then perform movement step.

    Otherwise you may find that it's not that reliable (rgb projectiles tend to clip through colliders if not set to continious at faster speed) or may eat up too much performance (based on their count).