0 votes

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.

in Engine by (34 points)

1 Answer

+1 vote

lets say movement_manager and player has same scene



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"):
    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

by (52 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.