Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D rigidbody units rotate using x as forward #14

Open
jjoshpoland opened this issue Aug 31, 2020 · 2 comments
Open

3D rigidbody units rotate using x as forward #14

jjoshpoland opened this issue Aug 31, 2020 · 2 comments

Comments

@jjoshpoland
Copy link

Using the 3d units, the lookatdirection function seems to orient units using the x axis as forward, as they will align their x axis with the velocity direction instead of their z axis.

I've tried messing with the LookAtDirection code and haven't been able to determine the issue. The math looks right, so I don't know if the x-forward assumption is made somewhere else I haven't found. This would be useful for most applications as the assumption is that z is forward.

@jjoshpoland
Copy link
Author

Update for insight - after recreating the code from scratch without any references to 2D or flying, I was able to implement logic that keeps the unit looking forward along the z axis without spinning in circles.

Logic for forward looking (doesn't work when inserted into current master branch):

public static Quaternion GetLookDirection(Vector3 direction, ISteerable unit)
        {
            direction.Normalize();

            Quaternion targetRotation = Quaternion.LookRotation(direction);

            Quaternion newRotation = Quaternion.Slerp(unit.Rotation, targetRotation, 20f * Time.deltaTime);
            return newRotation;

            
        }

@jjoshpoland
Copy link
Author

unit in the above case is just a interfaced reference to a monobehavior with the MovementAIRigidbody logic implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant