Search Unity

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!