2
\$\begingroup\$

I am currently working on a game inspired by traditional 2D Zelda games ("Link To The Past", etc.) in Unity using the 2D settings.

I am looking for the best way to handle objects that the character throws and how to handle the collisions correctly given the perspective of the camera. A thrown object is rendered further up the screen to create the illusion it is in the air however due to this it will collide with enemies and objects that are not on it's current plane.

Below is a screenshot of "Link To A Past" for those who aren't familiar with the perspective of the game.

Example of perspective

I have thought about two ways to potentially implement this system but both don't feel like good the solutions.

  1. Turn off collision during the throw until near the end of the throw. I feel for this solution that different colliders would be required to ensure the correct object is experiences the collision. The issue I see with this solution is that it doesn't account for taller objects. If I throw an object directly at a wall the object should detect that.

  2. A system where using Unity's physics layers I turn layers off during the flight and based off the location of the thrown object. For example turning off the physics layers of objects that are above the object but shouldn't be hit due to the perspective. This method seems like a lot of work but could be a solution to the problem.

Any thoughts for better solutions or refinements would be much appreciated.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You might be able to use a combination of the two approaches. You could turn off the collider of the thrown object when it's lifted, and use a simple, invisible, collider placed on the body like so:

collider is turned off on the pot

You could then fire this collider directly out from the body. It should be on the same plane as the player and the enemies, so it seems like handling hits from there should be simple. In ALttP (as far as I can remember), you can't swing under/over enemies that are on the same plane. So, anything that this invisible collider hits would also register a hit by the pot.

Another approach might be to just set a picked up object's Collider as a Trigger. Then, during OnTriggerEnter, you could check whether or not this was something to ignore (the north wall), or an enemy (or other "hittable" entity).

In either case, then just kick off damage/animations after the appropriate collision.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .