Enitity controlls
Blitz3D Forums/Blitz3D Programming/Enitity controlls
| ||
Gday all. I have just been playing around with the possibility of using the mouse to controll the player in the game i am working on. I have got it to work but the movement is way to jerky. Was wandering if someone could have a look at the example & possibly give me a few ideas on how to smooth out the movement. Cheers. :) Graphics3D 800,600,0,2 SetBuffer BackBuffer() tex=CreateTexture(32,32,11) ScaleTexture tex,5,5 SetBuffer TextureBuffer (tex) Color 0,50,0:Rect 0,0,32,32 Color 0,255,0:Rect 0,0,32,32,False SetBuffer BackBuffer() plane=CreatePlane() EntityTexture plane,tex PositionEntity plane,0,-1,0 EntityFX plane,1 EntityType plane,ground_col cube= CreateCube() ScaleEntity cube,2,.2,1 camera= CreateCamera() z_vel# = 0 z_roll# = 0 HidePointer While Not KeyDown (1) x_vel# = MouseXSpeed()/2 y_vel# = MouseYSpeed()/2 MoveMouse 800/2,600/2 If KeyDown(200) z_vel = z_vel + .05 If z_vel < .5 z_vel = .5 If x_vel < -1 x_vel = -1 If x_vel > 1 x_vel = 1 If y_vel < -.5 y_vel = -.5 If y_vel > .5 y_vel = .5 z_vel = z_vel - .03 z_roll = x_vel *-30 RotateEntity cube,0,0,z_roll TranslateEntity cube,x_vel,-y_vel,z_vel PositionEntity camera,EntityX(cube),EntityY(cube)+3,EntityZ(cube)-10 UpdateWorld RenderWorld Color 255,255,255 Text 0,0,"Use mouse to move left, right, up & down." Text 0,15,"Use Csr up to accelerate." Flip Wend End |
| ||
So you move to the side with MouseX, Forward with MouseY and Up and Down with a Cursorkey? Not exactly the kind of controls that I am familar with. However. I'd suggest to smooth all values. There are built in Commands, like AlignToVector to do that, but you can also write your own rubberband fx. For example the camera rotation (I still think of FPS): there may be 2 angles, the target angle (based on player action) and the current angle, eg: a1=a1+(a1-a2)/4.0, but here you still have to check if the angle passes the 360 deg. border, (eg. when a1 is 10 and a2 is 350 then the diffrence is 20, not 340! so when the diffrence is bigger than 180 then go the other way round..) Instead of TranslateEntity you maybe want to use Positionentity and some coordinate variables: x=x+x_vel y=y-y_vel z=z+z_vel positionentity gg,x,y,z now, you can do the same smoothing here as well, you even don't have to worry about the 360 deg. Eg: x=x+x_vel y=y-y_vel z=z+z_vel x2=x2+(x-x2)/4.0 y2=y2+(y-y2)/4.0 z2=z2+(z-z2)/4.0 positionentity gg,x2,y2,z2 Maybe not what you need, but it makes things less jerky, pretty smooth, where the "/4.0" allows the define the speed of the alignement. |
| ||
Gday Jfk. Cheers for the help. It wasn't realy what i was after but it made a difference with smoothing out the movement for the object. I don't know if you have run the code above but was more the jerkyness of the object roll that needs smoothing. Which i would say could be done with the a1=a1+(a1-a2)/4.0 part you were talking about. I will have another look at my code & see what i can come up with. Thank again. :) |
| ||
Have got it all going smoothly. But think i will go back to using the original way i was going to do it. Cheers for the help. :) |