I would like to set my monster destination to his startPosition if some event happened (collided with wall or sort of). So, i saved the start position of my monster at the Start() like this.
void Start() startPos = transform.position //store my initial object pos.
Ok, now i have so many options to do this, but all of them are giving me the same teleportation feeling, nothing actually moves the monster step by step to the startPos. So the following code:
transform.Translate(startPos) //instant position change. transform.Translate(startPos * Time.deltaTime * speed); // instant teleportation but to wrong position as the value of startPos has changed. transform.rigibody2D.MovePosition(startPos); //instant position change, similar to .Translate method but with more Physics affection. transform.rigidbody2D.MovePosition(startPos * Time.deltaTime * speed); // identical effect as the one above it .MovePosition(startPos); //below is another attempt suggested by a random guy, but it doesn't even cause the monster to move. Vector3 dist = startPos - transform.position; dist.Normalize(); transform.Translate(dist * Time.deltaTime * speed);
I hope someone can put some clear clarification for this issue as i’m started to get lost between these too many options which actually doesn’t achieve my goal.
NOTE: I have done all of these calls inside the OnCollisionStay2D() method.