Browse Source

Fixed mushrooms + hammer direction hit

master
Joshua Reason 4 years ago
parent
commit
43283e4c1b
2 changed files with 22 additions and 5 deletions
  1. +9
    -0
      Assets/Scripts/BlackHole.cs
  2. +13
    -5
      Assets/Scripts/HammerController.cs

+ 9
- 0
Assets/Scripts/BlackHole.cs View File

@ -10,11 +10,20 @@ public class BlackHole : MonoBehaviour
private void OnTriggerStay(Collider other) private void OnTriggerStay(Collider other)
{ {
var ball = other.GetComponent<BallController>();
if (ball != null)
ball.EatHorse = false;
var horse = other.GetComponent<PlayerController>(); var horse = other.GetComponent<PlayerController>();
if (horse != null) if (horse != null)
{ {
horse.AddForce((Vector3.up * 2 + transform.forward) * Force); horse.AddForce((Vector3.up * 2 + transform.forward) * Force);
return;
} }
} }
} }

+ 13
- 5
Assets/Scripts/HammerController.cs View File

@ -21,6 +21,7 @@ public class HammerController : MonoBehaviour
private float Speed; private float Speed;
private Vector3 startDir; private Vector3 startDir;
private Vector3 lastHitDir;
private void Start() private void Start()
{ {
@ -33,23 +34,30 @@ public class HammerController : MonoBehaviour
void FixedUpdate() void FixedUpdate()
{ {
float ratio = (Mathf.Sin(Time.time * Speed) + 1) / 2; 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; 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) private void OnTriggerStay(Collider other)
{ {
var ball = other.GetComponent<BallController>();
if (ball != null)
ball.EatHorse = false;
var horse = other.GetComponent<PlayerController>(); var horse = other.GetComponent<PlayerController>();
if (horse != null) 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"); Debug.Log("Hitting horse");
return;
} }
} }
} }

Loading…
Cancel
Save