I need to set object rotation of a vehicle to match that of the matrix so it tilts correctly. I get the matrix y value at 4 points around the vehicle location and calculate the tilt angles. How can I set the object angles to match these angles? When I do it the vehicle's orientation varies dependant on the y angle and ends up half submerged.
Here's the code
y#=get ground height(1,x#,z#)+18
ty1#=get ground height(1,x#+10*sin(an#),z#+10*cos(an#))
ty2#=get ground height(1,x#-10*sin(an#),z#-10*cos(an#))
ty3#=get ground height(1,x#+5*sin(wrapvalue(an#+90)),z#+5*cos(wrapvalue(an#+90)))
ty4#=get ground height(1,x#-5*sin(wrapvalue(an#+90)),z#-5*cos(wrapvalue(an#+90)))
position object 11,x#+10*sin(an#),ty1#,z#+10*cos(an#)
position object 12,x#-10*sin(an#),ty2#,z#-10*cos(an#)
position object 13,x#+5*sin(wrapvalue(an#+90)),ty3#,z#+5*cos(wrapvalue(an#+90))
position object 14,x#-5*sin(wrapvalue(an#+90)),ty4#,z#-5*cos(wrapvalue(an#+90))
xan#=atan((ty1#-ty2#)/20)
zan#=atan((ty3#-ty4#)/10)
zrotate object 1,zan#
yrotate object 1,an#
xrotate object 1,0-xan#
position object 1,x#,y#,z#
Any help greatly apreciated.