playMaker

Author Topic: Trigger Event issues  (Read 2392 times)

Red

  • Hero Member
  • *****
  • Posts: 563
Trigger Event issues
« on: October 19, 2011, 11:56:31 AM »
Using a script (my AIFollowRange script which is based off of berg-zerg arcade's and the Tornado Twins' AI script to follow only) and with the FSM set to detect the trigger intersecting with the player doesn't seem to trigger if the enemy enters into range (the trigger) unless the player is moving... it'd work find if the player is always moving but not every player will always be moving.

the script works allright (though i'd love to make a FSM to drive it but iTween doesn't seem to do what i need it to) but the trigger issue...

basically, if teh player stands still, the trigger doesn't activate the event... if the player is moving, it will... i need to make it so that the player will trigger it even if they're moving or not.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Trigger Event issues
« Reply #1 on: October 19, 2011, 02:40:56 PM »
basically, since i think i need to clarify just a bit... is there a way that i can make a script that does what their script does (i'll add in the script as code) but as an FSM?

 
Code: [Select]
//Code denotes a minimum and maximum distance from player in which to follow
//Code denotes a distance from player in which to face them

// Figure out how to isolate the axis responsible for vertical movement
// and include an option to lock it to prevent vertical movement

//Follow Variables
var target : Transform; //the enemy's target (drag player(s) to this field.)
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning

//Range Variables
var lookDist : float = 6; //How close to player before looking in Player direction
var minProximity : float = 1; //minimum range for movement.
var maxProximity : float = 4; //maximum range for movement.
var myTransform : Transform; //current transform data of this enemy... try to set this as private and not adjustable from the inspector.

function Awake()
{
    myTransform = transform; //cache transform data for easy access/preformance
}

function Start()
{
     target = GameObject.FindWithTag("Player").transform; //target the player

}

function Update ()
{
    var dist = Vector3.Distance(target.transform.position, transform.position);
if (dist < lookDist)
{
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

if (dist > minProximity && dist < maxProximity)
{
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}


since both berg zerg and the Tornado Twins cover this kind of script in their tutorials (though i have added to it) i don't think it's really prudent to say it's mine and be tight lipped... especially if keeping the code to myself won't help resolve this.

though, if someone has an FSM or template they can share that does the same thing, i'll be very grateful

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trigger Event issues
« Reply #2 on: October 20, 2011, 01:08:50 AM »
Hi Red,

 Have you tried to port it as an action? I think it could be made as an action as it's some specific. For such very specific work, I don't think you need to go into building a fsm with several states on that.

 I'll have some time this week end to look at this if you can wait until monday:) I don't see any problem in making this as an custom action really.

 Bye,

 Jean