Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: centaurianmudpig on July 30, 2015, 11:40:12 AM
-
Hello,
Trying to learn PlayMaker and figured I would do a simple Ping Pong clone. Problem is I cannot figure out how to get the ball to move 10 pixels in a random direction, as the ball is being served.
I would like to attempt this by calculating the X and Y velocity of the ball, instead of rotating the sprite and making it move forward and not using physics.
Thanks for reading.
-
how about making a helper object at the balls position, rotate the helper randomly and then add a phys force/impulse to the ball using the direction of the helper object?
-
I want to avoid using physics. I'm searching for an action that will set a Vector2 calculated from a velocity and angle, if one exists?
-
I couldn't find an Action, so I created my own. Possibly useful for others.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions {
[ActionCategory("Vector2")]
[Tooltip("Calulates the 2D position from a given angle and length.")]
public class SetDistance2D : FsmStateAction
{
[UIHint(UIHint.Variable)]
[Tooltip("Required angle (theta) in degrees")]
public FsmFloat theta;
[Tooltip("Distance to move by")]
public FsmFloat distance;
[Tooltip("Store distance as a Vector2")]
public FsmVector2 fsmStoreVector2;
public FsmFloat fsmStoreX;
public FsmFloat fsmStoreY;
public override void Reset()
{
theta = null;
distance = null;
}
public override void OnEnter()
{
float rads = theta.Value * Mathf.PI / 180;
Vector2 newVector = new Vector2(
Mathf.Cos(rads) * distance.Value,
-Mathf.Sin(rads) * distance.Value
);
if(fsmStoreVector2.UsesVariable) fsmStoreVector2.Value = newVector;
if (fsmStoreX.UsesVariable) fsmStoreX.Value = newVector.x;
if (fsmStoreY.UsesVariable) fsmStoreY.Value = newVector.y;
Finish();
}
}
}
-
Hi,
Great! You should however allow for Everyframe execution, so that it can evolve over time, if needed.
Bye,
Jean