Rigid body consistant speed

Hey all,

I’m trying to get an object moving with a rigid body. I’m using .applyForce and applyImpulse. Now, unless my eyes are lying to me, which very well may be the case, both those methods look the keep adding the force to my object and it keeps speeding up faster and faster. I just need a consistent speed

code in the update function looks like

this.entity.rigidbody.applyImpulse(1, 0, 0);

or

this.entity.rigidbody.applyForce(1, 0, 0);

Not sure what I am doing wrong, thank you for any help.

Ross

Hi @Ross_Lehr!

Does this object need to react to others touching it, or just move as an unstoppable the affects others? If it’s the latter, you can just change the rigidbody type to kinematic and use setPosition() or setLocalPosition() as you would any other object.

If you use it in the update function then that’s to be expected.

I’m curious if that is a normal behavior, because I didn’t notice that in my own game. Maybe it depends on the rigidbody settings?

If you can use a kinematic rigidbody and want to apply a constant speed you can also use the line of code below (in the update function).

this.entity.translateLocal(1, 0, 0);
1 Like

That worked. Thanks!!

Just a little more detail incase anyone else has the same question… the code in general is for NPC vehicles. They just drive around the city. The collisions spots live in intersections and tell the vehicles which way they can turn.

Ross

Sounds interesting, I’m curious to the result!

Yes, an NPC driving system seems cool

Is there a way to share the link to the compiled game? it’s very much a prototype, but I’m happy to share what I have.

Ross

If you mean a normal build of your (private) project, you can share here a link if you want.

Here’s what I have so far. Feel free to ask questions or offer suggestions Works pretty good, but every now and then the cars bunch up at an intersection.

You can reload the page and get a new random “city” layout.

NPC vehicle manager.

I’m a bit late to this, you can set the linearVelocity on the rigidbody component for this RigidBodyComponent | PlayCanvas API Reference

1 Like

Unfortunately, we are unable to see the launch page of your project if your project is private. You can show your progress by sharing a link of a build.

https://developer.playcanvas.com/en/user-manual/publishing/web/playcanvas-hosting