GameMaker: Studio

GameMaker: Studio

Statistiken ansehen:
Sprites continue to move after collision
Difficult to explain.

I have a playersprite that consists out of 3 sprites, arranged next to each other. All 3 Sprites are controlled by the middle sprite that handles the movement and moves the sprites left and right with it. When either the left sprite or the right sprite hit the level boundary, which is represented by an object called objWallSide, all 3 sprites are supposed to stop immediatly.

But they don't. The middle sprite continues to move until the middle sprite hits objWallSide, pushing the left and the right sprites on the same position where the middle one is. And yes, I added a movement modifier for all sprites in the collision routine.

Anyone got any hints?^^

< >
Beiträge 19 von 9
M.S.T.O.P. 3. Okt. 2012 um 1:49 Uhr 
How are you controling the movements? Using keyboard events? If so, are you setting the speed and direction of each object within those keyboard events?
Scorcher24 3. Okt. 2012 um 6:27 Uhr 
Yes, thats what I do. On Keypress I start moving it and and on key release I stop it.
I never used this software, but is there a way to get the code of your game? If so, you should probably post it. Or post anything that is describing the relationships between your objects and your logic. Some downsides of Game Maker Studios are becoming apparent...
Scorcher24 3. Okt. 2012 um 6:35 Uhr 
Well there is no code, otherwise I would post some :D.
I know programming and that's not my first prototype, but yeah, thats a downside of it :).
But maybe that screenshot hels:
It contains the visual scripts for objPlayerMiddle Keypress Event and the collision code of objWallSides.

The "Start moving in a direction" command in the Keypress Event is moving all 3 sprites into one direction when the key is pressed, the same command with parameter 0 is issued when the key is released or when either the left or the right sprite hit the wall.
Zuletzt bearbeitet von Scorcher24; 3. Okt. 2012 um 6:37 Uhr
Mizipzor 3. Okt. 2012 um 6:52 Uhr 
If a collision stops the sprite and a key press moves the sprite what happens if you hold down the key while the collision occurs? Just a guess but I think the key press takes precedence in your case. Maybe add a check after the key press but before you move that makes sure its valid for it to start moving.
Scorcher24 3. Okt. 2012 um 6:54 Uhr 
I tried that, it might prevent the sprite from moving at all after I touched the wall, since I did not find a "collision over" event. Also, even with setting a variable, this happened. Is there no way to just set some level boundaries where the player cannot move beyond? You can do that in Torque2D which I own.
Zuletzt bearbeitet von Scorcher24; 3. Okt. 2012 um 7:05 Uhr
M.S.T.O.P. 3. Okt. 2012 um 12:48 Uhr 
I think I got it. As mizipzor said, you need to check if there isn't a wall in the way before you move. You can do that by using a "Check Object" action in the keyboard events.

This code gets the desired results for me:
Scorcher24 3. Okt. 2012 um 16:48 Uhr 
Thanks mate :). I still think the world limits from Torque2D are cooler in that regard.
M.S.T.O.P. 3. Okt. 2012 um 21:10 Uhr 
There is an event called "Intersect Boundary" that triggers whenever an object intersects the boundaries of a room. You could tell the objects to stop in that event. Functionally, I think it's same as what you're doing, except you don't have to manually wall off every room you create.
< >
Beiträge 19 von 9
Pro Seite: 15 30 50

Geschrieben am: 2. Okt. 2012 um 21:59 Uhr
Beiträge: 9