+1 vote

Hi! I maked 2 kinematic bodys: Player and Car, Both got own script to move (not equal).
I am making a top down 2D game and I dont have a clue how to make the player enter the car.I want the car and the player same keys but if I do right now they are both moving.
I wanted to make something like: player need to get close to car click f then he enter the car and he ride a car.Some clues how to do that ?

I'm using Godot 3.2.1

in Engine by (13 points)

2 Answers

+1 vote

Sure.
You need a new variable, for example: var is_Player_in_car = false
If is_Player_in_car == true, you use the script for either the car or the player to move and the other to follow it. So you only use one to control the movement. (For following the one that is controlling the movement so they will look like a single object, you can use something like this: A.position = B.position)
Otherwise if the player is not in car, move the player as how it moves without bothering the car.
When you press F and when the condition that you are close to the car is true, turn is_Player_in_car to true, and make one of them to lock its position to the other that controls the movement. (You decides which one to control the movement, it can be player or the car, both are fine)

by (813 points)

I modify your plan a little, but it works. Thank you very much.

You're welcome.

+1 vote

Similar to @Sween123 's answer, keep a boolean to check if Player is close to Car. Just that instead of A.position = B.position, add the player as a child to the car. Then, disable the Player's movement script and enable the Car's movement script.

by (51 points)
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 Frequently asked questions and 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 [email protected] with your username.