Raycast between TransformDirection and Vector3.Forward?

Hello,

I’m having a bit of a coding/transform/vector issue, which I can’t my head around.

I’m currently firing a raycast from the direction my object is facing:

Vector3 _dir = transform.TransformDirection(Vector3.forward);

Works fine, but I would like to add in an ‘adjustment’ so I can range between the TransformDirection, and a World Forward (Vector3.forward) - and range between those values:

Vector3 _dir = Vector3.forward;

For example, if I have my ‘adjustment range’ at 0%, the raycast will point only in Vector3.foward World Space, but if I change it to 100%, the raycast will point in the TransformDirection (direction of transform).

Thus, if I have the range at 50% the raycast will be in between the values of Vector3.forward and TransformDirection.

I have no idea how to even code this up though? I can’t get my head around it :confused:

A point in the right direction would be much appreciated (no pun intended). Thanks.

Uhm so you want to slerp between world forward and local forward? Just do this:

Vector3 _dir = Vector3.Slerp(Vector3.forward, transform.forward, percent);

Note that “percent” are “programmer-percent” (aka in the range of 0 to 1 ^^) This might be a bit misleading but using something like “perunum” would be even more confusing as nobody speaks latin :slight_smile: