Player does not move with boat correctly

this videos shows and explains the issue

the fix I found

var Force = pc.createScript('force');
Force.attributes.add('target', {type:('entity')});
Force.attributes.add('xforce', {type:('number')});
Force.attributes.add('yforce', {type:('number')});
Force.attributes.add('zforce', {type:('number')});


// initialize code called once per entity
Force.prototype.initialize = function() {

};

// update code called every frame
Force.prototype.update = function(dt) {
    //this.target.rigidbody.applyForce(this.xforce, this.yforce, this.zforce);

    // 1. Create a vector from your attributes
    var localForce = new pc.Vec3(this.xforce, this.yforce, this.zforce);

    // 2. Transform the local vector into world space using the script giver's rotation
    var worldForce = new pc.Vec3();
    this.entity.getWorldTransform().transformVector(localForce, worldForce);

    // 3. Apply the rotated force to the target's rigidbody
    this.target.rigidbody.applyForce(worldForce);

    this.target.setRotation(this.entity.getRotation());
};

// uncomment the swap method to enable hot-reloading for this script
// update the method body to copy state from the old instance
// Force.prototype.swap = function(old) { };

// learn more about scripting here:
// https://developer.playcanvas.com/user-manual/scripting/
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.