- Home /
Walls Walking code problem
Hi guys,
I'm working on a walls walking code. What I'm trying to reach is to have two raycasts one in front of the player(looking down) and one behind the player looking down.
Here is my code
var rayDown: Ray;
var hitDown: RaycastHit;
var FrontPosition : Vector3;
FrontPosition = Vector3( transform.position.x, transform.position.y, transform.position.z + collider.bounds.extents.z);
rayDown = Ray( ((FrontPosition)), -myNormal);
var rayDown1: Ray;
var hitDown1: RaycastHit;
var BackPosition : Vector3;
BackPosition = Vector3( transform.position.x, transform.position.y, transform.position.z - collider.bounds.extents.z);
rayDown1 = Ray( ((BackPosition)), -myNormal);
if ( Physics.Raycast(rayDown, hitDown, SnapeRange) && Physics.Raycast(rayDown1, hitDown1, SnapeRange) )
{
Debug.DrawLine (FrontPosition, hitDown.point, Color.green, 30.0);
Debug.DrawLine (BackPosition, hitDown1.point, Color.black, 30.0);
isGrounded = ((hit.distance + hit1.distance)/2) <= distGround + GroundRange;
surfaceNormal = ((hit.normal + hit1.normal)/2);
print(hitDown.collider.gameObject.name);
}
else
{
//isGrounded = false;
surfaceNormal = Vector3.up;
print("sdasdasdasdadada");
}
this code works only when I'm moving in the right direction. However when I rotate the for example to the right (of 90) the raycasts became left and right.
I don't understand why any ideas?
Thank you.
Comment
Your answer
Follow this Question
Related Questions
Setting object Rotation to RayCast line 1 Answer
Rotating the player animation also rotates the player 2 Answers
transform.right not working correctly? 0 Answers
SphereCast help 1 Answer
Offset raycast by specific amount 1 Answer