Advertisement Jump to content
Sign in to follow this  
GroZZleR

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!