• 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 unity_O9yFOEld5ESRvw · Jul 21, 2018 at 01:35 AM · vector3beginnervector2teleportbegginer

Player slows down every time they are movies?

So I am calling a method attached to my player called "teleport," which simply moves the player to the set location. However, each time my player is teleported, their movement slows. This is the method being called: public void Teleport(float posX, float posY) { this.transform.position = new Vector3(posX, posY, 0);

 }

and this is the movement logic: float newVelocityX; if (Input.GetKey(KeyCode.LeftArrow)) { newVelocityX = -speed; animator.SetInteger("DirectionX", -1); } else if (Input.GetKey(KeyCode.RightArrow)) { newVelocityX = speed; animator.SetInteger("DirectionX", 1); } else { newVelocityX = 0f; animator.SetInteger("DirectionX", 0); } gameObject.GetComponent().velocity = new Vector2(newVelocityX, transform.position.y); if(transform.position.x >= maxPos) { transform.position = new Vector3(maxPos, transform.position.y,0); } if (transform.position.x <= minPos) { transform.position = new Vector3(minPos, transform.position.y,0); } I am probably missing something very, very obvious. Take pity on me.

Comment
Add comment · Show 1
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 Nomenokes · Jul 21, 2018 at 03:35 AM 1
Share

Your code isn't formatted nicely, darn near impossible to read. Could you edit that please, and format the code to be readable? Thanks

0 Replies

· Add your reply
  • Sort: 

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

118 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

Related Questions

Teleport Player in 2D game? 4 Answers

How to get the World position of a connectedAnchor? (2d) 1 Answer

I'm Having Trouble With Vector3.Reflect.. Please Help? 1 Answer

Prevent implicit cast from Vector3-Vector2 1 Answer

Vector3.Lerp result in "laggy" movement while running on iOS devices 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges