Forum rules - please read before posting.

Double click to teleport

From the title, is it possible to implement this functionality?
So instead of running to a spot, the player just instantly teleports?

Any help is appreciated, thank you!

Comments

  • Try this:

    using UnityEngine;
    using AC;
    
    public class DoubleClickTeleport : MonoBehaviour
    {
    
        public PolygonCollider2D navMesh;
    
        void Update ()
        {
            if (KickStarter.playerInput.GetMouseState () == MouseState.DoubleClick &&
                KickStarter.stateHandler.IsInGameplay () &&
                KickStarter.playerInteraction.GetActiveHotspot () == null &&
                KickStarter.playerMenus.IsMouseOverMenu () == false)
            {
                Vector2 mouseWorldPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
                Vector2 closestNavPosition = navMesh.ClosestPoint (mouseWorldPosition);
                KickStarter.player.Halt (true);
                KickStarter.player.Teleport (closestNavPosition);
            }
        }
    
    }
    
  • Thank you so much! I just tried this out, I think this works great!
    One minor thing to ask -- do you know if it possible to prevent the camera from lerping to the new character position, rather just snap to it?

    I still want the lerping / delay to exist when the character moves regularly, so I was just curious to know, thank you! :)

  • Ah. Should just be a case of calling the active GameCamera's MoveCameraInstant after the Teleport call:

    KickStarter.mainCamera.attachedCamera.MoveCameraInstant ();
    
  • Thank you so much!

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.