I am making a top down car game, using the new vehicle physics controller script. I am using the walls, so that car doesn’t go out of the environment, the one difficulty I am facing is that the car climbs the wall but I want it to bounce off the wall and not climb it.
@Leonidas Yes I tried to play with the Restitution, but got no result. I studied the script but couldn’t figure out on how to increase the height (Y axis) .
You can check out my project above.
@kungfooman Yes I tried this solution, if I hit from the front or back then it will not climb but if I am at max maximum velocity and hit the wall side ways ( i.e the wheels first), the car will climb up unfortunately.
You can check out my project above.
One more issue with this script is that when I apply force using the up arrow button, the vehicle will start moving and if I stop pressing the up arrow, the car will not slow down but it will keep on moving.
The code is this:
if (left && right) {
this.vehicleSteering = 0;
} else if (left) {
this.vehicleSteering = this.maxSteering;
} else if (right) {
this.vehicleSteering = -this.maxSteering;
} else {
this.vehicleSteering = 0;
}
if (up && down) {
this.engineForce = this.brakingForce = 0;
} else if (up) {
//console.log("Up");
// if we are moving backwards then apply brake
// otherwise apply engine force
console.log("up");
if (this.direction.dot(this.entity.forward) > 0) {
this.brakingForce = this.maxBrakingForce;
this.engineForce = 0;
} else {
this.brakingForce = 0;
this.engineForce = this.maxEngineForce;
}
} else if (down) {
// if we are moving forward then apply brake
// otherwise apply opposite engine force
if (this.direction.dot(this.entity.forward) < 0) {
this.brakingForce = this.maxBrakingForce;
this.engineForce = 0;
} else {
this.brakingForce = 0;
this.engineForce = -this.maxEngineForce;
}
} else { // Slowly stop the car if car is moving
this.engineForce = 0;
this.brakingForce = 0;
}
In the last else, if I set the brakingForce to 10 or any other value then 0, the car will slowly come to a stop but then another issue comes up. The issue is that when the car comes to a stop and I press the up arrow key to move the car, there will be delay in the car movement.
So this is the link in which the car will come to a stop but the force will have a delay in moving the car afterwards.( i.e you have to press the up or down button for half a second to make the car move), I set the this.brakingForce = 10, the car also gets stuck to the wall due to this change.
And this is the link where their is no delay in the input but the car wont stop moving:
I set this.brakingForce = 0 in the last else part. The car wont get stuck in the wall since brakingForce is set to 0.
I don’t think your code has any issue, it seems to be more like an Ammo.js issue.
I’ve just tried the default example, and I got the same behavior, releasing forward leaves the vehicle accelerating forward at a constant velocity:
Not sure if that is the default behavior of the applyEngineForce but it sounds more like a bug. I would try submitting an issue about this in the Ammo.js repository.
I checked this variable var velo = this.vehicle.getRigidBody().getLinearVelocity();
and it stays 0.1633 at idle. If I press the forward button it will increase and if I stop pressing it wont decrease but it stays the same, until I press the brake button or if I steer left or right then it also decreases a bit.
Yes this seems to be a bug in Ammo.js with either friction not applying or the applyEngineForce not removing the thrusting force when a zero value is passed.
Try submitting an issue to the Ammo.js repository about it: