2D Entering car

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

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

:bust_in_silhouette: Reply From: Sween123

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)

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

TheMixer | 2020-03-18 19:37

You’re welcome.

Sween123 | 2020-03-19 00:31

:bust_in_silhouette: Reply From: Anutrix

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.