TemplarAsh Posted February 3, 2015 Share Posted February 3, 2015 Hi guys, I need some suggestions on how to get a 3rd person controller's movement that is based on camera direction so the WASD moves the player according to the direction the camera is looking. I have spent hours with every 3rd person script I can find, local and global space settings and I cannot get this to work correctly. The other thing to mention is I do not want to strafe left and right, but rotate and move the character in that direction. I am using a modified version of the barbarian player controller from Darkness Awaits, but it runs like its always in global space, or just hard coded w&s z+- with a&d x+- which then it does not work correctly when the camera changes rotation. I have moved the camera rotation off of the 3rd party controller and attached it to a script on the camera then parented back to the controller while leaving the movement controls on the character controller. Not sure if that matters, but it seems to make more sense having them separated with this goal in mind. Do I need to get the Y rotation of the camera then base the wasd movement off of this, +- 90 degrees and -180, or do I just not understand how to set local space movement either on the controller or the camera, and which would it apply to? Any guidance is appreciated. ~Ash Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 3, 2015 Share Posted February 3, 2015 You have complete TPS example game here : http://www.leadwerks.com/werkspace/topic/11820-bombkiller/ Don't forget : Move that line of code from UpdatePhysics() to UpdateWorld() self:Movement() Quote Stop toying and make games Link to comment Share on other sites More sharing options...
f13rce Posted February 3, 2015 Share Posted February 3, 2015 Take a look at SetInput() using the camera's Y rotation on the model you want to move. That should do the trick. Quote Using Leadwerks Professional Edition (Beta), mainly using C++. Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz Previously known as Evayr. Link to comment Share on other sites More sharing options...
TemplarAsh Posted February 3, 2015 Author Share Posted February 3, 2015 Right on, I am off to work but will check this out tonight when I get home. Thank you for the assistance! ~Ash Quote Link to comment Share on other sites More sharing options...
TemplarAsh Posted February 4, 2015 Author Share Posted February 4, 2015 Hi Guys, I finally got it working, using +/- degrees off of the camerarotation.y. System:Print() was very helpful here finding the correct variable then added the appropriate degrees based on direction. --Movement --Code for detecting key hits for movement and attacks local targetRotation = self.currentyrotation if ActionMap:IsDown(ActionMap.block) then self.currentState = self.state.block end if ActionMap:IsDown(ActionMap.right) then movement.x=movement.x+1 targetRotation = camerarotation.y-90 changed=true end if ActionMap:IsDown(ActionMap.left) then movement.x=movement.x-1 targetRotation = camerarotation.y+90 changed=true end if ActionMap:IsDown(ActionMap.forward) then movement.z=movement.z+1 --if ActionMap:IsDown(ActionMap.freelook) then return end targetRotation = camerarotation.y+180 changed=true end if ActionMap:IsDown(ActionMap.back) then movement.z=movement.z-1 targetRotation = camerarotation.y changed=true end if ActionMap:IsDown(ActionMap.right) and ActionMap:IsDown(ActionMap.back) then targetRotation = camerarotation.y-45 changed=true end if ActionMap:IsDown(ActionMap.left) and ActionMap:IsDown(ActionMap.back) then targetRotation = camerarotation.y+45 changed=true end if ActionMap:IsDown(ActionMap.forward) and ActionMap:IsDown(ActionMap.right) then targetRotation = camerarotation.y-135 changed=true end if ActionMap:IsDown(ActionMap.forward) and ActionMap:IsDown(ActionMap.left) then targetRotation = camerarotation.y+135 changed=true end This is what changes the character direction... --Rotate model to face correct direction if (changed) then movement = movement:Normalize() self.currentyrotation = Math:IncAngle(targetRotation,self.currentyrotation,self.turnSpeed)--first two parameters were swapped end movement and targetRotation are local variables on the Character controller, camerarotation.y is a global variable at this point, since I moved the camera script off of the controller and attached it to the camera. I am sure there is a better way, even moving this back to the Character controller, but at least this gives you an idea on what to think about and work through. Took me a few days to understand this. 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.