https://developer.playcanvas.com/en/tutorials/vehicle-physics/
Please help me program the vehicle used in the above tutorial to rotate back straight after when the player is done swerving left or right and is holding the touch on the screen, i.e when swipeDelta = 0;
Here is my code. I have implemented touch movements.
VehicleControls.prototype.update = function (dt) {
var targetVehicle = this.targetVehicle ? this.targetVehicle : this.entity;
if (targetVehicle && this.canPlay)
{
var steering = 0;
var throttle = 0;
if(this.touching)
{
this.upButtonPressed = true;
let swipeDelta = 0;
if (this.touching)
{
swipeDelta = this.currentPosition.x - this.startPosition.x;
if(swipeDelta == 0)
{
this.leftButtonPressed = false;
this.rightButtonPressed = false;
}
else if(swipeDelta < 0)
{
this.leftButtonPressed = true;
this.rightButtonPressed = false;
}
else if(swipeDelta > 0)
{
this.leftButtonPressed = false;
this.rightButtonPressed = true;
}
this.startPosition.copy(this.currentPosition);
}
}
else
{
this.upButtonPressed = false;
}
if (this.leftButtonPressed || this.leftKeyPressed) steering++;
if (this.rightButtonPressed || this.rightKeyPressed) steering--;
if (this.upButtonPressed || this.upKeyPressed) throttle++;
if (this.downButtonPressed || this.downKeyPressed) throttle--;
targetVehicle.script.vehicle.fire('vehicle:controls', steering, throttle);
}