Movement issue
Blitz3D Forums/Blitz3D Beginners Area/Movement issue
| ||
Here is my code: Graphics3D 1024,768,32,2 SetBuffer BackBuffer() HidePointer Const Pcoll = 1 Const Tcoll = 2 Global Ground = CreatePlane() Global Sky = CreateSphere() Global PlayerCube = CreateCube() Global Camera = CreateCamera(PlayerCube) Global Light = CreateLight(2) GrassTexture = LoadTexture("Grass.jpg") SkyTexture = LoadTexture("Sky.jpg") EntityTexture Ground,GrassTexture EntityTexture Sky,SkyTexture EntityType PlayerCube,Pcoll EntityType Ground,Tcoll PositionEntity PlayerCube,0,0.3,0 PositionEntity Ground,0,-1,0 PositionEntity Sky,0,100,0 ScaleEntity Sky,200,200,200 ScaleEntity PlayerCube,1,1,1 FlipMesh Sky While Not KeyHit(1) mxs# = mxs#+MouseXSpeed()/4 mys# = mys#+MouseYSpeed()/4 If mxs# < 0 Then mxs# = 360 If mxs# > 360 Then mxs# = 0 If mys# > 80 Then mys# = 80 If mys# < -80 Then mys# = -80 RotateEntity PlayerCube,mys#,-mxs#,0 MoveMouse 400,300 RenderWorld() UpdateWorld() PlayerMove() Flip Wend End Function PlayerMove() If KeyDown(17) Then MoveEntity PlayerCube,0,0,0.02 If KeyDown(30) Then MoveEntity PlayerCube,-0.02,0,0 If KeyDown(31) Then MoveEntity PlayerCube,0,0,-0.02 If KeyDown(32) Then MoveEntity PlayerCube,0.02,0,0 End Function it works fine and all, but I want to make it so that I can move forward, even when my mouse is pointing at the ground. So whenever I move forward and aim the camera down, I just fly through the ground. (I haven't set up collisions properly yet). But when I tried to set up the collisions, everything worked fine until I tried looking down and moving forward, (I would just get stuck because of the plane's collisions I set up). Does anyone know how to fix something like this? ...I hope I explained everything properly :P |
| ||
Rotate the camera on the x axis, not the cube. Also I'm pretty sure UpdateWorld comes before RenderWorld? Man it's been a long time since I messed with Blitz. RotateEntity PlayerCube,0,-mxs#,0 RotateEntity Camera,mys#,0,0 Something like that. |
| ||
updateworld is only necessary if you want to detect collisions and update colliders and update animations. |
| ||
Thanks Stayne! I added that code into my code and it worked! Thanks so much! And yea, updateworld() comes before renderworld(). Thanks for all your help. |
| ||
Hi Eren, Don't know if you are aware of the [codebox \codebox] forum codes, they can let you present your code examples like this on the forums (if you want) Glad you got your issue resolved. |
| ||
I actually just found out another problem, I added the code that Stayne gave me to my code, and I thought it was working fine, until I realised that whenever you move forward and look at the ground, you move faster than looking forward and moving forward. Who knows the solution to this? |
| ||
It means your program doesn't have a timer to run at the same speed no matter what. Nothing is rendered off-camera so when you look down it runs faster. Read this post - especially Matty's reply. http://www.blitzmax.com/Community/posts.php?topic=81001#912030 |
| ||
I literally mean you WALK faster when you look at the ground and move forward |
| ||
That's because the total number of turns/moves per second will vary depending on the FPS. Here is a way to prevent this : http://www.blitzbasic.com/codearcs/codearcs.php?code=2916 |
| ||
stayne's comment above still applies Eren. |