Ok, I am a beginner scripting newbie here, uggh I am mad because I should be able to solve this problem myself
I am trying to create a simple script so that when my “player” touch an object (such as a “cube”)…the “cube” would be destroy…But…well…I fail…not sure what i’m missing though
I had also try using function OnTriggerEnter( hit : Collider )
and switch the cube as a trigger but to no avail…please help this newb out!
here is my script
var dead : Transform;
var lifeTime = 1.0;
function OnControllerColliderHit(hit:ControllerColliderHit)
you have a cube with a character controller?
if the cube hits a player it destroys the player… ?
it then accesses the destroyed player to instantiate a new object at its position and destroys itself.
I guess thats not what you want.
Put normal mesh/cube whatever fits collider to the cube.
Then you can decide if the player is in charge of destroying the cube or the cube in reacting to the player
if player: use OnControllerColliderHit, given that he has a Character controller attached.
if cube: use OnCollisionEnter, given that the collider is not set to trigger.
if cube, the script would look something like this (untested):
EDIT: but if i remember correctly the player needs to have a kinematic rigidbody attached to be able to generate collision events with the character controller.
hmm…I will do some more research on this… thank you for your help…
weird your advice on adding a rigidbody work! AMAZING that was what missing
This is my final script…does it look ok?
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag ==("object"))
{
Instantiate(dead, transform.position, Quaternion.identity);
Destroy(this.gameObject, lifeTime);
}
}
Please forgive me
some small questions (which you can choose to answer but don’t have to)…
first off, you added a void? so I assume it a c# script which I am NOT that familiar with…you have any resources where I can learn some more scripting? I am just curious with this “ContactPoint” you added in…does it still work if I switch “void” to function? I try that and I got an error lol…it told me there’s supposed to be a “)” after contactPoint instead of contact…
THANK YOU VERY MUCH…YOU DON"T HAVE TO ANSWER BACK IF YOU DON"T WANT TO I WILL MARK THIS AS SOLVE TOMORROW!
Thank You all! you guys been really helpful and this script you just gave me help me a lot! Wayyyy better than anything I could come up with
I still have much to learn