fumanshoo Posted October 28, 2012 Share Posted October 28, 2012 so I've been working on a first person controller, and I fixed a few things, but I'm stuck with one last problem if you guys would be so kind to help out.The problem is that the controller goes backwards, forwards, left right like it should, but when I turn the controller, I realize that the "WASD" keys are moving the controller according to the world, rather than the controller. So if I look diagonally, It still goes backwards or forwards according to the world... here's the script require("Scripts/constants/engine_const") COLLISION_CHARACTER=1 RegisterAbstractPath("") Graphics(800,600) fw = CreateFramework() camera = fw.main.camera camera:SetPosition(Vec3(3,2,-10)) light = CreateDirectionalLight() light:SetRotation(Vec3(45,45,0)) scene = LoadScene("abstract::animation_test_lab.sbx") scene:SetCollisionType(1) scene:SetRotation(Vec3(0,90,0)) controller = CreateController(1.8,0.3,0.5 , 45) controller:SetMass(5) controller:SetCollisionType(COLLISION_CHARACTER) controller:SetPosition(camera) controller:Move(Vec3(0,1,0)) DebugPhysics(0) MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) camRotation = Vec3(0) dx = 0.0 dy = 0.0 strafe = 0 move = 0 while KeyHit(KEY_ESCAPE)==0 do mx=Curve(MouseX()- GraphicsWidth()/2,3.0/AppSpeed()) my=Curve(MouseY()- GraphicsHeight()/2,3.0/AppSpeed()) MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) camRotation.x = camRotation.x + my / 8 camRotation.y = camRotation.y - mx / 8 camera:SetRotation(Vec3(camRotation.x,camRotation.y,1)) move = Curve( (KeyDown(KEY_W)-KeyDown(KEY_S)) * 5, move , 3 ) strafe = Curve( (KeyDown(KEY_D)-KeyDown(KEY_A)) * 5, strafe , 3 ) controller:Update(0, move, strafe, jump, 25 , 10) fw:Update() camera:SetPosition(Vec3( controller.position.x, controller.position.y, controller.position.z )) fw:Render() Flip(0) end Quote Link to comment Share on other sites More sharing options...
macklebee Posted October 28, 2012 Share Posted October 28, 2012 you need the Y angle value of the camera in the angle parameter of the Update controller command. controller:Update(camRotation.y, move, strafe, jump, 250 , 1, 0) Also you might want to increase the maxacceleration parameter from 25 to something significantly higher, unless you want a sliding effect. Also the camera position has to be offset from the controller, otherwise the camera is placed at the ground level. camera:SetPosition(Vec3( controller.position.x, controller.position.y+1.8, controller.position.z )) and this line does nothing: controller:SetPosition(camera) 2 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
fumanshoo Posted October 28, 2012 Author Share Posted October 28, 2012 wow, thank you so much you have no Idea how helpful this is. And as for the controller:SetPosition(camera), I don't really know how that got there... I was working on two projects at once late at night, so maybe something happened there... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.