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 / Get slope of terrain

Author
Message
david w
20
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 24th May 2012 21:27
What I want to do is get the slope of the terrain.

My idea was to take two samples within a radius and then subtract the two to get the difference. Then use this value to rotate a grass plain so that it lines up with the surface of the terrain.

Does anyone have any ideas how to make this work? Thanks.
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 24th May 2012 22:55
I don't quite remember right now, but I think Sparky's Collision has some type of raycasting to check angles of a surface. Not at my computer right now, but it might be a decent lead. Unless someone else gets to it, ill try to get something together when I get home later.

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.
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 24th May 2012 23:35
there's lots of topics about that on the forum, you just need to do a little search

Here's one code snippet


david w
20
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 24th May 2012 23:45
I did try to search, but it didn't return any relevant results. Thank you for the example.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 24th May 2012 23:47 Edited at: 24th May 2012 23:52
Here you go.



The player (or whatever object you want to tilt) uses a core object to which it is glued. This is so the x and z angles aren't screwed up when you rotate it on the y axis. Here you can see that I handle xz rotations separately from y rotations:



TheComet

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 25th May 2012 12:36
Hi there....it looks like a challenge here we go with a sample for a matrix terrain or Advance terrain...no Sparky`s



Cheers.

I'm not a grumpy grandpa
david w
20
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 25th May 2012 21:26
These are all really great samples, and I have learned from them. The more I looking into my problem I realize that I am not going to be able to rely on helper objects, or any external DLL's like sparkys, only built in commands.

My new idea is to use the get ground height function, and then get the polygon/face that is intersected and then somehow try to work out the angle based upon the positions or face normals returned.

If this is not possible can someone post that its not and if it is does anyone know the procedue to make this idea possible.

Thank you.
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 25th May 2012 22:02
you'd be more realistic by "slightly" randomly inclining along the vertical.
Plants feel gravity and almost always grow up straight regardless of terrain slope
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 25th May 2012 22:17 Edited at: 25th May 2012 22:19
Otherwise:
(loading carries the object number, terrain is object number 1))

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th May 2012 02:11
Well I've modified my example to not use a dummy object as you requested. I suggest you download sparky's, as it's at least a hundred times faster than any DBP collision commands.



I use limb 0 instead.

I'm waiting for someone to come along and solve it using EZrotate or something.

Give me a few minutes, and I'll code an example for you using only get ground height() if you really don't want to use sparky's.

TheComet

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th May 2012 02:53
Where did theory go wrong... Why doesn't this work? Can anyone help?



TheComet

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th May 2012 03:56
Quote: "Where did theory go wrong... Why doesn't this work? Can anyone help?"


Yeah...mmm it's driving me crazy....I can't see whats wrong...usually a minor error but I don't see it.

I'm not a grumpy grandpa
david w
20
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 26th May 2012 06:37
I changed it to this and it seems to work/follow the terrain correctly.



I don't know why its not working like you think but does this work as intended when you take those checks out?
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th May 2012 12:40 Edited at: 26th May 2012 12:42
Quote: "I changed it to this and it seems to work/follow the terrain correctly."


Not really ...it doesn't move as smooth as the Sparky's example. There is something strange that makes it shaky. There are several ways to achieve this effect....this is not a criticism, as the other example of TheComet works great, but in my example, I compare player height with just two more points (left and front), as presumably if we check at left and this point is lower than player then I roll object left (player height - left_height) ....if it is the case that left check is higher than player, then I roll it to the right....the same for the front checking, if the front is higher than player, I pitch object up and if it is lower I pith object down (in my example I use point objetc to an assistant hidden object). I think that if we make test front back left right, the response of the object would be the same, but maybe that will make it tremble.

Cheers.

I'm not a grumpy grandpa
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th May 2012 13:20 Edited at: 26th May 2012 13:20
Quote: "...it doesn't move as smooth as the Sparky's example. There is something strange that makes it shaky."


Oh that's just because I didn't add the smoothing functions yet.

The problem is that the rotations are correct when the player is moving at Player.angle.y# = 0, but as soon as you start moving in another direction, this happens:



TheComet

Login to post a reply

Server time is: 2026-07-22 00:35:44
Your offset time is: 2026-07-22 00:35:44