Answer the question
In order to leave comments, you need to log in
How to shoot a beam from one object in the direction of another?
Tipo determine the distance, but at the same time so that if there is a wall in front, then he would not go.
Answer the question
In order to leave comments, you need to log in
You can use Distance to determine the distance, and let Raycast in the direction of travel to check the obstacle.
Raycast requires Ray and distance as arguments (A number of other attributes are possible, but they are not very relevant to this topic).
Ray, on the other hand, requires you to specify a start point and direction when creating it. (Also, you can specify the start point and direction in Raycast instead of Ray).
In your case, the start point is the position of the first object, the direction is the subtraction of the position of the second from the position of the first (secondObject.transform.position - firstObject.transform.position). If the distance to the target is not important, you can write Mathf.Infinity in its place.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question