Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by Supermacka · Feb 28, 2018 at 07:04 PM · objectteleporting

How to make an object move after teleporting it to a specific location

Hi there!

I have a character which can move with the keys and I have a script attached to it which teleports it to a specific location. But after it has teleported it is stuck in this location and can't move anymore. How can i make my character move after being teleported, stop it from being fixed to the position? Sorry if this topic has already been discussed, i couldn't find anything on it.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Teleportation : MonoBehaviour {
 
     private Vector3 destination;
     Rigidbody rb;
     public float speed;
     public float jumpPower;
 
     // Use this for initialization
     void Start () {
         destination = new Vector3(4.70f, 2.9f, 4.699f);
         rb = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
 
         rb.AddForce(movement * speed * Time.deltaTime);
 
         Invoke("TeleportToDestination", 1f);
     }
 
     void TeleportToDestination()
     {
         transform.position = destination; 
     }
 }
 



Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by dishant27 · Feb 28, 2018 at 07:27 PM

You are calling the TeleportToDestination() method in FixedUpdate. So it's after 1sec of gameplay, Invoke method is called again and again which is responsible for the problem. Call it from start method or using OnTriggerEnter on the position from where you want to teleport.

Comment
Add comment · Show 3 · 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 Supermacka · Feb 28, 2018 at 07:52 PM 0
Share

Thanks dude!

How would i go about if i had to collect a number of objects before i can teleport. If i set the teleport method in "start" it will only be called once in the start of the game...

hmmm

avatar image dishant27 Supermacka · Feb 28, 2018 at 08:01 PM 0
Share

Place colliders on the places from where you want to teleport. Call the TeleportToDestination() from the OnTriggerEnter method. https://unity3d.com/learn/tutorials/topics/physics/colliders-triggers

avatar image Supermacka dishant27 · Feb 28, 2018 at 08:06 PM 0
Share

Alright! Thanks again <3

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.

Follow this Question

Answers Answers and Comments

78 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

Related Questions

How do I teleport one Object to an emptyGameObject? 1 Answer

Player gets teleported to wrong object. 1 Answer

rotation of the object to a given angle 1 Answer

how do I make a Object getcomponent and call a function 1 Answer

How to make flat object(Unity 2D) 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