• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Atis · Jun 02, 2020 at 05:02 PM · playerspawntestingteleportkeydown

Teleport Script by KeyDown for fast Level testing

Hi!
I have a problem with a C# Script which is made for faster level testing.


How it works:

You can make multiple empty GameObjects(Teleport points for now) and place them freely around the map and attaching the below script to them. After that you can choose which button should Teleport the Player to which GameObject.


My problem is very weird because the Script is works under 2017.2.5 just fine, but on 2019.2.5 when I try to teleport I instantly get back where I was.

I searched a lot but couldn't figured out myself, if you have any idea please share, I would appreciate a lot!

UPDATE:

I think I found where I should look into, I suppose the movement controller what I use Updates more frequently?(I'm not a coder) and rewrites this script all the time ? If I change the Update method to FixedUpdate, the code is working but only for one teleport point so the next step is how I should modify the code to enable the other teleport points too ?


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TestTeleportPoint : MonoBehaviour {
     
     [Header("Alpha is numbers on keyboard and numpad are numbers on the numpad")]
     [SerializeField]
     private Keys button;
 
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown((KeyCode)button))
         {
             GameObject.FindWithTag("Player").transform.position = transform.position;
         }
     }
 
     private enum Keys
     {
         
         Alpha1 = KeyCode.Alpha1,
         Alpha2 = KeyCode.Alpha2,
         Alpha3 = KeyCode.Alpha3,
         Alpha4 = KeyCode.Alpha4,
         Alpha5 = KeyCode.Alpha5,
         Alpha6 = KeyCode.Alpha6,
         Alpha7 = KeyCode.Alpha7,
         Alpha8 = KeyCode.Alpha8,
         Alpha9 = KeyCode.Alpha9,
         Alpha0 = KeyCode.Alpha0,
         Numpad0 = KeyCode.Keypad0,
         Numpad1 = KeyCode.Keypad1,
         Numpad2 = KeyCode.Keypad2,
         Numpad3 = KeyCode.Keypad3,
         Numpad4 = KeyCode.Keypad4,
         Numpad5 = KeyCode.Keypad5,
         Numpad6 = KeyCode.Keypad6,
         Numpad7 = KeyCode.Keypad7,
         Numpad8 = KeyCode.Keypad8,
         Numpad9 = KeyCode.Keypad9,
     }
 }
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by altan86 · Jun 17, 2020 at 11:22 AM

Hey everyone, I fixed this problem with a workaround and that is to: 1. disable the player character controller, 2. apply the transform modifier to the player Transform, and 3. enable the player character controller.

 CharacterController player = FindObjectOfType<CharacterController>();
 player.enabled = false;         
 player.transform.SetPositionAndRotation(transform.position,transform.rotation);
 player.enabled = true;

Apparently, in 2017 the character controller doesn't force the player transform values back to its current position whereas in 2019 it does that now when you apply a transform value to a GameObject with a character controller component and calling CharacterController.Move in the Update() loop.

Comment
Atis

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by MenimalsEntertainment · Jun 03, 2020 at 05:18 AM

@Atis Instead of setting the player's position to transform.position, create a new Vector3 based on transform.position. It would look like this:

 GameObject.FindWithTag("Player").transform.position = new Vector3(transform.position.x,transform.position.y,transform.position.z);



Comment
Atis

People who like this

1 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Atis · Jun 03, 2020 at 09:43 AM 0
Share

@skywalker31415 thanks for the advice and I think I found where I should look into, I suppose the movement controller what I use Updates more frequent?(I'm not a coder) and rewrites this script all the time...

Now if I change the Update method to FixedUpdate it works but only for one teleport point, so the next question is what I should change to enable the other teleport points too ?

avatar image MenimalsEntertainment Atis · Jun 03, 2020 at 02:50 PM 0
Share

I definitely use Update() a lot, especially for things such as movement that require constant updates. I think something to look into is having a controller code that manages all of the teleport points. Every teleport point (represented by the script) can be added to a list and all of them managed through a single code and a single Update() function. Otherwise, if the teleport points don't work, I would use Debug.Log to ensure that all the points are being set properly and see if the problem lies in setting the points or in changing the player's position.

avatar image Atis MenimalsEntertainment · Jun 03, 2020 at 07:02 PM 0
Share

Yeah, I think I have something wrong with the player controller, but I don't understand why yet... because it's the same code as was in 2017 version, maybe they changed something programming related in the 2019 versions ?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

162 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make enemy teleport right next to player? 4 Answers

Trying to Move Player Object Backwards But Only Works Once? 0 Answers

Spawn different Player models 0 Answers

Skyrim style door teleport 0 Answers

UNET Players not spawning on server change scene 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges