Its been a while since I have tried to script and I cannot figure this out…
I am trying to get the local direction of a parent object so I can add local force to a particle with a script. And I thought that
transform.parent.up
gave you the local direction and it worked in one situation but not in another. It just seemed to use the world direction as the scripting reference says…
So my question is how do I get the local up direction of a object?
All the possible direction vectors, not sure if you want a local or global:
using UnityEngine;
using System.Collections;
public class DrawSampleVecs : MonoBehaviour
{
void OnDrawGizmos()
{
Color color;
color = Color.green;
// local up
DrawHelperAtCenter(this.transform.up, color, 2f);
color.g -= 0.5f;
// global up
DrawHelperAtCenter(Vector3.up, color, 1f);
color = Color.blue;
// local forward
DrawHelperAtCenter(this.transform.forward, color, 2f);
color.b -= 0.5f;
// global forward
DrawHelperAtCenter(Vector3.forward, color, 1f);
color = Color.red;
// local right
DrawHelperAtCenter(this.transform.right, color, 2f);
color.r -= 0.5f;
// global right
DrawHelperAtCenter(Vector3.right, color, 1f);
}
private void DrawHelperAtCenter(
Vector3 direction, Color color, float scale)
{
Gizmos.color = color;
Vector3 destination = transform.position + direction * scale;
Gizmos.DrawLine(transform.position, destination);
}
}
Also remember that Transform.eulerAngles can be useful.