A Flash Developer Resource Site

1. ## rotating-problem of enemy

Hello folks,

I have this problem: there is this enemy which rotates to my player. While "orbiting" the enemy with my player I can see that the enemy is rotating towards my player.
And then the enemy suddenly turns around 360 degrees and facing to my player again. I don't know why it does this strange 360 degree turn but it happens everytime when I orbit the enemy for a few seconds. Please - can someone help me out with this problem? I appreciate every hint I can get because I don't know where the problem might be.

Code:
```
tempEnemy.dX = tempEnemy.x - player.x;
tempEnemy.dY = tempEnemy.y - player.y;

if(tempEnemy.frame < 0) tempEnemy.frame += 360;
if(tempEnemy.frame > 359) tempEnemy.frame -= 360;

tempEnemy.trueRotation = int((tempEnemy.rotateTo - tempEnemy.frame) / tempEnemy.rotateSpeed);

tempEnemy.vX += (player.x - tempEnemy.x) / tempEnemy._speed;
tempEnemy.vY += (player.y - tempEnemy.y) / tempEnemy._speed;

tempEnemy.vX *= tempEnemy.decay;
tempEnemy.vY *= tempEnemy.decay;```
Update:

Code:
```private function toDegrees(radians:Number):Number
{
var degrees:Number = Math.floor(radians * 180 / Math.PI);
//trace (degrees);
return degrees;
}

{

if (deltaY < 0)
{
}
}```

2. are you using different frames in a movieclip to change the rotation? or is there more code inside the enemy object that translates something to the rotation property?

3. I don't use movieclips cause they're slow. Basically that's the essential code I posted there. This is just an excerpt not the complete code of my game. But I will check my code maybe I can find something.

4. well unfortunately, there is only so much I can extrapolate from the code you have given.

Is one of those values the actual value you apply to the rotation property of the enemy?
Are you using a tweening engine?
When you say it does a 360 flip, is that because of the tweening engine?

5. Yes, I'm using a tweening engine (TweenLite). But not here. I use it for the interface and that kind of stuff. The game itself is blitted. There seems to be a bug with the radian / degree conversion but I'm not that sure 'cause I'm not very good in trig.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap