Stona Persona Posted February 19, 2023 Share Posted February 19, 2023 CamOffset = -5 CamRot = 0 CamHeight = 2 function Script:Start() PlayerCamera = Camera:Create() end function Script:UpdateWorld() PlayerCamera:SetPosition(self.entity:GetPosition().x, self.entity:GetPosition().y + CamHeight, self.entity:GetPosition().z + CamOffset) local window = Window:GetCurrent() local context = Context:GetCurrent() window:SetMousePosition(context:GetWidth()/2, context:GetHeight()/2) mx = context:GetWidth()/2 my = context:GetHeight()/2 CurrMPos = window:GetMousePosition() mxdiff = Math:Clamp(CurrMPos.x - mx,-45,45) PlAngle = Math:CurveAngle(self.entity:GetRotation().y + mxdiff, self.entity:GetRotation().y , Time:GetSpeed()) local move = 0 local strafe = 0 self.entity:SetInput(PlAngle, move, strafe) end Hello guys, so, i have this above code where im trying to get an entity to rotate around its Y-axis when i move the mouse from side to side. It kinda works but the rotation is not smooth and the entity just jumps to rotation values instead of rotating to them smoothly. What am i doing wrong there? Thanks in advance for your time. 1 Quote Link to comment Share on other sites More sharing options...
Alienhead Posted February 20, 2023 Share Posted February 20, 2023 Your going to want to use lerp to handle smoothing out the angle differences. function LerpNumber(p0, p1, a) a = math.min(a, 1) return p0 + ((p1 - p0) * a) end p0 is your new angle projection p1 is the current angle of the entity and a is the speed at which you want to move into that new projection angle. The function will return the amount to change the entity angle. So basically, rough example : self.entity:SetInput(LerpNumber(currentY, mx, .1), move, strafe) 2 Quote I'm only happy when I'm coding, I'm only coding when I'm happy. 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.