How to make Grenades ignore squares on the wall?

The grenade can be thrown at points that the wall is on. This is because it can also be thrown at the Crate which shares the obstacles layer. This allows me to throw a grenade at the wall and do damage to both sides of the wall. From a players perspective this may not be ideal.

Any suggestions to fix ?

I’m thinking make a separate layer for the crates and other objects we intend to be destroyed, or extend destruction to the wall, ala Battlefield.

My question is, in terms of game design, which makes more sense, to add a new layer to the crates or to adjust the logic to ignore squares under the wall; how would I go about the latter.

I might recommend a different approach that I have taken for other gridlike games… On each of the wall obstacles, I put an Obstacle component.

using System.Collections.Generic;
using UnityEngine;

public class Obstacle : MonoBehaviour
{
    public static Dictionary<GridPosition, Obstacle> Obstacles = new();

    void Start()
    {
        GridPosition position = LevelGrid.Instance.GetGridPosition(transform.position);
        Obstacles[position] = this;
    }
}

This would go on the walls, but NOT the Crates.

In your GrenadeAction, when checking for valid GridPositions, test to see if Obstacle.Obstacles.ContainsKey(gridPosition); If it does, then don’t add it to the list.

Brian, thank you for your assistance.

I have made it to the final section of the original course.

I see the final part is me designing what I want in a Level, using what we have learned.

I really appreciate you for suggesting a solution to my problem and I will definitely be implementing that code to make the walls not appear when they shouldn’t.

I hope this message finds you well.

Thank you!

Privacy & Terms