Rotating An Object Whilst Constraining Another Object To Remain In The Same Relative Place.
gamewizard99
Member, PRO Posts: 67
I have an object which is 200x200. I want to be able to rotate object2 so it remains in the same relative place to object1 even when rotated and moved. I've tried using constrain self.position.Y to (for object2);
100*sin( game.Object_Rotation )+( game.Object_Y +77.1)
The 77.1 just indicates the required distance between the two objects.
For the x axis I am using;
100*cos( game.Object_Rotation )+( game.Object_X -58.2)
The -58.2 is just for the required distance on the x axis between the two objects.
The rotation of object 2 is constrained to;
( game.Object_Rotation +28.1)
Object_Rotation = object1's rotation
Object_X = object1's X position
Object_Y = object1's Y position
My problem is it just doesn't work and I was hoping someone who has tried and hopefully succeeded to do this could point me in the right direction. Thanks!
100*sin( game.Object_Rotation )+( game.Object_Y +77.1)
The 77.1 just indicates the required distance between the two objects.
For the x axis I am using;
100*cos( game.Object_Rotation )+( game.Object_X -58.2)
The -58.2 is just for the required distance on the x axis between the two objects.
The rotation of object 2 is constrained to;
( game.Object_Rotation +28.1)
Object_Rotation = object1's rotation
Object_X = object1's X position
Object_Y = object1's Y position
My problem is it just doesn't work and I was hoping someone who has tried and hopefully succeeded to do this could point me in the right direction. Thanks!
Comments
http://gshelper.com/shop/advanced-game-functions/rotating-menu-level-select-template/
Its not exactly the same think but I think it uses similar principals.
Constrain Object2's X position to 100*cos( Object1's rotation)+ Object1's X position
Constrain Object2's Y position to 100*sin( Object1's rotation)+ Object1's Y position
Constrain Object2's rotation to Object1's rotation The '77.1' (where you have it positioned) will just give Object2 a general/absolute X,Y offset from Object1, it has no bearing on the distance between the two objects.
The '100' will determine the distance between the two centre points of the two objects.
If you want to offset Object2's angle relative to Object1 then add (or subtract) from the value cos and sin are operating on - in this case Object1's rotation, so you'd thrown in your offset like this:
100*cos( Object1's rotation) = no offset.
100*cos((Object1's rotation)+44) = a 44° offset.
And the same applies for Object2's rotation:
Constrain Object2's rotation to (Object1's rotation) = no offset.
Constrain Object2's rotation to ((Object1's rotation)+240) = a 240° rotational offset.
Hope that makes sense !
I've made a project to automate this kind of thing:
>> http://forums.gamesalad.com/discussion/62202/linkmachine
. . .
Watch this video, particularly the yellow and blue indicator circles and the red indicator line . . . . I've taken the constrain behaviour code I posted above and coloured the values to reflect the indicators in the video (so you can see more clearly what is going on when it comes to offsets).
Constrain Object2's X position to 100*cos(( Object1's rotation)+100)+ Object1's X position
Constrain Object2's Y position to 100*sin(( Object1's rotation)+100)+ Object1's Y position
Constrain Object2's rotation to Object1's rotation+100
Obviously I've just thrown '100' in for all the values, so the distance between the centre-points of the two objects (red) is 100 pixels, the angle offset between Object1 and Object2 (blue) is 100°, and Object2 is rotated (yellow) 100° around it's own centre-point . . . . change these values to whatever you want, the only rule is that you need to keep the values that share a colour the same.