Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function eFrame(e:Event){
- getOrbitAngle();
- rotateOrbitAngle();
- rotateBlaster();
- }
- // MathX is a class containing a few extra math functions I use a lot
- function getOrbitAngle(){
- var o:int = MathX.angleToObject(orbitPoint,new Point(stage.mouseX,stage.mouseY));
- targetAngle = MathX.normaliseAngle(o+90)
- }
- // angleToObject calculates the angle needed to rotate one object towards another
- //normaliseAngle returns a value between 0 and 360
- function rotateOrbitAngle(){
- if(currentAngle>targetAngle){
- if(currentAngle>targetAngle+180){
- rotateInReverse()
- }
- else{
- rotateNormally();
- }
- }
- else if(currentAngle<targetAngle-180){
- rotateInReverse()
- }
- else{
- rotateNormally();
- }
- currentAngle = MathX.normaliseAngle(currentAngle)
- }
- // rotate normally/
- function rotateNormally() {
- if(currentAngle > targetAngle){
- currentAngle -= playerSpeed
- }
- else if(currentAngle < targetAngle){
- currentAngle += playerSpeed
- }
- }
- function rotateInReverse() {
- // rotate in reverse
- if(currentAngle > targetAngle){
- currentAngle += playerSpeed
- }
- else if(currentAngle < targetAngle){
- currentAngle -= playerSpeed
- }
- }
- function rotateBlaster(){
- player.rotation = currentAngle
- var rad = MathX.degsToRads(currentAngle-90)
- player.x = orbitPoint.x + radius * Math.cos(rad); // Position The player Along x-axis
- player.y = orbitPoint.y + radius * Math.sin(rad); // Position The player Along y-axis
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement