Move on Z axis in 3D
Hello, I'm pretty novice, so excuse the question.
What I'm trying to do is have my character throw a ball down the Z-axis.
I have the camera locked only to move left and right on the X-axis currently.
I want to know how to have the mouse represent the location I want to throw the ball downfield, maybe have a circle go downfield to the area as a marker?
I want to achieve this by having the mouse moving towards the top of the screen represent a location further downfield and towards the bottom of the screen be closer.
I currently have a script attached to the ball to throw the ball forwards on the Z access at different strengths depending on how long the mouse is held down, but its nowhere near complete.
It is as follows:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Throw4 : MonoBehaviour { public float throwPowerZ = 1.0f; public float throwPowerY = 1.0f; public float throwPowerX = 1.0f; public float startTime = 0f; public float endTime = 0f; public float throwTime = 0f; public int releaseCounter = 0; public Rigidbody rb; void Update() { if (Input.GetMouseButtonDown(0)) { releaseCounter += 1; } if (Input.GetMouseButtonDown(0) && releaseCounter < 2) { startTime = Time.time; } if (Input.GetMouseButtonUp(0) && releaseCounter < 2) { endTime = Time.time; throwTime = endTime - startTime; GetComponent().isKinematic = false; rb.AddForce(throwPowerX throwTime, throwPowerY throwTime, throwPowerZ, ForceMode.Impulse); } } }
Any help would be much appreciated. Thank you!