Calculate route/path of a ball using Raycast
I want to create waypoints once i press a button. I want to shoot a ray, which can bounce off walls and once it hit the wall it instantiate a gameobject as waypoint on hit.
What i have so far:
void Update ()
{
Ray ray = new Ray (transform.position, transform.forward);
RaycastHit hit;
Debug.DrawLine(ray.origin, transform.forward, Color.red);
if (Physics.Raycast (ray, out hit, rayLength, WallLayer))
{
Vector3 reflectdir = Vector3.Reflect(ray.direction,hit.normal);
ray = new Ray(hit.point, reflectdir);// is this the right way?
Debug.DrawLine(ray.origin, hit.point, Color.blue);
if(hit.collider.gameObject.tag == "wall")
{
Instantiate(WayPoint, hit.point, Quaternion.identity); //everytime the ray hits the wall create one
}
}
}
Any Ideas?
pathidea1.png
(20.5 kB)
Comment
Answer by kewalkishang · Feb 05, 2017 at 03:52 AM
@OctoMan HEY did you get the solution to this problem ? Even i was looking for this .
Your answer