Hi, I want to be able to move an entity forward, back, left & right with the mouse, the problem im having is coming up with a good function to compensate for a change in the camera angle.
The code bellow shows the problem, if you rotate the camera(right mouse) and move the object(left mouse) the mouse movements obviously have to alter with the angle.
Any help would be great.
The code bellow shows the problem, if you rotate the camera(right mouse) and move the object(left mouse) the mouse movements obviously have to alter with the angle.
Any help would be great.
Graphics3D 800,600,32,2 Global camPiv=CreatePivot() MoveEntity camPiv,1.5,0,0 Global Camera=CreateCamera(camPiv) CameraClsColor Camera,0,0,0 CameraRange Camera,1,1000 MoveEntity Camera,0,30,-35 RotateEntity Camera,20,0,0 CameraViewport Camera, 0, 0, GraphicsWidth (), GraphicsHeight () Global nyaw#,npitch# Global dampen#=0.2 Global gameFPS = 60 Global Light=CreateLight() RotateEntity Light,45,-90,0 LightColor Light,200,200,200 AmbientLight 130,130,130 Plane=CreatePlane() EntityAlpha Plane,0.7 PlaneTexture=CreateTexture(128,128,9) ClsColor 0,0,0 Cls Color 255,255,255 Rect 0,0,64,64,1 Rect 64,64,64,64,1 CopyRect 0,0,128,128,0,0,BackBuffer(),TextureBuffer(PlaneTexture) ScaleTexture PlaneTexture,20,20 EntityTexture Plane,PlaneTexture,0,0 Mirror=CreateMirror() cube=CreateCube() ScaleEntity cube,4,4,4 PositionEntity cube,0,10,0 framePeriod = 1000 / gameFPS frameTime = MilliSecs () - framePeriod Repeat FlushMouse Repeat frameElapsed = MilliSecs () - frameTime Until frameElapsed frameTicks = frameElapsed / framePeriod frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod) For frameLimit = 1 To frameTicks If frameLimit = frameTicks Then CaptureWorld frameTime = frameTime + framePeriod If MouseDown(1) MoveEntity cube,MouseXSpeed()/5,0,-MouseYSpeed()/5 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 EndIf If MouseDown(2) nyaw#=-MouseXSpeed()*dampen+EntityYaw(camPiv) RotateEntity camPiv,0,nyaw#,0 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 EndIf MXS = MouseXSpeed() MYS = MouseYSpeed() MZS = MouseZSpeed() Next RenderWorld frameTween Flip False Until KeyHit(1) End