|
|
@ -21,6 +21,7 @@ public class HammerController : MonoBehaviour |
|
|
|
private float Speed; |
|
|
|
|
|
|
|
private Vector3 startDir; |
|
|
|
private Vector3 lastHitDir; |
|
|
|
|
|
|
|
private void Start() |
|
|
|
{ |
|
|
@ -33,23 +34,30 @@ public class HammerController : MonoBehaviour |
|
|
|
void FixedUpdate() |
|
|
|
{ |
|
|
|
float ratio = (Mathf.Sin(Time.time * Speed) + 1) / 2; |
|
|
|
float ratioOffset = (Mathf.Cos(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)); |
|
|
|
lastHitDir = Quaternion.AngleAxis(Mathf.Lerp(AngleLimit.x, AngleLimit.y, ratio), transform.parent.TransformDirection(RotationAxis)) * transform.parent.TransformDirection(HitDirection) * -Mathf.Sign(Mathf.Lerp(AngleLimit.x, AngleLimit.y, ratioOffset)); |
|
|
|
|
|
|
|
Debug.DrawRay(transform.position, hitDirection * Force, Color.green); |
|
|
|
Debug.DrawRay(transform.position, lastHitDir * Force, Color.green); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnTriggerStay(Collider other) |
|
|
|
{ |
|
|
|
|
|
|
|
var ball = other.GetComponent<BallController>(); |
|
|
|
if (ball != null) |
|
|
|
ball.EatHorse = false; |
|
|
|
|
|
|
|
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); |
|
|
|
horse.AddForce((lastHitDir.normalized + Vector3.up) * Force); |
|
|
|
Debug.Log("Hitting horse"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |