0 votes

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.

in Engine by (612 points)

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.

1 Answer

0 votes
Best answer

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
by (3,211 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.