I am trying to use the physics extension above to create a boxCast underneath the player which I could get it to work however there is a problem with the raycast detecting the player entity constantly.
code of the isGrounded function:
PlayerJumping.prototype.isGrounded = function () {
let halfExtents = this.playerCollision.collision.halfExtents;
let start = this.playerCollision.getPosition();
let end = this.entity.getPosition();
this.jumpRaycastStart.copy(start);
this.jumpRaycastEnd.copy(end);
// make adjustment to start and end points
//this.jumpRaycastStart.y += -;
this.jumpRaycastEnd.y += 0;
const result = this.app.systems.rigidbody.boxCast(halfExtents, this.jumpRaycastStart, this.jumpRaycastEnd);
let colliding = false;
if (result && result.entity.rigidbody && result.entity !== this.entity) {
colliding = true;
}
else {
colliding = false;
//return;
}
console.log(result.entity.name);
console.log(result);
// debug
this.app.drawLine(this.jumpRaycastStart, this.jumpRaycastEnd, colliding ? pc.Color.GREEN : pc.Color.RED);
return colliding;
};
As recommended in the topic of Mr LeXXik I made sure the player only jumps if the raycast result does not return the player entity which is the current entity (this.entity) but the player entity is detected by the convexcast and because of that sometimes the player is not able to jump when pressing space. I do not want the player entity being detected by the raycast. I tried to debug the issue but I do not know what I am looking for to fix this.
Below is a video of what I mean: How do I eliminate the player being detected by the convexcast which makes the player not able to jump when pressing space?
Hi @nasjarta! If the extension is like raycastFirst, your result will be unreliable if you want to filter the player entity, because it only checks for the first collision (even if the result is the player entity). What you might do is execute the ground check again if the result is the player entity.
i recommend doing result.entity.name !== "player_name"; instead of doing result.entity !== this.entity, this is the case because result.entity returns a object not a string. so its pretty much hard to filter by just doing the entity
I tested my suggestion myself and I get an Maximum call stack size exeeded error with this. Not sure why, but you can skip the suggestion.
Apart from that, I don’t really understand why your player entity is detected at all. I tried also raycastFirst and raycastAll with your setup and with this it works indeed fine. I hope @LeXXik knows the answer.
Right, so in order to avoid the player rigidbody, you should use filter masks. I didn’t add support for it in the original script, but you can do it like this:
Edit convex-cast.js:
// after this line
var convexCallback = new Ammo.ClosestConvexResultCallback(data.ammoPosFrom, data.ammoPosTo);
// add this one:
convexCallback.set_m_collisionFilterMask(pc.BODYMASK_ALL ^ pc.BODYGROUP_USER_1);
This will do a sweep test against all bodies in the physics world, except those that belong to user group 1.
And somewhere in your script, update your player rigidbody by assigning it to the first user group:
The filter mask is very useful to exclude certain entities not being detected by the convex cast.
Would anybody know is it possible to get the individual sides of a collider (e.g. cube)? I want to include them in the filter as well? Example of what I mean:
unfortunately I test that already it detects even collisions that are 0 on y axis. For example in the above cube the red filter areas make it multi-jump even when the collision is thin. I am trying to find a way to filter out the other sides of the cube apart from the top side.
Sorry, I don’t understand what you try to achieve. Red part is with filter so no ground detection here? Green part is without filter so ground detection here?
That is not possible if you assigned the player layer to this entity.
Not sure what you mean with this.
What about making the boxCast a little smaller than the actual collision component of the player? Then it’s almost impossible for the boxCast to have a collision with the sides of the box.
I put a thin collider (plane) on top of the cube and added the cube to the filter so only the plane is detected by the raycast. But once you are next to the cube on the side and spam jump the raycast still detects the plane collision and you can multi-jump: