- Home /
Question by
TheMasterfulDork · Jun 04, 2015 at 01:59 PM ·
camera2dplatformerorthographicaccuracy
ScreenToWorldPoint not accurate
I'm making a 2D platformer with a gun mechanic, and the gun is inaccurate. I'm using ScreenToWorldPoint, but it fires close to, yet not through, the mouse point. I've fiddled with it, and only made it worse. Here's my firing code:
if (Input.GetMouseButtonDown (0) && CanFire && onGround) {
Instantiate (bullet);
BulletPhysics obj = FindObjectOfType<BulletPhysics>();
obj.transform.position = gameObject.transform.position;
CameraMovement.following = GameObject.Find ("Bullet(Clone)");
Vector3 mousePos = cam.ScreenToWorldPoint (new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
obj.gameObject.GetComponent<Rigidbody2D>().velocity =
new Vector2(mousePos.x - gameObject.transform.position.x,
mousePos.y - gameObject.transform.position.y);
obj.color = GunColor;
obj.transform.GetChild (0).GetComponent<Light>().color = GunColor;
LevelInformation.bulletExists = true;
return;
}
My camera is 10 units away from the surface. I'm using a custom cursor.
Comment
Your answer
Follow this Question
Related Questions
Blur on first plane 0 Answers
Orthographic Camera settings for a 2D game 1 Answer
Resizing orthographic camera to fit 2d sprite on screen 1 Answer
Iphone 2d camera settings 1 Answer
2D Camera sizing and movement 0 Answers