# Vector3.Slerp is not working help.

Hello i want to rotate object y0 to y90 but it does not work this is what i tried:

``````using UnityEngine;
using System.Collections;

public class OpenDoor : MonoBehaviour {

public bool isdooropen = false;
private float dooropensmoothness = 2f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

if (isdooropen == true) {

Vector3 DoorOpenAngleTo = new Vector3 (0,90,0);

transform.rotation = Vector3.Slerp (transform.rotation.y, DoorOpenAngleTo.y, dooropensmoothness * Time.deltaTime);

} else if(isdooropen == false){

//transform.Rotate (new Vector3(0,10,0) * dooropensmoothness * Time.deltaTime);

}

}
}
``````

I tried everything but nothing works… can you stell me how to fix this slerp? this is what i want to happen: Unity 3D - Horror Game Tutorial #2: Open & Close Doors - YouTube but the video gives errors soo i am trying to use vector3.slerp to fix this.

I can see a few problems with your code, correct me if I am wrong:

1. Vector3.Slerp takes in two vectors and spherically interpolates between them. You are passing two floats to this function. Also note, Slerp treats these vectors as directions and not positions in space like Lerp.
2. You are setting a Quaternion, transform.rotation but Vector3.Slerp returns a Vector3. You should be seeing errors in your console for these 2 problems.
4. The Slerp function moves from a to b within time t. So when t = 0 the value returned should be a and when t = 1 the value returned should be b. See the Unity example in Vector3.Slerp. They have a total time in which they want to move from source to destination, called “journeyTime” and they store the “startTime”. During Slerp, they pass the fracComplete value. This is what you should be using to pass as the last parameter in Slerp functions.

void Update () {

``````		if (isdooropen == true) {

Quaternion DoorOpenAngleTo = Quaternion.Euler(0f,90f,0f);

transform.rotation = Quaternion.Slerp (transform.rotation, DoorOpenAngleTo, dooropensmoothness * Time.deltaTime);

} else{
Quaternion DoorOpenAngleTo = Quaternion.Euler(0f,0f,0f);

transform.rotation = Quaternion.Slerp (transform.rotation, DoorOpenAngleTo, dooropensmoothness * Time.deltaTime);

}

}
``````