Dynamically Change Position of RayCast

Hello,

I’m using a Transform to reference where I want to cast a ray from:

var referenceObject : Transform;

if(Physics.Raycast (referenceObject.transform.position, direction, hit))

But I want to be able to also dynamically change the position slightly within the code. For now, just add 3 onto the Z axis:

var firePos = referenceObject.transform.position;
var lineStartPos = Vector3(firePos.x, firePos.y, firePos.z + 3);

The only problem with that code, is that its in world space, and not local to the referenced object.

How would I fix this?

Thanks

Hello,

It’s hard to tell what you want to do, but if you want to transform a point from local to world space, you can use referenceObject.TransformPosition(point:Vector3) to make your point relative to the object.
If you want to change a direction from local to world space, you use TransformDirection :slight_smile:

Hope this helps,
Benproductiosn1