- Home /
How to get Ray rotation from direction
Hi, I have the player shooting out a ray to the center of the planet, the question is, how can I get the rotation of the ray, so I can use that for the gravity?
I am thinking to rotate the x and z axis of the player so transform.up will always be away from planet and the player to be able to walk freely on the surface of the planet
The raycast hit provides you with the info needed.
I'm assu$$anonymous$$g you're already doing a raycast and storing the RaycastHit info, correct? In something like: private RaycastHit hits; correct?
If so, then it's as simple as setting a constant AddForce() on your player, that is a negative of the hits.normal, make sure to disable gravity too.
rigidbody.AddForce(-hits.normal);
I is this possible with character controller ? I don't want to add rigid body to the player, I see that if I add rigidbody after I have some funny effects on collision.
And my real problem is how I rotate the player so is always standing?
Character Controller will give you worse effects on collision than a rigidbody does... You just need to learn about it more. You can't use the character controller with a rigidbody, since the character controller moves you with Translate, which you don't do with rigidbodies, ins$$anonymous$$d you would be using rigidbody.velocity, or rigidbody.AddForce(), to move the player.
I would suggest watching some tutorials on how to move a rigidbody in Unity, and learning a bit more about scripting so that you do not have to rely on the limitations of that basic CharacterController.