Car movement and speed control ?

Hello All,

I am working on car movement using swipe direction. I want if swipe direction is in the direction where car is moving then its speed gets increase but if swipe direction is opposite to car then its speed gets decreased. If you have any script or logic for doing this then please help me.

Thanks

I just built a system for something like this for the miniLD, except it’s not touch and it works on the X/Y axis.
The touch problem should be easy to fix though. I’ll publish it after I get it on my computer(it’s on my laptop atm).

For now any help on this ?

My code is pretty messy, but here’s the base of it:

//Speed
var CurrentAcceleration : float = 0.0;
var MovementAcceleration : float = 2.5;
var MovementDeceleration : float = 2.5;
var MaxMovementAccel : float = 15.0;
var CurrentAccelerationUp : float = 0.0;
var MovementAccelerationUp : float = 2.5;
var MovementDecelerationUp : float = 2.5;
var MaxMovementAccelUp : float = 15.0;

function Update(){
    if(Input.GetAxis("Horizontal") == 0){
        if(CurrentAcceleration != 0){
            if(CurrentAcceleration > 0){
                CurrentAcceleration -= MovementDeceleration;
            }
            if(CurrentAcceleration < 0){
                CurrentAcceleration += MovementDeceleration;
            }
            
            if(CurrentAcceleration >= 0  CurrentAcceleration <= 1){
                CurrentAcceleration = 0;
            }
            if(CurrentAcceleration <= 0  CurrentAcceleration >= -1){
                CurrentAcceleration = 0;
            }
        }
        this.rigidbody.velocity.x = CurrentAcceleration;
    }
    
    if(Input.GetAxis("Vertical") == 0){
        if(CurrentAccelerationUp != 0){
            if(CurrentAccelerationUp > 0){
                CurrentAccelerationUp -= MovementDecelerationUp;
            }
            if(CurrentAccelerationUp < 0){
                CurrentAccelerationUp += MovementDecelerationUp;
            }
            
            if(CurrentAccelerationUp >= 0  CurrentAccelerationUp <= 1){
                CurrentAccelerationUp = 0;
            }
            if(CurrentAcceleration <= 0  CurrentAccelerationUp >= -1){
                CurrentAccelerationUp = 0;
            }
        }
        this.rigidbody.velocity.y = CurrentAccelerationUp - 4;
    }
    
    if(Input.GetAxis("Horizontal")>0){
        if(CurrentAcceleration < MaxMovementAccel){
        CurrentAcceleration += MovementAcceleration;
        }
        //this.rigidbody.AddForce(transform.right * CurrentAcceleration);
        this.rigidbody.velocity.x = CurrentAcceleration;
    }
    
    if(Input.GetAxis("Horizontal")<0){
        if(CurrentAcceleration > -MaxMovementAccel){
        CurrentAcceleration -= MovementAcceleration;
        }
        //this.rigidbody.AddForce(transform.right * CurrentAcceleration);
        this.rigidbody.velocity.x = CurrentAcceleration;
    }
    
    if(Input.GetAxis("Vertical")>0){
        if(CurrentAccelerationUp < MaxMovementAccelUp){
            CurrentAccelerationUp += MovementAccelerationUp;
        }else{
            if(CurrentAccelerationUp > 0){
                CurrentAccelerationUp -= MovementAccelerationUp;
            }
            if(CurrentAccelerationUp < 0){
                CurrentAccelerationUp += MovementAccelerationUp;
            }
        }
        //this.rigidbody.AddForce(transform.up * CurrentAccelerationUp);
        this.rigidbody.velocity.y = CurrentAccelerationUp;
    }
}

Don’t exactly know how I would make this work with touch controls, you’ll probably have
to figure that out.

Thanks for this