Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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).

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.