Orbit task

Silvermurk

New member
Good day everyone. Kind of first experiance with BD tasks, so...
I made an moving target orbit script that does it`s job throu transform.position update.
But i don`t seem to find a way to turn it to BD task, but allready read manuals about that.
Also can`t think of a way to add a Falure task result (AI agent suposed to keep orbiting untill target is destroyed).
But think that there suposed to be Fail result for any task?
I fail to understand how to add the rotation part to navmesh, it works this way - but using RotateAround on Navmesh agent seems bad idea.
Would appritiate any help. Thanks in advance


For now it looks like this:
Code:
using UnityEngine;
using System.Collections;
using BehaviorDesigner.Runtime.Tasks.Movement;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;

[TaskDescription("Orbit the Y axis of target throu Navmesh.")]
[TaskCategory("Movement")]
[TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}CoverIcon.png")]
public class Orbit : NavMeshMovement
{

    public SharedGameObject target;
    public SharedFloat orbitDistance = 10.0f;
    public SharedFloat orbitDegreesPerSec = 180.0f;
    private Vector3 targetPosition;

    public override void OnStart()
    {
        base.OnStart();
        targetPosition = target.Value.transform.position;
    }

    public override TaskStatus OnUpdate()
    {
        if (!target.Value)
            return TaskStatus.Sucess;
        SetDestination(DoOrbit());
        return TaskStatus.Running;
    }

    private Vector3 DoOrbit()
    {
        // Keep us at orbitDistance from target
        //transform.position = target.Value.transform.position + (transform.position - target.Value.transform.position).normalized * orbitDistance.Value;
        transform.RotateAround(target.Value.transform.position, Vector3.up, orbitDegreesPerSec.Value * Time.deltaTime);
        return target.Value.transform.position + (transform.position - target.Value.transform.position).normalized * orbitDistance.Value;
    }
}
 
Last edited:
I'm not completely following your question but I can't see anything wrong with your task. The task will set a destination based on an orbit and will return success if there isn't a target (though should that be failure?)
 
I'm not completely following your question but I can't see anything wrong with your task. The task will set a destination based on an orbit and will return success if there isn't a target (though should that be failure?)
Looks like i need to be more exact in wording:)
I was looking for a way to implement orbit rotation throu navmesh. But failed to do so and had to use Transform.RotateAround.
So was asking maybe you, or someone else, can help me make it throu navmesh instead of transform methods.
 
Top