Working on a very simple piloting ability

Hi all,

I have been working on this piloting ability, which will allow my character to pilot generic crafts.

I just want to start simple and have my character jump in front of the pilot spot, and be able to steer it. Here's what I have so far.

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character;

[DefaultAllowPositionalInput(false)]
[DefaultAllowRotationalInput(false)]

public class Pilot : DetectObjectAbilityBase
{
    [Tooltip("A reference to the Ultimate Character Controller character.")]
    [SerializeField] private GameObject m_Character;
    [SerializeField] private Transform pilotSpot;
    //Vessel control variables.
    private float steerage;
    private float steerageRatio=1f;


    protected override void AbilityStarted()
    {
        base.AbilityStarted();
        m_Character.transform.parent = pilotSpot;
        //m_Character.transform.parent = pilotSpot;
        SetToPilotSpot();

        Debug.Log("Starting to pilot.");
    }

    private void SetToPilotSpot()
    {
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        if (characterLocomotion != null)
        {
            characterLocomotion.SetPositionAndRotation(pilotSpot.position, pilotSpot.transform.rotation);
        }
    }

    public override void Update()
    {
        base.Update();
        //Take input from the steering wheel.
        steerage = Input.GetAxis("Horizontal");

        Debug.Log(steerage*steerageRatio);
    }

    protected override void AbilityStopped(bool force)
    {
        base.AbilityStopped(force);

       Debug.Log("Piloting finished.");
    }

    /// <summary>
    /// The character has exited a trigger.
    /// </summary>
    /// <param name="other">The trigger collider that the character exited.</param>
    public override void OnTriggerExit(Collider other)
    {
        // The detected object will be set when the ability starts and contains a reference to the object that allowed the ability to start.
        if (other.gameObject == m_DetectedObject)
        {
            StopAbility();
        }

        base.OnTriggerExit(other);
    }
}

It isn't working, but I can't determine why.
The messages just come one after the other Piloting startedand then Piloting finished

I'm sure I've overlooked something silly here, but any ideas of what it is, would be very much appreciated.

Thanks!
 
Excellent question. I neglected that detail.:unsure:


I'll answer that with a short video:


The time between start and stop is so short that the ability never seems to visibly say it's active, but the character does snap to the pilotPost transform perfectly so it must run.

1580109622686.png
 
Last edited:
I would start by adding the AbilityStopped method to the ability and then placing a breakpoint within that method. The stack trace should then indicate why the ability stopped. If you have a stop type of manual you'll need to manually stop the ability with the StopAbility function.
 
That is fantastically useful to know, and I will use that technique in the future for certain. Thank you!
As it is, I got a suggestion that adding the third overload/parameter for SetPositionAndRotation may fix the problem, and It did. So now I am moving forward again!

Thanks so much Justin, for this awesome asset.
 
Top