Simple code has outwitted me :(
Blitz3D Forums/Blitz3D Programming/Simple code has outwitted me :(
| ||
can anyone tell me what is wrong with this code? Function move_player() playerx# = 0 playery# = 0 turn# = 0 If KeyDown(17) = True playerx# = playerx# + .3 Else If KeyDown(31) = True playerx# = playerx# - .3 EndIf If KeyDown(30) = True Then playery# = -.3 Else If KeyDown(32) = True Then playery# = .3 EndIf turn# = MouseXSpeed() TurnEntity player,0,-turn#,0 MoveEntity player,playery#,0,playerx# End Function it is meant to be the start of a movment engine i am playing with, but the turning via the mouse doesnt work. It works fine as long as you turn clockwise, but when you turn counter-clockwise, it will only turn as far as the original position it started (ie: 0 degrees) and wont turn any further. i have tried adding the lines: If turn# < 0 Then turn# = (360 - turn#) If turn# > 360 Then turn# = (turn# - 360) but that doesnt seem to help either. Can anyone help? If you want me to post the main code as well, i will. thanks ~V~ |
| ||
MouseXSpeed has to be used twice in a loop to be effective i think. Best check the docs with that one. The problem you might be having is blitz turns using zero as the start rotation. th elimits are -180 to 180. so try adjusting the rotations for that :) |
| ||
The problem is that the mouse is hitting the edge of the screen. When that happens, MouseXSpeed() will return 0. The best solution is to reset the mouse position to the centre of the screen each loop with: MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 |
| ||
Which really sucks for a windowed game. :-) You need to be able to detect when your window doesn't have focus anymore in a windowed game if you want to use this method. That way the user can alt-tab out. |
| ||
That's true. But you can add a simple Pause Function to the game. Make shure the user will know the pause-key. |
| ||
genius, i added the movemouse code and it works perfectly... thanks guys :D Now, on to my 30 million other problems lol ~V~ |