Hi,
I am using app.systems.rigidbody.raycastFirst
to build a playercontroller. However, it seems that this call will often fail for find colliders which it did pass through.
Every update, I cast a ray from the player’s position at the start of the frame, to the player’s position at the end of the frame.
Debugging my script, I can see a raycast going from outside the collision volume to inside the collision volume, and yet I do not get a results callback.
However, this behaviour is inconsistent. Sometimes it detects it, and sometimes it doesn’t. I can’t seem to find a pattern, although it is starting to seem like it might be related to really small movements (eg. if I move the player slowly they can slip through raycast detection - perhaps there is a min ray length).
Here is the abridged version of my code:
update: function (dt) {
var startPos = this.entity.getPosition().clone();
....
this.entity.translate(forwardVel.x, forwardVel.y, 0);
if (forwardVel.y < 0) {
this._checkGround(startPos);
}
},
_checkGround: function (start) {
var self = this;
app.systems.rigidbody.raycastFirst(start, this.entity.getPosition(), function (result) {
// OFTEN NOT CALLED WHEN IT SHOULD!
self.onTouchGround(result.entity);
});
},
Full source: PlayCanvas | HTML5 Game Engine