Sit down ability, triggered only once ...

discofever

New member
So i've been trying to make a new ability where :

1. Player teleports to sit down location
2. Sit down animation plays
3. State 'Sit' enables (limiting view + rotation)
4. When long pressing the Interact button stands up


First time it works just fine; after player stands up but then followin times it exits the state immediately.

Since i want the player to 'Teleport' to location I think i want to use an Interactable where i move the user and thus requiring this 'Interactable' ability first.


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

public class Sit : DetectObjectAbilityBase
{}

Ability Inspector
1702110789263.png

The Interactable Sofa

1702111046812.png

Interactable Couch code:
C#:
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Traits;
using UnityEngine;

public class InteractableCouch : MonoBehaviour, IInteractableTarget, IInteractableMessage
{
    [SerializeField] private Transform teleportTarget;
    [SerializeField] private bool snapAnimator = true;
    [SerializeField] private bool stopAbility = false;
   
    public bool CanInteract(GameObject character, Interact interactAbility)
    {
        return true;
    }

    public void Interact(GameObject character, Interact interactAbility)
    {
        var characterLocomotion = character.GetComponent<UltimateCharacterLocomotion>();
        characterLocomotion.SetPositionAndRotation(teleportTarget.position, teleportTarget.rotation, snapAnimator, stopAbility);
        var sitAbility = characterLocomotion.GetAbility<Sit>();
        if (!characterLocomotion.TryStartAbility(sitAbility)) Debug.Log("Cannot start ability");
    }

    public string AbilityMessage()
    {
        return "Sit";
    }
}

Animator Enter State

1702111118325.png

Animator Exit State:
1702111141329.png
 
When you want the ability to start again is the ability currently active? When it doesn't start, does the ability activate? If it does, my guess is that you need to add a transition from the current animator state to the ability state.
 
Thanks, at the end it turned out just to be the Stop Type; when 'Long Press' it doesn't work ... Button down and Button Toggle made it work as expected; i'm glad it's just that and not something 'deeper'.
 
Top