Instantiating under projectile

Hi, i would understand why in this lecture we can’t instantiate over an other collider .

i’ll explain myself better, understanding this is useful to me because this behavior caused in my glitch garden to not be able to spawn when a projectile is on the screen in a lane at the center of a box, and if there are a lot of monsters it is quite a bad thing

I understand that this is useful to not make the instantiation of two characters in one lane, but why i can’t instantiate over a moving projectile with a collider?

please help me i didn’t quite explained myself well but i tried everything ahahha i unchecked the collision boxes in the settings, i created 2 separate layers for the defenders and the projectile but NOTHING works, only removing the boxcollider from the projectile works

image
i want to instantiate clicking on the blue ball, but if the blue ball as if it is not there

Hi Shinos,

That’s an interesting question. :slight_smile:

Why are you able to spawn a defender? Because the raycast of your mouse hit a collider, and the script on the game object with that collider triggers the OnMouseDown method.

And the same happens when there is another collider on top of the “game” collider. It does not matter whether there is an enemy, a defender or a projectile. The collider which is closer to the camera gets hit by the raycast of the mouse and blocks it.

I agree with you that this behaviour is undesired in certain cases. There is a simple solution: Put the colliders which are not supposed to block the raycast onto a separate layer and enable “Ignore Raycast” in the layer options for that layer.

Did this fix it for you? :slight_smile:


See also:

1 Like

Hi, i’m trying to use your solution but i’m not quite understanding how to do it hahaha i’m doing a bit of research

ok i added on the projectile script in start this:

 private void Start()
    {
        gameObject.layer=LayerMask.NameToLayer("Ignore Raycast");
    }

and it works, but i’m not quite understanding some things, like WHAT IF i need it to not be ignored in some cases ? like i want it to ignore the raycast for example of one object but not the one of an other.

If i would want that the projectile collider Blocks only when i want to place a certain object but not an other how could i do

Please Nina do not abandon me :rofl: i watched the docs and read about the way it suggests by shifting the index of a layer and then by using

if (Physics.Raycast(transform.position, transform.TransformDirection (Vector3.forward), out hit, Mathf.Infinity, layerMask)) 

But i couldn’t get it to work :persevere: :persevere:

For example by taking the Game over background which Rick made us do to block any other interaction when " Losing "to be able to interact with something , i thought that by putting the thing i wanted to interact with in a layer and then using the formula given by the docs could do it ibut t doesnt work and i cannot understand why,

No worries. I did not abandon you, I’m just not working at the weekends. :wink:

like i want it to ignore the raycast for example of one object but not the one of an other.

You could either set the layer manually in the Inspector, or you could create a new script which you assign only to the game objects which are supposed to get ignored by the raycast of your mouse.

What exactly is the remaining problem you’d like to solve?

If you are dealing with Collider2D components, use the Physics2D class, not the Physic class. Maybe that’s why your code did not work as expected.

1 Like

Hi! i know it’s been two weeks but i have been super ultra busy and i thank you with all my gratitude for your response! i will try this as soon as i can

Take your time! :slight_smile:

1 Like

How are you getting on with this, @Shinos?

1 Like

hi Nina, you are right i forgot to update these posts while i went ahead with other sections, i’ll update first Can’t change sprite of the Child from Parent - Unity Courses / Ask - GameDev.tv the issue of this post here it needed a little bit of time by me rather than the one of the sprite, which i still can’t understand why doesn’t work

Did the other thread help you get a better understanding of this subject?

1 Like

yes, thank you nina

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms