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 / Advanced Terrain on a loaded object

Author
Message
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 14th Feb 2009 09:03
Hey guys,

I've got my level all set up as a .DBO file, but i'm having problems with the gravity, simply because checking for collision on the Y axis isn't working. I know that getting the height of terrain/a matrix would make it so much easier for me, but unfortunately i'm not using either of those, i'm using a .DBO object.

I remember there being a way to load an object normally, but have it function as a terrain (using Advanced Terrain), but for the life of me, I can't find where I saw it.

So, does anyone have any suggestions on what todo regarding gravity/movement up and down ladders using a DBO, or the solution to advanced terrain loading a .DBO?

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 14th Feb 2009 15:48
Ok so it looks like the simplest way to do it is cast a raycast from the position of the player directly downwards, and if there's a collision, then get the distance between the player and the point of collision, and then move the player down that specific distance. If a raycast isn't found, then we could assume the player is standing on thin air with nothing below him/her, so we can just drop the object forever.

However... putting that explanation into code has failed me. Any ideas?

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 15th Feb 2009 12:46
You really should look at the Return Float=INTERSECT OBJECT(Object Number, X, Y, Z, ToX, ToY, ToZ)
command, which DBP can do altho v.slowly.

Sparky's free collision .dll is a whole lot better and faster for doing it. and comes with a whole load of examples showing you how to use it.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 15th Feb 2009 12:56
Yeah sparky's is exactly how i've been trying to do it, using the sc_raycast command, but I never manged to figure out how to actually get it working properly for gravity.

Can't find any tutorials on it though sadly...

Jane Doe
17
Years of Service
User Offline
Joined: 29th Jun 2007
Location:
Posted: 16th Feb 2009 08:34
Hi Veron!

Maybe this will give you some ideas.



I hope this helps!

- Jane
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 16th Feb 2009 09:09
Wow Jane, that's amazing, and it seems to work almost perfectly, although, for example, if the player walks up a ladder, they can't walk back down it, they just hover over the top of it.

Also, if the player doesn't start on the ground, they have to press the spacebar to start them falling back to earth.

But thanks a lot for the code, and if you could help explaining those two issues then it would be great.

Jane Doe
17
Years of Service
User Offline
Joined: 29th Jun 2007
Location:
Posted: 17th Feb 2009 09:39
Hi Veron!

The code I posted before was some code I'd used for something or other at some time. I quickly modified it and commented it to give you some ideas about how gravity might work. This code is more suited to your needs. It's media-less, so just copy and paste it into your editor and you're away.

The biggest change is that the gravity procedure is executed every programme cycle (except the first), not just when jumping. That'll take care of falling back to Earth if you don't start on the ground - and is the correct way to do it, anyway. But if you execute the gravity procedure on the first programme cycle, it won’t do it for some reason.

With regard to the ladder, what I'd do is use a "climbing zone" which effectively shields the character from gravity. In the code, the green box represents the ladder. The climbing zone is the ghosted box adjacent to it (in real life, you'd hide it). When the camera is within the bounds of the climbing zone, you can climb up and down without the effect of gravity. If you climb to the top of the ladder and then exit the climbing zone, however, gravity will take over (Ouch!). If the ladder isn't free-standing like this one - that is, it's up against a wall or whatever - your climbing zone would only be on one side of it.

One thing I’d add is that you can’t climb up or down unless you’re facing the ladder. It’s a little hard to climb a ladder with your back to it.

I'm sorry I don't have more time to work on this right now (if you walk under the ramp, you'll pop up on top of it), but you'll get the idea. If you have any other questions, just post them here or e-mail me!



- Jane
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 18th Feb 2009 06:18
Hey,

Wow, thanks a lot for that, it's been extremely helpful, and the comments have helped me actually understand the code rather than just looking, vaguely taking it in, and then forgetting it.

Anyway, it works perfectly.. apart from the fact that when I start in midair, I never end up going all the way down to the ground. I can see that the CameraHeight# is what the player is always descending down to, but the CameraHeight# is, by default, set to 10.0, so the user will always descend to 10.0 with your code, rather than setting the CameraHeight# to the distance of the raycast touching the ground. No idea how to fix that though, since I tried using the GroundHeight# as the value for the CameraHeight#, but had no luck.

Also, what does the code below do, and what effect does the 10000.0 at the beginning have on the overall code? For example, I raised the 100000. to 20000.0, and the object was 10000 feet higher, so does that value also have something to do in determining the height of the ground below?

Quote: "GroundHeight# = 10000.0 - intersect object(mapobj, camera position x(), 10000.0, camera position z(), camera position x(), -10000.0, camera position z())"


Jane Doe
17
Years of Service
User Offline
Joined: 29th Jun 2007
Location:
Posted: 18th Feb 2009 07:45 Edited at: 18th Feb 2009 07:46
Hi, Veron!

I'm sorry. There are always a few ways of doing things and I did some things differently in the second code snippet than in the first. I should have pointed out that going from the first code snippet to the second, I changed the way the hit determination worked. In the first code snippet, a raycast is made from the camera position straight down the distance that the character would fall that programme cycle.

In the second code snippet, the height of the ground and of the ramp are determined at the character's current X/Z location and compared with where the character would fall to this programme cycle as represented by the variable CollisionPointY#. That's the purpose of...

GroundHeight# = 10000.0 - intersect object(GroundObject, camera position x(0), 10000.0, camera position z(0), camera position x(0), -10000.0, camera position z(0))

That's determining the ground height at the camera's current X/Z position. The way it works is a raycast from the point at the camera's X coordinate, Y coordinate 10000.0 and the camera's Z coordinate is made down through the camera's position to the point at the camera's X coordinate, Y coordinate -10000.0 and the camera's Z coordinate. This gives the distance from the point of origin of the raycast to where it intersects with the ground. If you subtract this number from the 10000.0 of the starting point, you get the altitude of the terrain at that point (see diagram).



Something else I introduced in the second code snippet is the variable CameraHeight#. In the first code snippet, the camera went all the way down to ground level. In the second snippet, the camera doesn't go all the way to the ground, just as when you're standing in your kitchen your eyes aren't right down on the linoleum (or whatever). CameraHeight# represents the distance from the bottom of your feet to your eyes. CameraHeight# should be set to 1.5 (metres). If you want multiple postures for your character - standing, crouching, kneeling, prone, whatever - just vary this variable.

I hope this answers your questions. If not, I'll talk to you later!

- Jane

Attachments

Login to view attachments
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 18th Feb 2009 08:05
Thanks a lot for the explanation - again, it's really helpful, especially with the diagram!

Sadly, it still doesn't shed light on why the player is always positioned at the CameraHeight#, which i've now set to 1.5.

Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 18th Feb 2009 13:44
Quote: "position camera 0, camera position x(0), GroundHeight# + CameraHeight#, camera position z(0)"


As jane said, this makes it so that the camera is perfectly at ground height, but as if you were stood up, viewing the terrain...

Btw, could you not just do collision detection, ie object so and so hits second object etc etc, would that work?
Sorry if thats a silly question...
=)

Jane Doe
17
Years of Service
User Offline
Joined: 29th Jun 2007
Location:
Posted: 19th Feb 2009 06:08
Veron,

Quote: "Sadly, it still doesn't shed light on why the player is always positioned at the CameraHeight#, which I've now set to 1.5."


I may have made an incorrect assumption about what you're doing. I assumed that you were doing a first-person perspective programme. If that's the case... When you're standing in your back yard looking around, your eyes aren't at the level of the grass. I don't know how tall you are, but 1.5 metres isn't an unreasonable distance from your eyes to the ground if you're standing upright. That's why I said that if you want different postures for your character, you can change this variable because as you crouch, kneel and lay prone, your eyes get closer to the ground.

If you aren't doing a first-person perspective programme and want the camera actually at ground level, you can either set CameraHeight# to 0.0 or get rid of it all together. The purpose of CameraHeight# is to define the distance from the ground to the camera.

Monk,

Quote: "Btw, could you not just do collision detection, ie object so and so hits second object etc etc, would that work?"


Yes. Actually, both methods that I used above use collision detection, just in a different way. I think what your asking about is the way it's done in the first code snippet I posted. As I said, there's always different ways of doing things.

Have fun boys!

- Jane
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 19th Feb 2009 09:10
Hey Jane,

No, you were correct (sorry for not describing it accurately), I am working on an FPS.

However, I still can't figure why i'm not hitting the ground. I mean, i'll start in the air, and fall a fair bit, but I won't fall to hit the ground, i'll still be hovering over it.

Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 19th Feb 2009 12:51
Quote: "However, I still can't figure why i'm not hitting the ground. I mean, i'll start in the air, and fall a fair bit, but I won't fall to hit the ground, i'll still be hovering over it. "


Thatd be because its stopping when it gets to head height...
You could possible add some code so that it slows down when it gets to head height, not just stop, and then return to head height,and that might make it better for you.

If youre making a fps, why are you falling?

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 19th Feb 2009 13:08
Quote: "If youre making a fps, why are you falling?"


Gravity? Jumping off the edge of a building, for example?

And yeah, it stops when it reaches the head height, but if I change the head height, and I jump off some other object, and land on something with a different height to the first jump, then the head height won't change, leaving the player suspended in mid-air, or underneath the floor.

So I suppose changing the head height would be the thing to do...

Jane Doe
17
Years of Service
User Offline
Joined: 29th Jun 2007
Location:
Posted: 20th Feb 2009 08:06 Edited at: 20th Feb 2009 08:07
Hi Veron!

You may be having issues related to a lack of horizontal collision. I suspect that the problem your experiencing is being caused by reaching the surface when the surface height is between the camera and the point CameraHeight# below the camera, the equivalent of...



The code I've posted thus far has really only dealt with the issues of gravity and climbing, and has kept pretty narrowly to vertical issues. There's a lot more to movement. For example, in the code posted so far, once you jump you can move in mid-air - including changing direction. You need code that records direction and velocity at the time of the jump and which slows that horizontal velocity during the jump. No matter how fast you're going horizontally when your feet leave the ground, if you fall long enough, you'll end up going straight down.

You also need some overhead collision code. In the code I've posted, if you walk under the ramp you snap up on top of it. You need code to check for overhead objects.

In this code, there are platforms that you can jump or step between. The motion walking down the platforms is pretty smooth because the gravity code takes care of the height change, but walking up them, the camera just snaps to the new height. You need to write some code to graduate the height adjustment going up the platforms.



Note that I changed the way the height determinations are done. This is more practical when you have a bunch of them to do.

Keep working at it. Add horizontal collision and address these other issues. I’ve no doubt you’ll have your movement system looking sharp in no time!

- Jane

Attachments

Login to view attachments
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 21st Feb 2009 08:53
Thanks a lot for all that Jane, it seems to be working very close to perfectly! The only problem being that if I walk on the ground, and there's something above me, i'll automatically appear on top of that thing above me.

Other than that though, it works great! Thanks a lot for all your help so far Jane, you've been a lifesaver.

Login to post a reply

Server time is: 2024-11-25 10:43:18
Your offset time is: 2024-11-25 10:43:18