MoveTowards add rotation.

BDSmith

New member
So I wanted to add the "seek" action to behavioral designer, so I added the listed WithinSight and MoveTowards behaviors following the support docs. Is there anything I can add into the MoveTowards class that would rotate the agent towards a defined GameObject (In my case, player)?

So I'm looking to add a public variable that will allow me to drag and drop my player into it in the inspector (I don't want to hard code the player for obvious reasons) and then the script will add in a piece where Agent will Rotate to look at the variable, in my current case/ need, player.


Code:
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;


public class MoveTowards : Action
{
   // The speed of the object
   public float speed = 0;
   // The transform that the object is moving towards
   public SharedTransform target;


   public override TaskStatus OnUpdate()
   {
      // Return a task status of success once we've reached the target
      if (Vector3.SqrMagnitude(transform.position - target.Value.position) < 0.1f) {
         return TaskStatus.Success;
      }
      // We haven't reached the target yet so keep moving towards it
      transform.position = Vector3.MoveTowards(transform.position, target.Value.position, speed * Time.deltaTime);
      return TaskStatus.Running;
   }
}

To note, I've tried to use several of the listed rotate actions in BD but can seem to find one that will work...

So for my BD
Entry->Repeater->Squence
WithinSight-Repeater
Parallel->Play->MoveTowards

Screenshot 2020-12-05 011410.png

I'm using the play for the walking animation because it just seems easier than what I read in the Docs. Also, it works so...
I've been trying to add a rotate child to the parallel but none of those seem to work to rotate the NPC towards the Player.
 
Just used unity's transform.LookAt to accomplish this, i just need to figure out how to add in the whole field of view like the WithInSight behavior has, and really figure out how to add in a certain distance as well too.
 
Top