- Home /
Trying to rotate player, how?
Im trying to get the player to rotate according to the normals of the surface below him. It works, however if you try to jump across platforms that are each slightly more rotated than previous blocks the player slowly shifts and eventually falls off. This is especially apparent if a moving platform rotates, the player will slide off. Here is how I'm doing it
vectorCheck = (rigidbody.velocity.normalized * 0.15f) + (-transform.up);
if(Physics.Raycast(transform.position, vectorCheck, out objHit, UGD)){ //CHANGE, CHECK LAYER AFTER RAYCAST
if(objHit.transform.gameObject.layer == 8){
pointHit = objHit.normal;
//targetNormal = (objHit.point - transform.position).normalized;
targetNormal = pointHit;
if(Vector3.Dot(transform.up, targetNormal) > UGA && transform.up != targetNormal){
Quaternion newRot = Quaternion.FromToRotation(transform.up, targetNormal) * transform.rotation;
transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.deltaTime * 16f);
}
}
}
UGD is just a float of 20f UGA is just a float of 0.6f
UGD helps the raycast check a distance of 20 below the player, and UGA with the dot product disregards any angle that is greater than 54 degrees different from the current rotation. Heres a visualization of the problem
The black capsule is the player, and the purple capsule is where the player will rotate after the fixedupdate method shown above runs. The blue capsule is where I want the player to be: rotated and positioned according to the surface normal, not just rotated. (Please forgive the image, the purple dot should be where the black dot is for the demonstration to be accurate I just realized that).
In short, the player rotates according to the normals but his position remains the same which causes glitchy inaccurate behavior. How can I get the player to pivot (or whatever you call it) instead of just rotate?
It seems slightly better, but its also choppier. Still doesn't do as I hope. The example is, jumping across platforms that corkscrew, if you start your first jump in the middle of the first platform, you will end up slightly to the right or left of the middle of the next jump, so much so that if you do not adjust your direction you will fall off.
Your answer
![](https://koobas.hobune.stream/wayback/20220613183321im_/https://answers.unity.com/themes/thub/images/avi.jpg)