I am just trying to load a character and move it around while its walking animation plays.
I am having trouble doing this seeming simply thing
I am not very good at coding so apologies if my code is very bad. I have loaded the character up and just want to use the arrow keys to move it around.
The character loads but if I press the up arrow it walks backwards. So I thought I would be clever and
YRotate Object the character on load but it still goes backwards
I also can't work out how to stop the animation playing once you stop moving. I tried checking if no keys were pressed but then the animation wouldn't play when it was walking.
I'd also like to use the left/right arrow keys to rotate the character, but again I don't seem to be able to that either. I thikn I need to check what direction I'm facing and then add/subtract from it but the character just 'jumps' to the different direction, and seeing as I can't even get it to go forwards or backwards properly yet I got rid of that code. Any tips on how I would go about doing that would be appreciated.
I attached the executable that goes with the code below so you could see what it does so far.
Rem Project: Move Man Test
Rem Created: Saturday, October 24, 2009
Rem ***** Main Source File *****
`Object Constants
#Constant Plr 1
`Image Constants
#Constant PlrImage 1
SetupGame()
LoadPlayer()
LoadGround()
Do
MovePlayer()
CameraFollowPlayer()
Loop
REM *** Functions ***
Function SetupGame()
Set Display Mode 800,600,32
AutoCam Off
EndFunction
Function LoadPlayer()
Load Object "Media\Crusader.x",Plr
Load Image "Media\crusader_1_D2.dds",PlrImage
Texture Object Plr,PlrImage
Loop Object Plr,210,234 `idle animation
Position Object Plr,0,0,500
EndFunction
Function LoadGround()
Make Matrix 1,1000,1000,10,10
Update Matrix 1
EndFunction
Function MovePlayer()
If UpKey() = 1
Set Object Speed Plr,1
Move Object Plr,0.1
Loop Object Plr,235,259
EndIf
If DownKey() = 1
Set Object Speed Plr,-1
Move Object Plr,-0.1
Loop Object Plr,235,259
EndIf
EndFunction
Function CameraFollowPlayer()
x# = Object Position X (Plr)
y# = Object Position Y (Plr)
z# = Object Position Z (Plr)
Set Camera To Follow x#,y#,z#,50,300,100,50.0,0
Point Camera x#,y#,z#
EndFunction
EDIT
I figured out turning the player, and I edited the code so that the player walks forward by making the movement speed negative to go forward. This doesn't really make sense to me but it works for now. So really I just need to know how to stop the walking animation when the character is stationary. Here's the edited code:
Rem Project: Move Man Test
Rem Created: Saturday, October 24, 2009
Rem ***** Main Source File *****
`Object Constants
#Constant Plr 1
`Image Constants
#Constant PlrImage 1
Global PlrDirection
SetupGame()
LoadPlayer()
LoadGround()
Do
MovePlayer()
CameraFollowPlayer()
Loop
REM *** Functions ***
Function SetupGame()
Set Display Mode 800,600,32
AutoCam Off
EndFunction
Function LoadPlayer()
PlrDirection = 0
Load Object "Media\Crusader.x",Plr
Load Image "Media\crusader_1_D2.dds",PlrImage
Texture Object Plr,PlrImage
Loop Object Plr,210,234 `idle animation
Position Object Plr,0,0,500
Yrotate Object Plr,PlrDirection
EndFunction
Function LoadGround()
Make Matrix 1,1000,1000,10,10
Update Matrix 1
EndFunction
Function MovePlayer()
If UpKey() = 1
Set Object Speed Plr,1
Move Object Plr,-0.1
Loop Object Plr,235,259
EndIf
If DownKey() = 1
Set Object Speed Plr,-1
Move Object Plr,0.1
Loop Object Plr,235,259
EndIf
If LeftKey() = 1
PlrDirection = PlrDirection - 1
YRotate Object Plr,PlrDirection
EndIf
If RightKey() = 1
PlrDirection = PlrDirection + 1
YRotate Object Plr,PlrDirection
EndIf
EndFunction
Function CameraFollowPlayer()
x# = Object Position X (Plr)
y# = Object Position Y (Plr)
z# = Object Position Z (Plr)
Set Camera To Follow x#,y#,z#,50,300,100,50.0,0
Point Camera x#,y#,z#
EndFunction
Of course if my code is hideously wrong and I could do things in a much simpler way, I would love to know.