PhysicsSetPosition

This function calculates and adds a force to move the entity to the specified position in one physics step.

Syntax

Parameters

Example

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-8)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Create a model
model = Model:Box(1,1,1)
model:SetColor(0.0,0.0,1.0)

--Add a physics shape
local shape = Shape:Box()
model:SetShape(shape)

mousepos = window:GetMousePosition()

rot = Vec3(45,0,0)

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end

mousepos = window:GetMousePosition()
mousepos.z=5
local pos = camera:UnProject(mousepos)

local turnspeed=2
if (window:KeyDown(Key.Up)) then rot.x=rot.x+turnspeed*Time:GetSpeed() end
if (window:KeyDown(Key.Down)) then rot.x=rot.x-turnspeed*Time:GetSpeed() end
if (window:KeyDown(Key.Right)) then rot.y=rot.y+turnspeed*Time:GetSpeed() end
if (window:KeyDown(Key.Left)) then rot.y=rot.y-turnspeed*Time:GetSpeed() end

model:PhysicsSetPosition(pos.x,pos.y,pos.z,0.5)
model:PhysicsSetRotation(rot.x,rot.y,rot.z,0.5)

Time:Update()
world:Update()
world:Render()

context:Sync()
end