trying to get working

4 sided Collision?

Posted 04 January 2009 - 01:16 PM

Hi guys im back again....
Another tough question.

I am using IntersecRECT colishions and I am having trouble understanding how to make stuff collide properly like for example mario. Mario jumps on a black and stops mario jumps under a block and he stops (or goes though it). mario jumps and hits the side of the block he falls to the ground.

I have been trying to do with with only 2 boxes.

do i have to make 4 boxes 1 for the top bottom left and right of the box because if i do then i can make the colishions fine i think. but i dont know how I would put it into my program.
Eneyways if you know how to make mario do everything properly with 2 boxes plz post somthing ENEYTHING!!

sorry im desprate

if you want my code i can post it here but its just a basic call of intersect rect with my 2 boxes and then an ifstatment to make marios velocY = 0 not mutch to it.

Re: 4 sided Collision?

Posted 05 January 2009 - 01:11 PM

I don't know what language you're writing it in, but you could say...

say your box on the screen is at position 500,300, you could draw a box, or the object, and have the graphics library recognise the deminsions and set it as "bad area", and have if statements as to what he does in comparison to his orientation around the box, or draw a rectangle from x,y to x1,y1.

Re: 4 sided Collision?

I've been giving this some thought and I think using bounding circles would be easier.

A bounding circle works like this...

Each object has a bounding circle around it. The circle should have:
1) A position.
2) A radius.

To test if two objects are "colliding" you find the distance between them, and then you see if the sum of their two circles' radii is greater than or equal to the distance.

When Mario and the box collide, you could find Mario's position relative to the box as an angle (counterclockwise from the origin, see picture).

Then you could do something like..

theta = Mario's position relative to the box (see picture)
if (theta <= 45 or theta > 315)
{
Mario is on the right of the box
}
else if (theta > 45 and theta <= 135)
{
Mario is on top of the box
}
else if (theta > 135 and theta <= 225)
{
Mario is on the left side of the box
}
else
{
Mario is under the box
}

There are probably more efficient ways to do this...
-------------

When you drop a ball on the ground, it bounces but usually not back up to the height at which you dropped it. The collision between the ground and the ball is mostly elastic, but a little bit of energy is lost (so the ball doesn't bounce as high).

In hindsight, Mario doesn't really bounce in the classic game, so forget what I said about reversing the direction.

Re: 4 sided Collision?

Posted 05 January 2009 - 04:08 PM

I had a similar problem (see my thread on Direction of Collision; ignore my solution though, I basically just gave up and made some concessions).

the problem with finding the angle of mario to the bounding box is that it's going to be different depending on the dimensions of the bounding box. you could try and find the angles of lines drawn from the origin of the box to the various endpoints, but in my mind that's a bit weak.

There has to be an easy method to see if the player is on top, bottom, right, or left of the bounding box. I've thought about line intersections, but that too is a less than perfect method.

Re: 4 sided Collision?

Posted 05 January 2009 - 04:51 PM

mastersmith98, on 5 Jan, 2009 - 06:08 PM, said:

the problem with finding the angle of mario to the bounding box is that it's going to be different depending on the dimensions of the bounding box. you could try and find the angles of lines drawn from the origin of the box to the various endpoints, but in my mind that's a bit weak.

Why? You would only have to calculate the angles (from the center to the corners) once as long as the box didn't change it's dimensions.

mastersmith98, on 5 Jan, 2009 - 06:08 PM, said:

There has to be an easy method to see if the player is on top, bottom, right, or left of the bounding box. I've thought about line intersections, but that too is a less than perfect method.

You could just test the player's position versus the position of each corner of the box, but I think that would be more work than using bounding circles.

Re: 4 sided Collision?

Posted 05 January 2009 - 05:55 PM

thank you for all your great ideas .
i am doing this in vb6 NeoTifa and i load a map from a file in the file i have a Boolean that makes it true when its a box Mario should not go in. so i guess that's a bad box and the boxes size will never change its always going be 16 by 16.

I am going to ask my Teacher tomorow about this if i dont get it tonight.
I will try your ideas if i fail.

Re: 4 sided Collision?

Posted 05 January 2009 - 08:50 PM

Aright so i messed around and i got 2 some what working collision handling
first one disables gravity unless you have hit the up key and throws you underneath or over the box depending if you move left or right.

and the other one puts you back to your previous spot witch would be befor you hit the block and sets your y Velocity to 0

this makes you unable to jump over something if you have hit it that's all i got today

I'm going to talk to my teacher tomorrow and work more on the second method.

Re: 4 sided Collision?

Posted 06 January 2009 - 10:57 AM

yay i showed my teacher the second colishion thing i made yesterday and he told me that if the spriteX is greater then the last position then it means im moveing right and so on for left up and down so now i know what side i hit of the box now i have to somehow make it so that mario can still jump when he hits a block becuase if i am running right and hit say a pipe it wount let me jump eny more because i have velocY set to 0 when i hit a block.

Re: 4 sided Collision?

Posted 06 January 2009 - 05:07 PM

well its ether me or a brain fart but i give up i tried doing the circle thing and i don't understand the position thing. but the bad tile method is something i haven't see do you have links in your game did you have gravidy forcing your character down ? this would help me a lot tnx
i'm going to search for this bad tile method.

Re: 4 sided Collision?

Posted 06 January 2009 - 06:45 PM

Thanks skyhawk. No I don't have a link. I did it in BASIC on my moms computer at her house. If you're doing a sidescroller, I would suggest having the ground horizontal y position set as a contant. For instance:

if (marioYPos > GROUND)
(marioYPos - 2); //or whatever speed you have your game set

and set that in a loop or something. I don't know. It's been a while. But say