Limb Position X/Y/Z(Object,Limb)
Quote: "This command will return the real number world x/y/z position of the specified limb of the 3D object "
Use that instead of Limb Offset X/Y/Z(Object,Limb), which returns the offset of the limb from the base object.
=================================
Limb Direction X/Y/Z(Object,Limb)
Quote: "This command will return the real number world x/y/z angle of the specified limb of the 3D object "
Use that instead of Limb Angle X/Y/Z(Object, Limb), which returns the local angle of the limb.
Here is a code I threw together quick to demo the different commands. The head is set back so you can see the body.
Sync On:Sync Rate 0:Autocam Off
`Make the player
Make Object Cube 1,1
Make Object Sphere 2,1
Make Mesh From Object 2,2
Delete Object 2
Add Limb 1,1,2
Offset Limb 1,1,0,2,-3
`Make some 'terrain' to go by.
For i =100 to 200
Make Object Cube i,1
Position Object i,Rnd(1000)-500,0,Rnd(1000)-500
Next i
`Main Loop
Do
_Player_Control(1,0)
Update_Head()
Update_Camera()
TimeFactor_Sync()
Loop
Function Update_Camera()
Position Camera 0,Limb Position X(1,1),Limb Position Y(1,1),Limb Position Z(1,1)
Rotate Camera 0,Limb Direction X(1,1),Limb Direction Y(1,1), Limb Direction Z(1,1)
EndFunction
Function Update_Head()
Rotate Limb 1,1,0,Limb Angle Y(1,1)+MouseMoveX()*TimeFactor(60),0
EndFunction
`When calling the TimeFactor() function, pass the target virtual frame rate (FrameRate)
`to achieve (i.e. 60 for 60 FPS, or 30 for 30 FPS). A value of 0 defaults to 60 FPS
`since previous projects use the array variable TimeFactor(0).
`Think of the return value as a percentage; multiply movement, turning, or other timer-based
`factor by the TimeFactor() return value.
Function TimeFactor(FrameRate as Integer)
Dim TimeStamp(0) as Integer
Dim TimeDiff(0) as Double Float
If FrameRate=0 Then FrameRate=60
MS#=1000.0/FrameRate
TF#=TimeDiff(0)/MS#
`If the frame rate is far too slow to support the virtual Frame Rate, the return value needs to be capped.
`Using value of 2.0 maximizes the return value at 200%, or 1/2 target frame rate. For example, if trying to achieve
`a virtual frame rate of 60, but the actual frame rate is less than 30, then this value will cap out at 200%
If TF#>2 then TF#=2
EndFunction TF#
`Call the Update_TimeFactor() once each frame, ideally after the Sync command.
`Do not use this function if using the TimeFactor_Sync() function (in the same loop)
Function Update_TimeFactor()
Dim TimeStamp(0) as Integer
Dim TimeDiff(0) as Double Float
If TimeStamp(0)=0 Then TimeStamp(0)=Timer()-16
TimeDiff(0)=Timer()-TimeStamp(0)
Timestamp(0)=Timer()
Endfunction
`Use this function to include a sync command while updating the TimeFactor values.
`Do not use this function if using the Update_TimeFactor() function (in the same loop)
Function TimeFactor_Sync()
Dim TimeStamp(0) as Integer
Dim TimeDiff(0) as Double Float
Sync
If TimeStamp(0)=0 Then TimeStamp(0)=Timer()-16
TimeDiff(0)=Timer()-TimeStamp(0)
Timestamp(0)=Timer()
Endfunction
`========================================================================
`_Player_Control Module
`Created On 03/28/09 15:48:47
`========================================================================
`========================================================================
`=EXPORT COPYLEFT PROTECTION=============================================
`========================================================================
` =
` This program is free software: you can redistribute it and/or =
` modify it under the terms of the GNU Lesser General Public License =
` as published by the Free Software Foundation, either version 3 of =
` the License, or (at your option) any later version. =
` =
` This program is distributed in the hope that it will be useful, =
` but WITHOUT ANY WARRANTY; without even the implied warranty of =
` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the =
` GNU Lesser General Public License for more details. =
` =
` You should have received a copy of the GNU Lesser General Public =
` License along with this program. If not, see =
` <http://www.gnu.org/licenses/>. =
` =
` EXPORT NOTE: This protection only applies to the exported code =
` and/or data. The software used to create this export =
` is protected separately and independently. =
` =
`========================================================================
`========================================================================
Function _Player_Control(ObjectID as DWord, GroundY as Float)
_Initialize_Player_Control()
_Main_Player_Control(ObjectID, GroundY)
_Cleanup_Player_Control()
EndFunction
Function _Initialize_Player_Control()
`The following lines prevent re-initialization, which is typically not needed.
Dim Init_Player_Control(0)
If Init_Player_Control(0) Then ExitFunction
Init_Player_Control(0)=1
`Note: Change the speed values below as desired.
Dim MoveSpeed(0) as Float:MoveSpeed(0)=.1
Dim TurnSpeed(0) as Float:TurnSpeed(0)=1.0
Dim RunSpeed(0) as Float:RunSpeed(0)=.2
Dim StrafeSpeed(0) as Float:StrafeSpeed(0)=.08
Dim JumpSpeed(0) as Float:JumpSpeed(0)=.5
Dim Momentum(2) as Float
Dim Friction(0) as Float:Friction(0)=.95
Dim Gravity(0) as Float:Gravity(0)=.02
`Insert any initialization code below this point.
`Code...
`Code...
`Code...
EndFunction
Function _Main_Player_Control(ObjectID as DWord, GroundY as Float)
lx#=Object Position X(ObjectID)
ly#=Object Position Y(ObjectID)
lz#=Object Position Z(ObjectID)
`Move Forward
If KeyState(17)
Move Object ObjectID, MoveSpeed(0)*TimeFactor(60)
EndIf
`Turn Right
If KeyState(32)
Turn Object Right ObjectID, TurnSpeed(0)*TimeFactor(60)
EndIf
`Turn Left
If KeyState(30)
Turn Object Left ObjectID, TurnSpeed(0)*TimeFactor(60)
EndIf
`Strafe Right
If KeyState(18)
Move Object Right ObjectID, StrafeSpeed(0)*TimeFactor(60)
EndIf
`Strafe Left
If KeyState(16)
Move Object Left ObjectID, StrafeSpeed(0)*TimeFactor(60)
EndIf
`Move Back
If KeyState(31)
Move Object ObjectID, (MoveSpeed(0)*-.5)*TimeFactor(60)
EndIf
`Run
If KeyState(19)
Move Object ObjectID, RunSpeed(0)*TimeFactor(60)
EndIf
`Jump
If KeyState(57)
If Object Position Y(ObjectID)<=GroundY
Move Object Up ObjectID, JumpSpeed(0)*TimeFactor(60)
EndIf
EndIf
Position Object ObjectID, Object Position X(ObjectID)+Momentum(0), Object Position Y(ObjectID)+Momentum(1)-Gravity(0), Object Position Z(ObjectID)+Momentum(2)
If Object Position Y(ObjectID)< GroundY
Position Object ObjectID, Object Position X(ObjectID), GroundY, Object Position Z(ObjectID)
EndIf
Momentum(0)=(Object Position X(ObjectID)-lx#)*Friction(0)
Momentum(1)=(Object Position Y(ObjectID)-ly#)*Friction(0)
Momentum(2)=(Object Position Z(ObjectID)-lz#)*Friction(0)
`Insert additional code below this point.
`Code...
`Code...
`Code...
EndFunction
`Use the following function to cleanup after the module (close files, null-out strings, undim, etc.)
Function _Cleanup_Player_Control()
`Code...
`Code...
`Code...
EndFunction
`========================================================================
`End of Module _Player_Control
`========================================================================

Open MMORPG: It's your game!