How do i make collision tests

Discuss new features and future development.

How do i make collision tests

Postby Prio » Sat Nov 10, 2007 9:01 pm

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??
Posts: 3
Joined: Sat Nov 10, 2007 8:40 pm

Re: How do i make collision tests

Postby joshcryer » Tue Nov 13, 2007 6:45 am

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

Re: How do i make collision tests

Postby slembcke » Tue Nov 13, 2007 1:22 pm

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! ->
User avatar
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: How do i make collision tests

Postby Prio » Tue Nov 13, 2007 7:14 pm

Thanks for the help. Yeah I think I will use my own collision system for it.
Posts: 3
Joined: Sat Nov 10, 2007 8:40 pm

Return to Features/Development

Who is online

Users browsing this forum: No registered users and 1 guest