Todays problem.. How can I create an L-shaped object that can be moved by touch?
StormyStudio
United KingdomMember Posts: 3,989
Ok so todays task.. How can I create an L-shaped object that can be moved by touch?
I know I need to link positions of two actors, a long rectangle one and a square one. But I also want to be able to move the object with touch, and it also be affected by gravity and if it rotate for it to stay together. Sort of like an 'L' shaped piece in Tetris....(I'm not making tetris but you get the idea).
Any ideas or experience doing this would be brilliant.
I know I need to link positions of two actors, a long rectangle one and a square one. But I also want to be able to move the object with touch, and it also be affected by gravity and if it rotate for it to stay together. Sort of like an 'L' shaped piece in Tetris....(I'm not making tetris but you get the idea).
Any ideas or experience doing this would be brilliant.
Comments
i think you will want to constrain the positionx/y of the 'square' to an offset of the positionx/y of the 'rectangle'. that way, you can move them and they will remain together because of the constraint.
ex; constrain position x of 'game.square x' to position x+30 of 'game.rect x'
constrain position y of 'game.square y' to position y-10 of 'game.rect y'
i think this will work, although someone else may have a better solution.
noodles...
Harrio, thanks for the reply, I thought it would be something along those lines, I'm not on GS right now so cannot test it, but would that work when either actor is touched and moved, or would it only work if the one actor was touched. I guess it would need the constraint on both objects onto each other. As well as touch settings on both. Also would this allow for rotation, or would the position go wrong....
Make two global game attributes that keep track of L1's X and Y
(In L1, constrain game.L1X to self.position.X...etc.)
Then have L1 spawn L2
In L2, constrain its position to game.L1X and game.L1Y plus the appropriate offset.
I believe you'll need trig for the rotation... someone just recently made a chainsaw demo that shows that...
Depends on the game though. If you have a lot of L's colliding with stuff at the same time this won't work. If you only have one collision at a time this will work.
If you intend to have only one "active" (receiving input) actor per screen, and a number of "passive" (not receiving input) actors of the same type, you could create a third actor and have the active actor destroy itself upon becoming passive.