Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Featured Threads
  inspiration alert!!!
(37 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies) Members Gallery
(516 replies)
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

[MAXScript] Aligning object to surface normal with maintained Z rotation
show user profile  Nanne
So there is a bug in CAT that doesn't let you assign a GroundNode for the footsteps via MAXScript. Everything else is working so the footsteps are being created along the path the character should be walking.

So I have to align the footsteps myself with MAXScript. I'm using intersectRay to get the surface normal of the ground mesh where the footsteps are. Mind you that the footsteps are already in the right place, except for the Z position and the direction of the footsteps are correct so it's just the X and Y rotation of the footsteps that needs to be changed in order to align to the slop of the ground mesh.

At first I simply used the intersectionRay Direction vector and assigned it to the footsteps Direction property, and it works for the X and Y rotation but the Z rotation gets messed up and almost randomized. So how do I set the rotation but maintaining the direction of the (Z-rotation) of the footsteps?

But there is another problem... the pivot of the footsteps does not match the world coortinate system. Y is forward, X is up and Z points towards left. Compared to Max's world space where Y is forward but X is pointing right and Z of course is up.

So I have to get the surface normal of the mesh and then convert that vector into rotations so that I can assign that rotation to the footsteps but without changing the Z rotation, and also do the axis convertion to account for the strange pivot point in the footsteps.

How can I do this? :)

Kristoffer Helander
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 260 times
10/10/2017 5:12:15 PM (last edit: 10/10/2017 5:12:15 PM)
show user profile  Sir_Manfred
To do the axis conversion, I think you just need to add or subtract 90 degrees of rotation around the Y-axis.

Visit my Portfolio

read 256 times
10/10/2017 5:26:06 PM (last edit: 10/10/2017 5:28:59 PM)
show user profile  Sir_Manfred
Like... if you store the surface normal rotation and before applying it to the foot you modify the Y-rotation so it matches the foots orientation.

Visit my Portfolio

read 252 times
10/10/2017 5:30:01 PM (last edit: 10/10/2017 5:30:01 PM)
show user profile  ScotlandDave
I'm just guessing here but as your footsteps are in the correct position already you may be casting your rays down from exactly where the hitpoint/intersection occur - which might cause the random rotation on one axis - try casting your rays from slightly above the footstep positions..

Website | Blog | Contact | Vimeo

read 236 times
10/10/2017 7:47:07 PM (last edit: 10/10/2017 7:47:07 PM)
show user profile  Nanne
@Sir_Manfred: Yes, that sounds like a good idea, but it doesn't work, I've been trying rotating it on all kinds of axels but the rotation just ends up looking random :P

@ScotlandDave: Yes, I'm taking the footsteps position for X and Y but I'm using 1000 for the Z value.

Here's the full script by the way:

navMesh = $'Plane001'

--Bobo's function:
fn GetAngleFromNormal theNormal =
local theZ = normalize theNormal
if (dot theZ [0,0,1]) > 0.99999 then
eulerangles 0 0 0
local theY = normalize (cross [0,0,1] theZ )
local theX = normalize (cross theY theZ)
local theTM = matrix3 theX theY theZ [0,0,0]
theTM.rotationpart as eulerangles

allPrints = $*Print*

for p in allPrints do
pR = ray [p.pos.x, p.pos.y, 1000] [0, 0, -1]
pInt = intersectRay navMesh pR
if pInt != undefined do
p.pos = pInt.pos
nRot = GetAngleFromNormal pInt.dir
in coordsys local p.rotation = eulerToQuat nRot
-- Move timeslider in order to update CAT
sliderTime = 0
sliderTime = 1
sliderTime = 0

Kristoffer Helander
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 222 times
10/11/2017 9:36:48 AM (last edit: 10/11/2017 9:36:48 AM)
show user profile  ScotlandDave
If the other axis rotations are working except for z can't you just grab the local z axis rotation to a variable before doing all the matrix stuff and then re-assign that rotation back onto the footprint after the other stuff is done..

Website | Blog | Contact | Vimeo

read 203 times
10/11/2017 5:29:49 PM (last edit: 10/11/2017 5:30:14 PM)
#Maxforums IRC
Open chat window