Z
Z
Zefirot2021-06-29 11:35:10
C++ / C#
Zefirot, 2021-06-29 11:35:10

How to “fly around” other objects while moving?

Here I have 2 objects (both have colliders), I send the 1st object to the 2nd

if(Vector3.Distance(ObjA.transform.position, ObjB.transform.position) > 0.01f){
  ObjA.transform.position = Vector3.MoveTowards(ObjA.transform.position, ObjB.transform.position, 5f * Time.deltaTime);
  }

if there are no objects on the way, then everything is fine, but now an obstacle in the form of a sprite (Sprite Shape) appears on the way, how to make interaction between them, in the sense that the object "circles" this obstacle, so that it understands this "wall", which you can’t fly through it, and flew around it in the shortest way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kachan, 2021-06-29
@MANAB

OnCollisionEnter to detect wall collision + navmesh to find path

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question