AI scripting for NPCs or BOTs

Okay, cool. Let’s summarize a bit, shall we?

First of all, the setup. As I want my NPC (collider and children model) to move only forward (referenced to the collider itself), and turn right/left (again referenced to the collider itself), this is the setup I came up with:

image

Now, the coordinates. I don’t think I should use world coordinates, but instead the local this.entity.forward vector, because I want to move the NPC forward (Z) to what he is facing in that moment, not the global Z (which is allways the same), right? The Y axis works the same I guess, I want my NPC to turn his right, not the world’s right… Right? :smile:

I really think I’m overkilling this simple task right now. If I try to torque my entity, they either do not torque at all, or spins furiously uncontrolled, and can’t even be syncronized with my turn animation at all. The same for moving. If I apply a force with entity.forward, it either doesn’t move at all, or as I increase the digits my NPC dissapears from the map at lightspeed.

I’m sure this has to deal with the Kilograms my NPC weights (50kg), the damping, the factors, the frictions and whatever other mathematical magnitude I’m surely forgetting…

So, to summarize again:

  • To rotate an entity (and its children with it), I should use:
this.entity.rigidbody.applyTorque(this.entity.up * this.rotateSpeed * dt);
  • To move an entity (and its children with it), I should use:
this.entity.rigidbody.applyForce(this.entity.forward * this.moveSpeed * dt);

Or instead:

this.entity.rigidbody.applyTorque(new pc.Vec3(0, this.rotateSpeed * dt, 0);
this.entity.rigidbody.applyForce(new pc.Vec3(0, 0, this.moveSpeed * dt);

Or neither?