Jump to content

Movement smoothing problem


YouGroove
 Share

Recommended Posts

Well like said, i put a bsic box with charcater controller.

Than put as child the model non physic, only rendering model player.

 

I try to smooth actual position and calculated position given by SetInput.

It seems it is not working ?

how to have character position and next position after the SetInput is called ?

 

 


function Script:Movement()

self.prevPos = self.entity:GetPosition()

-- handle player movement
self.playerMovement.z = ((App.window:KeyDown(Key.W) and 1 or 0) - (App.window:KeyDown(Key.S)and 1 or 0)) * Time:GetSpeed() * self.moveSpeed
--self.playerMovement.x = ((App.window:KeyDown(Key.D) and 1 or 0) - (App.window:KeyDown(Key.A)and 1 or 0)) * Time:GetSpeed() * self.moveSpeed

-- reduce speed when moving backwards
--if self.playerMovement.z < 0 then
-- self.playerMovement.z = self.playerMovement.z * .50
--end

-- move the camera to the player and set the yaw from 3rd person view
self.Camera:SetPosition(self.entity:GetPosition(true), true)
self.Camera:SetRotation(Vec3(self.cameraPitch, self.cameraYaw, 0), true)

-- offset the camera up and back
self.Camera:Move(0, 3, -7)

-- rotate the model along with the camera
self.entity:SetRotation(Vec3(0, self.cameraYaw, 0))

-- move the controller in the rotation of the player
self.entity:SetInput(self.cameraYaw, self.playerMovement.z, 0 --[[self.playerMovement.x]], 0, false, 1)


local x = Math:Curve(self.entity:GetPosition(true).x, self.prevPos.x, self.smoothen.x / Time:GetSpeed())
local y = Math:Curve(self.entity:GetPosition(true).y, self.prevPos.y, self.smoothen.y / Time:GetSpeed())
local z = Math:Curve(self.entity:GetPosition(true).z, self.prevPos.z, self.smoothen.z / Time:GetSpeed())

play=self.entity:FindChild("player")
if play ~= nil then
play:SetPosition(Vec3(x,y,z))
end



end

 

If anyone can help on that, i will make it a contribution as "smoothed character controller" in the workshop.

Stop toying and make games

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