- Home /
Enemies in top down shooter being affected by physics of bullet
Hi, I am making a top down shooter mobile game, and I want to know how to make the player's bullets not push the enemies around. The enemy gets pushed back a little bit by each projectile that the player shoots, and it makes the game look bad. Is there something that I do with my projectile's collision or the enemy's collision to make this go away? Also I have obstacles in the map that I don't want the enemy to go through, so I can't just make the enemy's physical presence go away so the bullet doesn't actually collide with it.
I am happy to give scripts if you guys want them, but this seems like the kind of thing that can be fixed with unity's built in system. Just in case, here's the bullet script:
public float speed;
public GameObject hitEffect;
private Transform player;
private Vector2 target;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Enemy").transform;
target = new Vector2(player.position.x, player.position.y);
}
void Update()
{
transform.Translate(Vector2.up * speed * Time.deltaTime);
}
void OnCollisionEnter2D(Collision2D collision)
{
GameObject effect = Instantiate(hitEffect, transform.position, Quaternion.identity);
Destroy(effect, 5f);
Destroy(gameObject);
}
Answer by VoidPhoenix96 · Feb 21, 2021 at 02:31 PM
Instead of detecting collision for dealing damage, you should raycast a short distance from the front of the bullet and deal damage + destroy the bullet from that. That would completely eliminate your problem, though it might be more complex.
Your answer
Follow this Question
Related Questions
How to do bullet spread in 2D? 1 Answer
Script Not counting enemy kills. 1 Answer
Trying to make an enemy fire at the player 1 Answer
coliders are not working 1 Answer
How do I move camera towards the mouse while anchoring it to the player? 0 Answers