#Trying to figure out a solution to having a large group of scenes interact with the Main scene.

36 messages · Page 1 of 1 (latest)

rough cargo
#

This is a rather specific problem that I'm not too sure how to handle. I'm recreating Super Mario 1-1.

I have a Level scene which is the level itself. I have a Brick scene which is the scene I use for the breakable blocks that Mario can hit with his head to destroy. The Level scene has multiple of the Brick scenes. I have a Player scene for Mario, and one Main scene to put everything together.

Right now I'm trying to work out how to make the breakable Bricks and Mario interact properly. At the moment I have a simple program in the Brick scene to have it so the Brick disappears when Mario enters the Area2D at the bottom of the Brick block.

The first thing I need is a way to make it so Mario can only break one block per jump. Mario's jump can hit multiple blocks in one hit, but I only want one block to break each jump, ideally with a way to bring Mario's velocity down one he hits a block.

The second thing I need is a way to tell the Blocks to only break when Mario is in Big or Fire form but not in Small form. I have a player_state variable in Player scene that indicates which form Mario is currently in. --- I know how I would solve this if it's just one Block in the level. I could just use signals to send player_state to the Block, but since I have a huge number of Blocks I'm not sure how to handle it.

analog torrent
#

You could make the bricks into staticbodies so that mario is pushed down automatically. Then have the brick removal be a function called by the mario script that will only break the first collider in a collision.

So mario -> on collision -> get first collidee that is a brick -> break that

rough cargo
#

the Bricks are StaticBody2D

#

oh yea I guess he immediately goes down

rough cargo
analog torrent
#

alright, you dont need areas for things with collisionshapes

rough cargo
#

how do I detect the if Mario is hitting the block then? Cuz it has to be specifically from the bottom

analog torrent
#

you can look at the normal of the collision

#

if the normal is pointing down then you hit a ceiling

#

well, the area approach is also fine, its not too big of a deal.

rough cargo
#

yea can we work out what I actually wanted to solve for now

analog torrent
#

but with the collisions you can check which bricks you collide with instead of having the areas all check _on_body_entered

rough cargo
#

hmm

#

so how would I use get_last_slide_collision or get_slide_collision

#

which one do I use, for that matter

analog torrent
#

from the documentation

for i in get_slide_collision_count():
  var collision = get_slide_collision(i)
  # PSEUDO CODE
  var node = collison.get_collider()
  if node == BRICK && collision.get_normal().is_ceiling_normal():
    node.destroy()
    break
rough cargo
#

would I put this in process

analog torrent
#

you put this after you call move_and_slide yes

#

if you use get_last_slide_collision instead you might miss the collision with a brick i guess.

rough cargo
#

right I'm seeing where this is going

#

now how do I do that

#

normal collision

#

thing

#

oh wait it's already in the code

#

I missed that, I was testing the top part

analog torrent
#

if your bricks are always axis-aligned then you can just check if the normal is equal to Vector2.DOWN

#

but it might be better to check that it is within some angle of the down direction of the brick

rough cargo
#

I tested it and yeah

#

it's always equal to the down vector

#

right so once I hook this up to the destroy function on the brick

#

that's basically it

analog torrent
#

You could also duck-type it

#FUNCTION IN BRICK CODE
jump_destroy(normal: Vector2):
  if normal == Vector2.DOWN:
    queue_free()
    return true;
  return false;

#IN MARIO PROCESS AFTER MOVE_AND_SLIDE
for i in get_slide_collision_count():
  var collision = get_slide_collision(i)
  # PSEUDO CODE
  var node = collison.get_collider()
  if node.has_method("jump_destroy") and node.jump_destroy(collision.get_normal()):
    break;
rough cargo
#

that turned out a lot easier than I expected. I'm glad I asked. I was trying so hard to think of ways to make it work using what I knew, turns out the solution was something I didn't know

#

thanks for the help

analog torrent
#

This way you can implement the jump_destroy function on anything and then mario will destroy it by jumping into it, but the behaviour is defined in the thing you are jumping into