Collision

Started by
4 comments, last by BrianJensen 12 years, 7 months ago
I have a Bounding box collision setup in my code and it works fine but now I want my player to walk on top of the other sprites. How do I do that?? For example In mario, player can walk on top of those after jumping on top of them.. I want similar functionality. Can anyone help?
Advertisement
I've never done something like this but here's how i would do it:

create a variable to keep track of the player's altitude and number of times it crosses a bounding box
have a bounding box on the item you want to walk on top of, and if the player intersects it and gets above the item's altitude have the player have it's default altitude above that bounding box

there's probably a better way of course but this is what i came up with off the top of my head...
[size="4"]-- [size="4"]Stuart, [size="2"]Currently: Messing with LibGDX (Java)
aspiring video game programmer. (follow @mastrgamr)
Programming on and off since 2008 in C++, and C# (XNA).
Attending college as a Computer Science major.

I have a Bounding box collision setup in my code and it works fine but now I want my player to walk on top of the other sprites. How do I do that?? For example In mario, player can walk on top of those after jumping on top of them.. I want similar functionality. Can anyone help?


You would declare the monster as dead, but still visible displaying the dead animation. Since the monster is dead you would no longer check collision on it. Basic. Then remove the monster by declaring !visible and you're good to go.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.

<br />I've never done something like this but here's how i would do it:<br /><br />create a variable to keep track of the player's altitude and number of times it crosses a bounding box<br />have a bounding box on the item you want to walk on top of, and if the player intersects it and gets above the item's altitude have the player have it's default altitude above that bounding box <br /><br />there's probably a better way of course but this is what i came up with off the top of my head...<br />
<br /><br /><br />

your method worked fine for making the player walk on top of the wall but I having trouble getting the player to fall down when the wall ends

[quote name='mastrgamr_' timestamp='1313899662' post='4851800']<br />I've never done something like this but here's how i would do it:<br /><br />create a variable to keep track of the player's altitude and number of times it crosses a bounding box<br />have a bounding box on the item you want to walk on top of, and if the player intersects it and gets above the item's altitude have the player have it's default altitude above that bounding box <br /><br />there's probably a better way of course but this is what i came up with off the top of my head...<br />
<br /><br /><br />

your method worked fine for making the player walk on top of the wall but I having trouble getting the player to fall down when the wall ends
[/quote]

Is up a constant? One way ive seen is in the level editor storing a bitwise value for solidness. So you do something like: Left Solid?/Top Solid?/Right Solid?/Bottom Solid? = 1110, which would represent a "tile" that was solid from the left, top and right, but you could jump through from the bottom.
Your character and every object in your game should be falling( or being pulled down constantly). Think about how it works in real life, Gravity. A constant force applied on us no matter what our collision is.

You should always check for a collision below your objects, if it isn't there apply a gravity variable to induce falling.

Sprite Creator 3 VX & XP

WARNING: I edit my posts constantly.

This topic is closed to new replies.

Advertisement