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.

Newcomers DBPro Corner / sliding collision

Author
Message
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 19th Apr 2008 09:13 Edited at: 19th Apr 2008 09:13
I know this has been asked not once, but probably 1000 times, but I want something different from the other topics : all I'm interested in, is how can I have sliding collision in DBPro without using any external DLL, like Sparky or NuclearGlory, etc. I just want someone to explain to me the BASIC idea cause I'll do the rest ... on the internet, there are dozens of tutorials but they only work if you know the normal of the wall you're intersecting and a whole bunch of other mathematical stuff .. but I can't possibly know the normal or the angle, etc. of a wall since my whole level is a single mesh could somebody please explain ??? thanks

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 19th Apr 2008 12:46
Hallo Twinsen, of course that there are a lot of good method and no dll needed. There are a very good one with intersect command but it´s a bit more difficult when we start with collision.

I show you a siple sliding collision method , very basic, and with the minimum cheking to slide in no rotated object.

If you want, I can show you other way to do it nearly perfect

cheers.



oh my god

Attachments

Login to view attachments
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 19th Apr 2008 14:34
Getting the normal of a wall will be very difficult to find without any DLL, however, I made a really nice collision system for my game XBALL a while ago.

I don't have the code to show you (I actually probably do, but it's integrated into the engine), but I can explain the principles.

Basically, you use the intersect object command to cast 3 rays, one in each direction. If you move up, then cast the Y ray up the way (by a factor of your object's size), if you are moving forwards then cast the Z ray forwards. If the X ray has intersected, stop moving in the X direction, same with Y and Z.

Don't you just hate that Zotoaster guy?
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 19th Apr 2008 14:45
hmm by the sound of it, your code just makes the player stop, Zotoaster ... were you referring to sliding collision ? cause I don't get it sorry

Chafari: your example works super but it's kinda hard for me to understand
Zotoaster: could you please explain a little bit more ??? I find your idea quite interesting

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 20th Apr 2008 00:51
Hallo again. The method I normally use is something like Zotoaster one, and if you find the one I showed you above this lines to complicated, the raycasting one is much more hard to understand.

Just imagine this piece of code five times to find out front back left and right posible obstacles around the player....



Believe me ! , we have sometimes to accept dlls as we can reduce time learning, but if you want to learn the <how to>, we have no alternative but to practise the more the best.

don´t give up !! cheers.

oh my god
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 20th Apr 2008 20:56
ok ... I've managed to cast for example 8 rays using INTERSECT OBJECT ... now how would I use them ??? again, I just want the global idea ... the details will be left for my brain

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 20th Apr 2008 22:42
Hallo Twinsen.
Intersect means that something are between the player and the object to check with.

Let see this line.

if INTERSECT OBJECT(esn,x,y,z,x+vol,y,z)>0 then x=x-(vol-INTERSECT OBJECT(esn,x,y,z,x+vol,y,z))

if intersect object(esn,x,y,z

Now wee are checking if something is between escenary,x,y,z

the line follows ,x+vol,y,z

now the ray ends in x+vol (vol means the value of the player radious

It was a check for x coordinate

then....

if intersect object(bla bla)>0 // if it is >0 then the player X, is:

then x=x-(vol- bla bla)

The idea is that we make an invisible ray that start in oldx and ends in newx and if this is the case....so we have to update the player position x .... x=x-(vol-bla bla.


Therefore, if we make four checking rays(front back right and left), we collide(slide like).

With this method we slide on wall and all surfaces, but no collide, as we had better setting all global collision off to avoid lost frames.

I hope you can catch the idea of raycasting ...if not let me know, and i´ll prepare a piece of code demo.

cheers.

oh my god
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 21st Apr 2008 16:25 Edited at: 21st Apr 2008 16:26
Chafari
Your code is great but it acts weird with 45 dgrees rotated walls

no rotation:




45 degrees:

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 21st Apr 2008 18:03
Scorpyo: are those 2 pieces of code your own and working ??? or are they just Chafari's corrected ones ???

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 21st Apr 2008 23:08
Hallo friends. Yep Scorpio...you need some setting and the way it works better, is with the arrows keys, and... any way, we can not apply more speed than the force back to slide on any wall.
Example:
soft=5 //force that push the player off the wall
//this could be the moving
if inkey$()="w" then s#=3
if inkey$()="s" then s#=-3
if scancode()=0 then s#=0 //we have to stop when not pressing any key...like comercial games

and we need as well a soft push out walls. something like this:
collx#=INTERSECT OBJECT(1000,x#,h#+5,z#,x#+20,h#+5,z#)
if collx#>0 then x#=x#-(20-collx#)/soft

Scorpyo
I made some changes to your good code...check if it goes better.

cheers.



oh my god
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 22nd Apr 2008 19:55
I see your codes work great guys but the thing is I still don't understand how you did it ... can you please explain in a few words the logics behind it ??? I don't need codes as I don't understand much of them ( it's hard to figure out what others did inside a code since all variables are illogical for outsiders ) also I never understood how others made a code and always enjoyed making it myself so that's why I just want someone to explain the basis, so I can code it myself thanks

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Apr 2008 22:44
Ok then Twinsen...I,ll help you step by step...but let me know your knowledge about collision.

Do you ever made a siple collision check?:

IF OBJECT COLLISION(MY_OBJECT,0)>0 DO THIS TASK...

Do you understand when we position an object in x,y,z and the case it collide to update the objects coordinates in oldx, oldy, oldz ?


In Dark basic we have the necesary commands to check if one object collision with the rest of objects....so if YES ...we can decide to make it jump, slide, run or whatever we decide.

Time time time ago,I made when just Darkbasic exist, the simplest collision system for my own and I called cross collision.You could slide pretty good in no rotated objects and it works with just two objects one scaled in x axis, and the second one in z axis...so the first check if the player position where colliding in X direccition and second one, check Z direcction...


Collision is a good theme to get crazy, believe me !! ha ha, but when we reach what we look for,it´s like we reach heaven ha ha.

Ohh, I become poetical this night...haha.
Start asking exactly what you don´t understand.


cheers.

oh my god
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 22nd Apr 2008 23:30
Quote: "Scorpyo: are those 2 pieces of code your own and working ??? or are they just Chafari's corrected ones ???"


It's just Chafari's concept used for checking collision in 4 directions from the object ( checkcoll: )

It's brilliant

below I made a graphical 3D example

the routine is casting 4 rays from the center of the object(to 20 units away in this case) to 4 sides (the ray ends where the small spheres are)

when the ray intersects the object wall (i.e. the example sphere touchin the wall) it keeps the player from going any further towards the wall.

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 22nd Apr 2008 23:32
thanks very much Chafari !!! well here's what I know and what I don't :

- so I know how to detect all collisions and everything, so what I want to do is know how to find out WHERE to reposition the player when the collision has occured, so that it appears as if it's sliding ... so when it hits the wall, I want to know how do I find out the spot on that same wall, where I must reposition the player, not letting him pass through ... thanks a lot !!!

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 23rd Apr 2008 23:04
OK Twinsen . What you have to do, if you know how to detect collision, first of all, save the last postion before colliding:

The example I show you here, save just Z position in a variable (lastz=z), and if we collide it`s been update (z=lastz).

Let´s have a look





All object that we create in Dbpro, unless we change position, it is placed in 0,0,0


For the command intersect object(x,y,z,lastx,lasty,lastz), we have the actual x,y,z of the object and the ray start just here....then the rest of coordinates( lastx,lasty,lastz), are the end of the ray


so if we say.... if intersect object (level,x,y,z,x+10,y,z)
it means than we are checking any polygon or object between the starting x ray(player position x) to the end of the ray in x+10


we have here just one check for the x coordinate, and as it is (x plus 10), we check the right side

if we have to check the left side ...is:

if intersect object (level,x,y,z,x-10,y,z)


By the same way, we can make so many rays as we need to determine how to act.


If we check in front:

if intersect object (level,x,y,z,x,y,z+10)>0
and the case, is that it is >0 it means that we are colliding in front...so:

we have to slide in z coordinate...??? HOW ?

well in that case we put something like:



And so on...

Have a look to the first example to get the idea and let see in next tutorial.

cheers.

oh my god
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 25th Apr 2008 00:14
Hallo again...Scorpyo, I didn´t see your settings for the code sorry....it is wonderfull endeed...I knew it slide nearly perfect, but I`d never saw the good representation you did with those little balls...it`s really brillant... I,ll keep your graphical 3D example, thankyou


cheers.

oh my god
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 25th Apr 2008 10:28
chafari, your code works but it seems it won't work for turned objects

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 25th Apr 2008 21:43
well...the example i showed you here, is just that...a example, and it shows you how to update objects when they collide with some other objects.


For rotated objects you will need much more ...but I did´nt want to confuse you with a big code.

Now if you have anderstood the example, you can go with SECOND CLASS.

cheers.

oh my god
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 26th Apr 2008 00:37
ahh thanks well just let me analyze this a bit more before moving on thanks a lot, you are a BIG help !!! I'll let you know when I'm ready to move on

Could you help me treat my injured Dino-Fly ?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Apr 2008 00:35
Hallo Twinsen....just checking how to show you a ray tutorial, I made some changes to one of my codes and instead of using ray (intersect object command),I use this time simple boxis to help the collision checking.I know that this method is a little bit old, and perhaps most people should find it useless, but any way for all friend that are looking for some codes easy to understand...here we go.

I hope you like it ...cheers.

No MEDIA needed



oh my god

Login to post a reply

Server time is: 2024-11-25 03:52:42
Your offset time is: 2024-11-25 03:52:42