- Home /
getting object local direction?
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?
Thanks!
transform.up should give you the local up direction- in what situation does 'transform.parent.up' not give you the correct value?
What's wrong with that? Why doesn't it give you the correct value? It's possible that it's a problem with your logic.
Well I don't really know.. It seemed to work in one instance. But in a different one it just seemed to give it world up force.
I am creating explosions on impact and they need to have gravity based on there angle. so I thought that changing there force in a Start function with that code would work..
Remember that the particle animator has setting for both world, and local, forces. If you set up the local force, you just need to rotate the object, and the particle animator will handle the rest. REDACTED no wait that's wrong.
I am not using shuriken particles.. I don't see a way to make local force on the old system.
Answer by gabs · Feb 09, 2012 at 08:28 PM
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.
Thank you you life saver. You deserve a full pitcher beer from me!
Your answer
Follow this Question
Related Questions
Problem retrieving transform.position after parent rotation 1 Answer
Parenting GameObjects 1 Answer
Transform position of an object at particular angle/direction 3 Answers
Unity 3D: How to pick up object and attached it to player on TriggerEnter? 1 Answer
Changing child's rotation changes parent's position 0 Answers