Jump to content

Clamp Y Axis For Camera


SlipperyBrick
 Share

Recommended Posts

I have a custom character controller script and I want to clamp the Y axis for my character controller. Right now I can move my mouse down on the Y axis and the camera will let me go completely around on the Y axis, I need to clamp the camera movement to a certain angle.

 

--[[
***LEADWERKS MEASUREMENTS***
Corridor Width = 256cm
Wall Height (Standard) = 320cm
Wall Height (Lowest) = 288cm
Doorway Width = 128cm
Doorway Height = 256cm
Wall Thickness (Doorways) = 32cm
]]--

function Script:Start()
local window = Window:GetCurrent()

--self.camera = players camera
--self.entity = temporary box to use for player movement
--creates a camera in the scene and parents to the entity
self.camera = Camera:Create(self.entity)

--sets the type of the object to player
self.entity:SetKeyValue("type", "player")
local mass = self.entity:GetMass()
if self.entity:GetMass() == 0 then
Debug:Error("Player mass should be greater than 0.")
end

--gets the entity position
local entpos = self.entity:GetPosition(true)

--sets the camera height
self.camera:SetPosition(entpos.x, entpos.y + 1.9, entpos.z, true)

--sets the camera rotation variable
self.camrotation = self.entity:GetRotation(true)
self.camera:SetRotation(self.camrotation.x, self.camrotation.y, 0, true)
mousex = Math:Round(window:GetWidth()/2)
mousey = Math:Round(window:GetHeight()/2)

--sets the camera post processing effects
self.camera:SetFOV(70)
self.camera:AddPostEffect("Shaders/PostEffects/ssao.lua")
self.camera:SetMultisampleMode(4)

end

function Script:UpdateWorld()

local window = Window:GetCurrent()

--gets the position of the mouse
local mouseposition = window:GetMousePosition()
window:SetMousePosition(mousex, mousey)
local dx = mouseposition.x - mousex
local dy = mouseposition.y - mousey
self.camrotation.x = self.camrotation.x + dy / 10
self.camrotation.y = self.camrotation.y + dx / 10
self.camera:SetRotation(self.camrotation.x, self.camrotation.y, 0, true)
end

function Script:UpdatePhysics()
local window = Window:GetCurrent()

--xmove = left/right speed
--zmove = forward/backwards speed
local xmove = 0
local zmove = 0

--key bindings for movement
if window:KeyDown(Key.W) then
zmove = 1
end

if window:KeyDown(Key.S) then
zmove = -1
end

if window:KeyDown(Key.A) then
xmove = -1
end

if window:KeyDown(Key.D) then
xmove = 1
end

self.entity:SetInput(self.camera:GetRotation(true).y, zmove, xmove)
end

 

Here is the script at the moment. Any help is appreciated.

Link to comment
Share on other sites

I don't ever remember having that issue. If you run my example shown do you have the same issue? If not, then i would suggest you set your code like my example - most noticeable difference is i set the mouse's position after setting the camera's rotation, not right after getting the mouse's position.

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