[SOLVED] How would i make a rigid body apply force in the direction of the entity?

How would I make a rigid body force in the direction of an entity???

Hi @Fus_ion,

Here is an easy way to do that using some vector math:

var posPlayer = playerEntity.getPosition();
var posEnemy = enemyEntity.getPosition();

var direction = new pc.Vec3().copy(posPlayer).sub(posEnemy).normalize();

// now you can use the direction and scale it to become a force
var force = new pc.Vec3().copy(direction).scale(1000);



No, I mean like how would I do on this project for the player???

Same way, calculate the direction between the two objects as shown above. And then apply the force to the player.

1 Like