Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 $$anonymous$$ · Aug 02, 2015 at 02:26 AM · cameradirectionsmooth

Problems with Lerp, or Smoothing direction.

Hello, i'm actualy working at camera control in my ThirdPerson Game.

I'm wanted to player change direction, when we are pressed the button. And i created this (with help from another questions [not my]):

 var otherObject : Transform;
 
 function Update () {
 
 if (Input.GetAxis("Horizontal")!=0){
 var newRot : Vector3;
  newRot = new Vector3 (0, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
  transform.rotation = Quaternion.Euler (newRot);}
  
 if (Input.GetAxis("Vertical")!=0){
 var newRota : Vector3;
  newRota = new Vector3 (0, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
  transform.rotation = Quaternion.Euler (newRota);}
 }

All is working, but it was great, when this change will be smooth. I found something like Lerp but i have problems with apply this in my code.

I'm think i must do: Quaternion.Lerp or Vector3.Lerp.

I don't know what to choose, i try to do something, but i have error with arguments in brackets. It would be great if you change this to C#, I don't like java, but when i try run this in C# i have errors after change varibles etc.

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 $$anonymous$$ · Aug 01, 2015 at 05:17 PM 0
Share

I'm lerning. But i want do something another than watching.

I want to try do this smooth change direction. But i'm don't know what exacly i do bad.

I'm good programmer in Game$$anonymous$$aker, and his language G$$anonymous$$L. Now it's hard do change from G$$anonymous$$L to Unity C#. In Unity is another type of scrpits and documentation.

Something like smooth i had: varible1 = lerp(from_varible, to_varible, amount);

It was easy. Now are Vector3.Lerp or Quaternion.Lerp there are very hidden arguments to change.

I'm too not Eanglish/Brit. $$anonymous$$en, and some verbs i must look of the translate, and sometimes translate like i found are bad.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by KdRWaylander · Aug 03, 2015 at 01:02 PM

Hi,

First: translation (not that hard as you can see)

 Transform otherObject;
 
 void Update () {
    if (Input.GetAxis("Horizontal")!=0){
       Vector3 newRot;
       newRot = new Vector3 (0, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
       transform.rotation = Quaternion.Euler (newRot);
    }
 
    if (Input.GetAxis("Vertical")!=0){
       Vector3 newRota;
       newRota = new Vector3 (0, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
       transform.rotation = Quaternion.Euler (newRota);
    }
 }

Then, answer:

Try using transform.Rotate() instead of transform.rotation

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 $$anonymous$$ · Aug 03, 2015 at 05:31 PM 0
Share

Ok, Thanks i do something else with translate :D

And i have to use:

 transform.Rotate(Vector3.right,newRota.right, Time.deltaTime/2);
 transform.Rotate(Vector3.left,newRota.left , Time.deltaTime/2);

Or i don't undersand documentation... It could happen.

Now i can not find self in this. In G$$anonymous$$, i had x,y and direction :D I can do x+=4 etc. or speed=2 to go where is direction :P

But now is no 2D, but 3D :D

avatar image $$anonymous$$ · Aug 03, 2015 at 05:31 PM 0
Share

Thanks for translate, i do something another :D

But i think, transform.Rotate is not smooth ? I think, i can do tranform.Rotate( new Vector3.Slerp.... ? or no ?)

avatar image KdRWaylander · Aug 04, 2015 at 07:07 AM 0
Share

You just need to pass a Vector3 inside Rotate():

 Vector3 _rotation = new Vector3 (x, y ,z);
 //with x, y and z being the speed on the different axis
 transform.Rotate(_rotation);
avatar image $$anonymous$$ · Aug 05, 2015 at 03:17 PM 0
Share

Ok i read some documentary and this code is calculating degree of 0, not of last degree. How to change this?

$$anonymous$$aybe save last rotate, and when rotate = wantrotate _rotation=0

avatar image KdRWaylander · Aug 06, 2015 at 07:34 AM 0
Share

Not sure to understand what you mean ?

Show more comments
avatar image
0

Answer by $$anonymous$$ · Aug 04, 2015 at 07:36 PM

Thanks, i translated all:

 using UnityEngine;
 using System.Collections;
 
 public class SetToCam : MonoBehaviour {
 
 public Transform otherObject ;
         
 void Update () {
 
     if (Input.GetAxis("Horizontal")!=0)
             {
             Vector3 newRot;
             newRot = new Vector3 (0, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
             //transform.rotation = Quaternion.Euler (newRot);
             transform.Rotate( newRot );
     }
  
     if (Input.GetAxis("Vertical")!=0)
             {
             Vector3 newRota;
             newRota = new Vector3 (0, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
             // transform.rotation = Quaternion.Euler (newRota);
             transform.Rotate( newRota );
         }
     }
     
 }

But your code, set direction to camera, when mouse is on half width of screen. But my camera is working with Orbit. And my character is Rotating with speed like screen width/2 + degree tilt.

Can you heklp me again, i don't know what kind of varibles i must to use. To change the rotate to rotation of camera. But no with speed of degre my roate >->> rotate camera.

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

1 Person is following this question.

avatar image

Related Questions

Why does the camera smoothly follow in one direction but not the other? 0 Answers

Change characters direction using camera view 0 Answers

Measuring XYZ coordinates in Unity vs in real life. 1 Answer

allows users to view 360º content without a VR headset 0 Answers

First Person Camera is extremely jerky 4 Answers


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