Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - MaDDoX

Pages: [1] 2 3 ... 10
Share New Actions / Smooth Look At 2D (bugfix)
« on: January 24, 2016, 01:48:37 PM »
"Finish Event" wasn't working properly, the angle was always returning zero due to the way Vector3.Angle operates. It was pretty frustrating since the whole point of a 'smooth look at' is to transition smoothly (duh) and fire up an event once it's finished. I did a very minor fix so it just calculates the absolute z offset between angles to assert if it's "done" or not. Here it goes, just copy and paste it over the SmoothLookAt2D.cs content:

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.
//--- __ECO__ __ACTION__ ---//

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
[Tooltip("Smoothly Rotates a 2d Game Object so its right vector points at a Target. The target can be defined as a 2d Game Object or a 2d/3d world Position. If you specify both, then the position will be used as a local offset from the object's position.")]
public class SmoothLookAt2d : FsmStateAction
[Tooltip("The GameObject to rotate to face a target.")]
public FsmOwnerDefault gameObject;

[Tooltip("A target GameObject.")]
public FsmGameObject targetObject;

[Tooltip("A target position. If a Target Object is defined, this is used as a local offset.")]
public FsmVector2 targetPosition2d;

[Tooltip("A target position. If a Target Object is defined, this is used as a local offset.")]
public FsmVector3 targetPosition;

[Tooltip("Set the GameObject starting offset. In degrees. 0 if your object is facing right, 180 if facing left etc...")]
public FsmFloat rotationOffset;

[Tooltip("How fast the look at moves.")]
public FsmFloat speed;

[Tooltip("Draw a line in the Scene View to the look at position.")]
public FsmBool debug;

[Tooltip("If the angle to the target is less than this, send the Finish Event below. Measured in degrees.")]
public FsmFloat finishTolerance;

[Tooltip("Event to send if the angle to target is less than the Finish Tolerance.")]
public FsmEvent finishEvent;

private GameObject previousGo; // track game object so we can re-initialize when it changes.
private Quaternion lastRotation;
private Quaternion desiredRotation;

public override void Reset()
gameObject = null;
targetObject = null;
targetPosition2d = new FsmVector2 { UseVariable = true};
targetPosition = new FsmVector3 { UseVariable = true};
rotationOffset = 0;
debug = false;
speed = 5;
finishTolerance = 1;
finishEvent = null;

public override void OnEnter()
previousGo = null;

public override void OnLateUpdate()

void DoSmoothLookAt()
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)

var goTarget = targetObject.Value;

// re-initialize if game object has changed

if (previousGo != go)
lastRotation = go.transform.rotation;
desiredRotation = lastRotation;
previousGo = go;

// desired look at position

Vector3 lookAtPos = new Vector3(targetPosition2d.Value.x,targetPosition2d.Value.y,0f);
if (!targetPosition.IsNone)
lookAtPos += targetPosition.Value;

if (goTarget != null)
lookAtPos = goTarget.transform.position;
Vector3 _offset =;

if (!targetPosition.IsNone)
_offset +=targetPosition.Value;
if (!targetPosition2d.IsNone)
_offset.x = _offset.x+ targetPosition2d.Value.x;
_offset.y = _offset.y+ targetPosition2d.Value.y;

if (!targetPosition2d.IsNone || !targetPosition.IsNone)
lookAtPos += goTarget.transform.TransformPoint(targetPosition2d.Value);

Vector3 diff = lookAtPos - go.transform.position;

float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
desiredRotation = Quaternion.Euler(0f, 0f, rot_z - rotationOffset.Value);

lastRotation = Quaternion.Slerp(lastRotation, desiredRotation, speed.Value * Time.deltaTime);
go.transform.rotation = lastRotation;

// debug line to target

if (debug.Value)
Debug.DrawLine(go.transform.position, lookAtPos, Color.grey);

// send finish event?

if (finishEvent != null)
//var targetDir = lookAtPos - go.transform.position;
//var angle = Vector3.Angle(targetDir, go.transform.right) - rotationOffset.Value;

var angle = Mathf.Abs(go.transform.rotation.eulerAngles.z - desiredRotation.eulerAngles.z);

if (Mathf.Abs(angle) <= finishTolerance.Value)


Share New Actions / Re: Set Visibility
« on: January 10, 2015, 12:21:24 PM »
I do not see the recursive option.  Am I missing something?
Yup, you're missing the new version :) The stock version is the older one, simply edit SetVisibility.cs (with MonoDevelop, Notepad or whatever text editor you use) and overwrite the text with what's in the first topic code block.

Maybe Alex or Jean would be kind enough to update the official version?

PS.: I've just tested it and it works perfectly, even with the new 4.6 UI Sprite Renderers. It's lovely to realize you wrote code years ago which stood the test of time ;)

Share New Actions / Re: Mecanim Animator Fsm State synchronization
« on: December 11, 2014, 12:54:04 AM »
This is absolutely terrific, congratulations Jean! :)

Outstanding and much needed, also nicely priced. I've just tweeted about it :)

I found this action to be quite useful, so I'm sharing it with you guys. I've originally developed it for my Ludum Dare #24 entry, I guess I've mentioned it here in the forums, but it was quite buggy so I've decided to postpone its release until it was solid. It took me surprisingly long to found out what was the problem, but the fact that it doesn't use a proper "counter" (for simplicity's sake) made me have to work out some unusual logic to run it the right amount of times. After some tests it seems quite solid, please inform me if you find any problems.

The follow screenshot shows an usage example, hopefully it's self-explanatory enough. Tell me if it isn't :)

PS.: Part of the code is based off of 'Get Next Child'.

PlayMaker Help / Re: Find FSM that uses an action
« on: November 22, 2011, 07:44:02 AM »
Not yet, but really want to get this into the next update...
That'd come quite handy in fact!

PlayMaker Help / Re: Changing speed of "Animate Float" action
« on: November 17, 2011, 04:33:29 PM »
Interesting question. First answer that pops into my mind is "don't use anim curves", ie. build your animation behavior in a separate fsm, having the wait duration between state updates controlled by a (possibly global) variable.

Thinking about it further though, these anim curves should definitely get a "multiplier" public variable to affect their speed. I haven't checked the code but it doesn't seem like anything tough to implement, and yet it'd be extremely useful to customize gameplay and animated feedback. Maybe make it a feature request?

Share New Actions / Re: Constrain
« on: November 17, 2011, 01:34:22 AM »
I've tried with a cartoon character and just one walk animation and it completely failed - during the step's leg stretch the pelvis comes all the way down to the ground, no idea how to limit it to some minimum height. In another character with more conventional animations (and a good number of them) it did work okay, but only after starting with the character laying down :) No idea what's the problem with his code, it's too deep-math and tricky to wrap my mind around it. Anyways, the final animation result is kinda "jelly", if you get what I mean, and it's probably not performant enough for mobile game development, so I didn't spend more time on it (then the lot I had already wasted). If anyone asks me I'll simply recommend to stay away from it with a 10-foot pole. Or longer.

PS.: I could send you the cartoon character scene if you're curious, the result is fricking ugly.

Share New Actions / Re: ArrayMaker is now available
« on: November 17, 2011, 01:27:47 AM »
Well, what can I say, you just blew my socks off. Ingenious, generous and super-handy, congratulations and many thanks Jean :)

Share New Actions / Re: Trigger Broadcast Event
« on: November 17, 2011, 01:22:06 AM »
This is exactly what I need, but where is the code?
It's attached to the first post. Can't you see it? :o

Share New Actions / Re: Using playMaker and FingerGestures
« on: November 17, 2011, 01:16:29 AM »
Very nice Vonchor, I'll check it out as soon as I get some.. time.. hmm.. when will that ever happen? :o RageTools development is really chewing up my time like crazy! But I might get an excuse to try this as I build the RageText web demo ;)

Share New Actions / Re: Constrain
« on: October 26, 2011, 02:23:59 AM »
In fact this is quite sexy already, even if limited to two parts. Thanks for the link - and congratz on it too, since Dogzer mentions you gave him a nice helping hand.

BTW, I've had lots of pain with Unity's Locomotion package in the past, have you ever tried - and managed to make it work - with a custom character?

Share New Actions / Re: Constrain
« on: October 21, 2011, 09:21:27 PM »
How much limbs and degrees of freedom for your IK action?
2D IK with a pole vector is the best option imo. I've seen some guys getting huge progresses on that, I didn't have the chance to check it closer though. If you can do it it'd be awesome Jean ;)

User Showcase / Re: Quick Game Prototype
« on: October 21, 2011, 09:17:14 PM »
Cool design and art, gratz :)

Thanks for the kind words everyone, me and my mates have been working hard to make it ever better, can't wait to show you what we've been cooking up for the next release :)

Rage Tools looks awesome!! If i can figure out how it will help me i think i will purchase for sure.
Then let me try to help you :D heh

I am looking for a solution to create some Logo transition animation.. Like when you see a logo break up into blocks or squares and flies around and then disappears or comes in like that.. Like Card Flip in Adobe Illustrator or the TrapCode particle effects you see.. like a logo or picture blowing away into sand.. I can picture a grid of rectangles with a single image mapped onto them and then using particle type controllers to move them around.. Not sure if Rage Tools fits into that at all?
For such an animation you don't even need the forthcoming "RageTools Pro" version, standard RageTools will do just fine! You'd simply slice your art (in your vector editor*) in as many pieces as you want, then import it to Unity using SVG-In. After that you'd toggle on the physics options** on the RageGroup component to automatically create the rigidbodys and colliders for all your parts. After that it'd be a simple case of applying PlayMaker physics/explosion action to the center of the object. Add a ground plane, etc, for nice bounces and you'll be all set :) When/If I get some free time I'll cook up a video showcasing it, it'd be a good display of RageTools potential *and* ultra-fun to make :D

*Illustrator or Inkscape directly supported yet most others which export to SVG will work too
**The RageGroup physics options are already in beta, will be available in the public Asset Store version next week

Pages: [1] 2 3 ... 10