42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace RR.Game2D.Entities.Projectiles
|
|
{
|
|
public class PhysicsProjectile : BasicProjectile
|
|
{
|
|
//protected override void OnEnable()
|
|
//{
|
|
// remainingPierce = maxPierce;
|
|
// if (maxLifetime > 0f)
|
|
// Invoke(nameof(Despawn), maxLifetime);
|
|
//}
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
rb.bodyType = RigidbodyType2D.Dynamic;
|
|
}
|
|
|
|
public override void Launch(Vector2 direction, float speed = -1f, GameObject thrower = null)
|
|
{
|
|
this.owner = thrower;
|
|
launched = true;
|
|
|
|
Vector2 dir = direction.sqrMagnitude > 0.0001f ? direction.normalized : Vector2.right;
|
|
float finalSpeed = (speed > 0f) ? speed : initialSpeed;
|
|
|
|
rb.simulated = true;
|
|
rb.bodyType = RigidbodyType2D.Dynamic;
|
|
|
|
rb.linearVelocity = Vector2.zero;
|
|
rb.angularVelocity = 0f;
|
|
|
|
rb.AddForce(finalSpeed * rb.mass * dir, ForceMode2D.Impulse);
|
|
|
|
transform.right = dir;
|
|
|
|
if (thrower != null && ignoreOwnerTime > 0f)
|
|
StartCoroutine(IgnoreOwnerTemporarily(thrower, ignoreOwnerTime));
|
|
}
|
|
}
|
|
} |