playMaker

Author Topic: Tilt To Terrain Actions Using Cross Product  (Read 2564 times)

iPetProjectDev

  • Playmaker Newbie
  • *
  • Posts: 23
Tilt To Terrain Actions Using Cross Product
« on: June 02, 2012, 06:11:29 AM »
I had been using two hit points, front and rear, on a quadraped (CharacterController centered on front leg pair)to derive a tilt angle (to tilt the mesh object which is the child of the CC) to conform to front to rear slope using atan(differenceBetweenFrontAndBackHitYaxis) and taking the slope and applying it to the localEulerAngles.x component. It worked awesome going downhill but would do jerks going uphill, conforming at times and at other it's arse way up or feet sunk. I concluded that it was the classic Euler Angle, WTF sign is this dilemma where I am assuming that it gets wonky incrementing as it passes 0 in the negative direction. So I am going to put this function in with the FSM animation controlling stuff.

Here is the outline.
1. I have the forwardDirection Vector3.
2. I have the hit.normal Vector3 derived from a raycast directly below the mesh object pivot.
3. I also have the distance between the front and rear raycast hit points and the height they should be at when idle.

I can get rid of 3 if I use 1 & 2 effectively. Getting rid of Raycasts is a good thing.

I can do this if I figure out how to derive the Cross Product of the forwardDirection Vector3 and the hit.normal Vector3 and apply it to the X axis rotation. In the FSM action there is a Vector Operator that gives me the Cross Product and has two outputs. A Float and a Vector3.

To begin with, does it matter which order the inputs are in?

Secondly, how do you use the output to change just one angle, in this case the X angle. My preliminary test just before crashing was giving me roll on the z axis as well and I do not need that.

TIA
Randy

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Tilt To Terrain Actions Using Cross Product
« Reply #1 on: June 04, 2012, 10:18:49 AM »
Hi,

 yes cross product order does matter:
http://en.wikipedia.org/wiki/Cross_product

As for the z axis roll, simply set it to 0 manually, but not sure it's going to help, as it's going to corrupt your result I feel ( I might be wrong tho, I am not fully following your vector maths :) )

Also, have you tried the quaternion way? it might be more difficult up front, but would likely work on all cases then.

bye,

 Jean