- Home /
Rb2D.MovePosition not working - weird error...
Why does this line not work: By the way, movementOptions.rb is a Rigidbody2D variable, positionToMove is a Vector2 and speed is a float.
movementOptions.rb.MovePosition(transform.position + Vector2.MoveTowards(transform.position, movementOptions.positionToMove, movementOptions.speed) * movementOptions.speed);
I get this error:
Assets/Scripts/Unit.cs(56,67): error CS0121: The call is ambiguous between the following methods or properties: `UnityEngine.Vector2.operator +(UnityEngine.Vector2, UnityEngine.Vector2)' and `UnityEngine.Vector3.operator +(UnityEngine.Vector3, UnityEngine.Vector3)'
Answer by Positive7 · Sep 05, 2015 at 04:29 PM
because transform position is Vector3 and you're trying to use it as Vector2. Something like this should solve it :
Vector2 PosXY = new Vector2(transform.position.x, transform.position.y);
movementOptions.rb.MovePosition(PosXY + Vector2.MoveTowards(PosXY, movementOptions.positionToMove, movementOptions.speed) * movementOptions.speed);
It gives the same error as last time (I switched out the GetComponent for the rb variable, which is already a rigidbdoy2d)
Sorry there was 2 transform.position. I updated my answer
No errors this time, but it flies off at like a million miles an hour to somewhere far in the distance (does it matter that my rigid body is kinematic)?
If you want, ill send you the whole script
Well that's what this piece of code does. What are you trying to achieve? Nope Is$$anonymous$$inematic dosen't matter since it's not Physics based moving.