C
C
CSharpMutant2021-05-05 12:16:15
Unity
CSharpMutant, 2021-05-05 12:16:15

How to make an object move in the other direction after it reaches a certain coordinate?

And so I'm trying to repeat the game City Tower, or whatever it's called.
The essence of the game is to build a tower of floors.
I ran into one problem due to my inexperience.
I need the object to move from one coordinate to another, after clicking on it it falls.
I did the fall and the creation of a new one, but I can’t do the looped movement

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lubitel_pelmen, 2021-05-05
@lubitel_pelmen

Hello. Although I'm not a professional in this, but try in the script of the object you want to move, write through if that when the object reaches a certain coordinate, its speed becomes negative. And yes, do it in Update . I think it helped

X
Xoggas, 2021-05-06
@Xoggas

Hello, try using Mathf.Sin(Time.time), it will return values ​​between -1 and 1. To increase the speed just multiply Time.time by the desired speed.
Let's say

public float Speed = 2f;
public float Range = 100f;
void Update(){
    transform.position = new Vector3(Mathf.Sin(Time.time * Speed) * Range, 0f, 0f);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question