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 / Finding the height of an object at a certain point

Author
Message
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 27th Jan 2010 14:49
Heyy again. I'm making a 3D game now just for some experience. I have a castle that came with DB that has a floor around it and so on and one of the goblins. How would I go about finding the height of the castle object at the position of the goblin? I have it walking on it but it only goes down slopes and not up them .

Thanks Malb

Don't make war, make tea.
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 27th Jan 2010 14:57
BY THE WAY!!!! I'm not using pro!! I keep forgetting to mention that!!!

Don't make war, make tea.
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 27th Jan 2010 16:20
Ok, I've basically managed it with this:



Anyone got a better way? It's a bit buggy. Also anyidea on how to diferentiate between horizontal surfaces (Floor) and verticals? (walls)

Don't make war, make tea.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Jan 2010 18:24 Edited at: 27th Jan 2010 18:31
What most people do is use a 'feeler object'. what i mean is have a box(usually) and position it where the player would be when it moved. You would then check collision with the building and get the collision y position. I'm not sure if you can get the height with dbc commands, but you definetly can with sparkys collision dll. If you are doing it for your enemies you won't need one for each enemy. You can just reposition the one you already have.

Edit:

btw this:



Could be simplified to this:



because if without this = 1 it just tests for > 1 and if there isn't any collision in the first place then the loop won't even execute at all.

New Site! Check it out \/
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 27th Jan 2010 19:15 Edited at: 27th Jan 2010 19:21
Yeah I did it like that to begin with but it kept crashing the college computers for some reason .

And about the box thing, I'd been thinking of doing something like that but didn't see how it could figure the height but it will definately come in usefull for checking walls I suppose just trying to figure that out now.

What does this dll do? and where is it??

Thanks =]


Just found it, is it useable on classic though?

Thanks again

Don't make war, make tea.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Jan 2010 22:47
@Malboro J
Check out:

Getting Ground Height

The link talks about 2 methods - feeler object and sparky's (for DBC) . The feeler object method could be modified to speed it up a little bit by using limits and casting an object from the height of the camera or another object straight down until collision to a certain limit.

Let's say you always wanted an object to be 50 units above the terrain. Start out by positioning the object some height you know is above the terrain, then cast an invisible object that is say 10 units large from the start position of the object to place. Run a small loop for a maximum of 100 iterations that moves the invisible object 10 units at a time down (that would be a maximum check to 1000 units below the object). As soon as the cast object collides with something, exit the loop, get the position of the invisible object, and position the placeable object 50 units above it. If the loop finishes and there is no collision, then the height is too high and the placeable object either falls to it's death or you start moving it down after the invisible object has passed 50 units.

Enjoy your day.
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 29th Jan 2010 16:18
Grooowl I used that technique but it really makes the game lag!! And when you fall off something it freezes until the feeler is at the ground height also the jumping is aweful! Also the DLL wont work!!

Don't make war, make tea.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Jan 2010 19:44 Edited at: 29th Jan 2010 19:58
Quote: "Also the DLL wont work!!"


I can only assume that you didn't run through the examples in the Ground Height link because they all work including the ones that use the dll. Or perhaps you have downloaded the wrong dll. There's a link in the above posted link that points directly to the DBC version of sparky's dll.

Quote: "And when you fall off something it freezes until the feeler is at the ground height"


Thus the statement:

Quote: "The feeler object method could be modified to speed it up a little bit by using limits and casting an object from the height of the camera or another object straight down until collision to a certain limit."

You have to account in the programming for the possibility of never reaching the ground and limit how long or far the feeler will check so that you can get out of the loop. If you review the code in the examples, you can see how things are handled and modify them to your needs. Using the dll is much faster than a feeler object. But, with time and trial, one can get the feeler object method to work fairly well.

I'm attaching an example of interior sliding collision that uses the feeler object principal. The collision method is a little different in that I use static collision boxes instead of polygon collision so the collision response is a little faster. The performance depends a lot on screen resolution. You have the option to select your display at the beginning. On my 10 year old machine, single core, AMD, 1.5 ghz , at 800x600x16 the max fps is about 110. @ 1024,768,16 the fps hums along at a steady 60 fps.

@800x600x32 about 70 fps
@1024x768x32 about 25 fps

In contrast, using the polygon collision method and the feeler object, all of the fps are about 5 to 10 fps lower. Not a huge difference, but a difference.

Using Sparky's the FPS were 5 to 10 fps higher. A little bit better. The only problem though is it's easy to fall through cracks using sparky's because it uses ray casting for collision detection.

Anyway, try out the attached exe. Move around with the up and down arrow keys, steer with the mouse. Hold the left mouse button to do a a "feeler" projection straight out in front of the camera. If the feeler collides with a wall, it will display a sphere at the point of impact. When casting the sphere, check the FPS. The closer the wall is, the less of an impact on performance. The further the wall, the more of an impact. But there is a limit to how far the test will go so that the program isn't waiting forever for a feeler test to return.

You'll also notice on the display Custom Line of sight box hit = 1 ; this is the constant test with a feeler and the ground to get height. The display "Camera Y = 101.something" is the approximate collision height. The camera will always try to be 100 units from the ground. The bottom floor starts at 0,0,0 so the initial height tries to be at 100 units.

The feeler method isn't perfect, but it's fairly simple to implement and you can probably tweak it to work how you need. But it definitely takes tweaking!

Here's the attachment:

Enjoy your day.

Attachments

Login to view attachments
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 3rd Feb 2010 15:38
YEYE Got the DLL to work perfectly for the ground height!! How would I go about using this to find a wall?? Gave it a try but it keeps hitting the floor and not letting me move!!

Thanks

Don't make war, make tea.
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 4th Feb 2010 22:15
Ah, used the usual collision test to get wall hits by placing a box around the head.

Thanks again

Don't make war, make tea.

Login to post a reply

Server time is: 2024-04-18 08:30:16
Your offset time is: 2024-04-18 08:30:16