private void Update() { float enter; ver = fixedJoystick.Vertical; if (fixedJoystick.Horizontal < 0) { hor += 0.25f; } else if (fixedJoystick.Horizontal > 0) { hor -= 0.25f; } Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); new Plane(-Vector3.forward, transform.position).Raycast(ray, out enter); Vector3 mouseInWorld = ray.GetPoint(enter); speed = new Vector3(hor, mouseInWorld.y - transform.position.y, mouseInWorld.z - transform.position.z - 90) * Power; transform.rotation = Quaternion.LookRotation(speed); Trajectory.ShowTrajectory(transform.position, speed); if (Input.GetKeyDown(KeyCode.Escape)) { Time.timeScale = 0; } }
public void OnDrag(PointerEventData eventData) { endMousePosition = Camera.main.ScreenToWorldPoint(eventData.position); Player.GetComponent <Animator>().SetFloat("aim_float", Mathf.Clamp(startMousePosition.y - endMousePosition.y, 0, 1)); trajectory.ShowTrajectory(spawnPoint.transform.position, startMousePosition - endMousePosition * shootForce); //Debug.Log(startMousePosition - endMousePosition * shootForce); }
private void DrawTrajectory() { if (currentArrow) { Vector3 initialVelocity = PhysicsCalcUtil.CalcInitVelocity(currentArrow.transform.position, targetPosition, hDisplacement, Physics.gravity.y).initialVelocity; Vector3 arrowRotationCompensator = currentArrow.transform.forward / 2; initialVelocity = initialVelocity - arrowRotationCompensator; trajectoryRenderer.ShowTrajectory(currentArrow.transform.position, initialVelocity); } }
private void Shooting() { if (Input.GetMouseButton(0)) { speed = (mousePos - (Vector2)aimPoint.position) * power; tr.ShowTrajectory(aimPoint.position, speed); } if (Input.GetMouseButtonUp(0)) { //Rigidbody2D figure = Instantiate(figurePrefab, aimPoint.position, Quaternion.identity).GetComponent<Rigidbody2D>(); figure.gameObject.SetActive(true); figure.transform.position = aimPoint.position; figure.AddForce(figure.mass * speed / Time.fixedDeltaTime); tr.ClearTrajectory(); RefreshFigurePrefab(); } }
private void Update() { float enter; Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); new Plane(-Vector3.forward, transform.position).Raycast(ray, out enter); Vector3 mouseInWorld = ray.GetPoint(enter); Vector3 speed = (mouseInWorld - transform.position) * Power; transform.rotation = Quaternion.LookRotation(speed); Trajectory.ShowTrajectory(transform.position, speed); if (Input.GetMouseButtonDown(0)) { Rigidbody bullet = Instantiate(BulletPrefab, transform.position, Quaternion.identity).GetComponent <Rigidbody>(); bullet.AddForce(speed, ForceMode.VelocityChange); //Trajectory.AddBody(bullet); } }
private void HandleTrajectory() { if (currentArrow == null || IsInitialArrowPos) { trajectoryRenderer.Enabled = false; return; } if (!trajectoryRenderer.Enabled && !IsInitialArrowPos) { trajectoryRenderer.Enabled = true; } Transform currentArrowTransform = currentArrow.transform; Vector3 currentArrowPosition = currentArrowTransform.position; Vector3 arrowRotationCompensator = currentArrow.transform.forward.With(0f, z: 0f); Vector3 arrowVelocity = (currentArrowTransform.forward * fireForce * currentStretchStrength) - arrowRotationCompensator; trajectoryRenderer.ShowTrajectory(currentArrowPosition, arrowVelocity); }
private void DrawTrajectory() { trajectoryRenderer.ShowTrajectory(transform.position, playerRgb.velocity + Vector3.up * jumpForce); }