Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How do I add force to a RigidBody2D?

$
0
0
So I have this scene, where I have a player that can shoot bullets at an enemy. I want to AddForce to the RigidBody2D of the enemy when the bullet hits, but until now I have no success. My bullet script: void Update() { theRB.velocity = transform.right * speed; } private void OnTriggerEnter2D(Collider2D other) { Instantiate(impactEffect, transform.position, transform.rotation); Destroy(gameObject); if (other.tag == "Enemy") { other.GetComponent().DamageEnemy(damageToGive); } } Where do I put the Addforce function? Do I have to get a reference from the enemy RigidBody on my Bullet Script? I'm kinda new to unity so any help is much appreciated! Thanks in advance. PS: I'm trying to make to a topdown shooter game.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>