-1

I'm extremely new to Godot 4 and trying to create a basic game where the player has to dodge falling rocks. I'm currently trying to make the rock move back up to top after it hits the bottom (I have an Area2D which sends a signal when the rock enters it), but to no avail. I have tried code such as "self.position = Vector2(xpos, ypos)" among others but the rock just stays at the bottom. The rock successfully moves to a random location when first entering the scene, but not when the function is called when the rock enters the Area2D.

Here is my code if you want to look:

Rock Code

Here is a screenshot of my level scene and rock scene:

Level Scene Rock Scene

Any help would be much appreciated :)

1 Answers1

0

The Area2D body_entered signal detects when a body enters. Where body refer to a PhysicsBody2D (which is either an StaticBody2D, CharacterBody2D or RigidBody2D)... Or a TileMap.

However, you have used a generic Node as root for the Rock scene, as a result the Area2D won't be able to detect it.


Furthermore a CollisionShape2D on its own does nothing. It should be a child of a CollisionObject2D (which is either an StaticBody2D, CharacterBody2D or RigidBody2D... Or an Area2D).


I did notice you happen to have a TileMap.

I do not know if the TileMap has collision defined (you would do that by editing its tile in the TileSet).

If the TileMap has collision defined, it might be triggering the signal. However, the object you would get as argument body of the body_entered would be the TileMap not the Rock (thus the check body == self in Rock would fail).


I do not see code for the Rock moving (aside from the teleportation), so you can still decide which kind of body it will be. Another of my answers might help you decide: link.

I have gone into more detail on how to setup physics in Godot elsewhere.

Theraot
  • 31,890
  • 5
  • 57
  • 86