Hi LeXXik.
Yeah, i figured you would ask that…
The thing is my project is too complex to easily simplify and I cannot share it…
So all I can give you are some samples of the code:
PlayerMovement.prototype.update = function (dt) {
PlayerMovement.testPosition = this.position.clone().add(this.direction.clone().mulScalar(this.speed * dt));
// I test if there is ground at this position
var result = this.app.systems.rigidbody.raycastFirst(
PlayerMovement.testPosition.clone().add(new pc.Vec3(0, 2, 0)),
PlayerMovement.testPosition.clone().add(new pc.Vec3(0, -2, 0)),
{
filterCollisionGroup: pc.BODYGROUP_USER_3,
filterCollisionMask: pc.BODYGROUP_USER_4
}
);
if (result) this.position.copy(result.point);
this.entity.rigidbody.teleport(this.position.x, this.position.y, this.position.z, 0, this.rotY, 0);
}
I really don’t think anything is wrong with that, I’ve reviewed this code in detail.
I was looking for some idea of where I should dig… If anybody ever experiences that?
I was gonna post when suddenly… an epiphany
Something I just noticed, and I think this might be the issue:
Why would colision / rigid body alter the teleport, even so slightly, when there are no obstacles?
I have different collision groups in my project.
The floor colides with the raycast as seen in my code.
And the charcater uses a different group that can collide with obstacles (such as walls), but not the floor.
I take back the position at the begining of every loop to benefit from the the collisions feedback, before calculating where I should teleport on this update (code seed up there).
When I teleport in an area free of obstacles, I can assert that my character will not collide with anything, so the rigid body should teleport exactly where I tell him to.
And yet, my character is teleported slightly less far than I ask for.
Enough so that it can make a big difference cumulatively, especially when the framerate is higher.
When I disable the collision of my character, although I run trhough any obstacles, I have no issues of slowing down. My character runs the same, fluidly, whatever the framerate.
I hope this is clear…
Do you have any idea of how I could handle this issue?
Thanks.