Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on February 09, 2012, 03:00:38 AM
-
Hi,
Following a post:
Please find a very important addition. being able to use the rotateAround function.
You can specific a gameObject to rotate around, and also specify that the axis are defined locally, ( so the gameObject will rotate around this target position AND axis).
Also, If you specific a gameObject to rotate around, the position variable will be use as an offset.
It's now also available on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) ( via snipt (https://jeanfabre.snipt.net/rotatearound-8ed6caa8/))
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Rotates Around a Game Object.")]
public class RotateAround : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[ActionSection("Rotation position")]
[Tooltip("Rotate around this GameObject.")]
public FsmGameObject aroundGameObject;
[Tooltip("Rotate around this point. If 'aroundGameObject' defined, will offset by 'rotationPoint'")]
public FsmVector3 rotationPoint;
[ActionSection("Rotation axis")]
[Tooltip("Rotate around this axis.")]
public FsmVector3 rotationAxis;
[Tooltip("If 'aroundGameObject' defined and 'useAroundGameObjectAxisSpace' TRUE, 'rotationAxis' will be defined in 'aroundGameObject' local space.")]
public FsmBool useAroundGameObjectAxisSpace;
[ActionSection("Angle")]
[Tooltip("Amount to rotate in degrees.")]
public FsmFloat angle;
[Tooltip("Rotate over one second")]
public bool perSecond;
[ActionSection(" ")]
public bool everyFrame;
public override void Reset()
{
gameObject = null;
aroundGameObject = null;
angle = null;
useAroundGameObjectAxisSpace = false;
perSecond = false;
everyFrame = true;
}
public override void OnEnter()
{
DoRotateAround();
if(!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoRotateAround();
}
void DoRotateAround()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
Vector3 _rotationPoint = rotationPoint.Value;
Vector3 _axis = rotationAxis.Value;
GameObject aroundgo = aroundGameObject.Value;
if (aroundgo!=null)
{
_rotationPoint += aroundgo.transform.position;
}
if (useAroundGameObjectAxisSpace.Value)
{
_axis = aroundgo.transform.TransformDirection(_axis);
}
float _angle = angle.Value;
if (perSecond)
{
_angle *= Time.deltaTime;
}
go.transform.RotateAround(_rotationPoint,_axis,_angle);
}
public override string ErrorCheck()
{
if (useAroundGameObjectAxisSpace.Value && aroundGameObject.Value==null)
{
return "'useAroundGameObjectAxisSpace' is only effective is 'aroundGameObject' defined";
}
return "";
}
}
}
Any suggestions or comments to improve it welcome as always.
Bye,
Jean
-
Yes! I just needed that :D thanks, very usefull for cinematic cameras
-
I'm trying to get my object to increment its rotation around another object each time a key is pressed, can't get it to work... coud someone post a screen on how to achieve this? Thanks in advance
-
Great Action Thanks :)
A small improvement whould be to have checkboxes for the axis instead of X Y Z forms.
It whould make this action more clear to understand.
Anyway great work ^^
-
Hi,
Well, doing so would constraint into orthonormal rotation, while offering the vector, means we can rotate around any direction in space.
But yes, less intuitive than check box I give you that...
Bye,
Jean
-
thank you for this! my own version of this wasn't nearly as useful :)
-
hi 4s4,
We all have to start somewhere, and I am sure this action can also be improved anyway! I hope you have learned things, and be able to apply it to new actions you will build, don't forget to share them back, this will be greatly appreciated!
Bye,
Jean
-
Lovely thx a lot Jean ;D :) :-*
Bye
-
Hi Jean and co,
I wanted to use this function and downloaded the CS script by Jean. I've dragged the file onto my project folder, then dragged this script onto a game object. However, I get the following message:
Can't add script behaviour RotateAround. The scripts file name does not match the name of the class defined in the script!
How can I go about implementing this function?
I have
- Unity 3.5.5f3
- Playmaker 1.4.3
- OSX
Thanks.
-
Hey Sinman,
I haven't used this action yet but i'm pretty sure you have to drag the script into your /PlayMaker/Actions/ folder for it to become active as an action via PlayMaker.
Once you've done that it should be accessible under the Transform action category.
Hope this helps :)
Simon
-
Hi Avrigus
Thanks for the input. The idea for looking into the action browser has totally eluded me. Works fine now. Thanks!
Sinman
-
I'm trying to use this, but I think I'm confused. Maybe I am trying to use this for the wrong thing? Here is what I'm trying to do:
World is 2D. Sun only moves on X & Y axis. Sun doesn't rotate, but moves in a circle around the core of the planet.
Is this something RotateAround does? Or should I be using another action? I'm avoiding iTween since I heard it's bad for mobile.
Thank you for any help.
-
Never mind, I found this. Didn't realize how simple it was.
http://answers.unity3d.com/questions/38932/Circular-movement.html
-
I humbly submit an enhanced version.
If you use the "every frame" mode, you can now specify, in "Stop Angle", a number of degrees after which the action will stop. If you leave zero, it will rotate around forever.
That is very useful if you want to string together a series of moves.
Beware:
1) I am an old super rusty programmer;
2) I have no experience at all for 3D stuff;
3) I have not studied how to program PlayMaker actions at all, I just "copied" what I saw in this action and tried to imitate the form and style as closely as I could.
So use with caution… For example: I suspect this would break down if the rotation speed was super fast because my check to stop the rotation is very primitive.
Maybe Jean or another seasoned programmer would want to check it. It's a very simple mod, it should take but a few seconds to validate.
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Rotates Around a Game Object.")]
public class RotateAround : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[ActionSection("Rotation position")]
[Tooltip("Rotate around this GameObject.")]
public FsmGameObject aroundGameObject;
[Tooltip("Rotate around this point. If 'aroundGameObject' defined, will offset by 'rotationPoint'")]
public FsmVector3 rotationPoint;
[ActionSection("Rotation axis")]
[Tooltip("Rotate around this axis.")]
public FsmVector3 rotationAxis;
[Tooltip("If 'aroundGameObject' defined and 'useAroundGameObjectAxisSpace' TRUE, 'rotationAxis' will be defined in 'aroundGameObject' local space.")]
public FsmBool useAroundGameObjectAxisSpace;
[ActionSection("Angle")]
[Tooltip("Amount to rotate in degrees.")]
public FsmFloat angle;
[Tooltip("Rotate over one second")]
public bool perSecond;
[ActionSection("Animation")]
public bool everyFrame;
[Tooltip("Amount to rotate in degrees before stopping animation. Zero rotates forever.")]
public FsmFloat stopAngle;
FsmFloat rotatedAngle = 0f;
public override void Reset()
{
gameObject = null;
aroundGameObject = null;
stopAngle = null;
angle = null;
rotatedAngle = 0f;
useAroundGameObjectAxisSpace = false;
perSecond = false;
everyFrame = true;
}
public override void OnEnter()
{
rotatedAngle.Value = 0;
DoRotateAround();
if(!everyFrame)
{
Finish();
}
else if (stopAngle.Value != 0f)
{
if (rotatedAngle.Value >= stopAngle.Value)
{
Finish();
}
}
}
public override void OnUpdate()
{
DoRotateAround();
if (stopAngle.Value != 0f)
{
if (rotatedAngle.Value >= stopAngle.Value)
{
Finish();
}
}
}
void DoRotateAround()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
Vector3 _rotationPoint = rotationPoint.Value;
Vector3 _axis = rotationAxis.Value;
GameObject aroundgo = aroundGameObject.Value;
if (aroundgo!=null)
{
_rotationPoint += aroundgo.transform.position;
}
if (useAroundGameObjectAxisSpace.Value)
{
_axis = aroundgo.transform.TransformDirection(_axis);
}
float _angle = angle.Value;
if (perSecond)
{
_angle *= Time.deltaTime;
}
rotatedAngle.Value += _angle;
go.transform.RotateAround(_rotationPoint,_axis,_angle);
}
public override string ErrorCheck()
{
if (useAroundGameObjectAxisSpace.Value && aroundGameObject.Value==null)
{
return "'useAroundGameObjectAxisSpace' is only effective is 'aroundGameObject' defined";
}
return "";
}
}
}
Modified: already one bug squashed...
-
Hi,
Excellent! I don't see anything wrong in the way you have implemented the angle stop check, I don't think I would have done it differently anyway!
Bye,
Jean
-
Hi,
useful action and nice feature "Stop Angle"!
I've played around with it and I think I found an issue. When you use negative values for stopAngle in order to rotate counter clockwise then it will never stop.
The line
rotatedAngle.Value += _angle;
should read
rotatedAngle.Value += Mathf.Abs(_angle);
Or is there another way to rotate counter clockwise? At least this worked for me.
Also a small question: Sometimes there's no file to download for a new shared action. Am I supposed to copy the code and create a .cs file or is there another trick? (I'm new to this forum, as you can see ;) ). Thanks.
-
Hi,
yes, copy the code snippet, create a c# file of the exact same name as the class defined in that code and paste it in there.
also, I always recommand that you create a special folder to host all your custom actions, like "PlayMaker Custom Actions", I go one more step as well, creating sub folders of the name of the category, so that all my custom actions are organized by categories in my project folder.
bye,
Jean
-
hello,
Is there a way to alter the code slightly so I can make the rotation stop when timescale is set to 0? Right now when the game is paused the rotation continues :/
tia
-
You could multiply your rotation angle by the current time scale. Use Get Time Info to get Time Scale and then Float Multiply.
-
Just by chance I have just needed to make this work in real time, thanks for the hint alex, just spent some time trying to figure this out!
-
Couldn't scripts like this be added to the Ecosystem? :)
-
Hello,
What does the Rotation Point do? Is it possible to create a rotation from which the GameObject will animate from like the Vector Rotation in the Itween Rotate action?
I am trying to get my camera to rotate around a character like a third person game. The Itween Rotate action is OK, but I wanted a bit more control over how and when the camera rotates.
Thanks,
Nog
-
Couldn't scripts like this be added to the Ecosystem? :)
Hi,
True, it's now up. Simply bump on the actions you want to see promoted to the Ecosystem, there is just too much existing actions on the forum already to go through manually :)
Bye,
Jean
-
What does the Rotation Point do? Is it possible to create a rotation from which the GameObject will animate from like the Vector Rotation in the Itween Rotate action?
Hi
Rotation point is your "center" around which you are going to turn, ( your character in your case).
Bye,
Jean
-
Hey Jean, the Script in the Ecosystem is not the updated one with the "Stop Angle" function.
The latest one can be found in this same thread here
http://hutonggames.com/playmakerforum/index.php?topic=1078.msg27003#msg27003
-
Hi,
Ok, done, redownload please.
Do you want to host it yourself? I used my snipt account, but you can create yours if you want and then you can update it.
Bye,
Jean