How to exit a car in 2d

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

hi, so I’ve been playing around with godot for a few months now and been trying to work out some simple architecture for my concepts and mechanics.

at the moment I’m working on a test project in 2d.

I’m trying to mimic the original gta game , a top down game with driving but also with on foot style gun play.

now I’ve successfully got my player to enter the car, but exiting the car isn’t working,

i used this YouTube video to as a baseline guide

func enteringCar():
if Input.is_action_pressed(“enter_vehicle”) && car_zone == true :

	var hidden_player = get_parent().get_node("Player") = false
	active = true

func leavingcar():

var vehicle = "."
var hidden_player = get_parent().get_node("Player")

var newLoc = vehicle.global_transform.origin - 2*vehicle.global_transform.basis.x
if Input.is_action_pressed("enter_vehicle"): = true
	print("exiting car")
	active = false
	print("de-activating vehicle")
	hidden_player.global_transform.origin = newLoc 

the issue seems to be var newLoc = vehicle.global_transform.origin - 2*vehicle.global_transform.basis.x and hidden_player.global_transform.origin = newLoc

it says invalid index “global transform” on base “string” now i know or have some idea that within the leaving car function the global transform isn’t recognised, I’ve tried using various alternatives
I’ve tried tweaking it and even put a position2d node at the side of the car and tried the get mouse position then to unhide the player model at the mouse position. I’ve tried making the player a child of the car, and tried rewriting the script to place the player at an area node.

so I guess I’m asking for a bit of help writing the leaving car function for 2d. my player is already hidden and the car is active, but no amount of experimentation seems to get the player to unhide, i will admit that positioning and placement are not really things i’m experienced on

:bust_in_silhouette: Reply From: Rargleth

I think that global_transform is used for 3D so if you want to make it 2D use position.

hidden_player.position = newLoc 

And as for the newLoc, I’m not sure what your formula does but if you use a Position2D you just have to do

newLoc = get_node("Position2D").position