- Home /
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.
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.
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
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
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 ?)
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);
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
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.
Your answer
Follow this Question
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