Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2010, 08:53 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default Perfect Collision

How do I make perfect collision where no matter how fast an object is moving it won't skip over another object in the way?


-Gan
Gandolf is offline   Reply With Quote
Old 02-16-2010, 08:54 AM   #2 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Calling a method with an NSTimer that's set at 0.001 and has CGIntersectsRect should work?
ZunePod is offline   Reply With Quote
Old 02-16-2010, 09:01 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

Quote:
Originally Posted by ZunePod View Post
Calling a method with an NSTimer that's set at 0.001 and has CGIntersectsRect should work?
I'm not sure, if the velocity was still high enough couldn't it still jump over?

Is it possible to check beforehand if an object is in the path of another object?


-Gan
Gandolf is offline   Reply With Quote
Old 02-16-2010, 09:32 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 234
warmi is on a distinguished road
Default

Quote:
Originally Posted by Gandolf View Post
I'm not sure, if the velocity was still high enough couldn't it still jump over?

Is it possible to check beforehand if an object is in the path of another object?


-Gan
Yeah, you have to either guarantee that your steps will be small enough to avoid tunneling or start doing sweep collision detection which is much harder.
warmi is offline   Reply With Quote
Old 02-16-2010, 09:41 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Location: London
Posts: 52
jackeveritt is on a distinguished road
Default Box2D?

What shape are the objects that are being checked for collision? Are the objects 2D or 3D?

Swept collision could be a good way to go - predict the new positions of the objects, then test for collision between the swept objects.

If you are working in 2D, Box2D has some good collision detection. Have you considered a third party solution?
jackeveritt is offline   Reply With Quote
Old 02-16-2010, 10:09 AM   #6 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Quote:
Originally Posted by Gandolf View Post
I'm not sure, if the velocity was still high enough couldn't it still jump over?

Is it possible to check beforehand if an object is in the path of another object?


-Gan
What about making the time out of what velocity the images are travelling at.
ZunePod is offline   Reply With Quote
Old 02-16-2010, 11:18 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

I actually have an idea for effective and perfect collision. What if I make a line along object 1's path then draw a line perpendicular to it that's the size of object 2. Then if the lines collide they collide. What do you guys think?


-Gan

Last edited by Gandolf; 02-16-2010 at 11:21 AM.
Gandolf is offline   Reply With Quote
Old 02-16-2010, 01:09 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 158
cribasoft is on a distinguished road
Default

Why not look at how it is done in the two leading open-source physics engines?

Box2D - Home

chipmunk-physics - Project Hosting on Google Code
cribasoft is offline   Reply With Quote
Old 02-16-2010, 04:40 PM   #9 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Quote:
Originally Posted by cribasoft View Post
Why not look at how it is done in the two leading open-source physics engines?

Box2D - Home

chipmunk-physics - Project Hosting on Google Code
Because that is laborius.

Gandolf, did you read my last post?
ZunePod is offline   Reply With Quote
Old 02-16-2010, 04:41 PM   #10 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

I've looked through the sources and they seem quite complex to decipher.
What exactly is the sweep collision test? Googled it and couldn't quite understand.


-Gan
P.S. I'm trying to do 2D and have intersection code for lines and circles.
P.S.S.
Code:
What about making the time out of what velocity the images are travelling at.
Not quite sure what you mean.
Gandolf is offline   Reply With Quote
Old 02-16-2010, 04:44 PM   #11 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Quote:
Originally Posted by Gandolf View Post
I've looked through the sources and they seem quite complex to decipher.
What exactly is the sweep collision test? Googled it and couldn't quite understand.


-Gan
P.S. I'm trying to do 2D and have intersection code for lines and circles.
P.S.S.
Code:
What about making the time out of what velocity the images are travelling at.
Not quite sure what you mean.
I'll try and explain as best I can.

In your iPhone game tutorials you set the xVel and yVel, so you should be able to work out if they've colided by looking at the speeds.
ZunePod is offline   Reply With Quote
Old 02-16-2010, 04:51 PM   #12 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

Yeah, I'm thinking the best bet would be to predetermine if they'll collide beforehand by using the velocity mixed in with line intersection of the paths of the object. Then compensate for overlapping collision or complete skips.
I think that's probably the best solution to get the most precise results. Though it's going to be a bit of a doozy to implement.


-Gan
P.S.
Quote:
In your iPhone game tutorials you set the xVel and yVel, so you should be able to work out if they've colided by looking at the speeds.
Wow, that makes me feel good. People are actually watching them...
I think I shall make more tutorials and add more resources. I also need to update the template to have code to detect points of intersection between lines, circles, and polygons. Maybe even image collision code for people who want pixel perfect.
Gandolf is offline   Reply With Quote
Old 02-16-2010, 05:36 PM   #13 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Just a quick question about your Template.

Is there a way to removeFromSuperview something that you have drawn in it?
ZunePod is offline   Reply With Quote
Old 02-16-2010, 05:51 PM   #14 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

Are you talking about buttons, textboxes, and other such GUI objects? If so, yes. I'll give the exact code when I get back to my mac.
If you aren't, explain a bit on what you wish to remove?


-Gan
Gandolf is offline   Reply With Quote
Old 02-16-2010, 05:53 PM   #15 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Quote:
Originally Posted by Gandolf View Post
Are you talking about buttons, textboxes, and other such GUI objects? If so, yes. I'll give the exact code when I get back to my mac.
If you aren't, explain a bit on what you wish to remove?


-Gan
Like say I put an image in there, using drawRect and then the Image thing, where do I put my removal code?
ZunePod is offline   Reply With Quote
Old 02-16-2010, 06:42 PM   #16 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

Anywhere. Just stop drawing the image. In DrawRect you draw the image 60 times per second. To stop drawing just make it not run the drawImage command:
Global Variable
Code:
BOOL drawImage;
AwakeFromNib
Code:
drawImage = TRUE;
DrawRect
Code:
if (drawImage) {
//Draw image code goes here
}
That way when drawImage is true it draws and doesn't draw when false. So if you wanted the image to disappear when you tap you'd put "drawImage=FALSE;" in TouchBegan or TouchEnded.


-Gan
Gandolf is offline   Reply With Quote
Old 02-16-2010, 06:53 PM   #17 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Ah thanks, genius.

EDIT: Are you thinking of adding a way to have a menu before the actual game engine bit.
ZunePod is offline   Reply With Quote
Old 02-16-2010, 07:02 PM   #18 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 86
Gandolf is on a distinguished road
Default

Easily code-able. I make a menu like this:
Global Variables
Code:
int currentView;
AwakeFromNib
Code:
currentView = 1;
DrawRect
Code:
if (currentView == 1) {
//Main menu image code here
} else if (currentView == 2) {
//Gameplay screen here
} else if (currentView == 3) {
//Death screen
}
Then in a touched event I'd put this to change:
Code:
if (location.x > # && location.y > # && location.x < # and location.y < #) {
//Simulates a button.
currentView = 2; //Hit play, lets go to the Gameplay screen
}

-Gan
P.S. Here's a preview of one of my menus in action:
http://web.mac.com/avisaria/SpellsTest.swf
Built using the template in my tutorials.

Last edited by Gandolf; 02-16-2010 at 07:05 PM.
Gandolf is offline   Reply With Quote
Old 02-16-2010, 07:04 PM   #19 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

WOW, you really are a genius, I'm bookmarking this thread for later
ZunePod is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 398
8 members and 390 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0