Public Group

# Slow sweeping turns instead of snapping to face a point?

This topic is 3653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all, I'm working on a little 2d dogfighter and am struggling with how to make the enemy planes take slow, sweeping turns to line up their shots instead of just instantly snapping to face the player (making it more or less impossible to get behind them). It's a flash game you can play here: http://www.grozzler.com/dump/Dogfighter.swf It works fine when you fly to the right of the enemy, but if you fly around the bottom left the enemy plane begins to act erratically. Here's what I'm using now:
var playerX : Number = gameState.getPlayer().getPosition().x;
var playerY : Number = gameState.getPlayer().getPosition().y;

var x : Number = playerX - position.x;
var y : Number = playerY - position.y;

var targetRotation : Number = Math.atan2(y, x) * 180 / Math.PI;

movieClip.rotation += (targetRotation - movieClip.rotation) * 0.05;
// movieClip.rotation = targetRotation; // <<< How to make it instantly snap to the face the player.


Anyone have any sort of insight? I'm guessing it has something to do with quadrants or imaginary numbers in parallel dimensions. My maths aren't great if you can't tell. ;) Thanks for the help!

##### Share on other sites
The technique you probably want is 'lerp'. Google for "lerp float".

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 14
• 14
• 45
• 22
• 27
• ### Forum Statistics

• Total Topics
634044
• Total Posts
3015211
×