I’m trying to make a weapon like homing mortar. The behavior I want is shown in the picture.
The black box represents the mortar and the red box represents the target.
In this example, the number 1 shows the frame when the mortar is launched initially. The mortar only have upward velocity at that time. For example its velocity is 0,0,10. At the same time the target is moving away from the mortar. Basically, the mortar has to do parabolic arc movement to hit the target, however, since the target is moving, the mortar should do a movement like the number 2. The mortar will start to accelerate and when it gets close to the target it should slow down, so it can hit the target.
The problem is a bit complex. The target can go around 3D world freely and there are some limitations:
-
The target’s velocity may change while the mortar is flying. So, the mortar has to adjust its velocity.
-
The mortar shouldn’t go backwards. For example; if the target stops and starts moving backwards the mortar shouldn’t follow instead it should continue on its movement. Like it’s shown in the image, the mortar should follow the blue line.
So far, I tried to manipulate the X and Z resolutions (forward and right) of the mortar’s velocity by calculating the distance and the direction between the target and the mortar, and I let the gravity to handle the Y resolution (up). By doing this, I got the number 2 movement perfectly. However, since I calculate the direction, the mortar always follows the target no matter the target starts moving backwards, which is not what I want.
Any help is appreciated.