Checking for above collision

Topics: Developer Forum
Jul 28, 2010 at 4:40 PM
Hello, How would I go about checking for collision for above the Geom? Its for objects that you can walk on but you can also jump on top of it from under it (a platformer game). I've used (code by Yoti): bool ground = (contacts.Find(contact => contact.Normal.Y > Math.Abs(contact.Normal.X)) != null); if (ground && !groundGeoms.Contains(obj)) groundGeoms.Add(obj); To check for collision below the geom (groundGeoms.Count > 0 is colliding with a floor). I think its a good and accurate method but can't figure out a similar way to do it for checking above collision. Thanks
Jul 29, 2010 at 11:26 PM

I've been doing something similar in FP2.1. I've got it working fine, it just compares the position of the platform compared to the players geom/body position.
Might need some tweaking and I'm sure there are better ways, but it works. Not sure if this is what you're looking for, I haven't looked at the code you're using.
Tiles is just a class that is passed the height/width/collisionType of a platform from an XML file, and then creates the body & geom for the platform.

//----- CHECK COLLISIONS -----// private bool OnCollision(Geom geom1, Geom geom2, ContactList contactList) { //check to see if collided geom is a platform if (geom2.CollisionCategories == CollisionCategory.Cat1) { //then collided geom is a platform. Find out whether it is passable or not platform = (Tiles)geom2.Tag; if (platform.Collision == Tiles.TileCollision.Platform) { //then platform is a one-sided platform //check position of the player compared to the platform // if player is NOT inbetween the platforms position if (position.X + width > platform.body.Position.X || position.X < platform.body.Position.X + platform.Width) { //if not, then check Y position if (body.Position.Y + ((height / 5) - 2 (this is a padding value,adjust depending on gravity) ) > platform.body.Position.Y - (platform.Height / 2)) { //then player is below the platform, so disable collisions until they have seperated platform.geom.CollisionResponseEnabled = false; } } } } }

Aug 5, 2010 at 10:27 PM

Thanks for the help! I mixed some of your idea with a Ray trace and it works great.