void Update() { if (!aimingMode) { return; } Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); Vector3 mouseDelta = mousePos3D - launchPos; float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; } if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.shotFired(); ProjectileLine.S.poi = projectile; } }
void Update() { //if slingshot is not in aimingmode, don't run this code if (!aimingMode) { return; } //get current mouse position in 2D screen coordinates Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); //find the delta from the launchpos to the mousepos3D Vector3 mouseDelta = mousePos3D - launchPos; //limit mousedelta to the radius of the slingshot sphere collider float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //move the projectile to this new position Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { //The mouse had been released aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.shotFired(); ProjectileLine.S.poi = projectile; } }
// Update is called once per frame void Update() { //if slingshot is not in aiming mode, tell this to screw off if (!aimingMode) { return; } //get current mouse position Vector3 mousePos2d = Input.mousePosition; mousePos2d.z = -Camera.main.transform.position.z; Vector3 mousePos3d = Camera.main.ScreenToWorldPoint(mousePos2d); //find the delta from the launchPos to mouse Vector3 mouseDelta = mousePos3d - launchPos; float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //move the projectile to new position Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.shotFired(); ProjectileLine.S.poi = projectile; } //lootboxes }