Replies: 1 comment
-
This is like a year later, but since this proposal is still open, I'll mention that I implemented the layer query function ( body.get_layer_for_body_rid(body_rid) ) when adding cuttable bushes, and it's now in the engine. Here's the code I used based on that function. func _on_body_shape_entered(body_rid, body, _body_shape_index, _local_shape_index):
# get the coordinates of the tile we collided with
if body.has_method("get_coords_for_body_rid"):
var collidedTile=body.get_coords_for_body_rid(body_rid)
var collidedLayer=body.get_layer_for_body_rid(body_rid)
if(bushCutter): cutBushTile(body,collidedTile,collidedLayer)
func cutBushTile(body,collidedTile,collidedLayer):
var cellSourceId=body.get_cell_source_id(collidedLayer,collidedTile,false)
var tileData = body.get_cell_tile_data(collidedLayer,collidedTile,false)
if tileData:
#check if it is a bush tile
if tileData.get_custom_data("TileType") == "BushTop":
#there is no easy way to check the properties of a specific tile in a tileset, so we are
#going to do a dumb hack, and *assume* that the tile located one row
#down in the tileset image is a bush base, and replace our bush with
#it, then immediately check if we are correct. If we are correct,
#do nothing. If we are wrong, erase our mistake and pretend it
#never happened.
body.set_cell(collidedLayer, collidedTile, cellSourceId, body.get_cell_atlas_coords(collidedLayer,collidedTile,false)+Vector2i.DOWN,0)
#if we did it wrong, blank the tile.
if(body.get_cell_tile_data(collidedLayer,collidedTile,false).get_custom_data("TileType") !="BushBottom"):
body.erase_cell(collidedLayer, collidedTile)
GlobalUtils.instantiate_scene_on_level(cutBushAnim, body.to_global(body.map_to_local(collidedTile)) )
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm working with tilesets in Godotv4.0-alpha2. I have a platformer in which tilessets use the newly added "custom layer" to expose certain metadata properties.
A specific use here is that I have a tileset with wall tiles I CAN walljump on and I CANNOT walljump on. In order to differentiate one from the other, I use a custom layer called "type" with either the value "WALLJUMP" or "NO_WALLJUMP" on each tile.
Now when I collide with a tile, I need to figure out which type of tile I'm colliding with (Walljumpable or not walljumpable).
Here is a sample implementation:
Here we have 2 problems:
This is an issue if I am using a tileset with two or more image sources, which uses more than one layer.
Does anyone have any workaround with this? Or does a proposal need to be made?
Beta Was this translation helpful? Give feedback.
All reactions