Jump to content

TPS controller and local space...


TemplarAsh
 Share

Recommended Posts

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

Link to comment
Share on other sites

Take a look at SetInput() using the camera's Y rotation on the model you want to move. That should do the trick.

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

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...