I am trying to make this substitute action for playmaker. It is meant to get the collider of the owner and grab anything that touches the collider and send it flying away.
using UnityEngine;
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics2D)]
[Tooltip("A 2D explosion.")]
public class Explosion2D : FsmStateAction
{
public FsmOwnerDefault gameObject;
public FsmFloat explosion_delay;
public FsmFloat explosion_rate;
public FsmFloat explosion_max_size;
public FsmFloat explosion_speed;
public FsmFloat current_radius;
private PlayMakerUnity2DProxy _proxy;
bool exploded = false;
Collider2D explosion_radius;
public override void Reset()
{
gameObject = null;
explosion_delay = 5f;
explosion_rate = 1f;
explosion_max_size = 15f;
explosion_speed = 3f;
current_radius = 0f;
}
// Use this for initialization
public override void OnEnter () {
explosion_radius = Owner.GetComponent<Collider2D>();
}
public override void OnUpdate()
{
explosion_delay.Value -= Time.deltaTime;
if (explosion_delay.Value < 0)
{
exploded = true;
}
}
// Update is called once per frame
public override void OnFixedUpdate()
{
if (exploded == true)
{
if (current_radius.Value < explosion_max_size.Value)
{
current_radius.Value += explosion_rate.Value;
}
else
{
}
//explosion_radius.radius = current_radius.Value;
}
}
public void OnTriggerEnter2D(Collider2D wel)
{
if (exploded == true)
{
if (wel.gameObject.GetComponent<Rigidbody2D>() != null)
{
Vector2 target = wel.gameObject.transform.position;
Vector2 bomb = Owner.transform.position;
Vector2 direction = 140f * (target - bomb);
wel.gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(direction.x * 10f, direction.y * 10f));
}
}
}
}
}
I am not sure why it is not grabbing the collider of the owner or of those that are hitting it. What am I missing here?