This functions set the movement parameters of an entity that uses the CharacterPhysics physics mode.
When an entity uses character physics, the physics will control the object's rotation, and calls to Entity::SetRotation() and similar functions will have no effect.
The input values should not be modulated by the application speed. The physics system will automatically adjust motion according to the framerate.
--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-8)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
--Enable navmesh debugging
camera:SetDebugNavigationMode(true)
--Create the ground
local ground = Model:Box(10,1,10)
ground:SetPosition(0,-0.5,0)
ground:SetColor(0.0,0.25,0.0)
--Create a shape
local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)
ground:SetShape(shape)
shape:Release()
--Create a model
--This is an obstacle the player will walk around
entity = Model:Box(1,1,3)
entity:SetColor(0.0,0.0,1.0)
entity:SetPosition(0,5,0)
entity:SetMass(1)
--Create a shape
local shape = Shape:Box(0,0,0,0,0,0,1,1,3)
entity:SetShape(shape)
shape:Release()
--Enable navigation obstacles
ground:SetNavigationMode(true)
entity:SetNavigationMode(true)
--Create a character
player = Pivot:Create()
local visiblecapsule = Model:Cylinder(16,player)
visiblecapsule:SetScale(1,2,1)
visiblecapsule:SetPosition(0,1,0)
player:SetPosition(-4,0,0)
player:SetMass(1)
player:SetPhysicsMode(Entity.CharacterPhysics)
while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
local move = ((window:KeyDown(Key.Up) and 1 or 0) - (window:KeyDown(Key.Down) and 1 or 0))*4
local strafe = ((window:KeyDown(Key.Right)and 1 or 0) - (window:KeyDown(Key.Left) and 1 or 0))*4
player:SetInput(0,move,strafe)
world:Update()
world:Render()
context:Sync()
end