-
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;
tempEnemy.rotateTo = toDegrees(getRadians(tempEnemy.dX, tempEnemy.dY));
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;
}
private function getRadians(deltaX:Number, deltaY:Number):Number
{
var radian:Number = Math.atan2(deltaY, deltaX);
if (deltaY < 0)
{
radian += (2 * Math.PI);
}
return(radian);
}
Last edited by drpelz; 11-03-2011 at 11:29 AM.
-
Flactionscrish
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?
ktu[k-two]
he who hesitates is lost; so i guess i'll wander intently
Are you sure this is real?
Life is Love, Love is Blind, Blind we go through Life.
Life isn't hard, dealing with your self is.
The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.
-
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.
-
Flactionscrish
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?
ktu[k-two]
he who hesitates is lost; so i guess i'll wander intently
Are you sure this is real?
Life is Love, Love is Blind, Blind we go through Life.
Life isn't hard, dealing with your self is.
The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|