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 / Help with collision...again with sparky dll.... woops forgot about it haha

Author
Message
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 16th Dec 2008 02:43 Edited at: 16th Dec 2008 02:55
so i had collision working fine on my fps but now i switched to using Sparky for collision and don't know how to go about it. because before i wasn't using strafing so i could just move it forward or backward during collision depending on witch button is being pressed. but idk how now gr can anyone help?
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 20th Dec 2008 15:39
why do you need to use sparky's?

~QJ
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Dec 2008 19:03
because with sparkys raycasting i don't need a box at the camera position for collision i just don't know how
Dragon Knight
18
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 20th Dec 2008 19:13 Edited at: 20th Dec 2008 19:15
Simple


Thus using the two points you could do the collision, no problem .

As it will detect if it HITS inbetween those two points then collide <> 0

also you can pull back data so for example if it was your bullets you could do a raycast and get back the angle to use for bullet holes. Or perhaps for a vehical crossing terrain?

Anyway hope that helps

----------------------------------
http://www.hybridwolves.co.uk
----------------------------------
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 21st Dec 2008 04:18
ok so what your saying is if collide>0 position object at oldx oldy oldz?
Dragon Knight
18
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 21st Dec 2008 17:13
no, I'm saying if it's not colliding hence me using less than and greater than.

Explanation:
I dunno how the DLL works itself so I'm not sure if the value can turn negative or not, it's good programming practice to program to handle all.

If you make the position oldx oldy oldz , it will make the object / your character stop completely, try looking up spark's slide collision , your character movement shall become FAR more smoother.

and remember you still have to request the collide information e.g. ray casting. That's the part where you will insert all the data.

----------------------------------
http://www.hybridwolves.co.uk
----------------------------------
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 21st Dec 2008 21:09
Wait i just realized something your talking about collision with a object i'm talking about not using a object so it just collides with the camera by using raycasting then if the ray go from the camera to lets say 10 or 25 in front of it hits a object stop the camera from moving. but i can't seem to get it to stop
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 21st Dec 2008 21:11
well accually i got it to stop but only moving forward and backword not strafing pluss it didint work well.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Dec 2008 16:29
Isn't there any documentation on Sparky's?


Goke of the day: I coded an AI replica of Steve Irwin. It crashed because of a string array.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 22nd Dec 2008 17:56
If you are speaking of the stuff that comes with it then yes but none of that was on player collision. i got the X-level thing from the codebase but i don't understand hhow to do his collision. although that was when i first started Sparky so i might have another look at it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Dec 2008 18:34
@Caleb1994

I plan on adding an example of sliding collision to my terrain collision examples, but until I do maybe this info will help.

How sliding collision works is by checking for collision in multiple directions and only adjusting your position according to the direction that is being collided with. The easiest implementation is to check for collision along the z axis anf the x axis of the object or the camera. In the case of Sparky's DLL and first person perspective, you would cast 4 rays all starting from the camera position to the front, to the back, to the left, and to the right. These rays will always be aligned to the world X and Z axes. That means if you could see the rays, wherever the camera was would be a plus sign + .

In this method, the rays don't rotate but are always aligned with the workd x and z. The start position is always from the camera position and the end position is the camera position and some distance from the camera. For example, if I want to cast the forward ray 30 units, that would be +30 on the z axis so if the camera position was (20,10,100) then the end of the ray would be (20,10,130). What about the ray cast to back? Well, that's -30 on the z axis so the end position would be (20,10,70). Left and right?
(-10,10,100) and (50,10,100). Get it?

Now, we test each of these four rays for collision. If there is collision with a particular ray, we move the camera 30 units in the opposite direction from the position that the ray hits. For example, if we are testing the left ray, and it collides with the environment, we retrieve the position where the ray is colliding using getStaticCollisionX() and ADD 30 to that position and move the camera to that position keeping the cameras current Z and Y. We ADD 30 in this case because remeber if we cast the ray to the left or rather, the -x axis, we originally subtract 30 from the camera x to get the end of the ray. If we have collision in that direction, we have to move the opposite way away from the collision so there isn't any more collision.

If you test in each of the 4 directions, then when you collide with x, the Z camera position is still being updated so you would slide along z. If z is colliding then the X position is still being udated so you would slide along x. This works very well for nice rectangular or square environments but may cause a jumping effect when hitting walls and such at 45 degree angles.

Ray casting is great for shooting weapons or testing line of sight. It's not great for collision detection between objects because there is a lot of empty space that the ray does not cover. You can use it for object to object collision and for ground height and environmental collision, but it's very difficult to account for all the posibilities of where collision may occur between objects.

The main key here with strafing and movement in general is not to rotate the ray in whatever direction the camera is facing or moving but to have a set of rays that are cast in set directions.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 22nd Dec 2008 18:52
This is what i figured i had to do but your right it would be weird going into a corner using this method. Whoever made the X-level in the code base got it but it looks really complicated haha well do think i should not use raycasting for collision?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Dec 2008 01:50
Quote: "well do think i should not use raycasting for collision? "

Using Sparky's DLL is still way faster than using DBCs built in collision commands, and you can make it work well for environmental collision with patience and trial and error. So I would say yes. I just wanted to caution you that raycasting has it's limits. And there are collision situations where a simple collision box around a character would be more efficient (too bad the DBC version of Sparky's doesn't test plane to plane or polygon to polygon intersection!) If I remember correctly about the Code Base example, it "spins" the ray around the camera at certain angle increments. The finer the increment, the more rays that are cast around the camera. This helps to close up the gaps in between rays. But, alas, it is also more function calls and collision tests so the trade off is in resource use and processing speed.

Hopefully, I'll stop being lazy and post some example code and a first person demo that strictly uses Sparky's - ramps, stairs, walls, and gunfire collision tests all in use... oh and I should probably throw in an enemy for the update command (never used that actually)

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd Dec 2008 02:28
oh ok i see i didn't know thats what he did in the example that clears up a little and ya that would be very helpful thanks latch
Stig Design Stig Magne
19
Years of Service
User Offline
Joined: 23rd Mar 2006
Location: Norway
Posted: 29th Dec 2008 03:12
ok but how can i do sliding collision with DBC orginal comand`s i have tried the
*Make Object Collision Box (obj),-x,-y,-z,+x,+y,+z,flag
and that woked on the x&z direction`s for sliding collision but then i tried to make another cube that whas rotated 45 degrees Horisontal
and changed the flag to 1 and the collision box disaspeard then i tried the flag as 0 but then the collision box apeard but nott after the rotated cube.
so what can i doo

**StigDesign** cheap 3D Modell Pack`s at www.stigdesign.piczo.com (for Home&Comersial use)soon other aplication`s
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Dec 2008 03:35
dbc's sliding collision is used with set object collision on and set object collision to 'whatever type you want' and then using object collision() command i know you can use make object collision box command but you don't need it
Stig Design Stig Magne
19
Years of Service
User Offline
Joined: 23rd Mar 2006
Location: Norway
Posted: 29th Dec 2008 03:56
ok so your saying that if i use this syntax

make object cube 2,100
scale object 2,100,100,400
position object 2,0,50,400
yrotate object 2,45
set object collision on 2
set object collision to polygons 2

but what more i have tested this before and it didn`t worked

my player object is 1
and it`s position is stored like this
object position x=X#
object position y=Y#
object position z=Z#

**StigDesign** cheap 3D Modell Pack`s at www.stigdesign.piczo.com (for Home&Comersial use)soon other aplication`s
Stig Design Stig Magne
19
Years of Service
User Offline
Joined: 23rd Mar 2006
Location: Norway
Posted: 29th Dec 2008 03:57
ok thank`s so your saying that if i use this syntax

make object cube 2,100
scale object 2,100,100,400
position object 2,0,50,400
yrotate object 2,45
set object collision on 2
set object collision to polygons 2

but what more i have tested this before and it didn`t worked

my player object is 1
and it`s position is stored like this
object position x=X#
object position y=Y#
object position z=Z#

**StigDesign** cheap 3D Modell Pack`s at www.stigdesign.piczo.com (for Home&Comersial use)soon other aplication`s
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Dec 2008 06:00
yes thats how you set up the collision but it's up for you to decide what you want to do with it so after you set it up then you need to have a if statement and say something like:

If object collision(1,2)=1
position object 1,oldX#,oldY#,oldZ#
endif

or you could put a zero instead of a 2 and make it >0 for all objects. and i'm not sure as i havn't used dbc's collision tons because it gave me trouble and i switched to sparky. but i think that you would need set object collision to boxes for a box.

polygon is for like complex objects like if you had a object you loaded in to dark basic like lets say a car then you would use polygon because from what i'v herd it checks for collision with every polygon. i'm not sure if that matters with standard dbc collision commands i know it does with sparky's dll.

hope that helps
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Dec 2008 12:15 Edited at: 29th Dec 2008 12:15
I don`t know if this has been mentioned, but to say "if collide<>0" is much slower than saying "if collide!0".

I ran some tests:

to check "if collide<>0 then a=1" 10000000 times takes 1.512 seconds.
to check "if collide!0 then a=1" 10000000 times takes 1.467 seconds.

So, it is faster to use "!", but doesn`t make a big difference...

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Dec 2008 13:58
Also if testing for true or false, dump the comparison operator(s) altogether:

if collide then a=1

This tests for non-zero values of collide. I clocked it at about 130 percent faster than either of the other 2 methods.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Dec 2008 19:12
The comet:

What does ! do? I'v never seen thaat before?

latch:

ya whoops thats how i do all my stuff but i forgot todo it like tht there sorry
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Dec 2008 19:51
! Is for NOT. So, if collide is NOT 0, then a=1. It is a faster way to check than <>, but you can also just leave it all out and do what Latch said.

TheComet

Peachy, and the Chaos of the Gems

Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Dec 2008 23:24
oh ok i had never seen that before lol thanks that can be very helpful

Login to post a reply

Server time is: 2025-06-07 20:39:55
Your offset time is: 2025-06-07 20:39:55