I want to have a dynamic player impelemnted to the game, and give it the tags “111” so the script will then get the player entity then pull the player towards the planet with a feild of gravity but the current script is not functional even when I disabled gravity. The script SHOULD get the entity with the tag “111” and pull it to the planet. Here is the current script:
var GravityScript = pc.createScript('gravityScript');
GravityScript.attributes.add('pullForce', { type: 'number', default: 5 }); // Adjust the pullForce value as needed
// Called every frame
GravityScript.prototype.update = function(dt) {
var entities = this.app.root.findByTag('111');
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var direction = this.entity.getPosition().clone().sub(entity.getPosition()).normalize();
var force = direction.scale(this.pullForce * dt);
entity.rigidbody.applyForce(force);
}
};
Your Box entity that has this script attached has a Static rigidbody. You will need to set it to dynamic to be able to apply forces/impulses and changes in its velocity.
Nah I fixed it just now. All I had to do was make the planet stop rotating so I could get a good view of what happens, then I gave the planet gravity, and now the planet has gravity.
However it does have a weird effect at the bottom of the planet, the boxes orbit under the plaet strangly, this is not what I need. i need gravity pulling from all sides to the ground.