You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
1.7 KiB

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.TransformDirection(RotationAxis)) * startDir;
Vector3 hitDirection = Quaternion.AngleAxis(Mathf.Lerp(AngleLimit.x, AngleLimit.y, ratio), transform.parent.TransformDirection(RotationAxis)) * transform.parent.TransformDirection(HitDirection) * -(Mathf.Cos(Time.time * Speed));
Debug.DrawRay(transform.position, hitDirection * Force, Color.green);
}
private void OnTriggerStay(Collider other)
{
var horse = other.GetComponent<PlayerController>();
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.TransformDirection(RotationAxis)) * transform.parent.TransformDirection(HitDirection) * -(Mathf.Cos(Time.time * Speed));
horse.AddForce((hitDirection.normalized + Vector3.up) * Force);
Debug.Log("Hitting horse");
}
}
}