The following code works.
Rem Project: dynzmix testing
Rem Created: Saturday, February 02, 2013
Rem ***** Main Source File *****
sync on
sync rate 60
autocam off
position camera 4,9,-10
set camera range 1,20000
rem ////////////////// THE AIRPLANE!
rem ************************** WHITE CUBE (airplane body)
rem tail cone
MAKE OBJECT box 9003, 5,3,5
color object 9003,rgb(200,200,200)
position object 9003, 0 , 12.36, -1.25
rem ************************** RED CUBE (vertical tail support)
rem rudder tail
make object box 9004,0.5,3,1
position object 9004, 0, 15.2, -3.31
color object 9004,rgb(255,0,0)
rem rotate object 9004,0,0,-90
rem ************************** TAIL MOVABLE RUDDER
make object box 9026,0.05,3,0.5
color object 9026,rgb(0,80,150)
position object 9026, 0.047, 15.2, -3.3
Offset Limb 9026,0,0,0,-0.4
Fix Object Pivot 9026
//---------------------------------------------------------------------------------
//----------------------------------------- Physics ON ----------------------------
//---------------------------------------------------------------------------------
DYN START
DYN SET PARAMETER 9, 1
DYN SET PARAMETER 39, 1
DYN SET PARAMETER 63, 1
DYN SET PARAMETER 53, 1
DYN SET PARAMETER 52, 1
DYN SET PARAMETER 28, 1
DYN SET PARAMETER 29, 1
DYN SET GRAVITY 0.0, -9.8, 0.0
rem //////////////////////////////////////////////////// TERRAIN
make object box 10000, 14500,10,14500
color object 10000,rgb(96,141,50)
position object 10000,0,0,0
DYN MAKE BOX 10000, 0.0 //Static terreno
rem ------------ PHYSICS AND JOINT FOR AIRPLANE PARTS --------------------
rem ----------------------------------------------------------------------
DYN COOK CONVEX MESH 9003, 5 rem white box
DYN MAKE CONVEX MESH 9003, 5, 0.4
DYN COOK CONVEX MESH 9004, 6 rem red box
DYN MAKE CONVEX MESH 9004, 6, 0.2
DYN MAKE BOX 9026, 0.07 rem MOVABLE RUDDER
DYN SHAPE SET LOC POS 9026,0, 0,0,-0.4
rem JOINTS!
makeJointFixed(1, 9003, 9004)
//-- NOTE: Fixed joint not good, will resist any movement or rotation.
//makeJointFixed(2, 9004, 9026)
//-- NOTE: Hinge joint better, fixed in position but allowed to rotate around a single axis
//-- Also note that the hinge joint function is setup for these objects and is not a generic function
makeJointHinge(2, 9004, 9026)
rem ********************************************************************************
rem ********************************************************************************
rem ******************************** MAIN LOOP *************************************
rem ********************************************************************************
rem ********************************************************************************
DYN SIMULATE rem GO SIMULATION!
DO
DYN FETCH RESULTS
DYN UPDATE
DYN DEBUG RENDER
rem ////////////////////////////////////////////////////////////////////////
rem ////////////////////////////////// MOVING THE RUDDER
rem ////////////////////////////////////////////////////////////////////////
if rightkey() = 1
degrees_rudder# = degrees_rudder# + 0.6
endif
if leftkey() = 1
degrees_rudder# = degrees_rudder# - 0.6
endif
//-- NOTE: Off-setting the local position means you will only get hinge like behaviour by rotating
//-- actor globally. Rotating locally will rotate around the center of the shape which is not what we want.
//DYN SHAPE SET LOC ROT 9026,0, 0,degrees_rudder#,0
DYN SET ROTATION 9026, 0, degrees_rudder#, 0
//-- NOTE: No need to rotate object since dynamic actor will update object automatically.
//rotate object 9026, object angle x(9026),degrees_rudder#,object angle z(9026)
rem DYN SHAPE SET LOC POS 9026,0, 0,0,-0.3
rem //////////////////////////////////////////////////////
rem /////////////////////////////////// MOUSE VIEW
rem //////////////////////////////////////////////////////
DYN SIMULATE rem ---------- FROM HERE CAMERA COMMANDS ETC
gosub mouse_view
sync
loop
DYN FETCH RESULTS
DYN STOP
//-- Fixed jo fixes two actors together as though they are one actor, they will not move
//-- or rotate relative to each other.
function makeJointFixed(jointID, objectA, objectB)
//-- Create descriptor data structure.
DYN MAKE JOINT DESC 1
//-- Locked motion relative to joint position.
DYN JOINT DESC SET MOTION X 1, 0
DYN JOINT DESC SET MOTION Y 1, 0
DYN JOINT DESC SET MOTION Z 1, 0
//-- Locked rotation also.
DYN JOINT DESC SET SWING1 MOTION 1, 0
DYN JOINT DESC SET SWING2 MOTION 1, 0
DYN JOINT DESC SET TWIST MOTION 1, 0
//-- What actors are involved?
DYN JOINT DESC SET ACTOR A 1, objectA
DYN JOINT DESC SET ACTOR B 1, objectB
//-- Must set this after actors have been set.
//-- Location of anchor can be anything for a fixed joint.
DYN JOINT DESC SET GLOBAL ANCHOR 1, 0, 0, 0
DYN JOINT DESC SET GLOBAL AXIS 1, 0, 1, 0
//-- Create joint.
DYN MAKE JOINT jointID, 1
//-- No longer need descriptor.
DYN DELETE JOINT DESC 1
endfunction
//-- Offset global joint position by 0.5(z axis) for our specific objects
//-- This positions our joint correctly
//-- also unlocked one rotation
function makeJointHinge(jointID, objectA, objectB)
//-- Create descriptor data structure.
DYN MAKE JOINT DESC 1
//-- Locked motion relative to joint position.
DYN JOINT DESC SET MOTION X 1, 0
DYN JOINT DESC SET MOTION Y 1, 0
DYN JOINT DESC SET MOTION Z 1, 0
//-- Locked rotation also.
DYN JOINT DESC SET SWING1 MOTION 1, 0
DYN JOINT DESC SET SWING2 MOTION 1, 0
DYN JOINT DESC SET TWIST MOTION 1, 2
//-- What actors are involved?
DYN JOINT DESC SET ACTOR A 1, objectA
DYN JOINT DESC SET ACTOR B 1, objectB
//-- Must set this after actors have been set.
//-- Location of anchor can be anything for a fixed joint.
DYN JOINT DESC SET GLOBAL ANCHOR 1, object position x(objectB), object position y(objectB), object position z(objectB) - 0.5
DYN JOINT DESC SET GLOBAL AXIS 1, 0, 1, 0
//-- Create joint.
DYN MAKE JOINT jointID, 1
//-- No longer need descriptor.
DYN DELETE JOINT DESC 1
endfunction
Function RandReal(IB as float, IT as float)
local out as float
out = (IB*1000)+ rnd((IT-IB)*1000)
out = out/1000.0
EndFunction out
mouse_view:
If keystate(59) = 1 then camera_numb = 0 : set camera range 1,20000 rem F1
IF camera_numb = 0
gosub vista_con_mouse
rem position camera object position x(8999)-6,object position y(8999)+5,object position z(8999)+17
rem point camera object position x(8999),object position y(8999),object position z(8999)
ENDIF
return
vista_con_mouse:
if mouseclick()=1 then cf#=1.5
if mouseclick()=2 then cf#=-1.5
cx#=wrapvalue(cx#+mousemovey()*0.5) rem velocità spostamento laterale mouse
cy#=wrapvalue(cy#+mousemovex()*0.5) rem velocità spostamento verticale mouse
if cx#<=290 and cx#>180 then cx#=290
if cx#>=70 and cx#<=180 then cx#=70
acx#=curveangle(cx#,acx#,5.1) rem inerzia movimento laterale camera
acy#=curveangle(cy#,acy#,5.1) rem inerzia movimento verticale camera
rotate camera acx#,acy#,0
acf#=curvevalue(cf#,acf#,20) rem inerzia movimento avanti/indietro
move camera acf#
cf#=0
return
Just some small changes:
- Changed joint from fixed to hinge
- Rotate actor globally, not locally.
I have put notes in the code. Now you have the joint set up correctly it might be worth looking into joint limits and steering the rudder with the joint motor commands. Rotating the actor yourself is not recommended for a stable simulation although it might be ok for your needs.
Thanks for taking the time to provide clear example of your problem without any media
EDIT:
Rotating actor globally is not an option I'm afraid, you will have to use joint commands or add forces to your rudder to move it.
Problem with setting the global rotation is that it then ignores the rotation of the plane body