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 / collision box problem

Author
Message
clay384718
8
Years of Service
User Offline
Joined: 28th Jan 2011
Location:
Posted: 28th Jan 2011 18:49
im having trouble getting this collision box set can anyone help me?

make object box 17, 100,20,100 : position object 17,10,500,500 make object collision box 17, -40,490,450,60,510,550,0
set object collision on 17
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Jan 2011 12:30 Edited at: 30th Jan 2011 12:30
I'm pretty sure the position of the collision box is relative to the host object, so positioning it at 490 on the x axis is actually 490 away from the object, not 490 from 0.
Alternatively you could just use (the ## is just to show this is code)

## set object collision to boxes 17

DB (Dark Basic) would then stick a collision box around your object for you.


Everything worthwhile requires effort.
TheComet
11
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Jan 2011 22:26
make object collision box is relative to the object, the position of the object doesn't matter, it's the size:

make object collision box 17,-50,-10,-50,50,10,50,0

Best thing to do is either make a function:



or go with what Obese said

TheComet

Latch
13
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Jan 2011 00:47
@TheComet
I could kick myself for not making a function like that years ago! Very smart!

And a note to all:
Creating a collision box with make object collision box results in MUCH MUCH faster collision testing than set object collision to boxes. The thing to keep in mind is, collision using make object collision box can only be tested against other objects that are using the same.

Set object collision to boxes, however, will test against set object collision to boxes, set object collision to shperes, and set object collision to polygons.

Enjoy your day.
Junebug
8
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 31st Jan 2011 18:45
I'm in the same class as Clay, infact I sit right next to him, and he just tried what Obese said, and it didn't work, and then he tried the function and that didn't work.
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Jan 2011 19:42
@Junebug & Clay (sounds like a cartoon lol)
How doesn't it work? What happens when you run the program?
I can't see any problems with either suggestion.
You're probably either using the wrong object number or something else entirely unrelated to this that is causing the problem.


Everything worthwhile requires effort.
Junebug
8
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 31st Jan 2011 20:05 Edited at: 31st Jan 2011 22:14
so he copied the code for your suggestion:

##make object box 17, 100,20,100 : position object 17,10,500,500
##set object collision to boxes 17

tried it, and that didn't work, then he tried the function:

Edit:
##make object box 17,100,20,100 : position object 17,10,500,500
##function MakeObjectCollisionBox(17,0)

## rem get object's size
## sx#=object size x(17)/2.0
## sy#=object size y(17)/2.0
## sz#=object size z(17)/2.0

## rem make the collision box
## make object collision box obj,0-sx#,0-sy#,0-sz#,sx#,sy#,sz#,0

##endfunction

that also didn't work
Latch
13
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Jan 2011 20:09
When you create an object collision box, you are surrounding the object with an invisible boundary in the shape of a box. When you make an object, it is positioned in 3D space at X,Y,Z location (0,0,0) . Generally, an object's center is also at (0,0,0) .

You want to be sure that the invisible boundary (the collision box) is around the entire object. To create it, always create it from the lowest values to the highest values. At creation or loading, objects face into the screen - that means they face in the +Z direction. The back of the object is pointing towards you. Therefore, to make a collision box from the lowest point to the highest, the lowest point is zero minus half of the size of the object and the highest point is zero plus half of the size of the object. That is what TheComets functions is doing:



Quote: "I'm in the same class as Clay, infact I sit right next to him, and he just tried what Obese said, and it didn't work, and then he tried the function and that didn't work."


Usually, a collision box is set up once, when the object is created or loaded. Once the collision box is setup, as I mentioned in a post above, an object using MAKE OBJECT COLLISION BOX can only detect collision with another object that has collision set up using MAKE OBJECT COLLISION BOX

Here's a quick example using TheComet's function:



Enjoy your day.
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Jan 2011 23:54
@Junebug
You still haven't shown us how you are testing collisions. That is going to be the cause of your problem, there aren't any problems with comet's code.

PS if you want to put code in a code snippet box highlight the text and click the code button, or type {code}code goes in here{/code} except with square brackets.


Everything worthwhile requires effort.
Junebug
8
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 1st Feb 2011 18:36
Quote: "You still haven't shown us how you are testing collisions. That is going to be the cause of your problem, there aren't any problems with comet's code."


what do you mean testing the collisions? We're running the game and seeing if the object we are controlling in the game can go through the object in question. How else would we test them?

PS I already knew that
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Feb 2011 20:58
Well this is what I'm trying to explain. You have to use the command OBJECT COLLISION() to test for collisions between objects, objects are not automatically solid and impassable when you turn collision on, you need to check if the objects are overlapping (collision) and then decide what to do about it to simulate a solid object.


Everything worthwhile requires effort.
Junebug
8
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 1st Feb 2011 22:37
oh alright, could you possibly give me something I could try in my code to make that happen? I'm still confused how to use the OBJECT COLLISION()
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Feb 2011 01:08 Edited at: 2nd Feb 2011 01:11
OBJECT COLLISION(Object P, Object R)

(P and R get replaced with whatever object numbers you are using).
This command will return 1 (true) if objects P and R are colliding (their meshes intersect) or 0 if there is no collision between them.

Alternatively you could leave object R undefined by entering 0 instead of an object number (0 cannot be used to reference an object or any other entity), this changes the behaviour and output of the command, it will test object P against all existing objects and if it finds a collision it will return the number of the object that is colliding with object P.

If there is no collision between the two objects on one iteration (run through the code in the program loop), but on the next iteration a collision is detected, something must have happened in between the two collision tests to produce a collision. Namely, one or both of the objects must have moved.

To produce the illusion of solid objects you obviously cannot allow them to pass through each other, so you must reverse the last movement to place the object back to where it was before the collision.

Also you mustn't allow objects to move long distances in one step, otherwise they could pass straight through other "solid" objects before collision is tested on the next loop. If you want objects to move fast you must find some way of checking the space in between the two points for collisions; you could position the object closer and closer to its target checking that the path is valid or use another object that is stretched to cover the entire path and check that for collisions with other objects. There are many methods as there are for any programming task.

I'm a bit tired to give an example but I hope that explanations helps.


Everything worthwhile requires effort.
Junebug
8
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 2nd Feb 2011 05:23
Right on, thank you.. So, how would I make it reverse the last move so it doesn't pass through the object? I can't just set it to go back a specific way, it has to go back the way it came from, so how do I do that? Answer it tomorrow, it's cool
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Feb 2011 19:44
Here is an example of the object collision command in action.
At the moment the program doesn't do anything about the collision, it just tells you when the two cubes are colliding.

There are a couple of things in there that you might not have seen before, such as arrays and sin().
I used sine to position the object because it has a nice trait of going back and forth from 1 to -1 when you give it an increasing number. Have you done trigonometry in maths class? Don't worry if you haven't got a clue about sine and cosine, they are still very useful for many things even if you don't understand the maths behind them, I don't think I've ever used tangent though.

I also used sine because I want to test you
I want to see if you can make cube one stop when it hits cube two.
If I'd been using regular numbers to position the cube you could have just subtracted the last movement when a collision was detected, but that is a bit trickier with sine and not the best way to do it anyway.


Everything worthwhile requires effort.
Junebug
8
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 3rd Feb 2011 05:04 Edited at: 3rd Feb 2011 18:52
Quote: "I also used sine because I want to test you
I want to see if you can make cube one stop when it hits cube two."

oh dear lol, well I'll certainly try my best, thanks for the help

The thing I want to use this code with is

so can you tell me how to implement that into the code you gave me?
Garfed
8
Years of Service
User Offline
Joined: 13th Apr 2011
Location:
Posted: 14th Apr 2011 04:23
Ich derzeit ne-Schule Training für chemisch-technische Assistentin bin, bin ich bereits im 2. Lehrjahr, und dieses Jahr bin ich auch die abschließenden Prüfungen...

Attachments

Login to view attachments
TheComet
11
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Apr 2011 16:36
ehm... Was hat das mit diesem Thema zu tun? Ausserdem ist deine Grammatik ziemlich schlecht, und wir reden in diesem Forum nur Englisch

Ich bin auch im 2. Lehrjar als Elektroniker, ich freu mich überhaupt nicht auf meine Teilprüfungen. Mein Beileid

TheComet

Login to post a reply

Server time is: 2019-08-19 21:55:22
Your offset time is: 2019-08-19 21:55:22