three.jswebglphysicsphysijs

Physijs Three.js - Set maximum velocity on an object


Hi there I am working with a simple box which I'm applying an impulse each frame to get it moving using

character.applyCentralImpulse({x: 1, y: null, z: null});

However I want to restrict it's velocity in a direction so it doesn't just fly off - but I can't figure out a way of doing this as I can't find anything in the documentation.

Is this possible with Physijs?


Solution

  • So it turn out the only way to achieve this is to check on each render the velocity of the object and to limit it manually

            //running right
            if(character.getLinearVelocity().x > 15){
                character.setLinearVelocity({x: 15, y: character.getLinearVelocity().y, z:character.getLinearVelocity().z});
            }
            //running left
            if(character.getLinearVelocity().x < -15){
                character.setLinearVelocity({x: -15, y: character.getLinearVelocity().y, z:character.getLinearVelocity().z});
            }