- Home /
transform.position not doing anything
So I've been making a game with a battle system. When the player presses down z or enter in the menu they enter an attack. So I made this code to teleport the character into the attack box and shrink them down. But they get shrunk down and don't teleport. Everything but transform.position
works. This is a sprite in a 2D game if that helps.
if (Input.GetKeyDown ("z") || Input.GetKeyDown ("return")) { textbox.SetActive (false); bulletboard.SetActive (true); soul.transform.position = new Vector3 (-0.3423029f, -1.97f, 0f); soul.transform.localScale = new Vector3 (0.1f, 0.1f, 0f); isfighting = true; }
Thanks in advance!
Answer by nj4242 · Sep 19, 2017 at 10:47 AM
Make a empty gameobject wherever your soul wanted to teleport. Then make a public Transform variable to store this empty soul's transform position, And drag it to the inspector. So, Instead of writing a raw xyz position of soul you can just use this empty gameobject's position which you setup in the scene where you want to teleport. You can do same for scaling too. Just scale down to 0.1f's to it scaling transform of empty game object. and set it like soul.transform.position = teleportPos;
and soul.transform.localScale = teleportScale
respectively.
I tried that but it won't move at all. I attempted using transform.Translate(1f,0f,0f);
to see if that would do anything as well but it won't move even if I remove all the rest of the code.
Your answer
Follow this Question
Related Questions
Sprite is not shown moving 1 Answer
How do I move my object slowly from its original position? 2 Answers
changing sprites depending on int value 1 Answer
Rotate the weapon sprite with a joystick 0 Answers
Simultaneous Animation for an Object 0 Answers