Move the object between points while avoiding the sphere

Hi,
I would like to move the object so that it travels from point B to A while avoiding the sphere with center D and given radius. Movement should follow a curve (it must be smooth) in 3d space.
I have tried to use the Animation Curve but to no avail - it is often a problem that the ball crosses its flight path. It is possible that you need to compute C, but unfortunately I can’t do it correctly either.

Please help and thanks in advance.


This is a non-trivial problem. A bit more information would be good before we go in depth on solutions that may not fit your actual use-case. Here are a couple questions:

  • I guess it has to run in realtime. But will it run every frame?
  • You said “it is possible you need to compute C”. This implies C is not (always) a given point?
  • Do we have to use all available points that are not inside the sphere, or can we just consider A and B and calculate any necessary in-between points ourselves?

It may also be helpful if you described your use-case a bit.

Since you require a smooth curve (potentially over a set of points), a Bézier curve comes to my mind. So assuming we only need to consider A and B and the sphere, something like below should work. With a bit more thought investment it should also work for following a given set of points.

  • Calculate a C that is perpendicular to BA. At least radius-units away from it, in the middle.
  • Calculate two quadratic Bézier curves using A, B and C. You can shape it as you want with the points inbetween (for giving the curve its shape). A good approach for what you want would be points perpendicular to BA for B and A, and parallel to BA for C, since we want the curve to first go away from BA, then over it at C, and down again.

A Bézier curve will always be smooth. A quadratic one connecting two points over one control point looks like so:

You would do that for AC and CB. There are also assets that already implemented this, like here:

Seconded. What are you actually trying to accomplish?

1 Like