Skip to main content
Formatting
Source Link
Laurent Couvidou
  • 9.2k
  • 2
  • 42
  • 58

To answer your question, if you only reference the sides and collision boolean variables when the object is moving in that direction, it should help.

ieI.e. (sudopseudo-code):

if(moving right AND NOT collision on right){
    move right.
}

orOr:

if(collision on right AND Dx > 0){
    Dx = 0.
}

Right now what you're doing wont allow you to move at all if there's a collision.
For

For example, it seems like if the player is standing on a platform, he can move left and right, but not up and down. However, if the player runs into a wall, every frame, collisions to the left or right will register true and prevent movement along the x axis as well.

Hope this helps,
Best,
Peter

To answer your question, if you only reference the sides and collision boolean variables when the object is moving in that direction, it should help.

ie. (sudo-code)

if(moving right AND NOT collision on right){
    move right.
}

or

if(collision on right AND Dx > 0){
    Dx = 0.
}

Right now what you're doing wont allow you to move at all if there's a collision.
For example, it seems like if the player is standing on a platform, he can move left and right, but not up and down. However, if the player runs into a wall, every frame, collisions to the left or right will register true and prevent movement along the x axis as well.

Hope this helps,
Best,
Peter

To answer your question, if you only reference the sides and collision boolean variables when the object is moving in that direction, it should help.

I.e. (pseudo-code):

if(moving right AND NOT collision on right){
    move right.
}

Or:

if(collision on right AND Dx > 0){
    Dx = 0.
}

Right now what you're doing wont allow you to move at all if there's a collision.

For example, it seems like if the player is standing on a platform, he can move left and right, but not up and down. However, if the player runs into a wall, every frame, collisions to the left or right will register true and prevent movement along the x axis as well.

Source Link
Peteyslatts
  • 360
  • 4
  • 11

To answer your question, if you only reference the sides and collision boolean variables when the object is moving in that direction, it should help.

ie. (sudo-code)

if(moving right AND NOT collision on right){
    move right.
}

or

if(collision on right AND Dx > 0){
    Dx = 0.
}

Right now what you're doing wont allow you to move at all if there's a collision.
For example, it seems like if the player is standing on a platform, he can move left and right, but not up and down. However, if the player runs into a wall, every frame, collisions to the left or right will register true and prevent movement along the x axis as well.

Hope this helps,
Best,
Peter