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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

get positition of moving object right before collision

Discussion in 'Physics' started by EliJNemer, May 7, 2020.

Thread Status:
Not open for further replies.
  1. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    hello,

    how can i get the position of an object right before collision. lets say that we have one sphere static and another moving toward the the static and they collide. how am i to get the position of the moving object right before they collided and trajectories changed.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Store the Rigidbody(2D) pose in the FixedUpdate callback. By default, simulation is run after all the FixedUpdate callbacks have been made.
     
    EliJNemer likes this.
  3. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    hi, thanks for your reply..

    could you please elaborate a little. i do not know what you mean by store the Rigidbody pose.. is pose position?

    also can i store rigidbody(3d)?

    how would this look like?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    I use the term pose to mean Rigidbody position and rotation.

    So in short, on a GameObject where you need to know what the position/rotation were before the simulation, add a FixedUpdate call and store both in a pair of private fields in your script.

    After FixedUpdate is called on all scripts, the simulation is run or you can manually run it yourself after all FixedUpdate callbacks have run. This means you have a script or scripts where the previous simulation position/rotation are stored to do whatever you like with.
     
  5. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    Thank you
     
Thread Status:
Not open for further replies.