Here is a simplified version of what I’m trying to make.
Each visible object, character, and building is going to be the same type so I can easily calculate which layer the object should appear. The calculation uses a child sprite referenced as POSITION using the arcade sprite data extension.
I want to know if there is a way to reference a parent sprite if it’s POSITION (child) sprite touches the POSITION sprite of another sprite to simulate depth. To do this, each sprite needs to have a POSITION sprite associated with it, and each POSITION sprite needs to be invisible.
Specifically, I want to:
- Destroy a projectile if it’s POSITION sprite touches another POSITION sprite.
- Prevent a character from moving in a direction if it’s POSITION sprite would overlap with the POSITION sprite of another sprite.
Any suggestions?
2 Likes
@Servillius i feel like you’re just complicating the overlap logic here by splitting up the sprites like this… can you give me an example of what you want the end result to be? is there a video game with movement/behavior you’re trying to mimic?
as for preventing one sprite from moving into another sprite, the only built-in way to do that in makecode arcade is to use the tilemap and turn walls on/off. if that doesn’t work for you, then you’ll have to implement your own physics instead of using the built in physics engine. if you go that route, i recommend checking out this blog post by Maddy Thorson (the creator of Celeste and Towerfall) which covers one way of doing things. fair warning though: the code in that article is written using C#
1 Like
Yeah, basically I want projectiles to be able to move behind a building as it travels. Imagine Binding of Isaac, with a slanted top-down view. Now put a large building in the middle. If a projectile is fired towards the building, there are three scenarios. Either the sprite of the projectile travels behind the building, travels in front of the building, or collides with the building. If the sprite travels behind the building or in front of the building, it’s sprite will still overlap with the sprite of the building, but I don’t want it to trigger a collision. The easiest way for me to do this is to have a separate sprite that indicates how “deep” the sprite is from a slanted top-down perspective.
As for my problem, I think I’ve found a sollution. I just need to set it so each sprite and it’s respective POSITION sprite reference each other (so I need “set Sprite1 dataX to Sprite2” AND “set Sprite2 dataY to Sprite1”. Since it’s not really a parent-child relationship, there’s nothing stopping me from doing this.
This is how it’s looking now, I can’t seem to work out how to stop the character from moving but I’ll probably work out the right logic.
1 Like
@Don that might work for one building, but it won’t scale for multiple.
the easier thing to do is to just set the z-depth of the sprite to be the same as the bottom. @Servillius your instinct in splitting each sprite into two (one for display and one for collisions) was a good one! here’s some sample code that shows how I would do this (comments inside)
1 Like
now if you also want to prevent the player from moving through buildings, that’s tougher. like i mentioned above, the only way to do this easily is to use the tilemap. i would draw your tilemap so that the bottom row of tiles that the building overlaps has walls turned on.
you might find it easier to fit your sprite’s size if you use the 8x8 tilemaps from the arcade-sprite-util extension, which has smaller tiles.
here is the same example as above, but i use the walls of the tilemap to prevent sprite movement (again, comments inside):
Wow! Thank you so much! The solution works really well, and the comments and explanation are really helpful for understanding how you put it together.
Thanks again!
1 Like