Hey, I just started a quick project using the newest engine version.
I’m getting the mouse position and then converting to world coords, then raycasting the mouse position to know where the mouse physically is with RaycastAll, then filtering the results using entity name to get the “Ground” entity.
So this works with no issue.
The surprise comes when I’m moving around the player controller (Sphere rigidbody) and collide it againast a box rigidbody which is NOT the “Ground” entity, just an obstacle in the world.
I’m getting this error:
launch.js:7876 RuntimeError: memory access out of bounds
at wasm-function[14]:0x34b1
at wasm-function[64]:0x567e
at gB.__destroy__ (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.js?id=30431389&branchId=90874b16-9c90-4d68-8d41-597770bbb8af&t=6b7ab3989e4f9f17c86e44380f9181c6:660:443)
at Object.b.destroy (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.js?id=30431389&branchId=90874b16-9c90-4d68-8d41-597770bbb8af&t=6b7ab3989e4f9f17c86e44380f9181c6:458:110)
at RigidBodyComponentSystem.raycastAll (https://code.playcanvas.com/playcanvas-stable.dbg.js:32509:12)
at script.TankController.SeekMouse (https://launch.playcanvas.com/api/assets/files/Scripts/tankController.js?id=30431652&branchId=90874b16-9c90-4d68-8d41-597770bbb8af:75:46)
at script.TankController.update (https://launch.playcanvas.com/api/assets/files/Scripts/tankController.js?id=30431652&branchId=90874b16-9c90-4d68-8d41-597770bbb8af:98:10)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:29833:21)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:29869:14)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:30284:51)
This is the SeekMouse function:
var farClip = Game.context.camera.farClip;
var nearClip = Game.context.camera.nearClip;
Game.context.camera.screenToWorld(this.mouseScreenPos.x, this.mouseScreenPos.y, nearClip, this.tempVec);
Game.context.camera.screenToWorld(this.mouseScreenPos.x, this.mouseScreenPos.y, farClip, this.tempVec2);
var results = this.app.systems.rigidbody.raycastAll(this.tempVec, this.tempVec2);
if(results){
var groundCast = results.filter(function(elm){
if(elm.entity.name === 'Ground'){
return elm;
}
});
if(groundCast !== null && groundCast !== undefined){
if(groundCast.length > 0){
this.tempVec.copy(groundCast[0].point);
this.tempVec.set(this.tempVec.x, this.turretHolder.getPosition().y, this.tempVec.z);
this.turretHolder.lookAt(this.tempVec);
}
}
}
If I move around without colliding against an obstacle, all is good. Problem comes when I do collide against something. It’s been a total surprise.
Things i’ve tried to fix:
- Remove the filter and just use the first result in the results array (exception happens).
- Change the Sphere collider to a Box collider (exception happens).
- Change to RaycastFirst (no exception happens).
What could be going on?