Topic was automatically imported from the old Question2Answer platform.
Asked By
Genesis689
I am making a game and for the start step I want to move the player to the start position using the main levels script but I can’t figure out how to do it from another objects script.
lets say movement_manager and player has same scene
|Game
|----Player
|----movement_manager
movement_manager
export var player_node_path: NodePath
#select player node in inspector
onready var player = get_node(player_node_path) as KinematicBody2D
var movement_speed: float = 200
var velocity: Vector2 = Vectory.ZERO
func _physics_process(delta: float) -> void:
# horizontal movement
velocity.x = Input.get_action_strength("right") - Input.get_action_strength("left) * movement_speed
# vertical movement (jump)
if Input.is_actioin_just_pressed("jump_button"):
jump()
velocity = player.move_and_slide(velocity)
there is more way to do this batter way. One is to call movement related function from player script without defining velocity and other movement related var in movement_manager script.
if movement manager is player node child then easy use is onready var player := get_parent()
or long way export var player_node_path : NodePath = ".."
`“…” denote parent