Playmaker Forum
PlayMaker Feedback => Action Requests => Topic started by: Phillament on December 18, 2013, 04:38:07 AM
-
Hi,
I've been trying to use the current Look At actions and nothing works for me, since I'm using Unity 2D. I was told that forward in Unity is in the Z axis, for whatever reason, and so this really clashes with the Unity 2D set-up. I think Playmaker needs an update for a 2D version of the Look At (and related) actions, just to maximize it's value and usability. I hope this isn't too much to ask.
-
Hi,
that's a good point, as did not think of them actions when I ported unity 2d, I think it makes a lot of sense to have these specific actions reworked for unity 2d.
bye,
Jean
-
Hi,
that's a good point, as did not think of them actions when I ported unity 2d, I think it makes a lot of sense to have these specific actions reworked for unity 2d.
bye,
Jean
Cool, I'm glad you agree! This would make my project a looot better, hahah. I hope it's not too tough to do. When do you think this updated could be in?
Thanks!
-
hi,
simply bump this thread early january if you don't hear from me before.
bye,
jean
-
All right, will do! Thanks, Jean!
-
After much experimentation I modified the LookAt action using the following code which seems to work quite well.
Vector3 lookAtPos;
if (goTarget != null)
{
lookAtPos = goTarget.transform.position;
}
else
{
lookAtPos = targetPosition.Value;
}
lookAtPos.z = go.transform.position.z;
go.transform.up = (lookAtPos - go.transform.position);
-
Cool, how would I go about using this with PlayMaker actions? Do I just go into the related c# script and add those lines of code? I don't want to accidentally break the current action, for when I do need the 3D Look At functionality. Again, thanks for bothering!
-
Hi,
It's always best to make a new action with a unique name, editing existing official action is very dangerous cause the next time you will update playmaker, your changes will be overwritten and your project will bug.
So I would duplicate the look at action, rename it's file and class to 2dLookAt or something and apply the changes described here.
bye,
Jean
-
So I'm trying to integrate this code into a duplicate of the Look At behaviour, but I have no idea what I'm doing. Where exactly am I to place this code? I don't know where it fits in the original action. This is what I've got so far:
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Rotates a Game Object so its forward vector points at a Target. The Target can be specified as a GameObject or a world Position. If you specify both, then Position specifies a local offset from the target object's Position.")]
public class LookAt2D : FsmStateAction
{
[RequiredField]
[Tooltip("The GameObject to rotate.")]
public FsmOwnerDefault gameObject;
[Tooltip("The GameObject to Look At.")]
public FsmGameObject targetObject;
[Tooltip("World position to look at, or local offset from Target Object if specified.")]
public FsmVector3 targetPosition;
[Tooltip("Rotate the GameObject to point its up direction vector in the direction hinted at by the Up Vector. See Unity Look At docs for more details.")]
public FsmVector3 upVector;
[Tooltip("Don't rotate vertically.")]
public FsmBool keepVertical;
[Title("Draw Debug Line")]
[Tooltip("Draw a debug line from the GameObject to the Target.")]
public FsmBool debug;
[Tooltip("Color to use for the debug line.")]
public FsmColor debugLineColor;
[Tooltip("Repeat every frame.")]
public bool everyFrame = true;
private GameObject go;
private GameObject goTarget;
private Vector3 lookAtPos;
if (goTarget != null)
{
lookAtPos = goTarget.transform.position;
}
else
{
lookAtPos = targetPosition.Value;
}
lookAtPos.z = go.transform.position.z;
go.transform.up = (lookAtPos - go.transform.position);
private Vector3 lookAtPosWithVertical;
public override void Reset()
{
gameObject = null;
targetObject = null;
targetPosition = new FsmVector3 { UseVariable = true};
upVector = new FsmVector3 { UseVariable = true};
keepVertical = true;
debug = false;
debugLineColor = Color.yellow;
everyFrame = true;
}
public override void OnEnter()
{
DoLookAt();
if (!everyFrame)
{
Finish();
}
}
public override void OnLateUpdate()
{
DoLookAt();
}
void DoLookAt()
{
if (!UpdateLookAtPosition())
{
return;
}
go.transform.LookAt(lookAtPos, upVector.IsNone ? Vector3.up : upVector.Value);
if (debug.Value)
{
Debug.DrawLine(go.transform.position, lookAtPos, debugLineColor.Value);
}
}
public bool UpdateLookAtPosition()
{
go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return false;
}
goTarget = targetObject.Value;
if (goTarget == null && targetPosition.IsNone)
{
return false;
}
if (goTarget != null)
{
lookAtPos = !targetPosition.IsNone ? goTarget.transform.TransformPoint(targetPosition.Value) : goTarget.transform.position;
}
else
{
lookAtPos = targetPosition.Value;
}
lookAtPosWithVertical = lookAtPos;
if (keepVertical.Value)
{
lookAtPos.y = go.transform.position.y;
}
return true;
}
public Vector3 GetLookAtPosition()
{
return lookAtPos;
}
public Vector3 GetLookAtPositionWithVertical()
{
return lookAtPosWithVertical;
}
}
}
-
Hi,
I have added this as a trello task:
https://trello.com/c/jLaS9RvH/42-unity-2d-look-at-and-related-actions-rework
Don't forget to vote for this task ( using the vote button), It will help prioritize things.
bye,
Jean
-
Awesome! Just voted for it! Thank you!
-
Hi,
How's the progress on this update going?
-
Hi,
It's still pending, hopefully, I will be able to put more time on clearing the tasks prior this one and get down to this.
bye,
Jean