Commit 6e5512ff authored by Danny Huang's avatar Danny Huang
Browse files

disable gun rotation if cursor is near hero's horizontal position

parent 7dc3bc25
......@@ -64,6 +64,10 @@ public class HeroInventory : MonoBehaviour
/* Used to determine if Hero is dead or not */
protected HeroDeathCtrl deathCtrl;
/* If mouse cursor is within Hero's mouse cursor horizontal threshold, do not update gun rotation,
otherwise, it will jitter. */
public float cursorHorThresh;
void Start ()
{
is_UI_inventory_opened = false;
......@@ -445,9 +449,16 @@ public class HeroInventory : MonoBehaviour
{
GameObject equippedGun = GetEquippedGun ();
/* Don't adjust rotation if mouse cursor is too close to Hero. Only update position. */
bool isUpdateRot = true;
Vector2 heroPos = this.transform.position;
Vector3 cursorAndHeroDist = mouseWorldPos - heroPos;
if (Mathf.Abs (cursorAndHeroDist.x) < this.cursorHorThresh)
isUpdateRot = false;
if (equippedGun != null) {
GunController gunCtrl = equippedGun.GetComponent<GunController>();
gunCtrl.CorrectOrientation (this.triggerFinger.transform.position, mouseWorldPos);
gunCtrl.CorrectOrientation (this.triggerFinger.transform.position, mouseWorldPos, isUpdateRot);
}
}
......
......@@ -237,7 +237,8 @@ public class GunController : ItemCtrl {
return (int) Random.Range (this.modMinDamage, this.modMaxDamage);
}
public void CorrectOrientation(Vector3 triggerFingerPos, Vector3 mouseWorldPos=default(Vector3))
public void CorrectOrientation(Vector3 triggerFingerPos, Vector3 mouseWorldPos=default(Vector3),
bool isUpdateRot=true)
{
bool isGunFacingRight = getDirection().x > 0f;
......@@ -245,8 +246,10 @@ public class GunController : ItemCtrl {
Vector2 fireDirection = mouseWorldPos - this.barrelTip.transform.position;
float fireDirectionDegAngle = Mathf.Atan2 (fireDirection.y, fireDirection.x) * Mathf.Rad2Deg;
this.transform.rotation = Quaternion.Euler (0, 0, fireDirectionDegAngle);
if (isUpdateRot) {
float fireDirectionDegAngle = Mathf.Atan2 (fireDirection.y, fireDirection.x) * Mathf.Rad2Deg;
this.transform.rotation = Quaternion.Euler (0, 0, fireDirectionDegAngle);
}
//Debug.Log (fireDirection.x + "_" + fireDirection.y + "_ " + fireDirectionDegAngle);
/* Flip gun vertically if facing left */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment