I’ve pretty much copy pasted the Raycast tutorial code into my project but i’m getting an error on one of the source files.
Uncaught TypeError: Cannot read property ‘setValue’ of undefined
at RigidBodyComponentSystem.raycastFirst (playcanvas-stable.dbg.js:29141)
var MyRaycast = pc.createScript('myRaycast');
// initialize code called once per entity
MyRaycast.prototype.initialize = function() {
// Find the first entity in the hierarchy with the name 'Camera'
this.cameraEntity = this.app.root.findByName('AR Camera');
// Setup the different positions to move to
this.firstPosition = new pc.Vec3(-1, 1.25, 6.5);
this.secondPosition = new pc.Vec3(1, 1.25, 6.5);
// Add a mousedown event handler
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.mouseDown, this);
// Add touch event only if touch is available
if (this.app.touch) {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.touchStart, this);
}
};
MyRaycast.prototype.mouseDown = function (e) {
this.doRaycast(e);
};
MyRaycast.prototype.touchStart = function (e) {
// Only perform the raycast if there is one finger on the screen
if (e.touches.length == 1) {
this.doRaycast(e.touches[0]);
}
e.event.preventDefault();
};
MyRaycast.prototype.doRaycast = function (screenPosition) {
// The vec3 to raycast from
var from = this.cameraEntity.getPosition ();
// The vec3 to raycast to
var to = this.cameraEntity.camera.screenToWorld(screenPosition.x, screenPosition.y, this.cameraEntity.camera.farClip);
// Raycast between the two points
var result = this.app.systems.rigidbody.raycastFirst(from, to);
// If there was a hit, store the entity
if (result) {
//Do Stuff.
}
};
Can anyone help?