Do we have to use rigidbodies for hitting enemies?

I’m just trying to add some kind of collision stuff to my project, which I would like to eventually work on the iphone.

I’m sure I read something here about rigidbodies not being the most efficient thing for iphone projects?

If this is the case, is it possible to make bullets from the gun collide with enemies without using a rigidbody?

(I’m using a rigidbody on the bullets at the moment which works fine, but I’d like to know if there is a more optimised way for iphone games)

This is the current code:

	void OnCollisionEnter(Collision collision)
	{
		if(collision.gameObject.tag == "scenery")
			{
				Destroy(gameObject); 				
				Debug.Log("it collided with scenery");
			} else if(collision.gameObject.tag == "enemy")
			{
				Destroy(collision.gameObject);
				Debug.Log("it collided with an enemy");
			} else
			{
				Debug.Log("it didn't collide");
			}
	}

You never need a rigidbody for a collision. All a rigidbody does is allow gravity and other physics based movement to occur. If you simply attach a collider, and check for a collision with the enemy you can do all sorts of things without ever touching a rigidbody. Of course, without a rigidbody you need to find other ways to make the bullet move, such as transform.Translate for instance.

Thanks NickAVV!

The code I had there didn’t seem to work without a rigidbody added to the objects in my scene… I was already moving the bullets with a normal translate

Is the code I’m using only really valid when using rigidbodies or is it something else I’m doing wrong? :slight_smile:

Here’s a snippet from the manual page on MonoBehaviour.OnCollisionEnter

There’s similar language in the documentation for triggers. And there’s a matrix somewhere in the collider doc that shows what events can happen with various collider/rigidbody combinations.[/quote]

You could of course also use a raycast collision detection system, which would probably be the best idea of you have super fast bullets and a super slow iPhone friendly physics rate.

Cool; this thread answers my question without me starting a new thread; it was only my fifth search attempt and only two pages to go through too. :o