playMaker

Author Topic: BergZergArcade's "Follow" ai script to an action.  (Read 5378 times)

Red

  • Hero Member
  • *****
  • Posts: 563
BergZergArcade's "Follow" ai script to an action.
« on: March 24, 2012, 03:20:53 PM »
So, to anyone that's followed BergZergArcade's Hack-n-Slash tutorial should be familiar with this one...

and i've tried (and failed miserably) to make this into a custom action... so, i'm officially asking for help turning this into a custom action so that i can use it.



Code: [Select]
//BergZerg Arcade helped with this one

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxDistance;

private Transform myTransform;

void Awake()
{
myTransform = transform;

}


// Use this for initialization
void Start ()
{
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxDistance = 2;
}

// Update is called once per frame
void Update ()
{
Debug.DrawLine(target.position, myTransform.position, Color.red);

//Looking at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
                                        Quaternion.LookRotation(target.position - myTransform.position),
                                        rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, myTransform.position) > maxDistance) {
//Moving to the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}

it works as a regular script but for the AI systems i've got to make, i need to control it much like you would with any Playmaker FSM... and it would be a lot simpler for what i need it for.

to note, i need this to be a "constantly on" action and the distance, speed and turning variables exposed so that i can control them with variables (or hard-coded in numbers.)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: BergZergArcade's "Follow" ai script to an action.
« Reply #1 on: March 24, 2012, 03:47:34 PM »
If you just need to manipulate some variables on the script, the Set Property action should be enough. Search for Set Property on the forums if you need an example of how to set it up...

Red

  • Hero Member
  • *****
  • Posts: 563
Re: BergZergArcade's "Follow" ai script to an action.
« Reply #2 on: March 24, 2012, 05:34:15 PM »
that doesn't do what i need it to...

is there a template or something i can use to turn this script into an action? how about a tutorial that you know of? all i need is to make that script into an action.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: BergZergArcade's "Follow" ai script to an action.
« Reply #3 on: March 28, 2012, 01:43:56 PM »
okay, so i found out through trial and error (manual seriously needs some serious improvement.)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: BergZergArcade's "Follow" ai script to an action.
« Reply #4 on: March 28, 2012, 03:01:02 PM »
Sorry, yeah the API docs need some work. Unfortunately they tend to slip in priority since we ship with hundreds of examples showing how to build actions, so normally you should be able to find an existing action as a starting point...

I'll try to add some high level pointers to the docs.

Are there particular things that you figured out that you'd like to see highlighted?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: BergZergArcade's "Follow" ai script to an action.
« Reply #5 on: March 28, 2012, 03:28:33 PM »
I started a Tips section for writing Custom Actions:
https://hutonggames.fogbugz.com/default.asp?W857

EDIT: Actually reviewing the Custom Actions section in the docs, it's better than I remembered:
https://hutonggames.fogbugz.com/default.asp?W166

I assume you looked at those docs?
Is it the process of converting an existing script that maybe needs a specific section?
« Last Edit: March 28, 2012, 03:37:59 PM by Alex Chouls »