// Update is called once per frame public void Update() { if (mInitTargetPos != mTargetObj.transform.position) { mTrialMode = TrialMode.eCustom; mBezierWalker.enabled = false; } if (mTrialMode == TrialMode.eCustom) { Vector3 translation = mTargetObj.transform.position - mStartObj.transform.position; if (translation.magnitude > 0.1f) { mStartObj.transform.Translate(Vector3.Normalize(translation) * Time.deltaTime * mMoveSpeed, Space.World); Quaternion targetRotation = Quaternion.LookRotation(Vector3.Normalize(translation)); mStartObj.transform.rotation = Quaternion.Lerp(mStartObj.transform.rotation, targetRotation, mRotationSpeed * Time.deltaTime); } else { mStartObj.transform.position = mTargetObj.transform.position; Quaternion targetRotation = Quaternion.LookRotation(Vector3.Normalize(translation)); mStartObj.transform.rotation = targetRotation; } } }
public void Create(GameObject startObj, GameObject targetObj) { mInitTargetPos = targetObj.transform.position; mTargetObj = targetObj; mStartObj = startObj; mMoveSpeed = 10; mRotationSpeed = 10; mTrialMode = TrialMode.eBezier; CreateBeizer(startObj, targetObj); }