• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Korthking · Jan 06 at 09:32 AM · transformquaterniontransform.rotationtransform.rotaterotatetowards

transform rotations overwriting eachother

I have a script for making my character turn, and I have a script which rotates it based on the leg positions (for making my spider wobble and align to the terrain). Do any of you know how I can make these work together?

Currently #1 makes #2 not able to turn anymore.

1:

 private void Update()
     {
         lastBodyUp = transform.up;
  
         nbLegs = legTarget.Length;
         if (nbLegs > 3 && bodyOrientation)
         {
             Vector3 v1 = legTarget[0].position - legTarget[3].position;
             Vector3 v2 = legTarget[2].position - legTarget[1].position;
             Vector3 normal = Vector3.Cross(v1, v2).normalized;
             Vector3 up = Vector3.Lerp(lastBodyUp, normal, 1f / (float)(smoothness + 1));
             // This works, but interfers with the mouseLook rotation of the Character
             transform.up = up; // <==
             lastBodyUp = up;
         }
     }

In this #1 code I do the mean position of my 4 legs, and rotates it based on their positions. It looks great for mechs and spiders on its own.

2:

    var step = RotationSpeed * Time.deltaTime;
    Quaternion lookRotation = Quaternion.Euler(0f, Camera.main.transform.eulerAngles.y, 0f);
    transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, step);

 

In this code I've used Cinemachine, and use the main camera to determine the direction of the camera, then make the character turn slowly towards it (steering with your camera)

I'll also add that these are two different files on the same gameobjects. I've also tried to play around with adding physics rotations instead, but with no luck yet.

The ideal solution is some way of adding these transforms together, to make both of them work somehow

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BetaFruit · Jan 06 at 12:33 PM

This really is not something I understand at all but you could be having a problem where the scripts are setting the rotations they dont change to 0 and messing up the other ones. In that case make them use the localrotation value instead of 0. And if thats not your problem try making both rotation scripts work together in one script like adding both rotations together then applying them.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Korthking · Jan 07 at 06:07 AM 0
Share

What do you mean by the scripts don't change to 0? I'm relatively new to Unity and still have some kinks and quirks to understand.

Regarding adding both rotations together, that's the solution I kind of want, but I'm having problems understanding how I can do that. In #1 I rotate the body using transform.up and Lerp, which works great. I am not 100% sure how transform.up works, and googling didn't make me understand it too much either (lol).

In #2 I use Quaternion.RotateTowards on transform.rotation. I believe the issue is that both methods use the transform to overwrite the other.

I might be asking the wrong question, but I believe it boils down to "Can I somehow merge Lerp on transform.up with Quaternion.LookTowards on transform.rotation?"

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

213 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change the Rotation X value without changing Y and Z 1 Answer

Rotate gameObject to a specific angle on one axis 0 Answers

Why does assigning a quaternion to transform rotation work but calling transform.rotation. doesnt? 1 Answer

Rotating transform more than 180 degrees 2 Answers

Object rotate and slowly stop to toward 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges