how to make your object move from point A to point B?
how to make your object move from point A to point B on itself without restriction complete beginner in programming problem and javascript
Answer by TBruce · Apr 10, 2016 at 05:10 PM
@AzMar18 There are several methods to achieve and would depend on what you were looking to do. One method would be by using the method Vector3.Lerp within a Coroutine. For example:
GameObject objectToMove;
GameObject objectToMoveTo;
StartCoroutine(objectToMove, objectToMoveTo.transform.position);
public IEnumerator MoveObject(GameObject obj, Vector3 newPosition)
{
// get player seat number
Vector3 startPosition = obj.transform.position;
float timer = Time.time;
while (pokerChip.transform.position != newPosition)
{
obj.transform.position = Vector3.Lerp(startPosition, newPosition, Time.time - timer);
yield return new WaitForSeconds(0.02f);
}
yield return new WaitForSeconds(0.5f);
}
Thanks, I am happy that you are able to continue on. BTW, as you probably have already seen I one of the lines in the example is incorrect.
while (pokerChip.transform.position != newPosition)
and it should be
while (obj.transform.position != newPosition)
I copied this from a piece of code I made a while back an missed that on the post.
Your answer
Follow this Question
Related Questions
Move gameobject when clicking on another gameobject 1 Answer
2D Using C# moving game object back and forth and random stop in between - all in x-axis 2 Answers
How to move a cube by flipping using keyboard input 1 Answer
Rigidbody FPS Controller isn't Moving. 0 Answers
input.getaxis returning -1 by default 0 Answers