using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class WalkingRig : MonoBehaviour { [SerializeField] private LayerMask ground; [SerializeField] private Transform footTargetLeft, footTargetRight; private Vector3 currentPositionLeft, currentPositionRight; private void Start() { currentPositionLeft = footTargetLeft.position; currentPositionRight = footTargetRight.position; } void Update() { Debug.Log(Vector3.Distance(currentPositionLeft, FootTargetPoint(-1))); if (Vector3.Distance(footTargetRight.position, FootTargetPoint(-1)) > 0.4f) { currentPositionLeft = FootTargetPoint(-1); } if (Vector3.Distance(footTargetRight.position, FootTargetPoint(1)) > 0.4f) { currentPositionRight = FootTargetPoint(1); } footTargetLeft.position = Vector3.Lerp(footTargetLeft.position, currentPositionLeft, 0.4f); footTargetRight.position = Vector3.Lerp(footTargetRight.position, currentPositionRight, 0.4f); if (Input.GetKey(KeyCode.W)) transform.position += 5 * Time.deltaTime * transform.forward; } private Vector3 FootTargetPoint(float sign) { if (Physics.Raycast(transform.position + 0.1f * Mathf.Sign(sign) * transform.right + transform.up * 2, -transform.up, out RaycastHit hit, ground)) { } return hit.point; } void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawSphere(FootTargetPoint(1), 0.1f); Gizmos.DrawSphere(FootTargetPoint(-1), 0.1f); } }