Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: RC on April 03, 2020, 07:20:54 PM
-
Hello, I just finish converting this scrip to Playmaker action and would like to share it with everyone. the script is from http://luminaryapps.com/blog/arcing-projectiles-in-unity/ (http://luminaryapps.com/blog/arcing-projectiles-in-unity/) and they are much appreciated!
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Custom")]
public class Projectile_to_target : FsmStateAction
{
[Tooltip("Position we want to hit")]
public FsmVector3 targetPos;
[Tooltip("Horizontal speed, in units/sec")]
public FsmFloat speed = 10;
[Tooltip("How high the arc should be, in units")]
public FsmFloat arcHeight = 1;
public FsmVector3 nextPos;
public FsmVector3 startPos;
FsmFloat archfloat = -0.25f;
[Tooltip("Repeat every frame.")]
public bool everyFrame = true;
// Code that runs on entering the state.
public override void OnEnter()
{
// Cache our start position, which is really the only thing we need
// (in addition to our current position, and the target).
startPos.Value = Fsm.GameObject.transform.position;
}
public override void OnUpdate()
{
// Compute the next position, with arc added in
FsmFloat x0 = startPos.Value.x;
FsmFloat x1 = targetPos.Value.x;
FsmFloat dist = x1.Value - x0.Value;
FsmFloat nextX = Mathf.MoveTowards(Fsm.GameObject.transform.position.x, x1.Value, speed.Value * Time.deltaTime);
FsmFloat baseY = Mathf.Lerp(startPos.Value.y, targetPos.Value.y, (nextX.Value - x0.Value) / dist.Value);
FsmFloat arc = arcHeight.Value * (nextX.Value - x0.Value) * (nextX.Value - x1.Value) / (archfloat.Value * dist.Value * dist.Value);
nextPos = new Vector3(nextX.Value, baseY.Value + arc.Value, Fsm.GameObject.transform.position.z);
// Rotate to face the next position, and then move there
Fsm.GameObject.transform.rotation = LookAt2D(nextPos.Value - Fsm.GameObject.transform.position);
Fsm.GameObject.transform.position = nextPos.Value;
}
void Arrived()
{
}
///
/// This is a 2D version of Quaternion.LookAt; it returns a quaternion
/// that makes the local +X axis point in the given forward direction.
///
/// forward direction
/// Quaternion that rotates +X to align with forward
static Quaternion LookAt2D(Vector2 forward)
{
return Quaternion.Euler(0, 0, Mathf.Atan2(forward.y, forward.x) * Mathf.Rad2Deg);
}
}
}
(http://i.imgur.com/bxbvvmV.gif)
-
Hi,
Very nice indeed! Few errors and things I'll correct before I put it on the Ecosystem, should be done this week.
Bye,
Jean
-
Hi,
Very nice indeed! Few errors and things I'll correct before I put it on the Ecosystem, should be done this week.
Bye,
Jean
thank you!
-
This is excellent rongconcrx! Thank your for sharing :D
-craigz
-
Hi,
Could you share your test scene, I had trouble making it work.
Bye,
Jean
-
Hi Jean. here is a test scene
-
I was just looking for something like this, nice work and thanks for sharing! Does this only work in 2D?
-
I was just looking for something like this, nice work and thanks for sharing! Does this only work in 2D?
thanks! yes, it's only work in for in 2d.
-
Is there anyway i can get this action?Really need it,Thanks!!!!
-
Hi.
i have something similar, try the attachment below.
it has an action and a Rigidbody2DExtensions script.
it has a range checker build in which will send an event if the target point can not be reached.
-
@djaydino.Thank a lot!!! ill try that.