Drive ability not activating

SeeSharpist

New member
Hey guys, I've been trying to create a bike based on another controller (Realistic Hover Bike Controller) while using the Drive ability to activate the bike. Although I'm not seeing any errors, I cannot for the life of me get the Drive ability to activate. No text when walking up to the vehicle and I don't ever see the ability active in the inspector. Am I correct that all you should need on the vehicle is an active script that implements IDriveSource as well as an AbilityStartLocation for the Move Toward ability? I attached my Drive ability, Ability Start location, and the bike script itself. Additionally, if I need another camera script to take over the camera (part of the HoverBike controller package) is it as easy as disabling the UCC Camera Controller? Any guidance would be much appreciated, thanks!


Code:
namespace Opsive.UltimateCharacterController.Demo.Car
{
    using Opsive.Shared.Events;
    using Opsive.Shared.Game;
    using Opsive.UltimateCharacterController.Character;
    using Opsive.UltimateCharacterController.Demo.UnityStandardAssets.Vehicles.Car;
    using Opsive.UltimateCharacterController.Objects.CharacterAssist;
    using UnityEngine;
    using Opsive.UltimateCharacterController.Camera;
    /// <summary>
    /// Provides a sample implementation of the IDriveSource.
    /// </summary>
    public class HoverBike : MonoBehaviour, IDriveSource
    {
        [Tooltip("A reference to the headlights that should turn on when the character enters the car.")]
        [SerializeField] protected GameObject[] m_Headlights;
        [Tooltip("A reference to the colliders that should be disabled when the character enters the car.")]
        [UnityEngine.Serialization.FormerlySerializedAs("m_Colliders")]
        [SerializeField] protected GameObject[] m_DisableColliders;
        [Tooltip("The location that the character drives from.")]
        [SerializeField] protected Transform m_DriverLocation;
        [Tooltip("The Hovercraft controller.")]
        [SerializeField] protected RHC_HovercraftController m_HovercraftController;
        [Tooltip("The Hovercraft third person camera script to activate/deactivate.")]
        [SerializeField] protected RHC_HovercraftCamera m_HovercraftCamera;
        [Tooltip("The UCC camera script to activate/deactivate.")]
        [SerializeField] protected CameraController m_UCCCamera;
        private static int s_OpenCloseDoorParameter = Animator.StringToHash("OpenCloseDoor");
        private GameObject m_GameObject;
        private Transform m_Transform;
        private Animator m_Animator;
        private Rigidbody m_Rigidbody;
        private Collider[] m_IgnoreColliders;
        private CarUserControl m_UserControl;
        private CarAudio m_Audio;
        private AnimatorMonitor m_CharacterAnimatorMonitor;
        private int m_HorizontalInputID;
        //private bool m_OpenedDoor;
        public GameObject GameObject { get => m_GameObject; }
        public Transform Transform { get => m_Transform; }
        public Transform DriverLocation { get => m_DriverLocation; }
        public int AnimatorID { get => 0; }
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Transform = transform;
            //m_Animator = GetComponent<Animator>();
            m_Rigidbody = GetComponent<Rigidbody>();
            m_IgnoreColliders = m_GameObject.GetComponentsInChildren<Collider>();
            //m_UserControl = GetComponent<CarUserControl>();
            //m_Audio = GetComponent<CarAudio>();
            m_HorizontalInputID = Animator.StringToHash("HorizontalInput");
            EnableDisableCar(false);
            enabled = true; //to keep the script enabled, needed for Drive ability?
        }
        /// <summary>
        /// Enables or disables the car components.
        /// </summary>
        /// <param name="enable">Should the car be enabled?</param>
        private void EnableDisableCar(bool enable)
        {
            enabled = /*m_UserControl.enabled = m_Audio.enabled =*/ enable;
            m_Rigidbody.isKinematic = !enable;
            for (int i = 0; i < m_Headlights.Length; ++i) {
                m_Headlights[i].SetActive(enable);
            }
            for (int i = 0; i < m_DisableColliders.Length; ++i) {
                m_DisableColliders[i].SetActive(!enable);
            }
            m_HovercraftController.canControl = m_HovercraftController.engineRunning = m_HovercraftCamera.enabled = enabled;
            m_UCCCamera.enabled = !enabled;
        }
        /// <summary>
        /// The character has started to enter the vehicle.
        /// </summary>
        /// <param name="character">The character that is entering the vehicle.</param>
        public void EnterVehicle(GameObject character)
        {
            //EventHandler.RegisterEvent(character, "OnAnimatorOpenCloseDoor", OpenCloseDoor);
            var characterLocomotion = character.GetCachedComponent<UltimateCharacterLocomotion>();
            for (int i = 0; i < m_IgnoreColliders.Length; ++i) {
                for (int j = 0; j < characterLocomotion.ColliderCount; ++j) {
                    Physics.IgnoreCollision(m_IgnoreColliders[i], characterLocomotion.Colliders[j], true);
                }
            }
            characterLocomotion.AddIgnoredColliders(m_IgnoreColliders);
        }
        /// <summary>
        /// Triggers the OpenCloseDoor parameter.
        /// </summary>
        /*private void OpenCloseDoor()
        {
            m_OpenedDoor = !m_OpenedDoor;
            m_Animator.SetTrigger(s_OpenCloseDoorParameter);
        }*/
        /// <summary>
        /// The character has entered the vehicle.
        /// </summary>
        /// <param name="character">The character that entered the vehicle.</param>
        public void EnteredVehicle(GameObject character)
        {
            m_CharacterAnimatorMonitor = character.GetCachedComponent<AnimatorMonitor>();
            EnableDisableCar(true);
        }
        /// <summary>
        /// Updates the animator.
        /// </summary>
        public void Update()
        {
            //m_Animator.SetFloat(m_HorizontalInputID, m_CharacterAnimatorMonitor.AbilityFloatData, 0, 0);
        }
        /// <summary>
        /// The character has started to exit the vehicle.
        /// </summary>
        /// <param name="character">The character that is exiting the vehicle.</param>
        public void ExitVehicle(GameObject character)
        {
            EnableDisableCar(false);
        }
        /// <summary>
        /// The character has exited the vehicle.
        /// </summary>
        /// <param name="character">The character that exited the vehicle.</param>
        public void ExitedVehicle(GameObject character)
        {
            //EventHandler.UnregisterEvent(character, "OnAnimatorOpenCloseDoor", OpenCloseDoor);
            var characterLocomotion = character.GetCachedComponent<UltimateCharacterLocomotion>();
            characterLocomotion.RemoveIgnoredColliders(m_IgnoreColliders);
            for (int i = 0; i < m_IgnoreColliders.Length; ++i) {
                for (int j = 0; j < characterLocomotion.ColliderCount; ++j) {
                    Physics.IgnoreCollision(m_IgnoreColliders[i], characterLocomotion.Colliders[j], false);
                }
            }
            //if (m_OpenedDoor) {
            //    OpenCloseDoor();
           // }
        }
    }
}
 

Attachments

  • DriveAbility.JPG
    DriveAbility.JPG
    65.7 KB · Views: 3
  • HoverBikeAbilityStartLocation.JPG
    HoverBikeAbilityStartLocation.JPG
    39.6 KB · Views: 3
It's tough to say without using the debugger but does Drive.CanStartAbility return true? I would start debugging there - if CanStartAbility returns false then you can step into that function to determine why it is returning false.
 
Thanks for responding. Looks like the the base CSA is returning true, but it was the ground check failing it, my object was a fraction above the ground so the start location was being skipped over :/ Thanks for pointing me in the right direction!
 
Top