What are the different area nodes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Syl

The ones that may trigger the area2Ds signals: area_entered (object area).

:bust_in_silhouette: Reply From: kidscancode

An area’s area_entered() signal is emitted when another Area2D node enters.

If you want to detect physics bodies (StaticBody2D, RigidBody2D, KinematicBody2D), they trigger the body_entered() signal.

Thxs but I’ve loaded my mouse-moved player/sprite with pickable kinematicbody2D and area2D, ant it remains undetected by my area2D… What is needed for that?

Syl | 2018-04-04 23:28

It’s hard to know exactly what you’re trying to do. Do you have collision shapes assigned to each? What do you mean by “loaded player with kinematicbody2D and area2D”?

kidscancode | 2018-04-04 23:31

Yes both with collisionshapes, and meaning that my sprite/player has a kinematicbody AND an area2D, added recently to experiment, but without success…
It’s a mini_map with a player/sprite moved by mouse click, that should trigger a change.scene when enterin area2D zone… But it remains undetected…

Syl | 2018-04-04 23:45

From what you’ve described, you should have an Area2D set up with its body_entered signal connected to a function that changes the scene. Then when your K2D player enters the area, that function would be triggered.

If it’s not working, you’ll have to share the code. Other things to check: is the Area2D monitoring property on? Have you changed/set the collision layer/mask on either of the objects?

kidscancode | 2018-04-05 00:16

That’s what happening. Here’s the code:
Node2D (player/sprite mouse movements):

extends Node2D

var terrain_speed = 1.0
var speed = 3*50 # triple speed
var first_input = false

func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
var map_pos = $Map/Sprite.global_position
var mouse_pos = get_global_mouse_position()
var delta_position = mouse_pos - $Player.global_position # mouse click relative to player sprite
var distance = map_pos.distance_to(mouse_pos)
var duration = distance * terrain_speed/speed
if first_input == false:
first_input = true

        $Tween.interpolate_property($Map/Sprite, "global_position", map_pos, map_pos - delta_position, duration,

And the signal func from my changing scene area2D (tried also with body_entered, but that’s not better):

func _on_Area2D_area_entered(area):

The monitoring is on, and the layers/masks are defaults, unchanged.
Here’s the scene: Imgur: The magic of the Internet

Syl | 2018-04-05 00:35

Your node setup is somewhat backwards. You have the player’s kinematic body as a child of a Sprite. That means that when the kinematic body moves, the sprite doesn’t, or worse when you move the Sprite, you’re not going to have any collision detection because kinematic bodies only detect collisions when they are moved using their move_* functions.

Normally, you make the body type the root node of a particular game object. Moving is the purpose of the player, and a physics body node is a thing that moves. Then you can add a Sprite as a child so that it has a texture which will move along with it.

It’s also confusing because it appears you’re moving your Map/Sprite, not your player. Again, that means no collisions occur because the Map body itself isn’t moving.

I can only really suggest that you look at the tutorials and demo projects to understand how the nodes you’re using actually work before you get even more tangled up.

Finally, please try and format your code when you post it so that it isn’t so difficult to read. Place four spaces in front of all lines to format it as code

# like this

kidscancode | 2018-04-05 05:04

Thxs for your reply, I changed the player as a child of my kinematic body, but the movin map is necessary to my minimap display… And it’s not linked to the collision of my Kinematic/player and the area2D, or is it? Nothing should collide with the map, it’s just a moving background.

Syl | 2018-04-05 05:25

Ok, solved, had simply to put the area2D in the sprite of the map. Thxs for your help! :slight_smile:

Syl | 2018-04-05 21:12