- Home /
Straighten out camera rotation
I have my player climbing walls when he presses space, the issue is, he can be looking at any angle, even have the wall to his back and still he will rise up. How can i ensure that he only can climb when facing the wall. Ive tried raycast but then he still can be at weird climbing angles...
Answer by HappyMoo · Jan 04, 2014 at 01:54 AM
Take the walls normal and the transform.forward of the Player.
Both vectors should be normalized - make sure they are, if you calculate them in some weird manner and it's not sure if they are normalized.
Then do something like this:
float dot = Vector3.Dot(wallNormal, playerForward);
bool facingWall = dot > 0.5f;
Debug.Log("dot: " + dot + ", facingWall: " + facingWall);
now adjust the constant 0.5f to your liking.
See also http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Dot.html
AHH EXCELLENT, thanks so much, i've been trying to figure this out FOREVER
Your answer
Follow this Question
Related Questions
making my space ship rotate then move. 0 Answers
Control object yaw by two axis 1 Answer
How to snap a model to the direction being moved in, without also rotating the character controller 3 Answers
Getting the face direction 2 Answers
How to get an object to face in the direction that it is traveling? 1 Answer