void GetRequest() { // PositionCollider positionCollider = Network.GetData().Result; //if (!isFire) //{ var pc = Network.GetData(firstName); if (pc != null) { projectile = Instantiate(prefabProjectile) as GameObject; // Зробити його кінематичним projectile.GetComponent <Rigidbody>().isKinematic = true; projectileRigidbody = projectile.GetComponent <Rigidbody>(); projectileRigidbody.isKinematic = true; Vector3 myPos = new Vector3(pc.pos.X, pc.pos.Y, pc.pos.Z); //positionCollider.pos;// projectile.transform.position = myPos; projectileRigidbody.isKinematic = false; Vector3 v = new Vector3(pc.velocity.X, pc.velocity.Y, pc.velocity.Z); //positionCollider.velocity; projectileRigidbody.velocity = v; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); // a ProjectileLine.S.poi = projectile; isFire = true; } //} Invoke("GetRequest", server_fps); }
// Update is called once per frame void Update() { if (aimingMode) { //Convert mouse to world coordinates Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePos.z = 0f; //Find the difference from the launchPos to the mouse Position Vector3 diff = mousePos - launchPos; //Limit the diff to be within the radius of the slingshot collider float maxDiff = this.GetComponent <SphereCollider>().radius; if (diff.magnitude > maxDiff) { diff.Normalize(); diff *= maxDiff; } //Move the projectile to this new position Vector3 projPos = launchPos + diff; projectile.transform.position = projPos; //What happens when the mouse is now released? if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectile.GetComponent <Rigidbody>().isKinematic = false; projectile.GetComponent <Rigidbody>().velocity = -diff * velocityMult; FollowCam.S.poi = projectile; //follow the projectile as it flies projectile = null; MissionDemolition.ShotFired(); } } }
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; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta = mouseDelta.normalized * maxMagnitude; } Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { aimingMode = false; FollowCam.S.lockFire(); MissionDemolition.ShotFired(); projectile.GetComponent <Rigidbody>().isKinematic = false; projectile.GetComponent <Rigidbody>().velocity = -mouseDelta * velocityMult; FollowCam.S.poi = projectile; autoReturn = 500; projectile = null; } }
// Update is called once per frame void Update() { if (!aimingMode) { return; } Vector3 mousePos2D = Input.mousePosition; //将鼠标光标为hi转换为三维世界坐标 mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); //计算launchPos到mousePos3D两点之间的坐标差 Vector3 mouseDelta = mousePos3D - launchPos; //将mouseDelta坐标差限制在弹弓的球状碰撞器半径范围内 float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //将projectile移动到新位置 Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectile.GetComponent <Rigidbody>().isKinematic = false; projectile.GetComponent <Rigidbody>().velocity = -mouseDelta * velocityMult; FollowCam.S.poi = projectile; projectile = null; MissionDemolition.ShotFired(); } }
void Update() { //if slingshot is not in aiming mode, don't run this code if (!aimingMode) { return; } //get the current mouse position in 2D screen coordinates Vector3 mousePos2D = Input.mousePosition; //convert the mouse position to 3D world coordinates 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; } if (Input.GetMouseButtonUp(0)) { //the mouse has been released aimingMode = false; projectile.GetComponent <Rigidbody>().isKinematic = false; projectile.GetComponent <Rigidbody>().velocity = -mouseDelta * velocityMult; FollowCam.S.poi = projectile; projectile = null; MissionDemolition.ShotFired(); } }
// Update is called once per frame void Update() { if (!aimingMode) { return; } else { 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; } } }
private 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; // Limit mouse delta to the radius of hte slingshot sphere collider float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } // Move Projectile to the New Position Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (projectile != null) { Vector3[] linePositions = new Vector3[] { leftArm.position, projPos, RightArm.position }; lineRendy.SetPositions(linePositions); } if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; lineRendy.enabled = false; } }
void Update() { // If Slingshot is not in aimingMode, don't run this code if (!aimingMode) { return; } // Get the 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 SphereCollider 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; leftSling.SetPosition(0, leftArm.transform.position); leftSling.SetPosition(1, projectile.transform.position); rightSling.SetPosition(0, rightArm.transform.position); rightSling.SetPosition(1, projectile.transform.position); rightSling.enabled = true; if (Input.GetMouseButtonUp(0)) { // The mouse has been released aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; leftSling.SetPosition(0, leftArm.transform.position); leftSling.SetPosition(1, rightArm.transform.position); leftSling.enabled = true; rightSling.enabled = false; } }
void Update() { if (projectile != null) { band.SetPosition(1, projectile.transform.position); } else { band.SetPosition(1, launchPoint.transform.position); } if (!aimingMode) { return; } Vector3 mousePos2D = Input.mousePosition; // c 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 SphereCollider // d 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)) // e // The mouse has been released { print("Band Released"); aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
void OnCollisionEnter(Collision dataFromCollision) { if (dataFromCollision.gameObject.name == "Trap") { MissionDemolition.ShotFired(); AudioSource trapSound = GameObject.Find("TrapSound").GetComponent <AudioSource>(); trapSound.Play(0); Object.Destroy(this.gameObject); } }
private void Update() { // if slingshot is not in aiming mode dont run this code if (!aimingMode) { return; } //get the current mouse position in 2d screen coordinate 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; //linit mouse delta to the radius of the slingshot 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 has been released aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileeLine.S.poi = projectile; } }
private void Update() { //if we aren't aiming don't do anything if (!aimingMode) { return; } //get mouse position and do weird stuff with the z that I don't get Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); //calculate delta for mouse position to launch position Vector3 mouseDelta = mousePos3D - launchPos; //get magnitude of radius float maxMagnitude = this.GetComponent <SphereCollider>().radius; //if the mouse delta magnitude is larger than the max then normalize and multiply it by the max magnitude if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //set projectile to where mouse is Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { //set camera point of interest to the current bullet FollowCam.POI = projectile; //no longer aiming aimingMode = false; //is affected by physics projectileRigidBody.isKinematic = false; //set velocity to the opposite angle in which the mouse in multiplied by a set value projectileRigidBody.velocity = -mouseDelta * velocityMult; //remove the projectile from memory projectile = null; //set shot fired in main script and new projectile line MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
void Aiming() { if (b_aiming) { Vector3 mousePos = Input.mousePosition; mousePos.z = -Camera.main.transform.position.z; Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos); Vector3 mouseDelta = worldPos - launchPos; float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; Vector3 bandPos = new Vector3(mouseDelta.x - 0.5f, mouseDelta.y - 0.7f, mouseDelta.z); bandLeft.SetPosition(0, bandPos); bandRight.SetPosition(1, bandPos); if (Input.GetMouseButtonUp(0)) { bandLeft.SetPosition(0, new Vector3(0, 0, 0)); bandRight.SetPosition(1, new Vector3(0, 0, 0)); b_aiming = false; projectileRigid.isKinematic = false; projectileRigid.velocity = -mouseDelta * velocity; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } } }
void Update() { //If we fired, flag will be false, this will make us invoke ResetFlag after 3 seconds has passed if (flag == false) { Invoke("ResetFlag", 3); } //If Slingshot is not in aimingMode or flag is off, don't run this code if (!aimingMode || !flag) { return; } //Get the 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 SphereCollider 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 has been released aimingMode = false; flag = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
void GetRequest() { // PositionCollider positionCollider = Network.GetData().Result; var pc = Network.GetData(secondName).Result; if (pc == null) { Invoke("GetRequest", frequency); } else { projectile = Instantiate(prefabProjectile) as GameObject; if (i >= materials.Length) { i = 0; } Material[] mats = projectile.GetComponent <Renderer>().materials; mats[0] = materials[i]; projectile.GetComponent <Renderer>().materials = mats; i++; // Сделать его кинематическим projectile.GetComponent <Rigidbody>().isKinematic = true; projectileRigidbody = projectile.GetComponent <Rigidbody>(); projectileRigidbody.isKinematic = true; //???????????? Vector3 myPos = new Vector3(pc.pos.X, pc.pos.Y, pc.pos.Z); //positionCollider.pos;// projectile.transform.position = myPos; projectileRigidbody.isKinematic = false; //???????????? Vector3 v = new Vector3(pc.velocity.X, pc.velocity.Y, pc.velocity.Z);//positionCollider.velocity; projectileRigidbody.velocity = v; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); // a ProjectileLine.S.poi = projectile; isFirstShot = true; Invoke("GetRequest", frequency); } }
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; // Display slingLine from slingshot to cursor slingLine.SetPosition(0, launchPos); slingLine.SetPosition(1, projPos); slingLine.enabled = true; if (canShoot && Input.GetMouseButtonUp(0)) { aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); canShoot = false; Invoke("AllowShooting", 3); ProjectileLine.S.poi = projectile; slingLine.enabled = false; } }
// Update is called once per frame void Update() { // Если рогатка не в режиме прицеливания, не выполнять этот код if (!aimingMode) { return; } Vector3 mousePos2D = Input.mousePosition; // с mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); // Найти разность координат между launchPos и mousePos3D Vector3 mouseDelta = mousePos3D - launchPos; // Ограничить mouseDelta радиусом коллайдера объекта Slingshot // d 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; Network.PostData(secondName, projPos, projectileRigidbody.velocity); isFire = false; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
private void Update() { //If Slingshot is not in aimingMode, don't run this code if (!aimingMode) { return; } // Get the current mouse position in 2D screen coordinates Vector3 mousePosition2D = Input.mousePosition; mousePosition2D.z = -Camera.main.transform.position.z; Vector3 mousePosition3D = Camera.main.ScreenToWorldPoint(mousePosition2D); // Find the delta from the launchPosition to the mousePosition3D Vector3 mouseDelta = mousePosition3D - launchPosition; // Limit mouseDelta to the radius of the Slingshot SphereCollider float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } // Move the projectile to this new position Vector3 projectilePosition = launchPosition + mouseDelta; projectile.transform.position = projectilePosition; if (Input.GetMouseButtonUp(0)) { // The mouse has been released // Enable TrailRenderer of Projectile trail = projectile.GetComponent <TrailRenderer>(); trail.emitting = true; aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMultiplier; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); } }
void Update() { //If Slingshot is not in aimingMode, dont run the code. if (!aimingMode) { return; } //////From page 546 //Get current mouse pos in 2d screen coords. Vector3 mousePos2D = Input.mousePosition; //Convert the mouse position to 3D world coordinates. 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 SphereCollider 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 has been released. aimingMode = false; projectile.GetComponent <Rigidbody>().isKinematic = false; projectile.GetComponent <Rigidbody>().velocity = -mouseDelta * velocityMult; FollowCam.S.poi = projectile; //From Page 550*********. //This line will use the singleton to set val of poi for the camera. projectile = null; MissionDemolition.ShotFired(); //from pg571. } //Basically all the above summed up as AMBLAA. A Minus B Looks At A. ****** Which one the vector will point at. //PAGE 548!!!!!! More explanation of how it all works.**** }
void Update() { // If Slingshot is not in aimingMode, don't run this code if(!aimingMode) return; // b // Get the current mouse position in 2D screen coordinates Vector3 mousePos2D = Input.mousePosition; // c 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 SphereCollider // d 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)) { // e // The mouse has been released aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); // a ProjectileLine.S.poi = projectile; // b } }
// Update is called once per frame void Update() { //if (Input.GetKeyDown(KeyCode.Space)) //{ //} if (!aimingMode) { return; } Vector3 mousePos2D = Input.mousePosition; // с mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); Vector3 mouseDelta = mousePos3D - launchPos; // Ограничить mouseDelta радиусом коллайдера объекта Slingshot // d 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)) { // e // Кнопка мыши отпущена aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; isFirstShot = false; Network.PostData(firstName, projPos, projectileRigidbody.velocity); FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); // a ProjectileLine.S.poi = projectile; } }
// Update is called once per frame void Update() { if (!aimingMode) { return; } // Get current mouse position in 2D screen coords Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); // Find delta from lanchPos to mousePos3D Vector3 mouseDelta = mousePos3D - launchPos; // Limit mouseDelta to the radius of the Slingshot SphereCollider float maxMagnitude = GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } // Move projectile to new position Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { // Mouse has been released aimingMode = false; projectileRigidBody.isKinematic = false; projectileRigidBody.velocity = -mouseDelta * velocityMult; FollowCam.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
}//void Start /************************************************************************************************* *** Update *************************************************************************************************/ void Update() { //If Slingshot is not aimingMode, dont run this code if (!aimingMode) return; //Get the current mouse position in 2D screen coordinates Vector3 mousePos2D = Input.mousePosition; //Convert the mouse position to 3D world coordinates 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 SphereCollider float maxMagnitude = gameObject.GetComponent<SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; }//if //Move the projectile to this new position Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = Vector3.MoveTowards(projectile.transform.position, projPos, Time.deltaTime * velocityMult * 2); if (Input.GetMouseButtonUp(0)) { //The mouse has been released aimingMode = false; projectile.GetComponent<Rigidbody>().isKinematic = false; projectile.GetComponent<Rigidbody>().velocity = -mouseDelta * velocityMult; FollowCam.S.poi = projectile; projectile = null; MissionDemolition.ShotFired(); }//if }//void Update
// Update is called once per frame void Update() { // if Slingshot is not in aimingMode, don't run this if (!aimingMode) { return; } // get the current mouse pos 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 this 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 }
private 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; //Если mouseDelta длиннее maxMagnitude его длина усекается до maxMagnitude if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //Передвинуть снаряд в новую позицию Vector3 bulletPos = LaunchPos + mouseDelta; Bullet.transform.position = bulletPos; //Если кнопка мыши отпущена if (Input.GetMouseButtonUp(0)) { AimingMode = false; _bulletRigidbody.isKinematic = false; _bulletRigidbody.velocity = -mouseDelta * VeloсityMult; FollowCam.POI = Bullet; MissionDemolition.ShotFired(); BulletLine.S.poi = Bullet; Bullet = null; } }
void Update() { //code runs only if slingshot is in aiming mode if (!aimingMode) { return; } //get mouse poisition in 2D screen coordinates Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); Vector3 mouseDelta = mousePos3D - launchPos; //limit delta to radius of slingshot spherecollider float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //move 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; } }
// Update is called once per frame void Update() { // Якщо рогатка не в режимі прицілювання, то не виконувати цей код if (!aimingMode) { return; } Vector3 mousePos2D = Input.mousePosition; // с mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); // Знайти різницю координат між launchPos і mousePos3D Vector3 mouseDelta = mousePos3D - launchPos; // Обмежити mouseDelta радіусом коллайдера об’єкта Slingshot // d 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; Network.PostData(secondName, projPos, projectileRigidbody.velocity); isFire = false; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
private void Update() { if (!aimingMode) { return; } //get current cursor coordinates Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); //it`s better do not let go out of radius of the sphere collider Vector3 mouseDelta = mousePos3D - launchPos; float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //let`s move our projectile with the mouse Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMult; FollowCamera.POI = projectile; projectile = null; MissionDemolition.ShotFired(); ProjectileLine.S.poi = projectile; } }
private void Update() { if (!IsAimingMode) { return; } var mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; var mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); var mouseDelta = mousePos3D - LaunchPos; var maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } var projectilePosition = LaunchPos + mouseDelta; Projectile.transform.position = projectilePosition; if (Input.GetMouseButtonUp(0)) { IsAimingMode = false; _projectileRigidBody.isKinematic = false; _projectileRigidBody.velocity = -mouseDelta * VelocityMult; FollowCam.POI = Projectile; Projectile = null; MissionDemolition.ShotFired(); ProjectileLine.Instance.POI = Projectile; } }
// Update is called once per frame 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; // находим лайн рендерер и добавляем туда три точки GameObject lineGO = GameObject.Find("SlingshotLine"); LineRenderer line = lineGO.GetComponent<LineRenderer>(); line.positionCount = 3; line.SetPosition(0, new Vector3(-8.39f,-6.11f, 1.96f)); line.SetPosition(1, projectile.transform.position); line.SetPosition(2, new Vector3(-9.68f, -6.11f, -1.99f)); line.enabled = true; if (Input.GetMouseButtonUp(0)) { // Если кнопку отпустили aimingMode = false; projectile.GetComponent<Rigidbody>().isKinematic = false; projectile.GetComponent<Rigidbody>().velocity = -mouseDelta * velocityMult; FollowCam.S.poi = projectile; projectile = null; MissionDemolition.ShotFired(); line.enabled = false; } }