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 WaterMinecraft · Sep 26, 2013 at 08:35 PM · camera rotaterotate objectvector3.slerpcusm rotation

How to use Lerp(Slerp) to rotate on the Z Axis.

Hey!

I've been looking at the videos and references and this place... But I can't for the life of me figure out how to rotate 35 degrees to either the right or the left. Smoothly. I can make the character rotate, but it snaps back and forth. So I though the Lerp function would work. Or Slerp... Though I have no idea how to use them. (: If anyone can help, it would be much appreciated!! ~WM

EDIT:

 using UnityEngine;
 using System.Collections;
 
 public class LeaningScript: MonoBehaviour {
 
     public float smooth = 6f;
     public float target = 35f;
 
     // Update is called once per frame
     void Update () {
 
         if (Input.GetKeyDown (KeyCode.Q)) {
             float angle = Mathf.MoveTowardsAngle (transform.eulerAngles.z, target, smooth * Time.deltaTime);
             transform.eulerAngles = Vector3 (0, 0, 35);    
         }
         if (Input.GetKeyDown (KeyCode.E)) {
 
             float angle = Mathf.MoveTowardsAngle(transform.eulerAngles.z, target, smooth * Time.deltaTime);
             transform.eulerAngles = Vector3(0, 0, -35);    
 
         }
 
     }
 
 }

So not quite sure what I'm doing wrong...?

Assets/LeaningScript.cs(14,49): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MrProfessorTroll · Sep 26, 2013 at 08:58 PM

If you want to rotate on a specific axis, you probably have to use Mathf.Lerp / Slerp. You create a quaternion.euler and in the Z value, you put the Mathf.Lerp. Like this: http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Lerp.html

Comment
Add comment · Show 7 · 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 Sisso · Sep 26, 2013 at 09:08 PM 0
Share

Two more references

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Slerp.html

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.$$anonymous$$oveTowardsAngle.html

avatar image WaterMinecraft · Sep 26, 2013 at 09:18 PM 0
Share

All right! (: I may be wrong... But that link refers to the position ins$$anonymous$$d of the rotation correct?

avatar image MrProfessorTroll · Sep 26, 2013 at 10:37 PM 0
Share

Well you can use them in rotations if you want. Actually, for anything that involves numbers :)

avatar image WaterMinecraft · Sep 26, 2013 at 11:38 PM 0
Share

So ... Would I substitute rotation in for position? (:

avatar image MrProfessorTroll · Sep 27, 2013 at 12:56 AM 0
Share

Something like this:

 transform.rotation = Quaternion.Euler(0f, 0f, $$anonymous$$athf.Lerp(transform.rotation.eulerAngles.z, TARGETROTATION, Time.deltaTime* 5f));

Replace TARGETROTATION with the value you want. I'm not sure if this is correct, as I haven't tested it. Let me know if you run into any problems

Show more comments
avatar image
0

Answer by Sisso · Sep 26, 2013 at 08:53 PM

Try to download some of unity3d sample projects and take a look how they solve this type of problem.

http://unity3d.com/gallery/demos/demo-projects

Comment
Add comment · 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
0

Answer by meat5000 · Sep 27, 2013 at 01:09 PM

Quaternion Slerp is what you need.

Vector3 Slerp will move an object in an arc without rotating it.

You can't call it once (like any lerp) and expect the function to do the rest. You must attend to it each frame progressively changing the value of t. This is why using deltaTime is a good option.

http://answers.unity3d.com/questions/229690/issues-with-lerps.html

Comment
Add comment · 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

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

18 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

Related Questions

really annoying rotation problem. 0 Answers

Changing this code to control camera with keys? 0 Answers

How to make the camera to focus on a player 1 Answer

Problem with Constraint Camera Rotation C# 3 Answers

Rotating Produces Odd Results [Unity 2D] 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