Game Development Community

Tilting Player Over Terrain

by Marcel Boule · in Torque Game Engine · 03/26/2006 (9:26 pm) · 3 replies

Hello.

My character needs to tilt over the terrain as the plane normals under his feet change.
He will only tilt by the X axis, and I know how to calculate the tilt, but in the player class the mRot.x is not used, so despite setting it to the tilt of the terrain my player remains perfectly erect.

How can I get my engine to use my player's X axis or how else can I go about getting the player to tilt?


Thank you.

#2
03/27/2006 (9:01 am)
I wouldn't use that resource though Tim. The problem with it is that the camera also conforms to the terrain, so you get flung all over the place on uneven ground which can be very distracting and nausiating. If we could modify it to only move the character or to NOT conform when in first-person, that would be ideal.
#3
04/06/2006 (7:41 pm)
I took out the camera code and using their other code my character tilts over the terrain exactly how a tank would, so that part is correct.

However, I need my character to tilt only forward and back over the terrain.

I had my own solution, which was to rotate the normal (of the terrain) under my character by the inverse of my character's Z (in other words, face the normal in the direction of my character around the Z), then tilt my horse by the resulting X factor.
It doesn't work, and I think it is partly due to the fact that I don't yet really know how to work with matrices in Torque (something like D3DXMatrixRotationZ() is more straightforward, and works with radians, so I can visualize and execute the math I need fine).



This is the code from the resource:

// ================
Point3F x,y,z;
z = surfaceInfo.normal;
z.normalize();
mat.getColumn(1,&y);
mCross(y,z,&x);
x.normalize();
mCross(z,x,&y);
mat.setColumn(0,x);
mat.setColumn(1,y);
mat.setColumn(2,z);
// ================


This will set my player to conform to all 3 dimensions of the terrain.


Can someone either explain how I would modify this to tilt my character only forward and back with the slope of the terrain, or explain what this is actually doing so I can understand for myself how to manipulate it to my bidding?


From my own understanding:

// Store the normal as a Z vector and normalize it.
z = surfaceInfo.normal;
z.normalize();

// Get the player's Y rotation? Y direction? Why?
mat.getColumn(1,&y);

// Anyway, they take the normal (Z) and the current player's Y and store the cross in X. Again, why?
mCross(y,z,&x);
x.normalize();

// Now they take the normal (Z) and the cross of the normal and the player's Y, and cross those two and overwrite the player's Y with the result.
mCross(z,x,&y);



I understand that crossing two vectors gets a third vector that is perpendicular to both of the crossed vectors but how exactly does that apply here?
What is the logic behind what they are doing?

Any help is appreciated.

Thank you.