- Home /
Is there a way to debug the physics forces acting upon an object?
In a situation where multiple forces may have acted upon an object (gravity, thrust, explosive forces etc.) is there a way to peek in to the physics engine to see the sum of forces being applied to the object during a fixed-update frame?
I have such a situation, where after being subject to different forces, a falling object appears to freeze in mid-air. (Everything else is running smoothly at that point, so it's not a performance related freeze). I can only assume there's some unlucky, permutation of forces that are cancelling-out, but I can't find a way to debug it.
Thanks for any ideas :)
Answer by tuanpham · Nov 19, 2016 at 03:06 PM
Use DrawLine & DrawRay to view visually force affect to object Debug.Log for value exactly in Console window
Debug.DrawRay(playerPos, velocity, Color.yellow); Debug.DrawRay(playerPos, gravityVector, Color.blue); Debug.DrawRay(playerPos, move, Color.green); Debug.DrawRay(playerPos, Physics2D.gravity, Color.red); Debug.DrawRay(playerPos, Physics2D.gravity + velocity, Color.cyan); // add to sum force
I used it in this experiment
https://www.youtube.com/watch?v=yeN6y-7Nez8
Good luck