2

It's very easy to position a sprite object in relation to another sprite object, if you don't mess with the rotation. As the title states I want to know how to position 2 MC in relation to an already rotated MC, so they are aligned to each other. The big rocket is at an angle of 35 degrees.

First i set the angle of the big rocket to 0 degree, I am adding the 2 small rockets on the stage and position them on each side of the bigger rocket. So far so good... I am rotating everything back to the initial angle (35 degrees), but something is not right, as you can see the results in pic1

What must I change, so that the 2 small rockets stays perfectly aligned (one on the left side, the other on the right side of the bigger rocket) and rotated, as in pic2?

The registration point for all objects is in the upper-left corner.

Edit: The 2 small rockets must reside outside the bigger rocket container, because, eventually they will be animated independently from the container.

pic1 pic2

var _rot = rocketShip.rotation;
rocketShip.rotation = 0;
addChild(_leftRocket);
addChild(_rightRocket);
_leftRocket.x = rocketShip.x - _leftRocket.width;
_leftRocket.y = rocketShip.y + 20;
_rightRocket.y = rocketShip.x + _rightRocket.width;
_rightRocket.y = rocketShip.y + 20;
rocketShip.rotation = _rot;
_leftRocket.rotation = _rightRocket.rotation = rocketShip.rotation;
LuciM
  • 59
  • 2
  • 8
  • 3
    It's a lot easier if you put the registration-point (Pivot) in the center of the rockets. Another way could be to add the rockets into a container-movieclip, and rotate that. – Marijn Jun 28 '13 at 08:02
  • You're right about the container thing. But it is very important for animation effect that the rockets must reside outside the container. – LuciM Jun 28 '13 at 08:59
  • It's not a problem of where to put the registration point. I tried that too. Same result. – LuciM Jun 28 '13 at 09:25
  • 1
    Not sure why you can't save yourself the headache and put the 3 rockets in a container and rotate that (you can still animate them individually within that container). What you can do, is make all their registration points in the same global spot. then they will all rotate as if they were in the same container. – BadFeelingAboutThis Jun 28 '13 at 16:48
  • This simulation is a simplification of a rocket into orbit. As you know, space rockets include one or more disposable tanks that are dropped when their fuel gets used up and fall back to Earth being pulled down by the Earth gravitational force. When the tanks detach from the rocket I set their velocities back to 0. The piece of code that makes the tanks drop under the graviatational force of the Earh is based on the Newton's second law. – LuciM Jun 29 '13 at 02:27

1 Answers1

0

Try to move _leftRocket and _rightRocket to the right position after rotation.

Here is the code move _leftRocket

//the old left bottom point of rocketShip
var point1:Point= new Point(0, rocketShip.height);

//the old right-bottom poiny of leftship
var point2:Point = new point(_leftRocket.width, _leftRocket.height);

//the old right bottom point of rocketShip
var point5:Point= new Point(rocketShip.width, rocketShip.height);

//the old left-bottom point of rightship's 
var point6:Point = new point(0, _leftRocket.height);

//.. Your code


//get the new position of rocketship's left bottom point after rotation,leftShip's right bottom corner will be in this point
var point3:Point =  rocketShip.transform.matrix.transformPoint(point1);

//get the new  point of leftship's right-bottom-corner after rotation.
var point4:Point =  _leftRocket.transform.matrix.transformPoint(point2);

//move the leftShip
_leftRocket.x -= point4.x - point3.x;
_leftRocket.y -= point4.y - point3.y;

Here to for right ship

//get the new position of right bottom point  of rocketShip after rotation,rightShip's left bottom corner will be in this point
var point7:Point =  rocketShip.transform.matrix.transformPoint(point5);

//get the new  point of rightship's left-bottom-corner after rotation.
var point8:Point =  _rightRocket.transform.matrix.transformPoint(point6);

//move the rightShip
_rightRocket.x -= point8.x - point7.x;
_rightRocket.y -= point8.y - point7.y;

And I think you should Change

 _rightRocket.y = rocketShip.x + _rightRocket.width;

To

 _rightRocket.x = rocketShip.x + rocketShip.width;
Pan
  • 2,101
  • 3
  • 13
  • 17
  • Still nothing. Thank you for your time. I will go for what Marjin and LDMediaServices said, and rotate the container parent. – LuciM Jun 29 '13 at 07:17