I'm trying to use a PxController for my player character, but I'm having a bit of trouble.
This is how I'm creating the controller:
local mat = physx.CreateMaterial(0.5,0.5,0.1)
local controller = physx.CreateCapsuleController({
height = 64,
radius = 18,
material = mat,
contactOffset = 0.01
})
local actor = controller:GetActor()
The code snippets are in lua, but all these functions do internally is call the equivalent physx-functions.
After the controller has been created, it's being moved every time the world is simulated:
local dir = Vector(math.sin(CurTime()),0,math.cos(CurTime())) -- Move the controller in a circle; CurTime() is the time that has passed since the program start
dir = dir *10
local disp = dir *DeltaTime() -- DeltaTime() = time since last world simulation
controller:Move(
disp,
0.01,
DeltaTime()
)
local vel = actor:GetLinearVelocity()
local speed = vel:Length()
print(math.abs(speed -dir:Length())) -- Should be 0, but fluctuates quite a bit
The actual movement works as intended. If I compare the new position, after the whole PxScene was simulated, to the old position (before the "Move"-Call), the difference is exactly the displacement vector.
The velocity, however, is behaving strangely. The way I see it, getLinearVelocity should return the same as the displacement vector, but there's a small, random, deviation, but it's too large to be a precision error of some sort. What am I missing?
One more thing:
I can move the controller in any direction, even upwards from the ground. How would I actually restrict the movement so the controller actually sticks to the ground? And what exactly is the point of the 'setUpDirection'-function for PxControllers if it doesn't already do that?