Force an actor to move at constant speed.

ProtoZoo

16-03-2007 17:37:32

Hi there!

I need to force an actor to move at a constant speed without slowing down. Like a rolling ball that never gets slower.

I did a very very 'brute-force'-like attempt by updating the actor each frame like this:

1) Get actors linear velocity to get the direction of the velocity
2) Set actors linear velocity with the constant value and the current direction.

Is there any better or more advance way to hold the same velocity continously?

Thanks a lot for your help! :D

betajaen

16-03-2007 17:56:02

That would work, but I don't know what would happen if it started to roll down a hill or up one for that matter.

You could try adding a force, calculating the velocity, then tune it up or down depending on what is needed. Problem is the beginning will be a gradual start up, until it "balances" itself out.

I'd try both and see what works best. :D

ProtoZoo

16-03-2007 18:01:14

That would work, but I don't know what would happen if it started to roll down a hill or up one for that matter.

The actor just moves on the xz plane. I've also implemented a function to prevent the body to bounce etc. by setting the y axis position to zero each frame.

I try that! Thanks a lot! :D

betajaen

16-03-2007 18:23:03

You can freeze the movement in the Y axis (body::freezeMovement(Vector3::UNIT_Y)), which is less harsh than your code and faster ;)

ProtoZoo

16-03-2007 18:46:34

You can freeze the movement in the Y axis (body::freezeMovement(Vector3::UNIT_Y)), which is less harsh than your code and faster ;)

Ah great! Thanks a lot! :D