#### Archived

This topic is now archived and is closed to further replies.

# Math Collision

This topic is 6140 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

It was a brilliant idea in theory, but just doesnt work!! Any suggestions (need 2d sliding collision)?? Thanx ox# = old x position oz# = old z position x# = current x position z# = current z position tempX# = current x position --------------------------------- _CHECKCOLLISION: x# = tempX# IF x# > 0 AND x# < 32 AND z# > 0 AND z# < 32 x# = ox# ENDIF IF x# > 0 AND x# < 32 AND z# > 0 AND z# < 32 x# = tempX# z# = oz# ENDIF IF x# > 0 AND x# < 32 AND z# > 0 AND z# < 32 x# = ox# z# = oz# ENDIF RETURN

Anyone?

##### Share on other sites
I'm afraid I can't really tell what you're trying to do from the code snippet posted. The ox#, oz#, x# and z# are fairly clear, but what is your object colliding with, and what should be the response if a collision is found?

At the moment, all three of your if statements appear to be identical so you're really doing:

  _CHECKCOLLISION:x# = tempX#IF x# > 0 AND x# < 32 AND z# > 0 AND z# < 32x# = ox#z# = oz#ENDIFRETURN

Edited by - Enigma on October 25, 2001 1:26:45 PM

##### Share on other sites
ok, ive got a mathamatical box...
ie.
0-----64
|......|
|......|
|......|
64----64

now, my object is at the bottom left side, moving toward and up at the box at 45 degrees. I want it to slide up that left wall,(or top, right, bottom)

Ok? Now what i was trying to do in my little snippet there, was update x first, and if its still colliding, up date z, but put back x, and if still, then update both. This doesnt work! Suggestion? Any other questions?

Edited by - Jerico2day on October 25, 2001 4:17:08 PM

##### Share on other sites
sorry bout the crappy box

##### Share on other sites
At the moment, as far as I can work out, your code is not working because as soon as the object hits the wall it will be constantly moved back to its old position and so won''t slide.

If your box is located at (0, 0) and has size (64, 64) as shown in your diagram then you could try something like:

_CHECKCOLLISION:   // check moving left to right and vice-versa   IF x# > 0 AND x# < 64 AND z# > 0 AND z# < 64      AND (ox# < 0 OR ox# > 64)         x# = ox#   ENDIF   // check moving top to bottom and vice-versa   IF x# > 0 AND x# < 64 AND z# > 0 AND z# < 64      AND (oz# < 0 OR oz# > 64)         z# = oz#   ENDIF   RETURN

I think this should work, but then again having had another look at your old code, I think that should have worked as well!

Give this a try and if it doesn''t work post back - i''d be interested to see what it DOES do!

##### Share on other sites
Holy buckets it works great! Thanks alot! I knew it was simple

##### Share on other sites
Am I missing something here? What language is this? Maybe this is C++ but witha bunch of #defines? Im not a complete newbie...at least I dont I am..... Whats up with all the #s?

Or is this VB?

##### Share on other sites
It''s pseudocode.

##### Share on other sites
Hey, your code looks amazingly similar to my current (not functioning) collision detection...
Except I''m doing a loop where it moves the sprite one pixel at a time on a line toward its new position, so it can''t fly through small things or stop right before it hits the ground.
But it basically does the same thing so maybe this will make it work^^

-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

1. 1
2. 2
3. 3
4. 4
frob
11
5. 5

• 10
• 16
• 13
• 20
• 12
• ### Forum Statistics

• Total Topics
632173
• Total Posts
3004579

×