Jump to content

Player falling "into" floor on move


Driklyn
 Share

Recommended Posts

Have a player created from a pivot added to my map via the editor with these physics properties set:

 

Physics: Character Controller
Mass: 1.0
Collision: Character

 

And a floor underneath, a box with these physics properties set:

 

Physics: Rigid Body
Shape: Box
Shape size: (Fit Shape)
Mass: 0.0
Collision: Scene

 

When running the game, the player falls a few feet and lands on top of the floor correctly. However, once I move in any direction or rotate greater than +/- 45º or so on the y-axis, the player instantly warps into the floor, moving from a y-position of 0.273252 to 0.001953.

 

Any ideas why?

 

Here's my player script:

 

function Script:Start()
   self.camera = Camera:Create()
   self.camera:SetPosition(self.entity:GetPosition())
end

function Script:Move()
   local w = window:KeyDown(Key.W) and 1 or 0
   local a = window:KeyDown(Key.A) and 1 or 0
   local s = window:KeyDown(Key.S) and 1 or 0
   local d = window:KeyDown(Key.D) and 1 or 0

   return Vec3(d - a, 0, w - s):Normalize()
end

function Script:Look()
   local mouse = window:GetMousePosition()

   local center = Vec2(context:GetWidth() / 2, context:GetHeight() / 2)
   window:SetMousePosition(center.x, center.y)

   return Vec3(mouse.y - center.y, mouse.x - center.x, 0)
end

function Script:UpdatePhysics()
   local move = self:Move()
   local look = self:Look()

   look   = look + self.camera:GetRotation()
   look.x = Math:Clamp(look.x, -85, 85)

   self.entity:SetInput(look.y, move.z, move.x, move.y)

   self.camera:SetPosition(self.entity:GetPosition())
   self.camera:SetRotation(look)
end

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