Jump to content

Controller not rotating unless moving


Rick
 Share

Recommended Posts

Below is some code that controls my character controller. It's pulled from Aggror's tutorial and modified slightly. The problem is if I'm NOT moving I CAN'T rotate the controller. If I'm moving I can rotate the controller just fine.

 

What am I missing?

 

I draw to screen the self.cameraRotation.y variable and I see it changing when I move my mouse, but the controller isn't rotating without movement of the controller.

 

 


function App:UpdateGame()
local move = ((self.window:KeyDown(Key.W) and 1 or 0) - (self.window:KeyDown(Key.S) and 1 or 0)) * Time:GetSpeed() * 1
local strafe = ((self.window:KeyDown(Key.D)and 1 or 0) - (self.window:KeyDown(Key.A) and 1 or 0)) * Time:GetSpeed() * 1

-- get the mouse movement
local currentMousePos = self.window:GetMousePosition()
local mouseDifference = Vec3()

mouseDifference.x = currentMousePos.x - 100
mouseDifference.y = currentMousePos.y - 100

-- adjust and set the camera rotation
self.cameraRotation.y = self.cameraRotation.y + mouseDifference.x / 15
self.window:SetMousePosition(100, 100)

self.player:SetInput(self.cameraRotation.y, move, strafe)
end

 

 

Code editing does not work very well on this site. I copy/paste and it messes it up. I go to edit and then for some reason I see tags in my code like , etc.

Link to comment
Share on other sites

This is in Lua now, but here is the entire code. You could just make a cube or something and give it a character controller physics body then save it as a prefab called player. You'll have to make a 'prefabs' folder also right off the base and the code should run as is then. I just created a little csg floor to test on.

 


--This function will be called once when the program starts
function App:Start()

--Set the application title
self.title = "Z Is 4 Zombie"

--Create a window
self.window = Window:Create(self.title)
self.window:HideMouse()

--Create the graphics context
self.context = Context:Create(self.window, 0)
if self.context == nil then return false end

--Create a world
self.world = World:Create()

--Load a map
local mapfile = System:GetProperty("map", "Maps/start.map")
if Map:Load(mapfile) == false then return false end

self.camera = Camera:Create()
self.camera:SetFOV(70)

self.playerLight = SpotLight:Create()
self.playerLight:SetIntensity(3)

self.cameraRotation = Vec3()

self.player = Prefab:Load("Prefabs/player.pfb")
self.moveSpeed = 3

self:CameraFollow()

return true
end

function App:CameraFollow()
-- over the shoulder view
self.camera:SetPosition(self.player:GetPosition())
self.camera:SetRotation(self.player:GetRotation())
self.camera:Move(.75, 1.8, -1)
self.camera:Turn(0, -5, 0)

local camY = self.camera:GetRotation().y
self.camera:SetRotation(self.cameraRotation.x, camY, 0)

-- a light so the player model stands out
self.playerLight:SetPosition(self.player:GetPosition())
self.playerLight:SetRotation(self.player:GetRotation())
self.playerLight:Move(3.75, .75, 0)
self.playerLight:Turn(0, -90, 0)
end

function App:UpdateGame()
local move = ((self.window:KeyDown(Key.W) and 1 or 0) - (self.window:KeyDown(Key.S) and 1 or 0)) * Time:GetSpeed() * self.moveSpeed
local strafe = ((self.window:KeyDown(Key.D)and 1 or 0) - (self.window:KeyDown(Key.A) and 1 or 0)) * Time:GetSpeed() * (self.moveSpeed * .66)

-- get the mouse movement
local currentMousePos = self.window:GetMousePosition()
local mouseDifference = Vec3()

mouseDifference.x = currentMousePos.x - 100
mouseDifference.y = currentMousePos.y - 100

-- adjust and set the camera rotation
local tempX = self.cameraRotation.x + (mouseDifference.y / 15)
if tempX > -25 and tempX < 25 then
self.cameraRotation.x = tempX
end

self.cameraRotation.y = self.cameraRotation.y + mouseDifference.x / 15
self.window:SetMousePosition(100, 100)

self.player:SetInput(self.cameraRotation.y, move, strafe)
end

--This is our main program loop and will be called continuously until the program ends
function App:Loop()

--If window has been closed, end the program
if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

--Update the app timing
Time:Update()



--Update the world
self.world:Update()

self:UpdateGame()
self:CameraFollow()

--Render the world
self.world:Render()

self.context:SetBlendMode(Blend.Alpha)

self.context:DrawText("Cam Rotation Y:"..self.cameraRotation.y, 0, 0)

-- draw crosshairs
self.context:SetColor(1, 0, 0, 1)
self.context:DrawLine(self.context:GetWidth() / 2, (self.context:GetHeight() / 2) - 15, self.context:GetWidth() / 2, (self.context:GetHeight() / 2) + 15)
self.context:DrawLine((self.context:GetWidth() / 2) - 15, self.context:GetHeight() / 2, (self.context:GetWidth() / 2) + 15, self.context:GetHeight() / 2)
self.context:SetColor(0, 0, 0, 1)

self.context:SetBlendMode(Blend.Solid)

--Refresh the screen
self.context:Sync()

--Returning true tells the main program to keep looping
return true
end

Link to comment
Share on other sites

  • 4 years later...

This was a long time ago. But I'm having the same issue now,. I worked around it by adding a Math:Random(-0.00001, 0.00001) to one of the movement parameters, this causes it to work. This should probarly get fixed though.

This is not occurring for me at all. So instead of necro-posting a 4 year old post, make a new post with an example that shows your problem. Add details like if you are using the beta or an older revision, are you using a custom script that controls the controller, etc...

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

I have a bug report on this.

http://www.leadwerks.com/werkspace/topic/15587-enttiysetinput-doesnt-rotate-without-movment/

Original Bug Report

http://www.leadwerks.com/werkspace/topic/15442-setinput/

 

Here is how I solve it.

  if (camMovementZ == 0 && camMovementX == 0)
  {
   camMovementZ = 0.001; // Not 0 but not enough to see
   camMovementX = 0.001; // Not 0 but not enough to see
  }
  this->playerModel->SetInput(cameraRotationY, camMovementZ, camMovementX);

Link to comment
Share on other sites

Here is how I solve it.

or just update your project to three of the available versions, beta (Ver4.4), stable (Ver4.3), or Ver4.1. This latest issue was caused by an "optimization" in the Ver4.2 that was resolved within Ver4.3 beta and was never part of the Ver4.3 stable release.

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

or just update your project to any of the available versions, beta (Ver4.4), stable (Ver4.3), or Ver4.1. This latest issue was caused by an "optimization" in the Ver4.2 that was resolved within a week or two and was never part of the Ver4.3 stable release.

 

This does occur in the latest (4.4) beta. The attached map should show this if you run it and don't move the player.

04-Moving Platforms.rar

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

Yeah, not quite sure what i should be seeing here in the beta. I can turn completely around with just the mouse while not pressing the WSAD keys.

 

What happens if you run it and don't move the mouse either?

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

huh? am i missing something? why wouldn't it not rotate if i don't move the mouse?

 

Maybe I missed something. I'm talking about the character falling through the platform.

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

Maybe I missed something. I'm talking about the character falling through the platform.

 

yeah- this post was about the character controller not rotating unless the controller was moving... because someone wasn't using an up to date version. The problem you are referring to is a completely different issue.

 

And yes, i do see that... but it only occurs on the start of the program - almost like the character physics werent created all the way yet prior to the platform moving. if you jump several times, you can get the character to land on top of the platform and its all okay after that. Definitely an issue, but as Josh is implementing the new newton physics engine version in a new way in this beta i suspect there will be issues. You should definitely make a bug report.

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

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...