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 Professional Discussion / Cube collision problem

Author
Message
Yellow Star
14
Years of Service
User Offline
Joined: 22nd Mar 2012
Location:
Posted: 27th May 2012 23:01


I'm using Sparky's for collision, and I want to collide with the platforms properly. I'd like to know how to do this with a cube instead of the sphereslide command that's usually used.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th May 2012 11:22
The following is all done without compiling, so I can't assure you it will actually work.

First off, I modified your jump() function to use a parabola instead of that "triangle jump". It feels much more natural:



And here's a collision function added in your main loop:



I hope that was useful If the collision part doesn't do what it's supposed to try replacing dec Main.X , SC_GetStaticCollisionX() with Main.X = SC_GetStaticCollisionX() etc.

I remember reading that SC_ObjectCollision() wouldn't do any actual return value calculations, so it could be that nothing at all happens.

TheComet

Yellow Star
14
Years of Service
User Offline
Joined: 22nd Mar 2012
Location:
Posted: 29th May 2012 22:02
Thanks for the help, the collision doesn't seem to work.

I stop from falling and can jump when I land on platforms, but it causes my character to sink quicksand style. And there doesn't seem to be any horizontal collision.

However, the jumping physics are much better.
Yellow Star
14
Years of Service
User Offline
Joined: 22nd Mar 2012
Location:
Posted: 8th Jun 2012 15:31
Bump
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 8th Jun 2012 21:26 Edited at: 8th Jun 2012 22:55
I'll post some more here in a minute, but the first thing I noticed is that when you are declaring a float, you are declaring it like: X as float You will need to put a pound(#) symbol after the variable name in order for it to be a float. X# as float Won't make too much of a difference, but still something you should be aware of. more to come.

TheComet got you on track, but I'm going to go in a little more detail on your original code:

First thing to realize when doing collision is that you will need to store the original X, Y, & Z of the object before it moves. I generally set these variables up as global, or inside of a type.You are doing this, but not in a way that is going to have an effect. The steps would be like this:

1. Store oldX#, oldy#, oldz#
2. Move object
3. SC_UpdateCollision
4. If collision occurs move object back to oldX#, oldy#, oldz#

I'll post an update to your code in just a moment....

EDIT: Had to eat some lunch!

Alright. I changed your code quite a bit, but I commented it with some info. It's probably not the most elegant way of doing it, but it works, and hopefully it'll make sense enough for you to work with and expand upon.



Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.

Login to post a reply

Server time is: 2026-07-07 21:09:57
Your offset time is: 2026-07-07 21:09:57