Platform Jump Throw How to get a child of a staticBody2D?

Godot Version

4.2

Question

Iam trying to make the player jump down a platform, but cant access the collision Shape on the other end?

whatever i try it returns null or error…
cant get the player to detect the right collision he sits on. Not even detect if onWayCollision in ON ?
is there a way to detect the collisions ? Even if i added multiple StaticBodies2D each one with their own collisionShapes the result would be the same , cant get to that oneWayCollision bollean

body.get_child(0)

Will return the first child of the platform. If it is a collision shape, that’s what you need.

You may need to look it up by other means that by index. Like a name, for example.
Even better if the platform script itself provides a reference to its collision shape.

your player node looks like a characterBody2D
and the signal of body_entered is from that area2d receiving any collision shape entered it, this body_entered signal from area2d with your lots of collision shape2d should connect to area2d script that’s not the player. example the area2d walls has a script that receive its own body_entered signal.
in theory, the player when stepped inside this area2d will trigger the body_entered signal of the walls

I can get multiple indexes of all the shapes2D’s using the signal “body shape entered”
child(0) has the index of 3
child(1) has the index of 17

I just cant these indexes into instancesID or names ?

Your walls are of type StaticBody2D, i.e. immovable objects. I believe just like with RigidBody, the “on_entered” event is never fired between static/rigid body and characterbody b/c they’re all “solid” objects and thus can’t enter each other. They only push on each other. So yes, they collide, but they don’t overlap, hence no entering/exiting.

As long as your wall’s Collision Mask is set to same number as your player’s Collision Layer property, the player will automatically stop when they get to the wall. I.e. the collision will happen.

If you want to check for collision programmatically, inspect the object returned by move_and_collide() method

I think move and collide returns the staticBody2D not the collision instance inside of it… either way i couldnt get it to work it takes to many values

this should work, it was on the manual

I just dont like the " body.shape_find_owner(body_shape_index) " it feels like he’s looping… the owner should be the body in just 1 on area enter… but it only works this way

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.