[SOLVED] Raycast not fireing

For some reason the raycast won’t fire.

// More information: http://developer.playcanvas.com/en/api/pc.RigidBodyComponentSystem.html
var Wallride = pc.createScript('Wallride');
var tilt = 'hi'
Wallride.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
    this.entity.collision.on('collisionend', this.oncollisionend, this);
    this.leftPosition = this.entity.findByName('raycast_left').getPosition();
    this.eulers = new pc.Vec3();
};

Wallride.prototype.onCollisionStart = function (result) {
    if (result.other.tags.has('wallride')) {
        console.log('1st hit')
        this.doRaycast_left()
        
        
    }
};



Wallride.prototype.doRaycast_left = function (screenPosition) {
    console.log('func started')
    // The pc.Vec3 to raycast from
    var from = this.entity.getPosition();
    // The pc.Vec3 to raycast to 
    var to = this.leftPosition;
    // Raycast between the two points

    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    
    // If there was a hit, store the entity
    if (result) {
        console.log('2nd hit')
        tilt = 'left'
    }    
};

hello?

Please wait patiently for a reply.

Your script seems to be correct. Can you share your project so someone can take a look? Please also mention which scenes, entities and scripts are involved.

https://playcanvas.com/project/1061069/overview/zoom

just wallrun and the end movement scripts are used.

On line 27 of your script you should do like below.

var to = this.entity.findByName('raycast_left').getPosition();

My example from the other topic is actually useless, because it just gets the position of the child entity at the start of the game. I will modify this example. Sorry about that.

1 Like