Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Reacting to a 2d collision


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 kevdotbadger   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 March 2012 - 03:43 PM

Hay, I've got 3 blocks. One is moveable with WASD and the other 2 are non-moveable. They all have bounding boxes and I've programmed it so that when 2 shapes intersects the moveable block gets moved back based on the width and height of the intersection. This works perectly, but only if collides with 1 block.

I hold the 2 non-moveable blocks inside a vector, then I'm looping through the vector and checking the collisions.

I've got 3 images to illustrate my problem.

Posted Image
This shows the layout, the red block is moveable, basically I'm going to be heading in an up-left direction. Holding the W and A keys.

Posted Image
This shows that the blocks collide correctly at this point, I am still holding W and A at this point.
Posted Image
I am continuing to hold W and A but the red block no longer heads in that direction. It gets stuck here. The problem, i think, is that the 2 green blocks are arguing with repositioning the red block based on the intersection.

How do I deal with this? Is there any example code I can look at to help me with this problem?

Sponsor:

#2 kevdotbadger   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 March 2012 - 06:36 AM

Here are my files, I'm using SFML, so you'll need to relink SFML then run it. Most of the collision code is in the gameObject and main.cpp files.

main - http://pastie.org/3654696
player - http://pastie.org/3654701
spriteManager - http://pastie.org/3654702
gameObject - http://pastie.org/3654708




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS