Area2D in overworld not triggered

XrayleaderXrayleader Posts: 22Member

I'm recently building an overworld for my game, it has a kinematic2D "pointer" that is used to enter levels a la Final Fantasy, the levels themselves are nodes containing an Area2D that, when the Kinematic 2D enters it, its supposed to emit a message to test collision, the problem is, it doesn't. I tried changing the Node2D for a pure Area2D node but it doesn't work either, it's gotta be a simple solution, but so far i haven't found it, which is why i'm asking for some help, if you have a better approach for an overworld i'm all ears as well.

Here's my "Level node" configuration:
-Node2D(Level
    ---Sprite
    ---Area2D(CollisionArea)
    -------CollisionShape2D(CollisionHitbox)

Here's the code:

extends Node2D #I tried extending Area2D as well, doesn't work
var nodetype = "Level"

func _ready():
   $CollisionArea.connect("area_entered", self, "_on_area_entered")
   $CollisionArea.connect("body_entered", self, "_on_body_entered")


func _on_body_entered(body):
  print("Working")

func _on_area_entered(area):
  print("Working")

Here's the Player pointer configuration:
-Kinematic2D(PlayerOverworld)
---Sprite
---CollisionShape2D

And here's it's code as well:

extends KinematicBody2D
var nodetype = "Player"

var velocity = Vector2(0,0)
var speed = 30



func get_input(delta):
    var right = Input.is_action_pressed('ui_right')
    var left = Input.is_action_pressed('ui_left')
    var up = Input.is_action_pressed('ui_up')  
    var down = Input.is_action_pressed('ui_down')
    var accept = Input.is_action_just_pressed('ui_accept')

    if up:
     velocity.y = -speed

    if down:
     velocity.y = speed

    if left:
     velocity.x = -speed

    if right:
     velocity.x = speed

    if !up and !down:
     velocity.y = 0

    if !left and !right:
     velocity.x = 0



func _physics_process(delta):
  get_input(delta)
  velocity = move_and_slide(velocity,Vector2(0, -1))

Answers

  • XrayleaderXrayleader Posts: 22Member

    UPDATE: Well, i created a "Wall" of sorts on my overworld to test for collisions, it works, the "pointer" is getting stopped by the "Wall", so it's definitely a collision detection issue, still dunno what it is exactly.

  • TwistedTwiglegTwistedTwigleg Posts: 3,330Admin

    If you place a something like a simple RigidBody2D node (with a collision shape) over the Area2D, does it print the message as expected? Also, do the Area2D and the KinematicBody2D have the same collision layer/mask setup?
    Not sure if it would help, but these things are what I would look into.

  • XrayleaderXrayleader Posts: 22Member
    edited October 22

    It actually doesn't, both are on Mask 1 and Layer 1, and i tried doing the RigidBody2D test and it didn't got triggered either.

  • TwistedTwiglegTwistedTwigleg Posts: 3,330Admin

    Hmm, well I guess that means the Area2D is causing the issue then? Otherwise I imagine the RigidBody2D would have trigger it, since its just a default setup.

    Well, one thing you could try is running the game with collision shapes enabled. You can find the setting in the debug menu. This would help show if the collision shapes of the Area2D are somehow being moved out of place. While I doubt this is happening, it never hurts to be thorough in checking.

    The second thing to do is look at the CollisionShape2D node for the Area2D. I might suggest making a new CollisionShape2D node for the Area2D, and make its shape really large for testing purposes. That way, things like collision tunneling due to small sizes shouldn't cause any issues with the collision reporting.

    Outside of that, maybe try recreating the Area2D and CollisonShape2D nodes and see if that fixes the issue? I don't know, to be honest I'm a little confused on why this issue is occurring. Based on everything you have said, I do not see why the Area2D would not be reporting collisions, leaving me to suggest a "kitchen sink" approach to debugging.

  • XrayleaderXrayleader Posts: 22Member

    I actually tried that just now, i created a new scene from scratch, placed a kinematic body , a Node2D with an Area2D and their respective collision shapes and no triggers either, it's kinda driving me crazy XD

  • XrayleaderXrayleader Posts: 22Member

    UPDATE: So in the midst of my desperation i tried using the "Level" node inside the working "Sidescroller scene" that is supposed to be represented by it and it does respond to collision, i still don't know what it is, but at least i know the "Level" node is not the issue, it's most likely the "Pointer" node

  • TwistedTwiglegTwistedTwigleg Posts: 3,330Admin

    Well, on the positive side, at least you are getting closer to figuring it out! I would offer more advice, but to be honest I'm really unsure on why it is not working.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file