so far i have compiled code to my atom for a pan and tilt head.
[code];[Head Tracking]
HeadTracking:
;Return to the middle position
HeadPanAngle=0
IF (ABS(TravelLengthX)>TravelDeadZone | ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelRotationY2)>TravelDeadZone) THEN
;Calculate walking direction X and Z
TravelLengthXZ = SQR((TravelLengthX * TravelLengthX) + TravelLengthZ * TravelLengthZ)
HeadPanAngle = TOINT(FACOS(TOFLOAT(TravelLengthZ) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180
;Add sign depending on the direction of X
HeadPanAngle = HeadPanAngle * (TravelLengthX/ABS(TravelLengthX))
ENDIF
;Calculate body angle depending on rotation
IF ABS(TravelRotationY2)>TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadPanAngle) THEN
HeadPanAngle = -TravelRotationY3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF
;----------------
HeadTiltAngle=0
IF (ABS(TravelLengthZ)>TravelDeadZone | ABS(TravelLengthX)>TravelDeadZone | ABS(TravelRotationY2)>TravelDeadZone) THEN
;Calculate walking direction X and Z
TravelLengthXZ = SQR((TravelLengthZ * TravelLengthZ) + TravelLengthX * TravelLengthX)
HeadTiltAngle = TOINT(FACOS(TOFLOAT(TravelLengthX) / TOFLOAT(TravelLengthXZ)) * 180.0 / 3.141592)-180
;Add sign depending on the direction of X
HeadTiltAngle = HeadTiltAngle * (TravelLengthZ/ABS(TravelLengthZ))
ENDIF
;Calculate body angle depending on rotation
IF ABS(TravelRotationY2)>TravelDeadZone & ABS(TravelRotationY3) > ABS(HeadTiltAngle) THEN
HeadTiltAngle = -TravelRotationY3 ; Rotation max = 166 to get max range of 90 deg.
ENDIF
return[/code]
*
so far its doing this:*
Left JStick:
when walking forward, the head looks up,
when walking backwards, the head looks down,
when walking to the right, the head looks right,
when walking to the left, the head looks left,
and
Right JStick:
when rotating left, the head looks left,
when rotating right, the head look right,
But,
im trying to STOP the head from doing this:
Left JStick:
when walking forward, the head looks up,
when walking backwards, the head looks down,
and get the head to DO this:
Left JStick:
when walking to the right, the head looks right,
when walking to the left, the head looks left,
and
Right JStick:
when rotating left, the head looks left,
when rotating right, the head look right,
and
when pushing the stick up, the head looks up,
when pushing the stick down, the head looks down,
Also i would like the head to pan and tilt when using body IK, which its not currently doing in the code.
iv tried to make this simple to understand. hopefully it is?
any help?