- Home /
I want to make it so when my player dashes they cant be hit
So I want to make my player invulnerable well dashing. how do I do this without disabling a RB or a box collider?
I also want it to make sure the bullets can't hit the player and they go through.
hmm. First idea would be to change the layer of the player during the dash. Said layer needs some tweeking in the physics collision settings to make projectiles on a specific layer NOT collide with it anymore while still having collisions with the environment.
Second one would be to store the dash state in a public boolean like "IsDashing" and let whatever script is interested in this state handle the true and false cases of it.
Third idea would be to have two colliders of equal size. One that is a trigger that is used for damage related collisions with projectiles or whatever and the other one is not a trigger for movement related collisions with the environment. You could then disable the trigger-collider whenever you don´t want your player to be hit by projectiles but still retain the collisions with the environment.
Answer by ZoeWheat · Apr 07, 2021 at 01:19 AM
I presume that you have a function that deals damage to the player. In the places you call said function, put an if statement around it that specifies that isDashing is false. Dunno if this is the most effective answer, but it's how I would go about it.
Answer by Tuttle321 · Apr 07, 2021 at 01:50 AM
Ok so i am using this code
void OnTriggerEnter2D(Collider2D other) { switch (other.gameObject.tag) { case "projectile": break; case "Player": Destroy(this.gameObject); break; default: Destroy(this.gameObject); break; } }
I tried the third idea. it works ish but when dashing the object acts like a wall. I think this is because it has a box collider but it needs this to work so how do I fix this.
Your answer
Follow this Question
Related Questions
Weird Box Collider and Rigidbody error 1 Answer
RigidBody2D - Ignoring other RigidBodies. 1 Answer
2D rigidbody Plane collision 0 Answers
Player stuck between 2D boxcolliders 3 Answers
wasd movement rigidbody no bouncing 0 Answers