Collision Issues
Moderator: Coders of Rage
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Collision Issues
I'm trying to make 2 boxes bounce off each other in a relatively realistic way. The 2 boxes have a x and y velocity and they bounce off the edges of the screen. When the blocks collide, either their x or y velocities are reversed depending upon which side box a hit box b at. I can check for collision between the boxes no problem, but i cant figure out how to check where box a hit box b. I'm stumped...
Also, does anyone know any good C++ physics tutorials?
Physics is what i suck most at at programming so i want to learn more
Also, does anyone know any good C++ physics tutorials?
Physics is what i suck most at at programming so i want to learn more
Last edited by mv2112 on Wed Jun 16, 2010 4:22 pm, edited 2 times in total.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Collision Issues
This question comes up rather frequently, actually. What you need is the "normal" vector resulting from your collision--this is the minimal separating axis that resolves the collision.mv2112 wrote:I'm trying to make 2 boxes bounce off each other in a relatively realistic way. The 2 boxes have a x and y velocity and they bounce off the edges of the screen. When the blocks collide, either their x or y velocities are reversed depending upon which side box a hit box b at. I can check for collision between the boxes no problem, but i cant figure out how to check where box a hit box b. I'm stumped...
Also, does anyone know any good C++ physics tutorials?
Physics is what i suck most at at programming so i want to learn more
Check the "Programmer's Education Index" for AABB collision. There should be lots of details there.
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Collision Issues
Thanks Falco! I did a search on the forums for the AABB collision and found a algorithm you posted that worked very well (with a little tweaking). Now i'll have to do some more research on how it works in detail.
Link to post -> http://elysianshadows.com/phpBB3/viewto ... art=999999
Link to post -> http://elysianshadows.com/phpBB3/viewto ... art=999999
Re: Collision Issues
Just to let you know, he posted an even BETTER collision function hidden somewhere in the forum. Search a bit harder.mv2112 wrote:Thanks Falco! I did a search on the forums for the AABB collision and found a algorithm you posted that worked very well (with a little tweaking). Now i'll have to do some more research on how it works in detail.
Link to post -> http://elysianshadows.com/phpBB3/viewto ... art=999999
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: Collision Issues
I believe you linked it in one of my topics.XianForce wrote:Just to let you know, he posted an even BETTER collision function hidden somewhere in the forum. Search a bit harder.mv2112 wrote:Thanks Falco! I did a search on the forums for the AABB collision and found a algorithm you posted that worked very well (with a little tweaking). Now i'll have to do some more research on how it works in detail.
Link to post -> http://elysianshadows.com/phpBB3/viewto ... art=999999
I ignored it and went with my shitty ass ghetto collision code |3.
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Re: Collision Issues
Yeah I think I've linked to it quite a few times.xiphirx wrote:I believe you linked it in one of my topics.XianForce wrote:Just to let you know, he posted an even BETTER collision function hidden somewhere in the forum. Search a bit harder.mv2112 wrote:Thanks Falco! I did a search on the forums for the AABB collision and found a algorithm you posted that worked very well (with a little tweaking). Now i'll have to do some more research on how it works in detail.
Link to post -> http://elysianshadows.com/phpBB3/viewto ... art=999999
I ignored it and went with my shitty ass ghetto collision code |3.
I just remembered, it's in the Programmer's Education Index thing. It's a topic stickied in this forum, so look around for it.
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Collision Issues <SOLVED>
This is off topic but I'd like to retract my statement on hating VS2010. I'm actually starting to like it a little. It just takes a lot of getting used to for me (Specifically defining include and lib locations for EVERY project and having to re-compile some libs to work with VS2010).
Re: Collision Issues <SOLVED>
I think there is a way that you can easily import them... But seeing as how I don't start many new projects I haven't really gotten too annoyed with it and haven't looked...mv2112 wrote:This is off topic but I'd like to retract my statement on hating VS2010. I'm actually starting to like it a little. It just takes a lot of getting used to for me (Specifically defining include and lib locations for EVERY project and having to re-compile some libs to work with VS2010).
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Collision Issues
I thought i would just revive this thread instead of making a new one. The collision function i have works for squares and rectangles that are almost squares.
However if i have rectangles that arn't like squares, the collision doesn't line up correctly. What am i doing wrong? Hopefully next year Geometry class will help me with this stuff.
Code: Select all
//Location and Size are vector2d<float>'s
bool Entity::Collision(Entity & b)
{
float xDist = abs(Location.x - b.Location.x);
float yDist = abs(Location.y - b.Location.y);
float xMinDist = Size.x/2 + b.Size.x/2;
float yMinDist = Size.y/2 + b.Size.y/2;
if(xDist >= xMinDist || yDist >= yMinDist)
{
return false;
}
float xOverlap = xDist - xMinDist;
float yOverlap = yDist - yMinDist;
if(xOverlap < yOverlap)
{
return true;
}
else if(xOverlap > yOverlap)
{
return true;
}
return false;
}
Re: Collision Issues
Is your position the center? And check to make sure your not assigning the same width and height to the dimensions even when the dimensions are NOT the same.
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Collision Issues
That was the problem, the position wasn't the center. But if this was the case, why wasnt the collision of squares offset like collision of rectangles?XianForce wrote:Is your position the center? And check to make sure your not assigning the same width and height to the dimensions even when the dimensions are NOT the same.
- ibly31
- Chaos Rift Junior
- Posts: 312
- Joined: Thu Feb 19, 2009 8:47 pm
- Current Project: Like... seven different ones
- Favorite Gaming Platforms: Xbox 360, Gamecube
- Programming Language of Choice: C++, ObjC
- Location: New Jersey.
Re: Collision Issues
I took the final exam for Geometry today. I can pretty honestly say that to take what you learn in Geometry and apply it is pretty hard, I don't think I learned anything this year that could really help me with programming.Hopefully next year Geometry class will help me with this stuff.
Website/Tumblr
My Projects
The best thing about UDP jokes is that I don’t care if you get them or not.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Collision Issues
Trust me, later in life you will realize how fundamental algebra and geometry are. Calculus will prove IMPOSSIBLE without a solid understanding of algebra, geometry, and trigonometry.ibly31 wrote:I took the final exam for Geometry today. I can pretty honestly say that to take what you learn in Geometry and apply it is pretty hard, I don't think I learned anything this year that could really help me with programming.Hopefully next year Geometry class will help me with this stuff.
I used to think the same things back in middle school and high school, but I'm constantly finding myself going back to the simple concepts to solve far more complex problems.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!