• 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 /
avatar image
Question by chrian · Oct 28, 2018 at 07:56 AM · rotationquaternionquaternionsconstraintsmultiply

Make Quaternion affected by float

Basically, I'm just trying to make targetRotation become affected by the float influence (a float ranging from 0 to 1). So if influence is 0, targetRotation will be 0. using System.Collections; using System.Collections.Generic; using UnityEngine;

public class RotationConstraint : MonoBehaviour { [SerializeField] private Transform targetObject;

 [SerializeField]
 [Range(0, 1)]
 private float influence;

 private Quaternion targetRotation;


 void Update ()
 {
     targetRotation = targetObject.transform.rotation;

     transform.rotation = targetRotation * influence;    // I get an error under targetRotation * influence
 }

}

Comment

People who like this

0 Show 0
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

Answer by Bunny83 · Oct 28, 2018 at 10:21 AM

"targetRotation will be 0" just makes no sense. What does 0 mean? A rotation / orientation is never "0". Do you mean the identity rotation? So eulerangles 0,0,0? In this case you can use Slerp. However if you just want to rotate towards you can use RotateTowards.

To use Slerp between the identity rotation and your target rotation you would do something like this:

 transform.rotation = Quaternion.Slerp(Quaternion.identity, targetRotation, influence);

In this case if influence is 0 the rotation will be the identity rotation. If it's 1 the rotation will be equal to the targetrotation. Of course if you want to slerp between two orientations you just have to pass the starting rotation as first parameter. However keep in mind that the start rotation has to be constant if you want that 0 is the start rotation. So using the current rotation as start rotation would be a decelerated "rotate towards" if influence is greater than 0.

Comment
unity_csUz1HXzf0ASHQ

People who like this

1 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 chrian · Oct 28, 2018 at 08:03 PM 0
Share

Thanks! So I am trying to use influence to decide how much my rotation is affected by the other object during the game. So if the object rotated 360 degrees and the influence is set to 0.5, I should only rotate half the amount (so 180 degrees), and if influence was set to 1, I would be rotated 360 degrees just like the object. So I am having trouble trying to decide what to use as the start rotation in the slerp.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

127 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

Related Questions

How to use quaternions to apply an offset to a rotation to calibrate a controller 1 Answer

Get real compass direction 1 Answer

How do i make my Mouselook behave when changing the z rotation? 0 Answers

How can I instantiate a gameobject facing another gameobject 2D? 0 Answers

How to rotate object based on another rotation. 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