So I have an object “Centerax” which moves on its local X-axis, however I need it to be always trying to return to its original position relative to its parent object. (The parent object is always moving/rotating)
Currently my code below is giving me the errors listed and nothing I’ve tried seems to fix it.
public Transform target;
public float upDistance = 7.0f;
public float backDistance = 10.0f;
public float trackingSpeed = 3.0f;
public float rotationSpeed = 9.0f;
public float returnSpeed = 3.0f;
public HoverControl hcs;
private Vector3 vPos;
private Vector3 oPos;
private Quaternion rPos;
void Start ()
{
oPos = target.localPosition;
}
void FixedUpdate ()
{
float mvSlide = -Input.GetAxis(“Horizontal”) * (hcs.agility * 2);
vPos = target.position - target.forward * backDistance + target.up * upDistance;
transform.position = Vector3.Lerp (transform.position, vPos, trackingSpeed * Time.deltaTime * hcs.velocity);
rPos = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, rPos, rotationSpeed * Time.deltaTime * (hcs.agility * 2));
hcs.centerax.transform.Translate(new Vector3(Mathf.Lerp(-mvSlide, mvSlide, Time.smoothDeltaTime), 0, 0));
Vector3 tmpPos = hcs.centerax.transform.localPosition;
tmpPos.x = Mathf.Clamp (tmpPos.x, -1f, 1f);
hcs.centerax.transform.localPosition = tmpPos;
hcs.centerax.transform.localPosition = Vector3.Lerp (hcs.centerax.transform.localPosition.x, oPos, Time.deltaTime * returnSpeed);
}
}
Errors:
-The best overloaded method match for `UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)’ has some invalid arguments
- Cannot convert ‘Float’ expression to type ‘UnityEngine.Vector3’