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 / align player rotation to terrain?

Author
Message
Mugen Wizardry
User Banned
Posted: 19th Aug 2010 18:50
i've created a vertex code. but am not sure how i should go about this.

i need my player to align to the terrain's rotation.

Landscape(terrainid).ground is my terrain
Object(playerid).id is my player



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 19th Aug 2010 21:28
First of all, I don't understand what you are trying to accomplish.... Please explain better. Second, if you are going to use vertex data, it would be better if you make a memblock outside the loop and reference it within-- this method is faster than locking and unlocking each frame.

The fastest code is the code never written.
Mugen Wizardry
User Banned
Posted: 19th Aug 2010 22:30
if the player goes down the hill, i want the player to rotate with the hill. appearing as if the player is really going down the hill.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 19th Aug 2010 23:48
I think he wants his player to be perpendicular to the slopes of his terrain.

My computer surpasses all the technologies of the day. What computer do I have?

Mugen Wizardry
User Banned
Posted: 20th Aug 2010 00:22
he is absolutely correct. i do

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 20th Aug 2010 01:34
What you're doing is pointless and a waste of effort. What you should really do is use the sparkys collision plugin. Set your terrain up as a complex object, then use the collision system to return the collision normal for the required point on the terrain. That way, you'll be able to point one object exactly on top of the terrain.

My signature is NOT a moderator plaything! Stop changing it!
Dia
21
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 20th Aug 2010 04:03
mugen, try the forum search for such terms as: terrain slope, terrain angle, ground slope, or related. I found about 8 examples in a couple of minutes, some dating back to as far as 2004!

This is not the Sig you are looking for....
Mugen Wizardry
User Banned
Posted: 23rd Aug 2010 15:47
i looked, and none of these examples show how to align the players rotation to the terrain

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 24th Aug 2010 01:33
example
Mugen Wizardry
User Banned
Posted: 27th Aug 2010 19:23
thats good but it only works for this example using this camera. is there any way you could turn these into functions so i can get the right terrain coords no matter which camera and object i'm using for the terrain and player?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 28th Aug 2010 02:23
You can put and use as many players you want (and terrains).
This example is rudimentary but might give you some ideas.
To tailor things to your exact needs you must put some effort at it.
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 02:39
i meant like whats with the frontoffset, backoffset, etc?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 28th Aug 2010 09:39
those data are needed to calculate the correct alignment, each object may have different pivot point and size and those data will vary accordingly.
For instance, if you have a wheel tractor, which rotation point is at the center of the back wheels, the front offset will be different from the rear offset.
see pic
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 15:46
yes but that kinda makes it impossible to use in my game, because i dont know how to calculate those.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2010 16:31
Looking at his code, this:


calculates it for you. Assuming the center of your model is in the middle.

If you're using scale object, try this:



Guns, cinematics, stealth, items and more!
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 16:48
i meant these



I have my own movement system and camera system. i dont want to use this 1. but the above variables are forcing me to.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Dia
21
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 28th Aug 2010 17:36
I think the problem with trying to use vertex code to adjust the pitch and roll of the entity is that they will only work out the surface normal data for a particular vertex, NOT for free flowing motion. Thats fine if you have a stop motion entity that moves in discrete steps, jerking from one vertex to another, but not for continuous movement

those 8 lines of code you mentioned above have nothing to do with entity movement, they are purely for working out what angle the entity should be rotated to in order to match the terrain

put simply, the offset positions are used to determine the pitch and bank of the terrain at the object position x,y,z. The offsets are multplied by sin or cos of the entity heading to account for whatever direction the entity is facing.

the pic attacked shows just the bank angle, and the side offsets

basically what is happening is that a virtual right angle triangle is constructed, then we use some triganometry to work out the correct angle, then your model is rotated to that angle

This is not the Sig you are looking for....
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 17:46
i never took trig because i was never given trig.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2010 18:08 Edited at: 28th Aug 2010 18:11
I found a function on my computer (I can't recall who wrote the original, but I remember modifying it quite a bit...) that does it in a different way, only the angles are worked out from the object's origin instead of the opposite side of the car. (for example, the side angle is worked out from the center of the car to the right side, not from the left side to the right side). This makes the function a little inaccurate (especially when going in reverse and moving left), but hopefully it won't matter too much. Here's the function. All you have to do is write TiltObjectToTerrain( terrainID, object ) and you're done.

While everyone appreciates functions that they can just plug into their game, I really do recommend that you try to understand what it's doing. It will help you down the road, and you'll be able to modify the code you use to suit your own needs.

What Dia said is correct. I suggest you read that post and look at the picture carefully. It requires some basic knowledge of trigonometry though.


Anyway here's the function. "Terrain" and "Object" are both object numbers. "Object" is the object that you want to tilt, and "Terrain" is the terrain that you want to tilt it to.

The object rotates around limb 0, so its movement angles will not be affected. Play around with the stepv variable if you need. And I don't believe the offset# variable is doing anything in there now that I look at the code again...




EDIT: Ah, you haven't taken trig yet. That's understandable. There's always online sources though! You can always teach yourself the basics of SIN, COS and TAN, assuming you've seen a right triangle before. If you want me to draw a simple picture for you then I can...


Guns, cinematics, stealth, items and more!
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 21:12
ok. this wont work. it wont rotate my player.

i used ur code and it didnt work.

then i tried this:



and it didnt work.

i called it in the do loop


terrain is a global integer i use like this:



and Object(playerid).id is a UDT array I use like this:



thanks!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2010 21:57
You just made a global variable with the same name as one of the function's local variables, which MIGHT confusing the function.

What happened to this:

Quote: "Landscape(terrainid).ground is my terrain"


Try naming your "terrain" variable something else, OR try changing the "terrain" variable in the function to something else.

Ok, I just tested the global variable thing and it seems like you can have global and local variables of the same name. I don't know what's wrong, could you post more of your loop code than that? What model are you using for your player? If the object is person-shaped (meaning it's tall and now very long or wide) then you should probably change this line in the function
to this
or something. If this variable "stepv" is zero or really close to zero then the code won't work properly.


Guns, cinematics, stealth, items and more!
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 22:01
i changed it. Landscape(terrainid).ground is NOT my id anymore. its terrain.

it is a person model.

here's my code:



world.dba:



thanks!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2010 22:16 Edited at: 28th Aug 2010 22:23
Looking at your code, it's not going to work if you use ROTATE OBJECT, because you reset the rotation of the object every loop (see the last line):



Try making the change that I mentioned in my above post and putting your TiltObjectToTerrain(terrain,Object(playerid).id) function call near the end of your loop. If your object starts moving off in random directions when you try to walk, try putting the ROTATE OBJECT in the function back to ROTATE LIMB.


Guns, cinematics, stealth, items and more!
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 22:30
ok NOT working.



Can u show me a small example of how to use it?

thanks!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2010 22:35
Sure. Download Scorpyo's example and replace his code with this:



You might want to make the change that I mentioned 2 posts ago for your game though. I just replaced his playergroundalign part with a function call...


Guns, cinematics, stealth, items and more!
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 22:45
you know what? can u make this function work with blitz terrains? that might be the problem

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2010 23:20
Here:



I fixed a few bugs in it as well. It should work. If not, then I don't know what to do.


Guns, cinematics, stealth, items and more!
Mugen Wizardry
User Banned
Posted: 28th Aug 2010 23:57
it works.

thanks!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Mugen Wizardry
User Banned
Posted: 29th Aug 2010 06:57
ok. now 1 more small question. how can i interpolate this so that when my character follows the terrain, it does it slowly so that way when it animates, it will look like its walking up the hill?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 29th Aug 2010 11:06
Few observations:

For biped characters, following the terrain is normally resolved via animation set, therefore usually what you need is only the ground height, because biped tend to stay vertical whatever the slope.
( see pic).

For vehicles or 4-leg characters you will have to use the ground align function as proposed.

As to your last question, you must link the character speed to the ahead terrain slope ( see pic again), and link the animation speed to the player speed.

cheers
Mugen Wizardry
User Banned
Posted: 29th Aug 2010 15:54
again, that is way too difficult. i was never given trig -.-

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Dia
21
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 29th Aug 2010 16:15
if you weren't 'given' trig, then maybe you will have to go out and learn a little bit 'for yourself', otherwise a LOT of 3D graphics programming will not make a lot of sense to you

I can suggest Dave's Short Course as a good starter

This is not the Sig you are looking for....
Mugen Wizardry
User Banned
Posted: 29th Aug 2010 16:57 Edited at: 29th Aug 2010 16:58
@sixty, how would i interpolate this?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 29th Aug 2010 18:14
'Sixty Squares', your little function is really awesome, smaller and less computing is needed than in my own, and you don't even use a second, "pivot" object for the Y axis. Really nice!

However, on "critical" slopes the Y rotation loves to be distorted at some point up to around ~20 degrees!... at least for me. Working on it hard, but if you have the solution or any suggestions, don't hold it back please!
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 29th Aug 2010 19:08
aha... i may know what's freaking me out with this terrain angle calculation! The 4 sampling point at the four sides of the object keeps distorting as it rotates on the matrix! (i use a hidden matrix behind the scenes to get height data faster than the "intersect object" command would do from an otherwise object based pre-modeled terrain in 3dsMax)

Per every 90 degrees it's perfect, but between it gets worse and at 45 degrees, 135, 225 and 315, the four points become two pairs, with each pair nearly at the same position. Also important thing, that on a flat surface it works perfectly. So the higher the slope, it gets more and more F-d up.

I guess this has something to do with the fact that the height values are called from totally above, and not with the actual normal of the matrix's tile in mind, the object is standing on.

I'm working on maybe distorting the position of the sampling points (or maybe everything i ever place on a matrix) according to the slope angle, but please if somebody knows a solution let me know!
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 31st Aug 2010 05:19
@Mugen Wizardry: I don't understand...

@Quel: Thanks, I believe it's based on another piece of code I found but I can't remember .

The function is a bit inaccurate at times. I tried to make it get the heights from the back/front and left/right of the car thinking it might improve things, but they just got worse . You bring up an interesting point though, maybe finding the normals could give a more accurate result than the inverse tangent calculations that are in place now.


Guns, cinematics, stealth, items and more!

Login to post a reply

Server time is: 2026-06-09 22:27:07
Your offset time is: 2026-06-09 22:27:07