Improving character controller
This commit is contained in:
@@ -94,7 +94,8 @@ tick_physx :: (scene: *PhysX_Scene, dt: float) {
|
||||
if physx_actor.type == .CHARACTER {
|
||||
vel := e.physics.velocity + PHYSX_GRAVITY * dt;;
|
||||
movement := vel * dt;
|
||||
flags := PhysX.PxController_move(physx_actor.controller, *movement, 0.001, dt, *filter, null);
|
||||
print("Velocity %\n", movement);
|
||||
flags := PhysX.PxController_move(physx_actor.controller, *movement, 0.0, dt, *filter, null);
|
||||
new_position := PhysX.PxController_getPosition(physx_actor.controller);
|
||||
position := Vector3.{xx new_position.x, xx new_position.y, xx new_position.z};
|
||||
e.physics.velocity = (position - e.transform.position) / dt;
|
||||
@@ -168,12 +169,16 @@ pre_physx_sync :: (game_scene: *Scene) {
|
||||
physx_actor := parray_get(*game_scene.physx_scene.actors, it.physics.physx_handle);
|
||||
if physx_actor.type == {
|
||||
case .DYNAMIC; {
|
||||
pose := PhysX.PxTransform_new(*it.transform.position, *it.transform.orientation);
|
||||
PhysX.PxRigidActor_setGlobalPose(physx_actor.dynamic, *pose, true);
|
||||
// @Incomplete: Might wanna do this differently or at least not every frame?
|
||||
// We could potentially cache the last saved position and not update the pose, if PhysX is synced up
|
||||
pose := PhysX.PxTransform_new(*it.transform.position);
|
||||
PhysX.PxRigidActor_setGlobalPose(physx_actor.dynamic, *pose, true);
|
||||
PhysX.PxRigidDynamic_setLinearVelocity(physx_actor.dynamic, *it.physics.velocity, true);
|
||||
}
|
||||
case .STATIC; {
|
||||
pose := PhysX.PxTransform_new(*it.transform.position, *it.transform.orientation);
|
||||
PhysX.PxRigidActor_setGlobalPose(physx_actor.static, *pose, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
create_physx_actor(it);
|
||||
@@ -213,10 +218,10 @@ create_physx_actor :: (e: *Entity) {
|
||||
desc.radius = e.physics.character.radius;
|
||||
desc.stepOffset = 0.2;
|
||||
desc.slopeLimit = cos(PI * 0.25);
|
||||
desc.contactOffset = 0.01;
|
||||
desc.contactOffset = desc.stepOffset * 0.1;
|
||||
desc.material = material;
|
||||
desc.position = .{xx e.transform.position.x, xx e.transform.position.y, xx e.transform.position.z};
|
||||
desc.density = 10.0;
|
||||
desc.density = 40.0;
|
||||
desc.userData = null;
|
||||
|
||||
scene := engine.current_scene.physx_scene;
|
||||
|
||||
Reference in New Issue
Block a user