Switching between fps walking controls and driving controls

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By andersmmg

I can’t seem to figure out a good, working way to do this.
I have a game with fps-style controls for walking around and doing things, and I also have a working vehicle. I want to be able to switch to driving (like get in and out of the car) like you do in a lot of games.

I think that would be 3D animation to get in and out of the vehicle and a script to attach the player to the vehicle (if you don’t have player-vehicle collision) then just enable/disable the script that handles FPS control and one that handles vehicle control.

Dlean Jeans | 2019-06-08 07:02

:bust_in_silhouette: Reply From: Magso

You can use the visible property to do this. You would first need to set up an area around the vehicle and check if the first person character has entered it. Then check for input to confirm getting in the vehicle and set visible to false and activate the vehicle script using a boolean. When getting back out you would need to teleport the first person character next to the vehicle and set visible to true. e.g.

func _on_vehicle_body_entered(body):
    if body.name == player.name && Input.is_action_pressed("enter_vehicle"):
        player.visible = false
        #assuming vehicle has script with is_driving boolean
        vehicle.is_driving = true

and for the vehicle

func _process(delta):
    if Input.is_action_pressed("exit_vehicle"):
        player.translation = Vector3(translation.x + car_width, translation.y, translation.z)
        is_driving = false
        player.visible = true