void SnapToPath() { Path3D.SplinePoint sp = m_Path.GetClosestPoint(this.transform.position); this.transform.position = sp.pos; this.transform.rotation = Quaternion.LookRotation(sp.forward, Vector3.up); }
void Move() { myPoint = m_Path.GetClosestPoint(this.transform.position); if (Input.GetKey(KeyCode.A)) { targetPoint = m_Path.GetClosestPoint(myPoint.pos + myPoint.forward); // this depends on direction currentForward = (targetPoint.pos - this.transform.position).normalized; m_Ridig.AddForce((currentForward * 20.0f * Time.deltaTime) - m_Ridig.velocity, ForceMode.VelocityChange); } else if (Input.GetKey(KeyCode.D)) { targetPoint = m_Path.GetClosestPoint(myPoint.pos - myPoint.forward); // this depends on direction currentForward = (targetPoint.pos - this.transform.position).normalized; m_Ridig.AddForce((currentForward * 20.0f * Time.deltaTime) - m_Ridig.velocity, ForceMode.VelocityChange); } }