Movement towards unreachable target - platform movement - character resume movement

I have two black platforms as shown in the image below. The blue part is a bridge. Both the platforms and the bridge are walkable.

The goal is for the red dot on the right-hand side platform to reach the green dot on the left-hand side platform. The red dot’s platform can be moved so that it touches the bridge.

When the scene starts, the red dot walks towards the green dot and stops at the edge of the platform as expected, since it can’t reach it. Problem is that after the red dot has stopped, when I move the platform to approach the bridge, the dot behaves weird and seems to move immediately to go back to the position where the platform used to be or to reach the green dot, sometimes falling off the edge, instead of remaining still and just “following” the platform as it moves.

Is there any way to ask if a target is reachable?

If it’s not reachable, move platform.
Is it reachable now? No, keep on moving platform…
Is it reachable now? Yes, move red dot to green dot.

Any help is appreciated!

Hi

I would recommend:

  1. Make the red dot walk to the edge of the platform
  2. Set the ‘canMove’ property of the AI for the red dot to false. This will make it stop moving completely.
  3. Move the whole platform including the red dot to the where it needs to be.
  4. Call AstarPath.active.Scan() to update the graph to account for the fact that the platform has moved
  5. Set ‘canMove’ to true again on the red AI.

Alternatively you can attach a DynamicGridObstacle component to the platforms which will update the graph all the time when the platform moves.

1 Like

Thanks Aaron, very useful hint.

One last question:
Is there a way to know when the red dot reaches the end of the platform and cannot move further?

I tried using the “endPoint” of the ABPath but not sure how do I know when the “endPoint” is actually the edge of the platform and not some point in between.
I tried overriding “OnTargetReached”, but it only gets triggered when the target is reached, not when an “intermediate” end of the path is reached, as far as I can tell.

Any other way?

Thanks!

I think I figured it out: ((path as ABPath).endPoint - transform.position).magnitude

1 Like