Question by
yachae · Aug 03, 2016 at 06:36 AM ·
errorvector2movetowards
Vector2.MoveTowards works strangely
I am very new to Unity and I'm working on this script which throws GameObject a(acorn) to GameObject s.
But the last sentence is the problem.
When throw() actions, 'a' goes to the strange position which is a Vector3 value. I mean, it moves to Z axis as well as X and Y.
I tried Debug.Log() to make sure that vec and cur has right value, and they did.
I can't find what's wrong. :(
Please help me
public class Acorn_throw : MonoBehaviour {
public GameObject s,a;
Vector2 vec, cur;
Rigidbody2D rg2;
void Start () {
rg2 = GetComponent<Rigidbody2D> ();
vec = s.transform.localPosition;
cur = a.transform.localPosition;
}
void Update () {
if (Input.GetKeyDown ("space")) {
Throw ();
}
}
void Throw(){
rg2.WakeUp ();
a.transform.position = Vector2.MoveTowards (cur, vec, 0.03f);
}
}
Comment
Your answer
Follow this Question
Related Questions
[C#] The left-hand side of an assignment must be a variable, a property or an indexer 0 Answers
Using a reference for another script in a method issue. 0 Answers
Javascript Script for Object Follow? 0 Answers
How to move more than one object together at a time? 1 Answer
How to use Vector2 movetowards? 1 Answer