This Character Control Script is interfering with my Teleportation

I followed this tutorial to create the script:

And now my teleportation anchors are teleporting me to play that aren’t where I placed the respective anchors, sometimes nowhere and sometimes onto one another. Is there any known is with the same or anything you can in this script that will cause the issue? Beginner here so I’m barely able to follow the logic as it is

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(CharacterController))]
public class JumpingScript : MonoBehaviour
{

    [SerializeField] private InputActionReference jumpButton;
    [SerializeField] private float jumpHeight = 2.0f;
    [SerializeField] private float gravityValue = -9.8f;

    private CharacterController _character;
    private Vector3 _playerVelocity;

    private void Awake() => _character = GetComponent<CharacterController>();

    private void OnEnable() => jumpButton.action.performed += Jumping;
    private void OnDisable() => jumpButton.action.performed -= Jumping;

    private void Jumping(InputAction.CallbackContext obj){
        if(!_character.isGrounded) return;
        _playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
    }

    private void Update(){
        if(_character.isGrounded && _playerVelocity.y < 0){
            _playerVelocity.y= 0f;
        }

        _playerVelocity.y += gravityValue * Time.deltaTime;
        _character.Move(_playerVelocity * Time.deltaTime);
    }

}

Hey, after waiting for over a day and browsing more on the topic, I can see the process of figuring out to make both Teleportation as well as Jumping work together seems to be in conflict and won’t work so If anyone has any insights to make them work together, would be much helpful

using UnityEngine;
public class Teleporter : MonoBehaviour // Place this script onto a teleporter that has a trigger collider
{
    public Transform teleportTarget; // Destination object
   
    void OnTriggerEnter(Collider other)
    {
        CharacterController cc = other.GetComponent<CharacterController>();
        if (cc)
        {
            cc.enabled = false;    // disable the character controller 
            other.transform.position = teleportTarget.transform.position;     // teleport the other object
            cc.enabled = true;
        }
    }
}
2 Likes

Hello @nilay11g and @zulo3d . This is a great catch. We will investigate and look into making the teleportation work more consistently with the CharacterController.

2 Likes

I’m glad it could be of help, been rabbit holing on this for a week going through several location motion methods. Would be great if you could simplify adding jumping locomotion in Unity.