How do i make collision tests

Discuss new features and future development.
Post Reply
Prio
Posts: 3
Joined: Sat Nov 10, 2007 8:40 pm
Contact:

How do i make collision tests

Post 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??
joshcryer
Posts: 18
Joined: Wed Sep 26, 2007 8:19 pm
Contact:

Re: How do i make collision tests

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How do i make collision tests

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Prio
Posts: 3
Joined: Sat Nov 10, 2007 8:40 pm
Contact:

Re: How do i make collision tests

Post by Prio »

Thanks for the help. Yeah I think I will use my own collision system for it.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests