Windows Collision detection not working when object's sprite changes

W

Wintermute()

Guest
Just a very quick one today for you very helpful GMS gurus :)

I have a object/sprite that when you press a key changes into another sprite (and back again when the key is released) both the default sprite and the changed sprite have collision masks made for them - and both look right, there is nothing different about the second sprite's collision mask or settings.

The collision detection works fine when the object's sprite is the default sprite, but as soon as the sprite changes on key press, the collision detection stops working, the mask is ignored.

Any ideas, gurus ?

Thank you!
W
 
D

Dudeidu

Guest
Im pretty sure that if you are just changing the sprite_index to another sprite, and mask_index stays the same then collisions shouldn't be affected.
 
W

Wintermute()

Guest
Im pretty sure that if you are just changing the sprite_index to another sprite, and mask_index stays the same then collisions shouldn't be affected.
I'm not changing the sprite_index as such, I'm just using the drag and drop 'change sprite' functionality to change the player sprite when a key is pressed (add a little booster rocket flame) but when i do, my ship with the booster rocket firing becomes invulnerable (collision mask does not work)
 
W

Wintermute()

Guest
Well I 'sort of' found a solution for this myself. I added the sprite I wanted to change to as a subimage of the original sprite. The when the keypress happens the sprite is just calling the subimage. Then the collision detection works.
 
P

ParodyKnaveBob

Guest
Changing the sprite should work -- whether by manually writing the sprite_index GML variable or by using the d'n'd action to do the same. I don't know if you've already deleted your other sprite, but did you make sure your origins were the same? (You tempt me to test this in Studio myself just to make sure there's no weird bug with the d'n'd action or something.)

Meanwhile, I'm glad to hear you solved the issue another way, although I know this solution complicates your ability to animate if you so desired...

Regards,
Bob
 
W

Wintermute()

Guest
Changing the sprite should work -- whether by manually writing the sprite_index GML variable or by using the d'n'd action to do the same. I don't know if you've already deleted your other sprite, but did you make sure your origins were the same? (You tempt me to test this in Studio myself just to make sure there's no weird bug with the d'n'd action or something.)

Meanwhile, I'm glad to hear you solved the issue another way, although I know this solution complicates your ability to animate if you so desired...

Regards,
Bob
Hi Bob,

yes the sprites were almost identical - the only difference was a flame behind the ship to simulate the booster rocket firing when you press the space bar.

The origin and dimensions and collision masks were identical. but when the sprite was changed to another sprite on keypress, my ship became invincible to everything ,and could also pass through solid objects.

Fortunately for my main sprite it was no big deal to add just one frame of the new sprite to the many frames of the main sprite's booster animation. But if the sprite was different altogether, the dirty solution I came up with would not work..
 
P

ParodyKnaveBob

Guest
Hmmmmmmmm...

How would you feel about posting all Object Information? (Assuming this is a small project..) Or perhaps the ship's Object Information and an object or two with which it collides? (You can get each object's info from the button on each object editor near "OK" at the bottom left -- but you can get all object info from the main dropdown menu: Edit -> Show Object Information.)

Bob
 
W

Wintermute()

Guest
Hmmmmmmmm...

How would you feel about posting all Object Information? (Assuming this is a small project..) Or perhaps the ship's Object Information and an object or two with which it collides? (You can get each object's info from the button on each object editor near "OK" at the bottom left -- but you can get all object info from the main dropdown menu: Edit -> Show Object Information.)

Bob
Yep I could do that, would love to know how to do it more cleanly ! I'll post them later on here, thanks :)
 
W

Wintermute()

Guest
Hmmmmmmmm...

How would you feel about posting all Object Information? (Assuming this is a small project..) Or perhaps the ship's Object Information and an object or two with which it collides? (You can get each object's info from the button on each object editor near "OK" at the bottom left -- but you can get all object info from the main dropdown menu: Edit -> Show Object Information.)

Bob
Hi Bob,

Life has been getting in the way of my game time lately.... but I get to sit down for a bit today. Here's an example: the ship's object information when you press the up key [when it changes sprite], and an enemy bullet info [an object it collides with]

As mentioned before the collision detection is working, but only if I have the sprite change set to a sub-image of the main sprite. If I choose another sprite for the object entirely, the collision detection will not work.

The strange thing is ALL collision stops working if I change sprite entirely, my ship can fly through everything - ie enemies, solid objects, hazards, etc.

I'm not sure if this helps, let me know if I'm barking up the wrong tree.... thanks!

The player:

----------------------------------------------------------------------------
Keyboard Event for <Up> Key:
set the sprite to spr_player with subimage 12 and speed 1
execute code:

motion_add(image_angle, 0.2);
if(speed > 9) speed = 9;

play sound sound_thrust3; looping: false
----------------------------------------------------------------------------

Collision object

Enemy Bullet:

----------------------------------------------------------------------------

Information about object: obj_bullet_saucer
Sprite: spr_bullet_saucer
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Collision Event with object obj_sun:
bounce not precisely against solid objects
-------------------------------------------------------------------------
 
P

ParodyKnaveBob

Guest
Howdy, Wintermute() -- and np about more important things in life, it happens. ~nodnod~

Thanks for posting some info there, but the only collision you showed was the event for obj_bullet_saucer (the enemy bullet) and obj_sun (which I'm guessing has nothing to do with the player ship)...

Also, the "set the sprite to spr_player with subimage 12 and speed 1" action tells me you player sprite has at least 13 subimages, and after you set it (while pressing Up), it's animating anyway (but I suppose it keeps getting reset to image_index 12, the 13th subimage, each frame because you're still holding Up, k, gotcha).

So anyway, I'd love to know more about your player vs. enemy bullet vs. sun stuff: if any of it's connected, or you accidentally c/p'ed the wrong part, or you thought one thing pertained to another, or so forth.

Regards,
Bob $:^ J
 
W

Wintermute()

Guest
Howdy, Wintermute() -- and np about more important things in life, it happens. ~nodnod~

Thanks for posting some info there, but the only collision you showed was the event for obj_bullet_saucer (the enemy bullet) and obj_sun (which I'm guessing has nothing to do with the player ship)...

Also, the "set the sprite to spr_player with subimage 12 and speed 1" action tells me you player sprite has at least 13 subimages, and after you set it (while pressing Up), it's animating anyway (but I suppose it keeps getting reset to image_index 12, the 13th subimage, each frame because you're still holding Up, k, gotcha).

So anyway, I'd love to know more about your player vs. enemy bullet vs. sun stuff: if any of it's connected, or you accidentally c/p'ed the wrong part, or you thought one thing pertained to another, or so forth.

Regards,
Bob $:^ J
hi bob, thanks for your reply!

yes I should have pasted the object code, whoops....! I reckon I'm going to sit on this one for now as I have a workable solution going - and I'm trying to keep making forward progress and not get bogged down with getting things perfect... I will definitely revisit this little issue when it is time for the spit and polish, so I'll give this thread a bump down the track.... cheers! :)
 
Top