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

Pages: [1]
1
Playmaker Help / Re: Hold key! (Get Key Down and Up doesn't work for me)
« on: September 06, 2016, 08:14:25 AM »
Hey guys, I'm trying to make a character controller with Play Maker but there is no action for "Key Holding". I know there is Get Key Down and Get Key Up but that makes my chart too complex. Is there any better way for this purpose?

I need when I Press a Key it switch to other state and after release it switch back automatically to previous state!

thanks.

I don't think there is a holding down event. You can just use Get Key Down and then in the state that goes to have a Get Key Up to go back. It would just be 2 states really.

2
Attached is a template I created to move a character towards another character. It uses Navmesh Raycast to see if it can simply move forward (using a root motion animation). If not, it will use Unity pathfinding. I call it using RunFSM  every game loop. I think I put a small wait in between calls so it can reevaluate whether to use pathfinding or not.

3
Playmaker Help / Re: Pathfinding Set Agent Destination Waypoints
« on: August 09, 2016, 04:17:05 PM »
I altered the Set Agent Destination As Game Object action to use a Finished action. I think the regular Set Agent Destination should be done this way too.

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory(ActionCategory.NavMeshAgent)]
[Tooltip("Set the destination of a NavMesh Agent to a gameObject. \nNOTE: The Game Object must have a NavMeshAgentcomponent attached.")]
public class SetAgentDestinationAsGameObjectWithEvent : FsmStateAction
{
[RequiredField]
[Tooltip("The Game Object to work with. NOTE: The Game Object must have a NavMeshAgent component attached.")]
[CheckForComponent(typeof(NavMeshAgent))]
public FsmOwnerDefault gameObject;

[RequiredField]
[Tooltip("Set the destination to navigate towards.")]
public FsmGameObject destination;

[RequiredField]
[Tooltip("Define the gameObject minimum movement distance to retrigger path computation.")]
public FsmFloat triggerThreshold;

[Tooltip("Distance from target to be considred in range.")]
public FsmFloat withinRange;

[Tooltip("Define the event called when in range of target.")]
public FsmEvent eventWhenInRange;

private NavMeshAgent _agent;

private Vector3 lastPosition;

private float lastDistance;

private float squareDistance;

GameObject _lastGo;

private void _getAgent()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

_agent =  go.GetComponent<NavMeshAgent>();
}

public override void Reset()
{
gameObject = null;
destination = null;
triggerThreshold = 1;
eventWhenInRange = null;
withinRange = 0;

}

public override void OnEnter()
{
// force refresh
_lastGo = null;

_getAgent();

DoSetDestination();

}

public override void OnUpdate()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

if (Vector3.Distance (destination.Value.transform.position, go.transform.position) <= withinRange.Value + 1 ) {
Fsm.Event(eventWhenInRange);
}

else
DoSetDestination();
}

void DoSetDestination()
{

if (destination.Value == null || _agent == null)
{
return;
}

bool forceUpdate = false;
if (_lastGo != destination.Value)
{
forceUpdate = true;
_lastGo = destination.Value;
}

if (lastDistance!= triggerThreshold.Value){
lastDistance = triggerThreshold.Value;
squareDistance = lastDistance*lastDistance;
}

Vector3 newPosition = destination.Value.transform.position;
Vector3 deltaPosition = newPosition-lastPosition;

if (deltaPosition.sqrMagnitude>squareDistance || forceUpdate)
{
_agent.SetDestination(newPosition);
_agent.stoppingDistance = withinRange.Value - 1;
lastPosition = destination.Value.transform.position;
}

}


}
}

4
Share New Actions / DoesColliderContainPoint
« on: July 15, 2016, 06:19:37 PM »
I created an action to find if a gameobject or a Vector3 point is in the bounds of a box collider. I found this pretty useful so thought I would share.

5
Action Requests / Re: DoTween Move By
« on: July 15, 2016, 12:20:02 PM »

6
Playmaker Help / Re: See if an aninmation has finished (SOLVED)
« on: July 14, 2016, 08:07:04 PM »
I got this working using the PM Animation State Synchronization Script

7
Playmaker Help / (SOLVED) See if an aninmation has finished
« on: July 14, 2016, 08:55:11 AM »
Is there an easy way to see if an animation has finished once you start it with a Set Animation Trigger action? I know I can have animation events which is great, but I wondered if there's a simple way to start an animation then find out if it has completed.

8
Share New Actions / Useful for NavMeshAgent debugging
« on: July 02, 2016, 01:07:19 AM »
I created a debugging action for tracking a character's NavMeshAgent path. It will draw a Debug line from the character to each point in the path.

If the path is white, it is complete and therefore successful, yellow is partial and red is invalid.

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Debug)]

public class PathUtils : FsmStateAction {
[RequiredField]
[Tooltip("The Game Object to work with. NOTE: The Game Object must have a NavMeshAgent component attached.")]
[CheckForComponent(typeof(NavMeshAgent))]
public FsmOwnerDefault gameObject;

private NavMeshAgent agent;

private Color color;

private void _getAgent()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

agent =  go.GetComponent<NavMeshAgent>();
}

public override void OnEnter() {
_getAgent ();
}

public override void OnUpdate()
{
DrawPath (agent.path);
}

void DrawPath(NavMeshPath path) {
if (path.corners.Length < 2)
return;
switch (path.status) {
case NavMeshPathStatus.PathComplete:
color = Color.white;
break;
case NavMeshPathStatus.PathInvalid:
color = Color.red;
break;
case NavMeshPathStatus.PathPartial:
color = Color.yellow;
break;
}

Vector3 previousCorner = path.corners[0];

int i = 1;
while (i < path.corners.Length) {
Vector3 currentCorner = path.corners[i];
Debug.DrawLine(previousCorner, currentCorner, color);
previousCorner = currentCorner;
i++;
}
}
}
}


Pages: [1]