- Home /
Question by
sunnykwong91500 · Oct 08, 2018 at 10:10 PM ·
2dtopdownshootershaking
2D Top down shooter, gun is shaking while moving and Cursor solutions
Hello all, I am trying to create a 2D top down shooter but for some reason when I move around my gun and crosshair start to shake, like it's lagging behind my mouse.
Below is a video showing the shakiness of the gun and crosshair: https://www.youtube.com/watch?v=csBpL23KQRo
Below are the codes I use:
void CalculateAngle()
{
OA = (crossHair.transform.position.y - player.transform.position.y) / (crossHair.transform.position.x - player.transform.position.x);
angle = Mathf.Rad2Deg * Mathf.Atan(OA);
}
void RotateGun()
{
Quaternion quat = Quaternion.Euler(new Vector3(0, 0, angle));
transform.rotation = quat;
if (player.GetComponent<SpriteRenderer>().flipX)
{
transform.localScale = new Vector3(-1, 1, 1);
}
else
transform.localScale = new Vector3(1, 1, 1);
}
void SetCrosshairPosition()
{
mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
transform.position = new Vector3(mainCamera.ScreenToWorldPoint(mousePos).x, mainCamera.ScreenToWorldPoint(mousePos).y, -1);
}
I'm using a cusor script because whenever I try to change the Texture2D to a specific image of my cursor it ends up being blurry. I tried different import settings but it is still blurry. Thank you all in advance.
Comment