Let's say I want:
1) The player object to detect a tile below while somersault jumping like in contra (= shorter collisionbox)
2) When a tile is detected, change the player to using a taller, standing collisionbox. This would probably mean that player is now colliding with the tile.
3) move the player up until it is standing on said tile and no longer colliding
How would you do this?
My current approach has an Area2D+CollisionShape2d, if the Area2d detects a body it sends a signal:
func _on_FloorDetect_body_shape_entered(body_rid, body, body_shape_index, local_shape_index):
var coordinate: Vector2 = Physics2DServer.body_get_shape_metadata(body_rid, body_shape_index)
var tileid = tilemap.get_cellv(coordinate)
var shapes = tilemap.tile_set.tile_get_shapes(tileid)
var shape = shapes[0]["shape"]
var otherTrans = shapes[0]["shape_transform"]
var contacts = FloorDetectShape.get_shape().collide_and_get_contacts(FloorDetectShape.transform, shape, otherTrans)
I don't get any contacts like this, it's something about the transforms most likely.
But even if I get the contacts, I'm not sure how I'd proceed with them.
here's some hints here how to use them, but I don't think I quite get it yet.
https://docs.godotengine.org/en/stable/classes/class_shape2d.html#class-shape2d-method-collide-and-get-contacts
The other idea would be to use 16 downward Raycast2ds (Width of the player collisionboxes) and determine player vertical position based on those, but this seems like a non-optimal approach.
Any better ideas or improvements on this?