question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transform Direction Extractor UseLocal result not expected

See original GitHub issue

Environment

  • Code source: github
  • Code version: 18d34c1

Steps to reproduce

Goal: make a up-right camera following HeadsetAlias

  1. Set up tilia xr environment (unityxr, tracked alias, etc)
  2. Create a camera named “Record Camera”
  3. Create a game object “Follow Position”, add component “TransformPositionExtractor”
  4. Drag HeadsetAlias into Source field, Extracted event calls Record Camera.transform.position. We want the Record Camera follow the world space position, so turn off UseLocal. image
  5. Create a game object “Follow Rotation”, add component “TransformDirectionExtractor”
  6. Add the custom script AxesToRotation (see the Append). It takes two Vector3 axes and compute a Quaternion rotation.
  7. Drag HeadsetAlias into Source field of direction extractor, Extracted event calls to AxesToRotation.Forward and AxesToRotation.EmitRotation(). We want the Record Camera’s world space forward direction, so turn off UseLocal.
  8. AxesToRotation rotation emitted event calls to Record Camera.transform.rotation. We want the upright orientation, so we use the ConstructFrom = Forward and Up vectors. image
  9. Add MomentProcess to both FollowPosition and FollowRotation, create a MomentProcessor to execute both of them. image

Current behavior

The Record Camera’s position is followed correctly, but it is pointing in world space’s z direction, not following the forward direction of HeadsetAlias.

For Transform Position Extractor, when UseLocal is off, it returns the source transform’s world space position, while UseLocal is on, it returns the source transform’s localPosition

        protected override Vector3? ExtractValue()
        {
            ...
            return UseLocal ? Source.transform.localPosition : Source.transform.position;

However, the current Transform Direction Extractor, when UseLocal is off, it returns the Vector3.forward (which is independent of any source), while UseLocal is on, it returns the source transform’s world space forward instead of local space forward

        protected override Vector3? ExtractValue()
        {
                ...
                case AxisDirection.Forward:
                    return UseLocal ? Source.transform.forward : Vector3.forward;

Expected behavior

The transform direction extractor, when UseLocal is off should return the source transform’s world space direction, and when UseLocal is on should return the source transform’s local space direction . i.e. return UseLocal ? Source.transform.localRotation * Vector3.forward : Source.transform.forward;

Append

namespace VRToolkitExtras.Data.Type.Transformation
{
    using System;
    using Malimbe.PropertySerializationAttribute;
    using UnityEngine;
    using UnityEngine.Events;

    public class AxesToRotation : MonoBehaviour
    {
        [Serializable]
        public class QuaternionUnityEvent : UnityEvent<Quaternion>
        {
        }

        [Serialized]
        public Vector3 Forward { get; set; } = Vector3.forward;
        [Serialized]
        public Vector3 Up { get; set; } = Vector3.up;
        [Serialized]
        public Vector3 Right { get; set; } = Vector3.right;

        public enum ConstructFromType
        {
            ForwardAndUp,
            ForwardAndRight
        }
        [Serialized]
        public ConstructFromType ConstructFrom { get; set; } = ConstructFromType.ForwardAndUp;

        public Quaternion Rotation { get; private set; }

        public QuaternionUnityEvent RotationEmitted = new QuaternionUnityEvent();

        public void EmitRotation()
        {
            switch (ConstructFrom)
            {
                default:
                case ConstructFromType.ForwardAndUp:
                    {
                        Rotation = Quaternion.LookRotation(Forward, Up);
                        RotationEmitted?.Invoke(Rotation);
                    }
                    break;
                case ConstructFromType.ForwardAndRight:
                    {
                        Vector3 up = Vector3.Cross(Forward, Right);
                        Rotation = Quaternion.LookRotation(Forward, up);
                        RotationEmitted?.Invoke(Rotation);
                    }
                    break;
            }
        }
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
thestonefoxcommented, Aug 22, 2020

Affected repos: Tilia.Input.CombinedActions.Unity Prefabs:

  • Input.CombinedActions.AngleRangeToBoolean
  • Input.CombinedActions.AxesToAngle

Both have a CalculateDirectionOffset operation that uses a TransformDirectionExtractor both set to UseLocal so if these changes are applied, then both need switching so UseLocal is false.

How do you check for sure which repo is affected? Or you happen to remember which may have used the component?

I added all of the prefabs in all of the repos to a scene and just searched for t:TransformDirectionExtractor 😉

1reaction
thestonefoxcommented, Aug 22, 2020

Right so you’re saying

the transform.forward is the actual global forward direction

so in this case

Cube (rotation y 180) –Cube1 (rotation y 180)

in fact the world forward of Cube1 is still z 1 because whilst you’ve rotated the Cube1 round 180 to point in the other direction, it’s parent is actually rotating it back to pointing in the z 1 direction

but the local forward of Cube1 is actually z -1 because that locally has been rotated 180

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help with trying to understand transform. ...
So transforming a local space direction into a world space direction does only "rotate" that direction vector relative to the object.
Read more >
Weird results with Transform.TransformDirection()
I found out that Transform.TransformDIrection returns a Vector in a direction and not the eulerAngles of the Vector.
Read more >
Help with understanding Transform.TransformDirection
Context: I am trying to make a Gizmo line that displays where my camera is actively pointing at. I have found that the...
Read more >
Common SAML issues | Elasticsearch Guide [8.9]
This error indicates that the SAML metadata for your Identity Provider do not contain a <SingleSignOnService> endpoint with binding of HTTP-Redirect (urn:oasis: ...
Read more >
Component Reference - Apache JMeter - User's Manual
Several test elements use JMeter properties to control their behaviour. These properties are normally resolved when the class is loaded.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found