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 / Why won't this collision testing code work? (No sparkys)

Author
Message
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 5th Aug 2010 04:32
Yeah I have sparkys collision but I didn't use it, I've used this way of collision before and it works perfect (Thanks Hawkblood ) but when my player starts he just does a wierd thing then keeps falling.
This code should work with anyone (I didn't use any media)


Darkbasic Pro 7.4-7.5
Windows Vista

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 5th Aug 2010 09:50
I'm sure you didn't mean to do this:


Not sure why you're not using Sparky's for this... If not for the amazing sliding collision, for the raycasting. Sparky's raycasting is much better than DBPro's.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Aug 2010 19:03
And it's much faster too. It would be very easy to implement into your current code, since the intersect command in sparky's is almost no different.

TheComet

CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 5th Aug 2010 20:04 Edited at: 5th Aug 2010 20:27
ohh!!! Kira thanks I'll edit that now, I was copying and pasting from my other code because this is a test code.
Ok, I didn't want to edit all of my code so I used my old one, there pretty much the same, but test it and you'll see that when you go to the top and try to go left or right it has the collision of a box and I know that thats because of the intersect objects (This is also my code).

Anyway with sparkys do you have to decide where your collisions are (or whatever) like in above or does it do something like view your object and then make collisions (so it's more precise)? If so how would I do that?

For example in my code above making collisions for a box is easy but if you wanted something like a circle I don't think it would be very precise.

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 5th Aug 2010 21:18
I'm not sure what you're asking about Sparky's, but here's an example I threw together for sliding collision using Sparky's.

Test it out, study the code, read the help files for commands you don't understand. If you've done all that and still don't know what's going on, we'll be happy to help.

CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 5th Aug 2010 22:15 Edited at: 6th Aug 2010 01:39
I will try to understand it, and what I mean't was in my code above it has box collision so if the player wasn't a box and but a circle the circle would still have the box collision, can sparkys do precise collision so even if you had something like this it would have precise collision?
EDIT: I just tested that code of yours, it seems to do the exact same thing as mine

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th Aug 2010 02:44
First yours casts axis-aligned rays from each corner of a cube downward, and then casts rays from the center of the cube through the center of each of the four sides for collisions. That leaves a lot of room for collisions to go undetected. Here, I've setup a little scene using your code to highlight the problems. I've placed the player very high up so he'll fall at the beginning. There's a "spike" underneath him that will go undetected, and then there's a crack in the wall ahead that he can walk through. When you run the code, just let the character fall to the ground and after he lands, walk straight forward.

Here it is:

Oh, and I've simply moved the camera placing commands to fix that one-frame-long lag that happens whenever you move.

My code, on the other hand, casts a perfect sphere along the direction of travel, eliminating any of the same problems.

Change line 87 and 88 of my code to this:

to see how the code deals with corners and such.

CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 6th Aug 2010 03:11
Can you recreate that scene using sparkys to show me what difference it makes?

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th Aug 2010 03:32
Quote: "My code, on the other hand, casts a perfect sphere along the direction of travel, eliminating any of the same problems"

...is the difference it makes...

Here it is anyway...


CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 6th Aug 2010 04:27
How would you add jumping to sparkys using that code?
I understood it with the other code, so it's gonna take me a bit to understand this one (hopefully not 70 posts like understanding the first collision...)

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th Aug 2010 04:34
Have you looked? If you look in the movement section of the code, it would appear that the variables XVel#, YVel#, and ZVel# control the velocity of the player. That should be enough info to figure it out. Try some things first and everyone will be more willing to help you.

CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 6th Aug 2010 04:52 Edited at: 6th Aug 2010 05:54
I tried this

in hopes to if you press spacekey and the player is on the ground it will position object 1, 5 places above then activate the gravity. What is wrong with it?

I want coke, not Pepsi!
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 6th Aug 2010 10:33 Edited at: 6th Aug 2010 10:35
I don't understand most of this (pretty much the whole code but i'll point out the main parts, then we can work on the other stuff)


Problem 1

in that code what does SC_setupObject do and with these 2,TerrainGroup,2 what does that mean?

problem 2:

in that, I don't undertand these

could you explain that? I don't really understand any of it.

problem 3, this is a big one:

Pretty much just the way the collision is but i'll point out the main parts in this I don't understand
1.SC_sphereSlideGround
2.TerrainGroup (50-50 understand)
3.SC_getCollisionSlideY()
4.SC_getStaticCollisionY()
5.if abs(SC_getCollisionNormalY())>MaxSlope# (don't get any of that)
6.SC_sphereCastGroup

If anyone could explain those to me (I know it's long) I would VERY much appreciate it. THANKS
If I figure out those 6 things above it should help me alot.


I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 6th Aug 2010 15:19
Sorry I got to the conversation late..... Now that you understand the basics of collisions, you SHOULD go to a .dll like Sparky's. The thing I like about it is that you have more options and more info for collisions.

The fastest code is the code never written.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th Aug 2010 20:45 Edited at: 6th Aug 2010 20:46
@CocaCola: Ah, this is good.
Problem 1:
SC_setupObject has syntax: Object Number, Group Number, and Type of Collision. Basically, it sets up Object Number to be used in collision calculations. The Group Number parameter tells it which group we want to put it in. This isn't really essential, but it makes everything easier to put all of the terrain objects in one group, and then check collision among the entire group. Finally, the Collision Type can have one of three values: 0, 1, and 2 for Polygonal, Sphere, and Box, respectively. Check the help file for more info.

Problem 2:
The keystate function tests for key presses of the key inside the brackets. W, A, S, and D are 17, 30, 31, and 32 respectively. W moves forward, S moves backward, A strafes left, and D strafes right.
How I actually go about doing that is a little more complicated. Right before that section, I set XVel# and ZVel# to 0. These variables are added to the player's position each loop, so they control the player's lateral velocity. The "inc XVel#,Speed#*sin(object angle y(Player)) : inc ZVel#,Speed#*cos(object angle y(Player))" part increases the X and Z velocities a certain amount based on the speed of the player, and the direction the player is facing. I use some simple trig to do this, but you could also use DBPro's newxvalue (and y and z) commands to do that for you. I just prefer the math.
The "dec YVel#,Gravity#" part simply subtracts the acceleration due to gravity from the Y velocity.

Problem 3:
Here, I'll write in a lot of comments to the code:

I hope that helps. If you need clarification on any segment, feel free to ask, but first check the Sparky's DLL help files for how the commands work.

CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 6th Aug 2010 20:46 Edited at: 6th Aug 2010 20:48
Quote: "Sorry I got to the conversation late..... Now that you understand the basics of collisions, you SHOULD go to a .dll like Sparky's. The thing I like about it is that you have more options and more info for collisions."


Ok, thanks I'm trying.

I want coke, not Pepsi!
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 6th Aug 2010 20:51 Edited at: 6th Aug 2010 20:52
doesn't this not work well? (My other way doesn't fix it but this is kind of doing the same thing)

so if I had a player I would have to choose if a box, sphere, or polygonal is best for collision? wouldn't that make it so if you had something like this and you tried to go through the hole where you put your hand you couldn't?

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th Aug 2010 22:14
In my code, I never actually setup the player object (object 1) for collision. This is because there is no need to. When we check for collision between the player and other objects, we don't actually use the player's object. We just create an imaginary sphere around where the player is and use that instead. This is a common misconception for newcomers to Sparky's. The only time we would need to setup the player's object for collision would be if we need to check for collision between other objects and the player (which is different from "the player and other objects"), or when the player is not moving, but other objects are moving toward the player.

If you have complex terrain, you should set that up as polygonal, and actually, it would probably be better to use the SC_setupComplexObject command.

CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 7th Aug 2010 01:10
Quote: "SC_setupComplexObject"

and whats that do?

I want coke, not Pepsi!
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 7th Aug 2010 01:18
It sets up polygon-based collision for an object by using an octree structure to efficiently divide up an object for quicker collision detection. It's useful for objects with high poly counts.

Login to post a reply

Server time is: 2026-07-25 12:05:20
Your offset time is: 2026-07-25 12:05:20