0 votes

How can i make a scene find a node even if its in another place
Im making a jump-pad that launches the player as soon as they enter its area the thing is idk how to alter the player velocity since its in another scene
Here's how my code for the jump pad looks like this:

Onready var Player = get_tree.get_root().find_node("Player")
func _on_throw_body_entered(body):
   if body.is_in_group("Player"):
      Player.Velocity.y = 100
      Player.jumppadding = true

Again this is the script for an independent scene which is the jump pad i want it to find the player and change its velocity once they enter the area

Godot version 3.5
in Engine by (57 points)

2 Answers

+2 votes
Best answer

How about use the has_method() function on the object that entered the area? For example:

func _on_throw_body_entered(body):
    if body.has_method("fling_player"):
        body.fling_player(100)

Add a function (e.g. fling_player()) to the player's node that would make them move as though they were thrown off a jump pad.

by (3,144 points)
selected by
+1 vote

To do this you will want to make a Global script or "singletons" https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html,
you will wanna do this by making a new script and just declaring a variable

var myvar = 100

and in project settings under AutoLoad adding that script with a node name,
once you do this you can go to any script in any file and instance that var by doing this

MyGlobalScriptName.myvar = 200

doing this will be used a lot down the line from making hp bars to store things in files

Hope this helped! if you have any question on how to do just ask and Ill do my best to answer!

by (99 points)

Thank you but i already found a much simpler solution
So when the player enter the area it checks if they're in that group if so simply this line works

Body.velocity.y = 75

Its really simpler than i thought i also already have couple of singletons for that specific reason but they aren't that helpful besides marking events or saving stuff

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.