- Home /
Transform.Rotate a child object can't get it to work.
Hi, I have a particle system in attached to a child object behind a plane, acting as the exhaust. The play flips depending on the direction it's facing, however the particle system doesn't. I figured I have to rotate the transform of the child object in order to properly align the emission direction to the plane. I'm using this code, and somehow it ends up rotating the plane itself.
private Transform exhaust;
void Start ()
{
myTrans = transform; // Cache the transform component
exhaust = GetComponentInChildren<Transform>(); // Get the transform of the particle system.
if (myTrans.position.x > 0) //Define the direction of travel based on starting location
{
speed *= -1;
Flip();
}
Debug.Log ("Current rotations is:" + exhaust.rotation);
void Flip ()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
exhaust.Rotate (0,180,0);
Answer by Kensei · Jun 19, 2014 at 03:02 PM
I solved my own problem, the solution was that instead of using exhaust.Rotate I should've used exhaust.localRotation.
Answer by AndyMartin458 · Jun 18, 2014 at 04:49 PM
Your problem most likely stems from this line exhaust = GetComponentInChildren(); // Get the transform of the particle system.
Are you certain that there is only one child object? You should probably store the transform of the exhaust via the inspector just to make sure that you are getting the exact transform that you want.
I tried that too. I have only 1 child object though. The problem is that with this code the exhaust is in the right direction but the plane now isn't.
Your answer
Follow this Question
Related Questions
Access gravity modifier in the particle system by Script (C#) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Activate a particle system on click c# script 1 Answer
Rotating Cuboid Around Pivot 2 Answers