- Home /
OnCollisionEnter inside FixedUpdate?
I'd like to add this code to a script, but I'm not sure it's correct.
function OnCollisionEnter (collision : Collision)
{
print (collision.collider);
collision.rigidbody.AddForce (Vector3.up * 1000);
}
Since it includes AddForce, should it be inside FixedUpdate? But then, I guess I can't include the whole OnCollisionEnter function inside FixedUpdate?
Answer by Patyrn · Apr 19, 2011 at 07:46 PM
OnCollisionEnter is added at the root of your class like any other function.
Is there no problem if it includes an Addforce statement? I was thinking perhaps it was necessary to store the GameObject from the collision in a variable and apply the force in the next call of FixedUpdate?
@oquendo: No, there's no reason to do that and several reasons not to. The code you have in your question is fine.
What can I do if I want to move a platform only when the player collides with it. Using OnCollisionEnter does not gives the smooth motion. I want to move in fixed update OnCollision. How can I use it.
Your answer
Follow this Question
Related Questions
Force physics collision calculation (forced fixed update) 0 Answers
Changing transform.localScale but OnCollisionEnter isn't executed 1 Answer
Collision Query 1 Answer
2D Collider aren't exact? 6 Answers
Location of RigidBody2D on collision 3 Answers