Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by sephiroth111 · Sep 21, 2012 at 02:15 PM · c#rotationchild

Problem with child rotation

Hello, before i proceeding here i already searched the best solution but i couldnt solve the problem.

I have a main character(child) that belongs to main character object(parent) (they are equivalent on name only, pardon for confusing), i need to rotate the child main character so it is facing to left, right, forward backward same as god of war if you know it.

my problem is i cant set the exact value for child main character's rotation y axis and it gave weird value. if i set the y axis to 90 degree the debug.log method shows the value of decimal numbers such as 0.7000... something. If i look the child's transform rotation it displayed not exactly like 90 but more than 90. Im already confused. I dont know how to solve this kind of issue since im still a beginner.

ill show you my code,

 public float rightValue = 0.0f;
 private GameObject childPlayer;

void Start ()

 {
     childPlayer = GameObject.FindGameObjectWithTag("Child Player");

}

void Update ()

 {
     if (Input.GetKey(KeyCode.W))

     {
         rightValue = 90.0f;
         if (rightValue >=90.0f)
         {
             childPlayer.transform.localRotation = Quaternion.Slerp(Quaternion.identity, new Quaternion(0, rightValue, 0, 0), .5f);
             childPlayer.animation.CrossFade("idle Run Forward");
         }
         else
         {
             
         }
     }
     else
     {
         childPlayer.animation.CrossFade("idle 01");
     }

}

Please help me. Thank you in advance Im using the CharacterController class to control the main character parent.

Comment
Add comment · Show 1
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 sephiroth111 · Sep 21, 2012 at 02:31 PM 0
Share

pardon for confusing. i already edited the topic.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · Sep 21, 2012 at 03:43 PM

Ok so you are trying to modify the individual properties x,y,z,w of a Quaternion - this isn't a good idea unless you happen to be good at visualising 4 dimensional space! Those properties do not represent real world angles. Instead you should use Quaternion.Euler which converts x,y,z rotations into a Quaternion for you.

Secondly - your Slerp is always going to return a single value half way between Quaternion.identity and whatever you set the target to - that's because you are using a fixed 0.5f value in the time parameter. It would give you a basic damped rotation if you used Quaternion.Slerp(childPlayer.transform.localRotation, Quaternion.Euler(0, rightValue, 0), 0.5f). To accurately Slerp between two locations over a fixed time you need to initialise a time variable to 0 and then add Time.deltaTime to it each frame.

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 sephiroth111 · Sep 21, 2012 at 03:52 PM 0
Share

thank you for the help and thank for clear explanation. my new code is flowslessly working :)

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

11 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

Related Questions

Flip over an object (smooth transition) 3 Answers

FPS Controller rotate between two points c# 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

How to parent an object without losing its 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