using System.Collections; using System.Collections.Generic; using UnityEngine; public class HammerController : MonoBehaviour { [SerializeField] private Vector2 AngleLimit; [SerializeField] private Vector3 RotationAxis; [SerializeField] private Vector3 HitDirection; [SerializeField] private float Force; [SerializeField] private float Speed; private Vector3 startDir; private void Start() { transform.forward = Vector3.up; startDir = transform.forward; } // Update is called once per frame void FixedUpdate() { float ratio = (Mathf.Sin(Time.time * Speed) + 1) / 2; transform.forward = Quaternion.AngleAxis(Mathf.Lerp(AngleLimit.x, AngleLimit.y, ratio), transform.parent.InverseTransformDirection(RotationAxis)) * startDir; Vector3 hitDirection = Quaternion.AngleAxis(Mathf.Lerp(AngleLimit.x, AngleLimit.y, ratio), transform.parent.InverseTransformDirection(RotationAxis)) * transform.parent.InverseTransformDirection(HitDirection) * -(Mathf.Cos(Time.time * Speed)); Debug.DrawRay(transform.position, hitDirection * Force, Color.green); } private void OnTriggerStay(Collider other) { var horse = other.GetComponent(); if (horse != null) { float ratio = (Mathf.Sin(Time.time * Speed) + 1) / 2; Vector3 hitDirection = Quaternion.AngleAxis(Mathf.Lerp(AngleLimit.x, AngleLimit.y, ratio), transform.parent.InverseTransformDirection(RotationAxis)) * transform.parent.InverseTransformDirection(HitDirection) * -(Mathf.Cos(Time.time * Speed)); horse.AddForce((hitDirection.normalized + Vector3.up) * Force); Debug.Log("Hitting horse"); } } }