- Home /
Question by
Zahid · Jan 31, 2013 at 07:24 AM ·
physicsraycastraycasting
why Physics.Raycast is not working
Can some body tell me why the the following code is not working
void Move()
{
RaycastHit hit;
if (Physics.Raycast(transform.position,Vector3.forward,out hit,10))
{
//if wall is on the front stop
if(hit.transform.tag=="Walls")
{
Debug.Log("i am stop");
ch.Move(Vector3.zero);
}
else
{
//Debug.Log(hit.transform.tag);
Debug.DrawLine(transform.position, hit.point, Color.red);
velocity = Player.transform.position - transform.position;
velocity = Vector3.Normalize(velocity);
velocity *= moveSpee;
ch.Move(velocity * Time.deltaTime);
}
}
}
}
Comment
Best Answer
Answer by fafase · Jan 31, 2013 at 07:47 AM
The line below casts the ray from the object position in the direction of the Vector3.forward, the world's forward
if (Physics.Raycast(transform.position,Vector3.forward,out hit,10))
I guess you want to cast in the object forward
if (Physics.Raycast(transform.position,transform.forward,out hit,10))
Your answer
Follow this Question
Related Questions
Raycast does not work with touch input but works well with mouse input why? 0 Answers
Raycast stop at distance 3 Answers
Raycasting not behaving as expected? 2 Answers
Some raycasts don't hit the object 0 Answers