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 / maths collision and Sparkys collision demos

Author
Message
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 7th Apr 2012 23:56 Edited at: 8th Apr 2012 00:02
I have two collision demos for you, one using maths and the other using sparky's dll.

Maths demo:

This is a continuation of my previous thread:

http://forum.thegamecreators.com/?m=forum_view&t=167811&b=10
and uses some of the functions.

This demo is in the style of a racing game, where collision with the wall is detected by determining if any vertex is on the other side of the wall compared to the position of the object.



If a collision is detected, as shown in the diagram, the red point is calculated and the object is moved a distance in the x and z direction that is equal to the difference between the vertex and the red point, ie so that the vertex is now placed on the red point.



I've used a simple box for a car but you can use any object you wish. However, I've seen major slow down if there are too many vertices.


Sparky's collision demo:

Now, not having used DBC in a while, I'd forgotten that there aren't any sliding collision commands and then I remembered that the idea came to me because of the above demo.

If you look at the diagram, the dotted line is just a ray cast from the centre of the object to a vertex. Where the ray cast intersects the wall (in the case of sparky's this will be a ploygon), the intersect point can be used in the same way the red point is used in the first demo. I.e. the difference between the point P and the intersecting can be used to simulate sliding. In Sparky's the interest point is the static collision coordinates so is easy to calculate.

So you could do the above demo using Sparky's or for an FPS style game you could place an invisible box around the player. However, the box is only be being used to determine the end point of the ray cast so for FPS collision you can get rid of the box and simply use some maths to calculate the end point of the ray cast.



I've used primative but it will also work for models that are loaded in. There are no ramps in the demo but this will work with ramps. The only problem with ramps is that you get a sort of hopping motion when going down ramps. I also struggled to get this to work with lifts, going up was fine but not coming down. The lift would go down faster than gravity could accelerate the player downward, which it does in the real world but real world gravity in games always seems to fast in games. I suspect that there's an easy way to sort this out.

Anyway, enjoy.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Apr 2012 19:01
That's pretty impressive, this is really going to help me thanks.

WARNING: The above comment may contain sarcasm.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Apr 2012 19:05
Thanks Obese,

These were the last two things I started in DBC before moving to DBP.

They were both intended to end up as proper games but I moved to DBP to create the first person shooter and the race game recently got turned into a 20 line challenge, that sadly doesn't work on DBC due DBC's ropey collision.

Anyway, glad you liked it and that you found it helpful.

Login to post a reply

Server time is: 2024-04-16 23:46:40
Your offset time is: 2024-04-16 23:46:40