playMaker

Author Topic: 2D Physics Explosion substitute (SOLVED)  (Read 1973 times)

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
2D Physics Explosion substitute (SOLVED)
« on: July 30, 2015, 05:06:24 PM »
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.

Code: [Select]
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?
« Last Edit: August 03, 2015, 06:28:21 PM by sebaslive »
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: 2D Physics Explosion substitute (coding help)
« Reply #1 on: August 03, 2015, 10:32:44 AM »
Bumpity
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: 2D Physics Explosion substitute (coding help)
« Reply #2 on: August 03, 2015, 06:15:06 PM »
Figured it out. I will share shortly when I get it to also include collision layers.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: 2D Physics Explosion substitute (SOLVED)
« Reply #3 on: August 03, 2015, 08:52:45 PM »
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez