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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get Transform the frame before OnCollisionEnter

Discussion in 'Physics' started by Yapp-Yapp, Feb 26, 2015.

  1. Yapp-Yapp

    Yapp-Yapp

    Joined:
    Feb 26, 2015
    Posts:
    8
    Hi,

    A camera is attached to a projectile (as a child), when the projectile enters in collision with another object I would like to detach the camera from the projectile to stop the camera motion and watch the projectile continuing physics simulation.
    Actually, when the projectile hits something and calls OnCollisionEnter, I store the current camera's rotation, I trigger DetachChildren on my projectile (camera's parent) to get the camera free of it then I apply saved rotation to the detached camera. However the wanted angle is not preserved and I think it is because the projectile angle is already affected by the collision when OnCollisionEnter is triggered.

    Is there a way to get the angle the frame before the collision occurs?

    void detachCamera() {
    Quaternion currentRotation = ProjCamera.transform.rotation;
    gameObject.transform.DetachChildren();
    ProjCamera.transform.rotation = currentRotation;
    }
     
  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
  3. Yapp-Yapp

    Yapp-Yapp

    Joined:
    Feb 26, 2015
    Posts:
    8
    Hi Matthew, and thank you for your reply :)
    (it' seems so evident now you've said it, shame on me…)
    btw I took a look at Flashbang website, nice work, congrats!