Say you have three objects in a layout. Lets say one is a (slowly moving) bullet type object headed towards a target object. A third object is invulnerable to the 'bullet' and wants get between the bullet and the target to intercept, or block, the bullet and protect the target. How could one achieve this in C2?
So far I am using the custom movement behaviour for the 'blocker' object for other purposes, so a solution using that would be best.
Here is my pseudo code solution, but I don't know how to do this in C2?
* Find the bullet nearest to the target (in case there are more than one)
* Find the point of intersection between the line between target and bullet and the shortest line between the blocker and this line ( I hope that makes sense)
* Set angle of motion of blocker to that point
* Set the speed of the blocker to as fast as possible (limited by an instance variable of the blocker)
Note that this doesn't anticipate the bullet's motion, so isn't the most optimal solution for the blocker to save the target, but it would be a start.
I can't find the required information in order to construct a (complex!) expression that could be used to set the blockers angle of motion. How do I determine the location of the closest bullet? The location of the target I can do.
I know C2 is supposed to be 'programming free' but is it possible to in expressions to create temporary variables in some way? I need to set the blockers angle of motion, but first I need to work out the point to set the motion towards, then do some trig to get the angle. This would be a mighty ugly site as a single expression, even if I could find the required raw numbers to put it together. If I could insert a small 'script' in place of the expression that would be clearest.