Page 1 of 1

How do i make collision tests

Posted: Sat Nov 10, 2007 9:01 pm
by Prio
Hi,
I'm trying to detect whether 2 shapes intersect. I want to do this without calling cpSpaceStep.

I need this so that I can check whether an object is in the line of sight of a player. The LOS is a triangle. So basically is it possible to do something like this:

Code: Select all

cpShape shape1 = circle(70,70,5)  // A circle at (70,70) with radius 5
cpShape shape2 = triangle(10,20, 150,60, 60,120) // A triangle with vertices: (10,20), (150,60), (70,40)
....
bool collides = CheckCollision(shape1, shape2)
I don't want to make a shape and attach it to a body everytime I want to check a collision between 2 shapes. Is it already possible to do this or are there workarounds etc??

Re: How do i make collision tests

Posted: Tue Nov 13, 2007 6:45 am
by joshcryer
It seems you can use cpCollideShapes but I am unsure as to this as it would be an undocumented feature. Check Collision.c and see what happens? :) There's a bit of voodoo working there that I don't quite understand so I'm not sure.

Re: How do i make collision tests

Posted: Tue Nov 13, 2007 1:22 pm
by slembcke
What you really want is ray tracing. An oft requested feature. I have plans for using it myself at some point in the future for line of sight, lasers, etc. I'll get around to it sometime, I just can't promise when.

The problem with what you want to do is that you would have to check the LOS shape against everything in the space to see if the player is obscured. I probably wouldn't use Chipmunk to handle this for you at the moment. If you can get away with static line segments, store them separately in your own code and check against them there. That would be pretty easy to implement.

Re: How do i make collision tests

Posted: Tue Nov 13, 2007 7:14 pm
by Prio
Thanks for the help. Yeah I think I will use my own collision system for it.