- Home /
RayCast problem :)
Trying to do something like
int layerID = LayerMask.NameToLayer("Platform"); if (!Physics.Raycast(transform.position, -Vector3.up, 0.8f) || !Physics.Raycast(transform.position, Vector3.forward, 0.8f, layerID)) { switch (state) { case State.Left: state = State.Right; break; case State.Right: state = State.Left; break; } }
if (state == State.Right)
{
transform.Translate(Vector3.right * amtToMove);
}
else if (state == State.Left)
{
transform.Translate(Vector3.left * amtToMove);
}
Aint working that well sadely, enemies or just freezing or looks like switching State on every FPS..
Answer by Bunny83 · Apr 05, 2011 at 07:43 PM
I don't really get what this script should do, but i guess that your (strange) condition with the two Raycasts will not turn false next frame if it's true. So it will toggle each frame until both raycasts hit something.
btw, just a small hint:
according to the boolean algebra:
(not R1) or (not R2) == not(R1 and R2)
Answer by Bormeth · Apr 07, 2011 at 09:54 AM
The script sends raycast out to check if there is something under it or infront of it, then changes direction :)
Its an enemy in 2D ;) Mario Look alike approche.
Your answer