- Home /
On Collision my Player Spins Wildly
Whenever my player (with rigidbody, controlled with transform.Translate) touches another object, it spins wildly out of control on all axes and then will travel on a tilted axis. My player is just a sphere, nothing fancy. The problem was fixed by making it kinematic, but now none of my OnCollisionEnter scripts will trigger. I tried using scripting to freeze rotation whenever the player made contact with something, but that seemed to do nothing even though my Debug.Log confirmed that it was colliding. If I check all of the "freeze rotation" boxes in my inspector, the problem is solved, but I want my player to be able to spin on its y-axis using input (I just use a transform.Rotate for this). I've also tried taking the rigidbody off of my player and adding a rigidbody to my objects with OnCollisionEnter scripts, but the player wouldn't trigger these. I'm super new to Unity, so if you could keep it simple, that would be great.
Answer by lgarczyn · Nov 21, 2019 at 03:35 AM
A kinematic rigidbody is usually the right choice for a player character, but it needs to be paired with raycasts checks for movement, and the MovePosition and MoveRotation methods. You also won't get any OnCollisionEnter events from two kinematic rigidbodies, though you should get trigger events.
If chose a non-kinematic player, you can increase the drag and angular drag factors, but most importantly the weight factor. You also need to freeze any axis but the Y axis, and you may want to have the camera follow the player, but have its own rotation instead of using that of the rigidbody. Alternatively, you should set the angular Y velocity yourself. You should also set the velocity to move, instead of moving the position directly.