- Home /
Question by
TheKidProgamer · Mar 26, 2014 at 12:09 AM ·
movementmove an objectvector3.position
What is wrong with my movement code
My goal is to have 2 sepreat objects move away from each other than back hears the code
if (timer <= 1)
{
door.position += speed = new Vector3 (0,0,openSpeed * Time.deltaTime);
door1.position -= speed = new Vector3 (0,0,openSpeed * Time.deltaTime);
timer += 1 * Time.deltaTime;
}
if (timer >= 1)
{
door.position += speed = new Vector3 (0,0,openSpeed * Time.deltaTime) * -3;
door1.position -= speed = new Vector3 (0,0,openSpeed * Time.deltaTime) * -3;
timer = 0f;
}
Comment
Answer by Sildaekar · Mar 26, 2014 at 03:01 AM
It would probably be better to move it like such:
if (timer <= 1)
{
door.position = Vector3.forward * openSpeed*Time.deltaTime;
door1.position = (Vector3.forward*-1) * openSpeed*Time.deltaTime;
timer += Time.deltaTime;
}
if (timer >= 1)
{
door.position = (Vector3.forward*-1) * openSpeed*Time.deltaTime;
door1.position = Vector3.forward * openSpeed*Time.deltaTime;
timer -=Time.deltaTime;
}
However, I didn't see you post any error messages, and you didn't tell us what it is doing right now so there's not really much I can do to help you out.
Also, I re-tagged your question since it's not really possible for this to run in "1 frame".
What it was doing is it would just continuously go in the first direction. Wit the code you gave me sidekar it would go in the same place and stay their. I figured out that to close the "door" is to have a bool but I don't know how to set than unset a bool after a period of time.
Your answer
