|
I was wonder if there is a way to allows a moving player to pass through a game Object with rigidbody attached to it. For instances, i want the player to collect the carrots only if both have the same matching colours. Else the player will just pass thru the carrots. Is there a way to achieve this?? Please, any suggestion. Thanks alot. function OnCollisionEnter( collision : Collision ) { if(collision.gameObject.tag == "Carrot1" && playerNo == 1 && carrotNo == 1) { Destroy(collision.gameObject); scores.addScore(); scores.addMultiply(); } else { rigidbody.detectCollisions = false; }
(comments are locked)
|
|
OPTION #1 Take a look at Physics.IgnoreLayerCollision. If you have one carrot prefab whose color you're setting in script, then you can put all carrots of the same color in one layer (use the "layer" property of the GameObject), and enable/disable collisions with carrots of that color using Physics.IgnoreLayerCollision. OPTION #2 But if you have 1 prefab for each color of carrot and 1 prefab for each color of player, then you can set up the collision rules you want in the Editor.
thanks for the suggestion Tom, however i have no idea how to use the Physics.IgnoreLayerCollision. >< is there any examples out there i could follow? thanks!
Nov 15 '10 at 01:20 AM
Avery
How you use Physics.IgnoreLayerCollision depends on how you're creating the carrot and player GameObjects. If you have a prefab for each color of carrot and for each color of player, then you can accomplish this in the Editor without writing any code. I'll update my answer to include instructions for this case.
Nov 15 '10 at 04:42 PM
Tom 10
ty works perfectly!!!
Dec 22 '10 at 09:46 AM
amit
(comments are locked)
|
|
You can use something like OnCollisionEnter(){ if (colorMe!=colorCarrot){ rigidbody.detectCollisions = false; } Then turn detectCollisions true whenever you wish thanks for the suggestion however when i tried that method, it doesnt seems to work, i updated my code above. ;)
Nov 15 '10 at 01:19 AM
Avery
What kind of a problem does this method cause? As you probably know the script has to be placed in the rigidbody object, and do not forget to add "rigidbody.detectCollisions = true;" after the if else lines
Nov 16 '10 at 03:31 PM
towerer
(comments are locked)
|
