Player Controls
Blitz3D Forums/Blitz3D Beginners Area/Player Controls
| ||
Hi there, Just looking for a suggestion to a problem i am having. I am creating a small demo and have a model walking using the following code If KeyDown(200) Then If player_walking=0 Animate player_hero,1,.3,1 player_walking=1 player_running=0 EndIf MoveEntity player_hero, 0, 0,1 Else If player_walking=1 Animate player_hero,0,.3,15 player_walking=0 player_running=0 Else If Animating(player_hero)=0 Then Animate player_hero,0,.3,16 EndIf EndIf This works fine, however when i want to have the player running by using "UP Cursor key"+"Shift" then the running animation simply freezes Here is the code i have for my hero_control_movement() function If KeyDown(200) Then If player_walking=0 Animate player_hero,1,.3,1 player_walking=1 player_running=0 EndIf MoveEntity player_hero, 0, 0,1 Else If player_walking=1 Animate player_hero,0,.3,15 player_walking=0 player_running=0 Else If Animating(player_hero)=0 Then Animate player_hero,0,.3,16 EndIf EndIf If (KeyDown(200)) And (KeyDown(54)) Then If player_running=0 Animate player_hero,1,.1,2 player_running=1 player_walking=0 EndIf MoveEntity player_hero, 0, 0,2 Else If player_running=1 Animate player_hero,1,.3,15 player_running=0 player_walking=0 Else If Animating(player_hero)=0 Then Animate player_hero,1,.3,16 EndIf EndIf Does this look right to you? Can someone please give any pointers. Much appreciated :) Kind Regards |
| ||
Every time the up key is pressed it starts animating the run sequence over and over. You need to set flag to say when the key is pressed and unset it when the key is released. This way you only use the animate command once. |
| ||
Hey Rob Thanks for that, now working :) Excellent Kind Regards |
| ||
You might try changing to key hit vice keydown see demo code below ; KeyHit Example Press down key with in time period ; to execute code loop While (1) ; Set up the timer current=MilliSecs() ; Wait 1 seconds While MilliSecs() < current+1000 ;waiting xx millisec Wend hitcount = KeyHit(208) If (hitcount) Then Print "Executing code loop - key pressed " + hitcount + " times" Else Print "Key not pressed during last time period " EndIf Wend |
| ||
It's not a great idea, I think, to have a 1s wait each loop. |
| ||
I only put the 1sec wait into to show the effect of using keyhit vice keydown not to actually use in game code. |