I'm new to godot and I have some questions relating the script

Godot Version

Godot v4.2.1


Hey, I’m a new game developer and I an just beginning to learn about how godot’s script works, and I thought I had figured some basic stuff out, but it’s giving me errors and I’m clueless.

As I just started, I wanted to make a simple game, and so I started making geometry dash in 3d.
I have a few questions relating the scripting that I would really appreciate some help with.

  1. I tried to use .velocity.y += 5 to bounce the player upwards, but im getting errors like “This line has no effect” even when it used to work.

Here is my current code that doesn’t work: ??? - Pastebin.com
I would also really appreciate it if someone could tell me what I did wrong.

(Here I tried making the yellow booster orb from geometry dash that boosts the player up when they use the jump key while touching the orb)

  1. I’d like to know how to ‘teleport’ or instantly move objects (or the player) to different locations in the same scene.

  2. I’d love to know how to get a global variable referencing the player, so that “player” in any script will be directly referring to the actual player.

Thanks in advance to anyone who helps, I appreciate your time.

The line target.velocity.y == 1 looks suspicious. Is it supposed to be a part of the if condition or did you want to assign 1 to target.velocity.y?

The first line serves no purpose as it is immediately changed to something else, unless you want to reset it? Which might be what you want. Unless it’s x you want to set to 1, not y… which then would be a typo.

		target.velocity.y == 1
		target.velocity.y += 8

I know of Geometry War, but never played it.

To move things around the world, just set their position to where you want them to be. Usually through an invisible marker on the map.

As for the last, one way would be to use a singleton that you autoload and then set a player variable inside that singleton once the player is created. From that singleton, you can call the variable.

#Somewhere in code

# In some class or .gd
some_object.position = Singleton.player.position
# Or something like that.

That’s one way to do it.

1: You have an extra equal sign, use target.velocity.y = 1 instead of target.velocity.y == 1 .
but this:
target.velocity.y = 1
target.velocity.y += 8
is the same as this:
target.velocity.y = 9

2: You can “teleport objects” by setting the global_position of a Node (should be a Vector2 or an Vector3.)

3: Any variables defined at the top of one script can be accessed from other scripts.
Setting a var in one Node:
Using it in another:

1 Like

OMG, how didn’t I see this? headdesk That’s what happens when you work all night.

1 Like

I wanted to assign the velocity to 1 so that no matter how fast the player is falling it will get boosted the same height. Didn’t work though.

That’s what we’re saying.

== is a comparison token. It would give you a true or false. Assignment is =.