Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 2d object collision

Author
Message
mmmpie
19
Years of Service
User Offline
Joined: 18th Apr 2006
Location:
Posted: 24th Apr 2006 05:02
How do i do 2D object collision so when a circle you control hits a square it will not go throuh it. I think it has to do with sotoring an restoring old position but im not shure.
General Sephiro
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location:
Posted: 24th Apr 2006 20:11 Edited at: 24th Apr 2006 20:12
basic layout

You have the position of the character(a.k.a. circle)

Then a square that you do not want the circle to go through


The Theory Behind it
`----------------------------------------
Get position of the box and width by bredth
For example the box is 10 x 10

If Circle position goes into the box's square within the 10 x 10 field then position the circle back to where it was before it was moved.


Some Example code


zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Apr 2006 20:28 Edited at: 24th Apr 2006 20:38
use sprites.

Pay close attention to the difference between sprite hitand sprite collisioncommands.

Which one you use will depend on how accurate the collision needs to be and how much transparent space is around your circle sprite.

I can't remeber which is which off-hand, but one command will detect the collision of the bounding rectangles of the sprites, the other will take into consideration the transparent portion of a sprite allowing the sprite to overlap until a nontransparent portion collides.

I hope that makes sense to you.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Apr 2006 00:14
There are a few ways as you can see. There are about 5 different ways to do that.

mmmpie
19
Years of Service
User Offline
Joined: 18th Apr 2006
Location:
Posted: 25th Apr 2006 04:27
thanks for the code but could you put the box and circle in to your example script. i cant seem to fit it in right
General Sephiro
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location:
Posted: 27th Apr 2006 03:00 Edited at: 27th Apr 2006 03:05
Edit->> Haha i realise now i used 3d objects.., oh wel same theory behind it. X and Y positions in all....

This is a full working example... i did within 1 minute



You will notice i used 50, instead of 25 for the collistion. As you have to take into account the sphere's size

X_MEN
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 27th Apr 2006 23:27
hope this help


You can do it if you try

Login to post a reply

Server time is: 2025-05-23 15:03:06
Your offset time is: 2025-05-23 15:03:06