Forum rules - please read before posting.

Keep direction while moving to marker

edited December 2023 in Technical Q&A

Hi

I am using the move to marker on the hotspot.

Is there a way to have the player keep it current direction while moving?
I have a swinging door and when the player is too close the door and player collides. I would like the player to take step back rather than turning around.

atm i am using interaction boundary as a workaround but it doesn't quite feel natural.

thanks

Comments

  • Is it that the door is causing the Player to turn, or just that the NavMesh requires the Player to turn around to reach the Hotspot's Marker?

    It's a bit hacky, but you should be able to lock the rotation with this script (LockDirectionToHotspot.cs), attached to the Hotspot:

    using UnityEngine;
    using AC;
    
    public class LockDirectionToHotspot : MonoBehaviour
    {
    
        private bool lockDirection;
        private Vector3 direction;
    
        void OnEnable ()
        {
            EventManager.OnHotspotInteract += OnHotspotInteract;
            EventManager.OnHotspotReach += OnHotspotReach;
            EventManager.OnHotspotStopMovingTo += OnHotspotStopMovingTo;
        }
    
        void OnDisable ()
        {
            EventManager.OnHotspotInteract -= OnHotspotInteract;
            EventManager.OnHotspotReach -= OnHotspotReach;
            EventManager.OnHotspotStopMovingTo -= OnHotspotStopMovingTo;
        }
    
        void LateUpdate ()
        {
            if (lockDirection)
            {
                KickStarter.player.SetLookDirection (direction, true);
            }
        }
    
        void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspot.gameObject == gameObject)
            {
                lockDirection = true;
                KickStarter.player.retroPathfinding = true;
                direction = KickStarter.player.TransformForward;
            }
        }
    
        void OnHotspotReach (Hotspot hotspot, AC.Button button)
        {
            if (hotspot.gameObject == gameObject)
            {
                lockDirection = false;
                KickStarter.player.retroPathfinding = false;
            }
        }
    
        void OnHotspotStopMovingTo (Hotspot hotspot)
        {
            if (hotspot.gameObject == gameObject)
            {
                lockDirection = false;
                KickStarter.player.retroPathfinding = false;
            }
        }
    
    }
    
  • i tried using this but player just tries his hardest to to walk into the hotspot(on the door) rather than taking a step backwards

    to answer your first question, its not the door thats turning the player its the navigation.

    im not using a navmesh, just using walk to marker from the hotspot.

  • I'm not clear on the behaviour - is this a case of the movement being incorrect, or just the rotation?

    If you can share a video/annoted screenshots of the behaviour (both before and after the script, if there's a difference), it'll help clarify the underlying situation.

  • Hi Below is link,

    before script

    after script.

    thanks

  • Thanks for the clear explanation.

    The camera turns because the Player is moving backward to reach the Marker. What you can do instead is rely on the Moveable component to simply beeline to the Marker without the use of pathfinding.

    Set the Hotspot's Player action field to Do Nothing, attach a Moveable component to your Player prefab, and then begin your Interaction with an Object: Transform Action.

    In this Action, check Move Player?, and set the field beneath to Copy Marker. Reference the Hotspot's "Walk-to" Marker, and adjust the transition values to suit. The Player should then lerp from where they are to the Marker in a straight line - also accounting for the Marker's rotation.

  • Thanks! that seems to do the trick.

    I did try the object transform on the player before but i didnt realise that i needed the moveable component on the player.

    thanks for the great support

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.