playMaker

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 - jeanfabre

Pages: 1 ... 814 815 [816] 817 818 ... 863
12226
Share New Actions / Drag RigidBody
« on: March 27, 2012, 08:19:54 AM »
Finally :)

 yes, finally, you can drag rigidBodies arounds with a single action, not complicated or manual setup :)

 I made it so that you can drag from a given fictive plane defined by a gameObject Up axis. This is very convenient if you want to drag objects on the ground instead of from the camera point of view.

 It of course against the moto of actions I feel, because it lacks of flexibility and it has too much responsability and not real implementation of how fsm should work, but there you go, it's a start :). For example it would be good to set up a mask variable to only allow for certain objects to be dragged. but that would be already for real scenarios. in that case, don't hesitate to come back to me for mods and more granular dragging properties.

usage: create a fsm, and on the start state, simply have this action. Play the scene and you'll be dragging any rigidbodies ( not set to kinematics of course).



Code: [Select]
// (c) copyright Hutong Games, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Drag a Rigid body with the mouse. If draggingPlaneTransform is defined, it will use the UP axis of this gameObject as the dragging plane normal \n" +
"That is select the ground Plane, if you want to drag object on the ground instead of from the camera point of view.")]
public class DragRigidBody : FsmStateAction
{

[Tooltip("the springness of the drag")]
public FsmFloat spring;

[Tooltip("the damping of the drag")]
public FsmFloat  damper;

[Tooltip("the drag during dragging")]
public FsmFloat drag;

[Tooltip("the angular drag during dragging")]
public FsmFloat angularDrag;

[Tooltip("The Max Distance between the dragging target and the RigidBody being dragged")]
public FsmFloat distance;

[Tooltip("If TRUE, dragging will have close to no effect on the Rigidbody rotation ( except if it hits other bodies as you drag it)")]
public FsmBool attachToCenterOfMass;

[Tooltip("If Defined. Use this transform Up axis as the dragging plane normal. Typically, set it to the ground plane if you want to drag objects around on the floor..")]
public FsmOwnerDefault draggingPlaneTransform;


private SpringJoint springJoint;

private bool isDragging;

private float oldDrag;
private float oldAngularDrag;

private Camera _cam;

private GameObject _goPlane;

private Vector3 _dragStartPos;

private float dragDistance;

public override void Reset()
{
spring = 50f;
damper = 5f;
drag = 10f;
angularDrag = 5f;
distance = 0.2f;
attachToCenterOfMass = false;
draggingPlaneTransform = null;

}

public override void OnEnter()
{
_cam = Camera.main;
_goPlane = Fsm.GetOwnerDefaultTarget(draggingPlaneTransform);


}
public override void OnUpdate()
{

if (!isDragging && Input.GetMouseButtonDown (0))
{


// We need to actually hit an object
RaycastHit hit;
if (!Physics.Raycast(_cam.ScreenPointToRay(Input.mousePosition), out hit, 100))
{
return;
}

// We need to hit a rigidbody that is not kinematic
if (!hit.rigidbody || hit.rigidbody.isKinematic)
{
return;
}

StartDragging(hit);

}

if (isDragging)
{
Drag();
}


}

private void StartDragging(RaycastHit hit)
{
isDragging = true;

if (!springJoint)
{
GameObject go = new GameObject("__Rigidbody dragger__");
Rigidbody body = go.AddComponent<Rigidbody>();
springJoint = go.AddComponent<SpringJoint>();
body.isKinematic = true;
}

springJoint.transform.position = hit.point;
if (attachToCenterOfMass.Value)
{
Vector3 anchor = _cam.transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
anchor = springJoint.transform.InverseTransformPoint(anchor);
springJoint.anchor = anchor;
}
else
{
springJoint.anchor = Vector3.zero;
}

_dragStartPos = hit.point;


springJoint.spring = spring.Value;
springJoint.damper = damper.Value;
springJoint.maxDistance = distance.Value;
springJoint.connectedBody = hit.rigidbody;

oldDrag = springJoint.connectedBody.drag;
oldAngularDrag = springJoint.connectedBody.angularDrag;

springJoint.connectedBody.drag = drag.Value;
springJoint.connectedBody.angularDrag = angularDrag.Value;

dragDistance = hit.distance;

}

private void Drag()
{

if (!Input.GetMouseButton (0))
{
StopDragging();
return;
}

Ray ray = _cam.ScreenPointToRay (Input.mousePosition);
if (_goPlane!=null)
{
Plane _plane = new Plane(_goPlane.transform.up,_dragStartPos);
float enter;

if (_plane.Raycast(ray,out enter))
{
springJoint.transform.position =ray.GetPoint(enter);
}

}else{

springJoint.transform.position = ray.GetPoint(dragDistance);
}



}

private void StopDragging()
{
isDragging = false;
if (springJoint==null)
{
return;
}
if (springJoint.connectedBody)
{
springJoint.connectedBody.drag = oldDrag;
springJoint.connectedBody.angularDrag = oldAngularDrag;
springJoint.connectedBody = null;
}
}

public override void OnExit()
{
StopDragging();
}
}
}


 Bye,

 Jean

12227
Hi,

 to answer one of your question out of the blue ( I am currently looking up the rest of your questions).

 you can't blend animations made with sprites. by that I mean, the animation will have to stop in order to show a different image, this is not "animations" like in 3d where you can blend bones transform.

 So, really wait for the animation to end or just display the new animation. OR create in between animations to "transit" from one animation to the other.

 Does that make sense?

 Bye,

 Jean

12228
Playmaker Help / Re: Triggering an animation on the sprite falling
« on: March 27, 2012, 01:07:05 AM »
Hi,

I wrote a custom action to get the speed of a gameObject, that would come handy in your situation.

http://hutonggames.com/playmakerforum/index.php?topic=1182.0
 
 Coupled with checking if the player is grounded, I think you would have enough to detect when to trigger fallling and landing animations.

Do you have a problem of understanding how to plug the various actions to trigger an animation or do you have problems finding the logic of how actually you would go about this ( even if it wasn't in playmaker).

 Bye,

 Jean

12229
Hi,

 I tested here ( tho without your asset, I am not sure how to load a .asset file, how did you get that asset?, make a package instead, tho for license reason, you are not allowed to distribute EZGUi scripts... so)


 I have created a Fsm Object variable, set it to type "UIPanel", then select an GameObject with a UiPanel
and there is only one property "index" as int. And it seems to work.

 So, what property of the uiPanel are you exactly looking for?

 Maybe you are missing a procedure, for example, using get property action on a gameObject will nto show the various component s( tho it could be nice Alex :) ) so you have to make a FsmObject variable first and set it up to the object type you want, then you'll have access to all these properties to store values from.

 Bye,

 Jean

12230
Playmaker Help / Re: Pathfinding Set Agent Destination Waypoints
« on: March 26, 2012, 10:51:29 PM »
uhm...

I think it might be due to the fact that the agent doesn't have yet a path assigned and therefore the remaining distance doesn't make sense until it has computed its path.

try to check first with GetAgentPathPending action or GetAgentPathStatus action. These two actions will inform you about the state of the path for that agent, and then decide if you check for the remaining distance or not.

 Bye,

 Jean

12231
Playmaker Help / Re: Drag Rigidbody
« on: March 26, 2012, 10:47:47 PM »
Hi,

 I have a pending post on the same topic, that I meant to make a sample for it.

Unity has a script for this in the standard asset DragRigidbody.js And I need to port this into playmaker.

Basically you attach a spring to your gameObject, and you control the other end of the srping with your mouse position.

This becomes a very popular request on this forum, so will post on the wiki a sample made in playmaker.

Say tune :) ( sorry some hard core deadline in the way :) )

Bye,

 Jean

12232
iOS Help / Re: How "expensive" is Sample Curve
« on: March 26, 2012, 10:20:59 PM »
Hi,

 The most expensive things in real time engines are rendering the meshes ( texture, materials, etc etc). Physics also can be a killer. So don't worry too much about using animation curve, Script in general is rarely not the bottle neck of an application.

Having said that, there are few known things to be avoided with scripting:

-- don't find gameObjects in the game loop. The game loop is code that is performed every frame or more than one time per frame. Finding gameObject takes time, so cache or reference your gameObjects in variable and use the variable.

-- adding components and removing components also can create hickups.

Most experienced developer on their talk tell us that optimization should be done after you have your game working. So make your game, make it work, then see how it performs, you can always improve then. This is better then trying to find the optimal way of doing something that you don't even know the full implication in your game... a mistake I did many times... the code ended up in the bin ( but it was very efficient.... conclusion: waisted my time...)

Also, Unity has a profiler window where you can really see where is the cost of things. So run your game with the profiler on, and you'll see where you stand between mesh, physics and scripts.

Bye,

 Jean

12233
Playmaker Help / Re: Best top scores
« on: March 26, 2012, 10:11:10 PM »
Hi,

 Don't hesitate to share what you have if you can :)

Bye,

 Jean

12234
Playmaker Help / Re: 2DToolKit Actions Documentation
« on: March 26, 2012, 01:43:57 AM »
Hi,

 I am glad it worked. I am not sure what went wrong in the first attempt, hopefully this was just a miss.

 Documentation: yes, I agree, hopefully a second pass on this will allow us to work out a comprehensive help and a set of samples.

Meanwhile, do not hesitate to ask question on forum and share your findings! :)

 Bye,

 Jean

12235
Playmaker Help / Re: Pathfinding Set Agent Destination Waypoints
« on: March 23, 2012, 05:12:33 AM »
Hi,

 This is exactly where pathfinding frameworks fails to deliver a suitable api... so...

 The way to go about it would be set up a trigger around the destination, so that when an agent trigger that volume, you know he's close enough and you can then set him to the next destination.

 that would be the more sensible and 100% reliable system. Now it could be problematic if several agents are trying to access the same way point, but that would be already something to adress specifically for your needs.

I am not sure I can propose another solution that would be as reliable.

 Don't hesitate to report back this via the unity bug reporting, I did, the more they hear about this, the better, they might address it properly in a future update.

 bye,

 Jean

12236
Playmaker Help / Re: Prefab variables (I searched, I swear) [SOLVED]
« on: March 23, 2012, 12:40:12 AM »
Hi,

 no, I just dragged the prefab onto the scene, then edit the variables directly, and it worked.

If you edit the prefab, Fsm editor will warn you with an overlay tho.

when I select an instance from the scene, it does properly select the fsm of that instance, not the prefab. Odd.

Bye,

 Jean

12237
Playmaker Help / Re: Set Property color, Playmaker 1.3.2
« on: March 22, 2012, 10:24:25 PM »
Hi,

Have you tried using the Set Material Color action instead: https://hutonggames.fogbugz.com/default.asp?W380

set property action is for "object" variables only for now.

If you are not confortable with the general concept of playmaker, let me know, and I'll detail a lot more with a step by step instruction.

 Bye,

 Jean

12238
Good question! I just got the free android plugins and was wondering the same basically :) don't want to buy a device and find it's not supported...

12239
Playmaker Help / Re: Prefab variables (I searched, I swear)
« on: March 22, 2012, 10:16:12 PM »
Hi

Yes, I think you might have a problem on your end. I tested here to make sure, and it is indeed working.

 I created a prefab with a fsm variable, made that gameObject as a prefab, instantiated several, and changed that variable value on each of the instantiated prefabs and they do behave as expected.

 note: be careful with the unity set of buttons for prefabs ( Select | revert | apply), playmaker has his own menu for this ins the editor ( next the lock button of the fsm view ). For example if you want to revert, you'll see in the fsm editor "PRefab instance (modified)", click on it and select "revert to prefab", if you click on the unity button "revert" in the inspector it will not work very well...

Make sure you have the latest version from the app store as well.


Bye,

 Jean

12240
Action Requests / Re: RayCastAll
« on: March 22, 2012, 01:34:15 PM »

Pages: 1 ... 814 815 [816] 817 818 ... 863