- Home /
Slerp Probems
Im doing the Menu screen for my game and i'm currently using unity's new UI system. When the Options button is pressed then I need the camera to move and rotate slowly to a place.This seems really easy but for some reason it doesn't slerp no matter what i put in and it lerps to a completely random place? here's my code:
using UnityEngine;
using System.Collections;
public class MainMenuCaller : MonoBehaviour {
public GameObject MainCam;
public Vector3 movePos=new Vector3(-6.1232f,-0.30558f,20.013f);
public GameObject canvas;
public bool Moved=false;
public GameObject NewCanvas;
public bool Instantiated=false;
public Quaternion OptionsCamRot= new Quaternion(0,67.69f,0,0);
public Vector3 CameraMovePos= new Vector3(-3.4777f,-0.30558f,22.199f);
public void Exit()
{
Application.Quit ();
}
public void CampaignStart()
{
Application.LoadLevel ("campaign");
}
public void Online()
{
MoveCam ();
}
public void MoveCam()
{
MainCam.transform.position = Vector3.Lerp (MainCam.transform.position, movePos, 1.5f * Time.deltaTime);
Destroy(canvas,4f);
Invoke ("OnlineMenu", 4f);
}
public void OnlineMenu()
{
Instantiate (NewCanvas);
CancelInvoke();
}
public void Options()
{
MainCam.transform.position = Vector3.Lerp (MainCam.transform.position, CameraMovePos, 1.5f * Time.deltaTime);
MainCam.transform.rotation = Quaternion.Slerp (MainCam.transform.rotation, OptionsCamRot, 1.5f * Time.deltaTime);
}
}
You need to call $$anonymous$$oveCam() continuously maybe move the lerp to some Update() function. If it lerps to a random place you might be using local coordinates, so try switching transform.position to transform.localPosition
$$anonymous$$ove cam is being done continuosley and the camera isn't a child of anything?
If anyone has a solution please, it would be highly appreciated
Answer by b1gry4n · Nov 30, 2014 at 03:26 PM
I suggest you follow this guide on using lerp:
http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly
no it isnt, youre using time.deltatime. read the guide, trust me
using a lerp with time.deltatime may work, but it is incorrect. The guide will explain this. The reason your code isnt working is because you are not continuously updating your lerp. I dont even see an Update() in your code. Luckily though, you will not be using Update() if you follow the guide and understand it
no because im updating as an event trigger in the inspector using unity's UI system
Your answer
Follow this Question
Related Questions
Lerp Rotation C# 3 Answers
Keeping UI Element To Game Object When Camera Moves 2 Answers
Crouching script not working? 0 Answers
Is it good idea to implement camera drag with UI drag event? 2 Answers
Moving the player toward a direction 1 Answer