body_entered signal problem

Godot Version

` Godot 4.5.1

Question

` Hi! I’m currently working on my first mini-game in Godot.

I’ve implemented a mechanism—let’s call it a “Jumper”—that’s designed to detect the player and apply a strong directional force. This force should push the player either upward (if they look up) or horizontally (in the opposite direction of the Jumper’s side).

I’ve encountered two main issues with the current implementation:

Slow Entry Problem: If the player enters the Jumper’s detection area slowly, the push effect doesn’t activate or work reliably.

Horizontal Placement Bug: The Jumper doesn’t work at all when it is placed to apply force horizontally.

I suspect the physics processing or detection logic might need adjustment. Here is the code for the Jumper:
extends Area2D

Called when the node enters the scene tree for the first time.

func _ready() → void:
body_entered.connect(func(body:Node2D)->void:
if body is Player:
if int(rotation)%360==0:
body.velocity.y-=2400.0
elif int(rotation)%360!=0:
body.velocity.x-=(gravity+400)*position.angle()
)

Hello, although your description is kinda vauge (are these like springs that can be placed horizontally or vertically?) I did notice some things. It looks like the issue comes from how you’re detecting and applying the force. body_entered only triggers once, so if the player moves in slowly, it might miss it or not have enough velocity change to notice. You’ll get more consistent results if you apply the push during _physics_process while the player is still inside the area. Also, position.angle() isn’t giving you the direction you think, it’s the angle from the world origin, not the “Jumper’s” facing direction. You should use rotation or a vector based on it.