Archived

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

Jerico2day

Math Collision

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

Share this post


Link to post
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# < 32
x# = ox#
z# = oz#
ENDIF
RETURN




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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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^_^)

Share this post


Link to post
Share on other sites
Well, its not pseudo code. Its a language called DarkBASIC, works alot like basic, but made for 3d(Im making a 2d rpg)!! Very simple and easy to use, tho not nearly as powerful as c++. If u want check it out goto www.darkbasic.com

Share this post


Link to post
Share on other sites
So that''s what DarkBASIC looks like! Too similar to BASIC and FORTRAN for me, thankyouverymuchI''llnevertouchthestuffnotevenifyouofferedmeamilliondollars.

DekuTree64: moving a pixel at a time is horrendously inefficient, unless you know that you will always have that many redundant cycles. Instead, calculate when your object would collide with any other object (in terms of frames) and move it until then.

Share this post


Link to post
Share on other sites