Search Unity

How can I obtain vectors like transform.up when using a TransformAccess?

Discussion in 'Scripting' started by sordidlist, Jul 18, 2020.

  1. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86
    I'm using a TransformAccess inside an IJobParallelForTransform job, and I'd like to be able to compute a set of vectors in this job and write them to a NativeArray<Vector3> as output.

    Ideally, I would just return transformAccess.up, transformAccess.right, etc. But these aren't available in the TransformAccess API, so I think I need to compute them myself. Is there a Vector3 transformation I can apply, or do I need to do the math manually? If I have to do it manually, I think I'm overthinking the math itself, and would appreciate some pointers.
    Thanks!
     
    Evgeni_Incineration likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    The math is pretty simple, just multiply the world vector you want by the object's world rotation.

    I have not used that IJobs transform accessor you refer to, but if you have the Quaternion that is the object's world rotation (ie., normally called
    transform.rotation
    outside of Jobs/ECS), then the various helpers are:

    transform.up
    is
     transform.rotation * Vector3.up

    transform.right
    is
    transform.rotation * Vector3.right

    transform.forward
    is
     transform.rotation * Vector3.forward
     
  3. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86

    Thank you!
     
    Kurt-Dekker likes this.