- Home /
How to keep local rotation when using raycasts?
Hi!
When I try to make a game object and rotate it, I want to keep the raycast casting point rotating with the object in a local position, but the raycast point doesnt rotate the way I want it to. blue x is the raycast point.
My code:
var hit : RaycastHit;
var desDir = transform.TransformDirection(Vector3.down);
if (Physics.Raycast (Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z), desDir, hit, Mathf.Infinity)) {
if (hit.transform.CompareTag("nem")){
target = hit.transform;
print(target);
}
}
ray.png
(9.3 kB)
Comment
Answer by Slobdell · Jul 13, 2013 at 12:50 AM
Place an empty gameobject in the scene in the location and rotation you want it. Child it to the other Gameobject. Shoot raycast a forward from the empty gameobject