- Home /
how to morph character on collision enter with gameobject
Hey there I been researching about how to do this but I cant seem to find a way. What i want is my player to collide with a gameobject which then changes to another character. any suggestions people ? Would really appreciate it as I am still in my learning stages of unity :)
I need to do this without using c# because we havent learnt that yet :)
kind regards Daniel Fry
Answer by adrenak · Feb 14, 2012 at 04:34 AM
I feel that a good way to do this would be to destroy the current charactor and instantiate a new (another) character in its place. Although there are different ways, but this is how I would have done :
var differentCharactor : GameObject; //add the charactor *prefab* in this variable through the editor
var posToSpawn : Transform;
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "player")
posToSpawn.position = other.gameObject.transform.position ; //record the character's position
Instantiate(differentCharactor , posToSpawn.position, other.gameObject.transform.rotation); //instantiate prefab at same position and with same rotation
Destroy(other.gameObject); //destroy the old charactor
}
}
I have assumed that the gameobject that changes the character has a trigger collider and the player has a tag called "player".
I Hope this helps!
Thanks it works so well, The great thing is I actually understand the code fully as well :).
I got it functioning in my work so when my player collides with the object it will create a new player and destroy the old and the object collided with. I was wondering how I would switch the main cameras target on collision with the object, so my camera follows my new character.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Issues with Translations and OnTriggerExit 0 Answers
Problem with acclerometer 0 Answers
Problem with jcar script for android mobile 1 Answer
How do I check if an object is touching another object? 1 Answer