Rotation Issue

Subscribe to Rotation Issue 5 posts

Sign in to reply


 
avatar for LeadingManNIgel LeadingManNIgel 19 posts
Flag Post

I have two Sprites, A ship and a Turret. The turret is a child of the ship. The turret rotates to mouse fine but when I move the ship using arrow keys the rotation gets all messed up, it gets a offset then it just completely goes off course.

 
avatar for UnknownGuardian UnknownGuardian 6220 posts
Flag Post

Post your code.

 
avatar for LeadingManNIgel LeadingManNIgel 19 posts
Flag Post

private function moveShip(e:Event):void {
var dx:Number = stage.mouseX – x;
var dy:Number = stage.mouseY – y;
var angle:Number = Math.atan2(dy, dx);
var toD:Number = angle * 180 / Math.PI
trace(angle);
ship.rotation = toD;

if (Key.isDown(Keyboard.RIGHT)) {
ship.x += 4;
}
if (Key.isDown(Keyboard.LEFT)) {
ship.x -= 4;
}
if (Key.isDown(Keyboard.UP)) {
ship.y -= 4;
}
if (Key.isDown(Keyboard.DOWN)) {
ship.y += 4;
}
}

 
avatar for LeadingManNIgel LeadingManNIgel 19 posts
Flag Post

Should be turret.rotation not ship.rotation was messing around

 
avatar for ssjskipp ssjskipp 258 posts
Flag Post
var dx:Number = stage.mouseX – x;
var dy:Number = stage.mouseY – y;

Using stage coordinates based on local coordinates. Ship may be inside another movieclip that’s getting moved, or something of the ilk. Just use “mouseX” and “mouseY”.

Sign in to reply