- Home /
Vehicle (tank) for my character
Hi,
I have a problem, I want my character control a tank for a little period of time on my game. So I need ideas for doing an script. First by a collider I want the player disappear and you control the tank (but I want to store in some way my character inside the tank, I want to stop using the tank by using jump button). So I don't know how to do it. It's important too to say that the character prefab, have some hiden parts, by default, so I don't know if this is a problem.
What I can do to solve my problem?
Lot of thanks
Answer by Antony-Blackett · May 09, 2011 at 09:38 PM
When the character collides with the tank, assign a GameObject variable on the tank to the player object. Then call SetActiveRecursive(false); on the player object. After that enable the tank controls.
To get the character out of the tank make the Jump button and control on the tank itself that when pressed calls SetActiveRecursive(true); on the player GameObject variable you set earlier and sets the player's position to the position you want them to be when the jump out of the tank begins.
Good luck.
I have done a function with this:
function OnCollisionEnter(collision : Collision) { collision.gameObject.SetActiveRecursive(false); }
But my player doesn't look like if it is on the tank. What I'm doing wrong?
Setting the player object active to false will make the player disapear. I though this is what you wanted as it'd look like the player went inside the tank, If you want the player on the tank then you'll have to disable collision for those two objects on impact and then set the player's parent collision.gameObject.transform.parent to a node on the tank that you wish your player to appear at. Then also set the player to is$$anonymous$$inematic = true on its rigidbody to stop it simulating. Then when the player exits the tank, do the opposite.
But with the function I have done: OnCollisionEnter(collision : Collision) { collision.gameObject.SetActiveRecursive(false); } There is no effect X__X
There will be, maybe you just can't see it. If the node that the physics body is on is not the root node of the player character then you'll have to find the root of the player character and deactivate that. Depending on how your scene is setup try this collision.gameObject.transform.root.gameObject.SetActiveRecursivley( false );
Your answer
Follow this Question
Related Questions
Tank Turret move on XAxis by Mouse XAxis 1 Answer
Script for getting in and out of a tank 2 Answers
Controllable boat script 0 Answers
Enter Vehicle Script not working! 1 Answer
How to check hit on tank 1 Answer