Hi, at the moment i am trying to make my character rotate to suit the angle of an incline.
I can get the angle of the normal by using
Vector3.Angle(hit.normal, Vector3.up)
But i don’t know how to use this to correctly rotate my character.
Thanks.
Hi, at the moment i am trying to make my character rotate to suit the angle of an incline.
I can get the angle of the normal by using
Vector3.Angle(hit.normal, Vector3.up)
But i don’t know how to use this to correctly rotate my character.
Thanks.
i’m having the exact same issue myself.
we wanted to have organic terrain like hills and such, but our player will have to rotate to match the individual inclines of the terrain.
i thought since the character collider can recognize slope i could tie it’s rotation into that, but i haven’t figured out how.
i’m going to try having two points ray cast downwards, then using the two contact points, i should be able to draw a line between the two that would give me a decent enough rotation.
god i hate when the answer is so simple -.-
transform.rotation = Quaternion.FromToRotation (Vector3.up, surfaceNormal);
^ That works but i was wondering how i could combine the that with my XZ rotation as in i have this
transform.rotation = Quaternion.LookRotation(xzMove);
transform.rotation = Quaternion.FromToRotation (Vector3.up, hit.normal);
Which will ignor the first rotation how would i combine the two. Sorry i’m not good with this stuff yet.
You might try this:
transform.rotation =
Quaternion.FromToRotation(Vector3.up, hit.normal) *
Quaternion.LookRotation(xzMove);
^ Thanks thats not really working though if i am coming down a slope i am rotated to be facing up the slope going up a slope is working though.
i have fixed one of my problems and thats if the charcater is walking up a hill they will be rotated that way, and if they are walking down a hill they will be rotated correctly as well but if they turn on the side the character is rotated up and is on air.
Is there a clean way of doing this?
Can you post your current code for orienting the character?
Also, are you sure the character is positioned appropriately in local space? (To get the results you’re after, the origin in local space should probably be centered and near the feet.)
I’m not proud of this… It doesn’t work.
I’m not sure how i would know where the center is at the moment it would be in the center of the model i think how would i move it to the bottom?
Note that you’re building the orientation like this:
transform.rotation =
Quaternion.LookRotation(xzMove) *
Quaternion.FromToRotation (hit.normal, Vector3.up);
Whereas what I suggested was this:
transform.rotation =
Quaternion.FromToRotation(Vector3.up, hit.normal) *
Quaternion.LookRotation(xzMove);
I don’t know enough about what you’re trying to do to guarantee that that’ll work, but you might at least try my suggestion and see what you get.
Ohh i am so so sorry, That works i read what you posted wrong. Thankyou!
Me again just wondering is there an easy way to tell if my player is facing up a hill or down a hill?
Its just that i have 2 animations when sliding one for if they are facing up a hill and another for if they are facing down a hill thanks alot!
It might be sufficient just to check the y value of the character’s forward vector. If its absolute value is greater than some threshold, you’re either going up or down a hill. You can then determine from the sign whether you’re going up (+) or down (-).
How did you define xzMove (for the rest of us) ?