x


need trigger + collide

Hi there. i have some [fireBall] which have rigidbody and checked as Is Trigger.

Then player have code like this:

unction OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "respawnPoint") { dead = true; HealthControl.LIVES -= 1; }

if(hit.gameObject.tag == "enemyProjectile")
{
    gotHit = true;
    HealthControl.HITS += 1;
    Destroy(hit.gameObject);
}

}

everything is fine, just how should i do, that fireBall would collide on walls or terain? Becouse now fireBall is going through terain, walls, mountains, etc..

Thank you very much.

more ▼

asked Jun 22 '11 at 01:44 AM

kropcik gravatar image

kropcik
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

This is happening because you've set Is Trigger to true. It seems you need a trigger to detect "respawnPoint", but usually it's not a good thing the "enemyProjectile" to be a trigger. Uncheck Is Trigger in the FireBall object and detect it in OnCollisionEnter (or OnControllerColliiderHit, if the player is a Character Controller):

function OnTriggerEnter( hit : Collider ) { 
  if(hit.gameObject.tag == "respawnPoint") { 
    dead = true;
    HealthControl.LIVES -= 1; 
}

function OnCollisionEnter( hit : Collision ) {
// function OnControllerColliderHit( hit : ControllerColliderHit) {
  if(hit.gameObject.tag == "enemyProjectile") {
    gotHit = true;
    HealthControl.HITS += 1;
    Destroy(hit.gameObject);
  }
}
more ▼

answered Jun 22 '11 at 04:48 AM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

(comments are locked)
10|3000 characters needed characters left

Yeah, firstly i used: OnControllerColliderHit( hit : ControllerColliderHit)

but problem is If i want the code to work with OnControllerColliderHit (), i need to move with my playerCharacterController. If I stand still, when enemyProjectile hits player, nothing happens.

more ▼

answered Jun 22 '11 at 10:57 AM

kropcik gravatar image

kropcik
1 1 1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1467
x981
x8

asked: Jun 22 '11 at 01:44 AM

Seen: 838 times

Last Updated: Jul 16 '11 at 12:25 PM