Hello everyone.
I am having an issue with transform.rotation = Quaternion.Lerp( currentRotation,endRotation.rotation, delta);
When I set it to 0 in an other script it’s still moving here is my code for both scripts:
This one is a rotating object. Inside this object there is another object following the rotation.
using UnityEngine;
using System.Collections;
public class RopeRotator : MonoBehaviour {
private Quaternion currentRotation;
public Transform endRotation;
public float smoothness = 0.6f;
private bool goBack = false;
private float delta = 0;
// Use this for initialization
void Start () {
currentRotation = transform.rotation;
}
// Update is called once per frame
void Update () {
RotationChange();
}
void RotationChange(){
if( goBack == false ) {
delta += Time.deltaTime * smoothness;
if( delta >= 1 ) { goBack = true; }
} else {
delta -= Time.deltaTime * smoothness;
if( delta <= 0 ) { goBack = false; }
}
transform.rotation = Quaternion.Lerp( currentRotation,endRotation.rotation, delta);
}
}
then in this script, when I turn “ropeRotatorScript.smoothness = 0f;”. The rotating object is still rotating. The weird thing is when I set delta to 0 manually(without script) It is indeed NOT moving(as it should). What am I doing wrong?
using UnityEngine;
using System.Collections;
public class RopeExtender : MonoBehaviour {
private float speed = 0.03f;
private float smoothness = 0.01f;
private float delta;
public Transform ropeEndPos;
private bool extend = false;
private Vector3 startPos;
private RopeRotator ropeRotatorScript;
// Use this for initialization
void Start () {
startPos = transform.position;
ropeRotatorScript = (RopeRotator)FindObjectOfType(typeof(RopeRotator));
}
// Update is called once per frame
void Update () {
RopeMovement();
}
void RopeMovement(){
if(Input.GetKeyDown(KeyCode.RightControl)){
extend = true;
}
if(extend){
delta += Time.deltaTime * smoothness;
transform.position = Vector3.Lerp(transform.position,ropeEndPos.position,delta);
ropeRotatorScript.smoothness = 0f;
Debug.Log(ropeRotatorScript.smoothness);
}
}
}
Here is a screenshot to make it a bit easier to understand:
Thank you for checking :)!
-Levi