Intercepting A Sprite

This topic has to do with the concept of intercepting a moving sprite (A) with another sprite (B). This is done by the AI in my game and I’m having trouble doing this in a way that looks as fluid as when a player does it. Currenlty im using the speed at which sprite A is traveling at to figure out where it will be during the time sprite B is going to move to it. This works out well until I make sprite A suddenly stop moving at which time sprite B arives at a point which is in the tregectory of sprite A but not on A. So then I make B move to the spot A is at because it’s no longer moving. This appears very computerized and if I make A move while B is moving to the spot where A was stopped at then I have another issue. To sum up, the method I am using is not workin like I’d like and if anyone knows a good way to do this I would appreciate if you’d let me know.

I figured it out! All I had to do was create a line between the two points and loop a move action(or just use set position) for every point in between. For the speed I made the move action move more points per loop. The loop always has an up to date location of the target point as to have the proper line everytime(even if it’s moving). As long as the sprite isn’t moving away faster than the intercepting sprite is moving it should work. And in that case, it intentionally shouldn’t intercept.

This method looks way better than the last although it still looks pretty bad. I could see a variation in the speed making it look a bit more human like. Also, having it arrive at a point that isn’t always the same could make it better so I’m going to try that.

Hope this helps someone, and if anyone still has any ideas of how to improve it I’m all ears.

I did this sort of thing for ‘homing missiles’ by applying turning my missile a few degrees toward the current location of the target, and applying a force in the direction it was now pointing, at every timestep.

This looks pretty good (well, I think so!) as the missile continually ‘seeks’ the target, as it moves.

You could improve this somewhat by aiming the missile towards where the target will be in x seconds, so it anticipates the collision, but this wasn’t necessary in my game (and it actually looked nicer that the missile tends to end up ‘chasing’ the target.)

Long time ago I’ve used code from “Cocos2d for iPhone 1 Game Development Cookbook”. There are all you need. Here is code I’ve used https://github.com/006/ios_lab/blob/master/Cocos2d%20for%20iPhone%201%20Game%20Development%20Cookbook/RecipeCollection03/RecipeCollection03/Recipes/Ch7_AIFlocking.h

A very short demo of /Ch7_AIFlocking.h in this video at the beginning:

https://www.youtube.com/watch?v=0KjgWWEzccg&t=1s