|
Post by PiratSS2 on Aug 29, 2004 4:18:45 GMT 1
Hey walaber, I was wondering what was the best way to get a collision between objects.
I tried this: for i=1 to 2500 if body(i)>0 and NDB_GetCollision(body(i),BodyMatrix)>0 then end
next i
where body(i)= one of my bullets and BodyMatrix is a rigid body of my matrix. This method gave me extreme lag for some reason. Anyhow, is there any better way to see if two objects are collided?
Thanks again.
|
|
|
Post by Kjelle69 on Aug 29, 2004 6:21:29 GMT 1
wow... you have 2500 bullet bodies?!?!?! that seems a little excessive... also, try only calling the collision checker IF the body exists. so change your code to this:
for i=1 to 2500 if body(i)>0 if NDB_GetCollision(body(i),BodyMatrix)>0 then end endif next i
that way it only calls the GetCollision when the body exists, not every loop (the "and" operator has to call the function to get a result, and then check for the overall result)... that might speed it up a little.
otherwise, I think 2500 rigid bodies is a few too many. are you re-using slots after a bullet has hit something?
|
|
|
Post by PiratSS2 on Aug 29, 2004 6:25:29 GMT 1
Well, 2500 is a lot, I tuned it down to 25(still a lot, but this will make sure that no errors are made in the future).
Thanks for that suggestion, I will try it as soon as I get home. ;D
|
|
|
Post by Kjelle69 on Aug 29, 2004 16:01:30 GMT 1
that should speed it up substantially. let me know how it goes.
|
|
|
Post by PiratSS2 on Aug 30, 2004 4:44:59 GMT 1
I dont get collision returned, even though I am sure that the body numbers are right. Do i need to use CollisionCallback ?
Thanks again.
|
|
|
Post by Kjelle69 on Aug 30, 2004 8:12:37 GMT 1
yup. you need a material set for both bodies (you can set them both to the same material if you want), and then call the NewtonMaterialSetCollisionCallback for that material, that's the most important part.
it will only keep track of collisions for bodies that have a material with the CollisionCallback function called for it.
|
|
|
Post by PiratSS2 on Aug 30, 2004 20:52:18 GMT 1
Well, I couldnt get it to work after 1 hour of trying >< I tried everything, but the collision just wasnt there. I actually found another way of working with my bullets by using pos x,y and z from Darkbasic. commands. This gave me flawless control over my terrain, and elimentaed the "fast objects" bug.
Thank you for trying to help me.
|
|
|
Post by Kjelle69 on Aug 31, 2004 1:05:50 GMT 1
if you are shooting small objects REALLY fast, Newton will miss the collision. it's an issue that's been discussed on the Newton forums quite a bit... glad you found a workaround
|
|
|
Post by PiratSS2 on Sept 2, 2004 1:44:36 GMT 1
if you are shooting small objects REALLY fast, Newton will miss the collision. it's an issue that's been discussed on the Newton forums quite a bit... glad you found a workaround While we are on topic, what would be considered a small object, and what speed is fast I could use this data to make my level smaller because I usually shoot object with speed of 800.
|
|
|
Post by Kjelle69 on Sept 2, 2004 4:05:39 GMT 1
if an object is movinge more than half it's size in a single frame, collision can possibly be missed. a speed of 800 could be really fast or completely reasonable, depending on the scale of your world. if you want to send me some example code from your project, I'll see if it's a code problem or a Newton problem.
|
|
|
Post by PiratSS2 on Sept 2, 2004 4:35:29 GMT 1
if an object is movinge more than half it's size in a single frame, collision can possibly be missed. a speed of 800 could be really fast or completely reasonable, depending on the scale of your world. if you want to send me some example code from your project, I'll see if it's a code problem or a Newton problem. I have actually decided to scale down my word by -400%. This could solve some of the bugs I had with newton ^^
|
|
|
Post by Kjelle69 on Sept 2, 2004 5:12:01 GMT 1
your game is a Scorched Earth clone, right? so I seriously doubt the projectiles are moving too fast for Newton to detect collision... it's probably a simple mistake in the code or the setup of the rigid bodies...
let me know how it goes after you adjust the scale!
|
|
|
Post by omnxae on Aug 22, 2008 6:18:50 GMT 1
|
|