- Home /
Question by
NickP_2 · May 28, 2014 at 03:56 PM ·
spritepositionscreentoworldpoint
2D sprite worldposition different than 3D?
I have some sprites which should walk toward my mouseposition, which I converted using:
Vector2 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Bu somehow, the sprites don't walk towards the position entirely, they stop a few units before.
To debug this, I spawned a cube at my mouse position, which works perfectly. But it's when I checked the inspector, I realised the x positions of both the sprite AND the cube are the same, yet they are apart.
Here's a screenshot:
Here's the code for the movement of the nail sprite:
//body movement
Vector2 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mousePos.y = parentTransform.position.y;
cube.transform.position = mousePos;
parentTransform.position = Vector3.Lerp (parentTransform.position, cube.transform.position, Time.fixedDeltaTime * walkSpeed);
untitled.png
(58.6 kB)
Comment
Well actually it's not 2D vs 3D, since both transforms are in 3D space...