Skip to main content
Tweeted twitter.com/StackGameDev/status/943859002848497665
added 1 character in body
Source Link
DyingIsFun
  • 1.3k
  • 1
  • 17
  • 41

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve my desired goal (rolling under wallwalls) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling and a wall centered at my enemy's position could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls?

I am open to drastically changing my collision resolution system.

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve my desired goal (rolling under wall) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling and a wall centered at my enemy's position could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls?

I am open to drastically changing my collision resolution system.

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve my desired goal (rolling under walls) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls?

I am open to drastically changing my collision resolution system.

Simplified the question to make it less of a two-parter
Source Link
DyingIsFun
  • 1.3k
  • 1
  • 17
  • 41

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

I also want my sprite to be unable to run through enemies, and unable to stand on top of them, but to be able to roll through them.

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve both of my desired goalsgoal (rolling under walls and through otherwise impassable enemieswall) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling and a wall centered at my enemy's position could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner. Also, the above method wouldn't prevent the sprite from standing on top of enemies.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic. Also, this wouldn't prevent standing on top of enemies.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls and rolling through otherwise impassable enemies?

I am open to drastically changing my collision resolution system.

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

I also want my sprite to be unable to run through enemies, and unable to stand on top of them, but to be able to roll through them.

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve both of my desired goals (rolling under walls and through otherwise impassable enemies) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling and a wall centered at my enemy's position could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner. Also, the above method wouldn't prevent the sprite from standing on top of enemies.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic. Also, this wouldn't prevent standing on top of enemies.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls and rolling through otherwise impassable enemies?

I am open to drastically changing my collision resolution system.

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve my desired goal (rolling under wall) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling and a wall centered at my enemy's position could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls?

I am open to drastically changing my collision resolution system.

Source Link
DyingIsFun
  • 1.3k
  • 1
  • 17
  • 41

Selective Collision Resolution While Rolling

I am working on a 2D action platformer in Pygame, though my question is a general one.

The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.

My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.

The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).

My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:

enter image description here

I also want my sprite to be unable to run through enemies, and unable to stand on top of them, but to be able to roll through them.

Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.

I was thinking I might be able to achieve both of my desired goals (rolling under walls and through otherwise impassable enemies) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling and a wall centered at my enemy's position could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.

A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner. Also, the above method wouldn't prevent the sprite from standing on top of enemies.

Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic. Also, this wouldn't prevent standing on top of enemies.

So, my questions are: What are my other options? How do other games deal with collision while rolling under walls and rolling through otherwise impassable enemies?

I am open to drastically changing my collision resolution system.