- Home /
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.
Your code isn't formatted nicely, darn near impossible to read. Could you edit that please, and format the code to be readable? Thanks
Your answer
Follow this Question
Related Questions
Teleport Player in 2D game? 4 Answers
Use Rect.Contains to define an area on touchScreens 1 Answer
Should I use Vector3D in a 2D game? 1 Answer