how to move only one object ?
I am building a parachute game. i have a helicopter and a third person character from standard assets Ethan. third person's controlling are working done. i apply this moving code to my helicopter
void Update()
{
Helicopter = GameObject.Find("mi17"); Helicopter.transform.Translate(0,0,-2); Helicopter.transform.rotation = Quaternion.Euler(0, 0, Mathf.Sin(Time.time * 0.8f) * 10 + 0);
}
after jumping to land from helicopter, character is moving as helicopter code. i need to stop it need to stop that moving after landing to ground. help me,
The character jumps out of the helicopter. Then he is supposed stop moving when colliding with the ground. How can I make him stop moving once he jumps out?
Tbh I dont think I understood the question so is that your question?
Using GameObject.Find in Update, is not only not needed but not recommended performance wise. Why don't you just put that script on the Helicopter object itself and use transform
ins$$anonymous$$d of Helicopter.transform
.
Answer by Cuttlas-U · Apr 12, 2017 at 05:15 PM
Hi; usually these kinds of problems can be solved by a bool;
u define a bool like :
public bool IsPlayerInHeli = false;
and set its value to true when the player is in the helicopter; then in the update method u check and make it to only if this value is true the moving code work for u;
void Update()
{
if ( IsPlayerInHeli == true )
{
Helicopter = GameObject.Find("mi17"); Helicopter.transform.Translate(0,0,-2); Helicopter.transform.rotation = Quaternion.Euler(0, 0, Mathf.Sin(Time.time * 0.8f) * 10 + 0);
}
}
and if player is child of helicopet parent dont forget to null the parent so it dont move with the heli;
Player.transform.parent = null;