Yue Posted October 23, 2019 Share Posted October 23, 2019 self.GetWheelMouse = self.window:GetMousePosition().z if self.GetWheelMouse ~= self.sWheel then self.sWheel = self.window:GetMousePosition().z -3.0 self.pivotCamera:SetPosition(0,0,self.sWheel,false ) end I'm trying to implement a limit by zooming the camera in and out with the mouse wheel, but my logic doesn't work. Any suggestions? TEMP 2019-10-23 11-27-18.mp4 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted October 24, 2019 Share Posted October 24, 2019 You could try Math:Clamp(number to clamp, minimum zoom, maximum zoom) https://www.leadwerks.com/learn?page=API-Reference_Object_Math_Clamp 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted October 24, 2019 Author Share Posted October 24, 2019 5 minutes ago, havenphillip said: Puede probar Math: Clamp (número para sujetar, zoom mínimo, zoom máximo) https://www.leadwerks.com/learn?page=API-Reference_Object_Math_Clamp Thanks for the information, but that doesn't have an example. I can deduce that it sets a number as a minimum and a maximum, but I have no idea how to implement it, the translator does not help much without an example. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted October 24, 2019 Share Posted October 24, 2019 Something like: function Script:UpdateWorld() if MouseWheel(Mouse.Back) then cameraposition.z = cameraposition.z - 1 end if MouseWheel(Mouse.Forward) then cameraposition.z = cameraposition.z + 1 end Math:Clamp(cameraposition.z,0, 10) end 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted October 28, 2019 Author Share Posted October 28, 2019 Where does Mouse.back come from? Nor the MouseWheel?? although the editor highlights it in blue. I can't find any documentation Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted October 28, 2019 Share Posted October 28, 2019 On 10/24/2019 at 12:32 PM, ?Yue? said: Thanks for the information, but that doesn't have an example. I can deduce that it sets a number as a minimum and a maximum, but I have no idea how to implement it, the translator does not help much without an example. In your code you will want to "clamp" the self.sWheel variable. Math:Clamp(self.sWheel,0,30) You will need to alter the 0 to whatever minimum value you wish to set your zoom to. The 30 value will be your maximum zoom value. 2 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted October 28, 2019 Share Posted October 28, 2019 You know what I just assumed there was something like a "mouse.back." I made it up as a dummy command because I thought you already had something there. I sort of got it working from this post. I've never bothered with the mouse wheel: This sort of works: function Script:UpdateWorld() self.maxZoom = 10 self.minZoom = 0 local oldWheelPos = 0.0 if self.currentMousePos ~= nil then oldWheelPos = self.currentMousePos.z end self.currentMousePos = window:GetMousePosition() self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) local newWheelPos = (self.currentMousePos.z - oldWheelPos) * 0.1 if newWheelPos > 0.0 or newWheelPos < 0.0 then self.curZoom = oldWheelPos + newWheelPos self.camera:Move(0,0,self.curZoom) self.curZoom = Math:Clamp(self.curZoom, self.minZoom, self.maxZoom) -- limits the zoom to stay between min and max zoom end 2 Quote Link to comment Share on other sites More sharing options...
Yue Posted October 28, 2019 Author Share Posted October 28, 2019 function this:ZoomCamera() self.wheel = self.window:GetMousePosition().z if self.wheel ~= self.sWheel then self.sWheel = self.window:GetMousePosition().z end self.pivotCamera:SetPosition(0,0,self.sWheel,false ) end I only have this, I've tried several things with Clamp, but it doesn't work. Sometimes it jumps and stays in some limit, and doesn't come back. Quote Link to comment Share on other sites More sharing options...
Yue Posted October 28, 2019 Author Share Posted October 28, 2019 This is the closest, but it turns out that if you continued to turn the wheel of the mouse when you reach the limit, continues to gain value, then when I want to go forward it takes quite some time, because the value of the wheel continues to increase beyond the limit established with Clamp. self.pivotCamera:SetPosition(0,0,Math:Clamp(self.sWheel,0,10),false ) Quote Link to comment Share on other sites More sharing options...
Solution havenphillip Posted October 29, 2019 Solution Share Posted October 29, 2019 This appears to be doing it. It's limiting the zoom but the wheel is cumulative I don't know how to fix that. Once you reach the limit, if you keep rolling the wheel it keeps counting it... Script.minZoom = 0 Script.maxZoom = 30 Script.curZoom = 0 function Script:Zoom() local oldWheelPos = 0.0 if self.currentMousePos ~= nil then oldWheelPos = self.currentMousePos.z end self.currentMousePos = window:GetMousePosition() self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) local newWheelPos = (self.currentMousePos.z - oldWheelPos) if oldWheelPos < 0.0 then self.entity:Move(0,0,self.curZoom) self.curZoom = 0 - newWheelPos System:Print("Zoom in") if self.currentMousePos.z < self.minZoom then --limits max in zoom self.curZoom = 0 end elseif oldWheelPos > 0.0 then self.entity:Move(0,0,-self.curZoom) self.curZoom = 0 + newWheelPos System:Print("Zoom out") if self.currentMousePos.z > self.maxZoom then -- limits max out zoom self.curZoom = 0 end end end 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted November 2, 2019 Author Share Posted November 2, 2019 On 10/29/2019 at 7:53 AM, havenphillip said: This appears to be doing it. It's limiting the zoom but the wheel is cumulative I don't know how to fix that. Once you reach the limit, if you keep rolling the wheel it keeps counting it... Script.minZoom = 0 Script.maxZoom = 30 Script.curZoom = 0 function Script:Zoom() local oldWheelPos = 0.0 if self.currentMousePos ~= nil then oldWheelPos = self.currentMousePos.z end self.currentMousePos = window:GetMousePosition() self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) local newWheelPos = (self.currentMousePos.z - oldWheelPos) if oldWheelPos < 0.0 then self.entity:Move(0,0,self.curZoom) self.curZoom = 0 - newWheelPos System:Print("Zoom in") if self.currentMousePos.z < self.minZoom then --limits max in zoom self.curZoom = 0 end elseif oldWheelPos > 0.0 then self.entity:Move(0,0,-self.curZoom) self.curZoom = 0 + newWheelPos System:Print("Zoom out") if self.currentMousePos.z > self.maxZoom then -- limits max out zoom self.curZoom = 0 end end end Thanks, I've managed to get my own script here. Always something new to learn from more advanced users like you. Thank you very much. function this:ZoomCamera() self.w = self.window:GetMousePosition().z if self.w ~= self.sW then if self.w > 0 then self.pC = self.pC -1 if self.pC < -10 then self.pC = -10 end end if self.w < 1 then self.pC = self.pC +1 if self.pC > 0 then self.pC = 0 end end self.w = self.window:FlushMouse() end self.pivotCamera:SetPosition(0,0,self.pC-3,false) end Quote Link to comment Share on other sites More sharing options...
havenphillip Posted November 2, 2019 Share Posted November 2, 2019 Cool, man. I had fun trying to solve that one. 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.