4
\$\begingroup\$

I have implemented missiles that steer towards a target, however this feels kind of boring.

I want to add loops! Loops are cool! To do this I thought I could use catmull-rom splines, but that seems very static - loops would always end up at the same position unless I made several premade patterns.

Anyone have any other ideas on how I can do this?

I'm using a simple steering function: EDITED

         var toTarget = player.Position - missile.Position;
        toTarget.Normalize();

        float turnSpeed = 0.1f;
        float momentum = 3f;
        float speed = 1f;

        currentDirection = Vector2.Lerp(lastDirection, toTarget, turnSpeed);

        currentDirection.Normalize();

        lastDirection = currentDirection;
        lastPosition = missile.Position;


        player.Update(gameTime);
        missile.Update(gameTime);

        missile.Position = lastPosition + currentDirection * speed + lastDirection * momentum;

I have tried using the player as an attractor object which kind of works - the missile orbits the player object, but it mainly looks like it's moving backwards and forwards while the player object is standing still.

\$\endgroup\$
0

2 Answers 2

3
\$\begingroup\$

You can use the steering to create loops. Simply have two targets for your missile. The player is one, and a loop target is the second.

Every N seconds, set the loop target to the missiles current position (plus a small random amount to either side of the missile's heading), and set the missile to steer towards that target. Since it's already in flight, it'll have to pull a u-turn to make it back to the loop target. Once it's either touched the loop target, or come "close enough" to the loop target, switch its target back to the player.

I imagine this will produce loops and probably even figure 8s (dual loops). The small random amount to either side means the turn direction for loops will change, you can set it to the same side each time if you want loops in the same direction.

Alternatively, you can have the rocket steering be normal, but have an additional force on the rocket. This force would be perpendicular to the direction of travel and the strength would vary over time (perhaps with a sine wave). You'd have to test it out, but I think that would give you bigger loops, without changing the turning radius of your rockets. Perhaps something like the rockets in The Clone Wars (the only clip I could find showing this, rockets just past the 56 second mark).

\$\endgroup\$
0
\$\begingroup\$

Instead of having just one target (the actual target), you can setup another "loop" target that updates as time passes to move in a circle. Instead of steering towards just the actual target, you can do some weighting to factor in the loop target. To make the loop target more prominently weighted at times, you could increase the loop weight every so often.

This would achieve both the effect of looping WHILE still moving towards the target.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .