- Home /
How to reset an game object's position
I am working on a piece of code using itween that move's a game object left and right and I keep it in a ping pong loop. After I press a button, it calls the stop by name function and the object stops (as it should) but it stops at the last position and I want to set it to a specific position. I tried using gameobject.transform.position = new vector3(0,0,0) and it works perfectly. However, it restrains the object from moving again. Is there a way to arrange the game object's position the way I want it? Thank you in advance.
Answer by GoCatGoGamesLLC · Dec 28, 2013 at 03:37 PM
Have you tried creating a variable to hold the "at rest" position instead of just setting the transform? That way it could either be ping-ponging OR set to its default position, allowing you to transition between the two.
I don't use iTween much, so apologies if I steer you wrong.
how would i set the at rest? Is it as simple as just doing it like this: vector3 atRest = new vector3(0,0,0);
I would have two states for the object: pingponging and at rest. On your button click, you could set a boolean atRest to be true, giving it your at rest position. Otherwise atRest is false.
Unfortunately I am on my iPad and can't effectively type or copy/paste useful code.
That's quite alright, you have dome quite enough for me. I have it working now. It was a mixture of finding the answer as I was writing the question and then the answer you gave me just made it a LOT clearer. So Thank you; full points to ye!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Rotating an object using itween 1 Answer
Waiting between pingpong loops 2 Answers
using itween to move objects in the 6 degrees of freedom 1 Answer
Using iTween for custom variables 3 Answers