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 /
This question was closed May 12, 2012 at 08:29 AM by Inan-Evin for the following reason:

Duplicate Question

avatar image
0
Question by Inan-Evin · May 11, 2012 at 07:46 PM · quaternionrotatelerpweapon

Rotating the weapon back using Quaternion.Lerp

Hello everyone. I want to rotate my gun to left & right when player moves to left & right. So I made a code like this :

  var from : Transform; // a gameObject for start
     var to1 : Transform; // a gameObject which is for left limit of rotating ( 0,0,1.5)
     var to2 : Transform; // a gameObject which is for right limit of rotating ( 0,0,-1.5)
     var orig : Transform; // a gameObject which has the original rotations of gun(0,0,0)
     var current : Transform: // a gameObject for the weapons current rotation
     var speed = 0.1;
     private var rotateLevel : int =0; // a value to stop rotating left
     private var rotateLevel2 : int =0; // a value to stop rotating right
 
 function Update(){
     if(Input.GetKey("a")){
     if(rotateLevel<40){
     rotateLevel+=1;
     rotateLevel2-=1;
      transform.rotation =
           Quaternion.Lerp (from.rotation, to1.rotation, Time.deltaTime * speed);
           }
     }
     else if(Input.GetKey("d")){
     if(rotateLevel2<40){
     rotateLevel-=1;
     rotateLevel2+=1;
      transform.rotation =
           Quaternion.Lerp (from.rotation, to2.rotation, Time.deltaTime * speed);
           }
     }
     
     
     else{
     
   ?????
     }
 
 }

This works well, it moves smoothly & good according to the variables that I adjusted. But when I stop walking, it stays in the position which it was at. So all the aiming and other things get messed up. I need to turn the gun back to it's original rotation smoothly. For that, I made a code like that but didn't work :

 else{
 
  transform.rotation =
       Quaternion.Lerp (current.rotation , orig.rotation, Time.deltaTime *speed);
 }

but as I said it did not work. I need help, any ideas ? Thanks =)

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

  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · May 12, 2012 at 05:32 AM

Try

transform.rotation = Quaternion.Lerp( transform.rotation , from.rotation, Time.deltaTime *speed);

I'm not sure of what is the diff between from and orig though.

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 Inan-Evin · May 12, 2012 at 08:03 AM 0
Share

It did not work, I don't know if I wrote the code & if statements in wrong way but when I put Debug.Log in to else{} it works, but when the code I wrote or the code you said just doesn't work. Thanks for the help though, but you got any ideas ? :)

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Copy rotation of targetObject to current object with an influence in the range from 0-1. 0 Answers

Use Lerp to rotate object 2 Answers

Rotate camera around player 2 Answers

instant rotate an object 3 Answers

Align two parents based on child position and 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