How can I use clicked position for an object and camera movement at he same time?
Hi everyone.
How can I use these codes when camera is moving? Because I clicked the any button which has the script and then clicked somewhere object is moving where I clicked, but camera is not working anyhow anymore.
public void SetTargetPosition() {
if (Input.GetMouseButton(0))
{
cubes.SetActive(true);
if (EventSystem.current.IsPointerOverGameObject()) return;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Vector3 clickPosition = -Vector3.one;
if (Physics.Raycast(ray, out hit, 1000))
{
float cubeYScale = cubes.transform.localScale.z*0.12665f;
clickPosition = hit.point;
clickPosition.y = (clickPosition.y) + (cubeYScale);
cubes.transform.position = Vector3.Lerp(cubes.transform.position, clickPosition, 0.1f);
Time.timeScale = 0;
}
}
}
Camera movement codes like this: if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { newPosition += (transform.forward movementSpeed); } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { newPosition += (transform.forward -movementSpeed); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { newPosition += (transform.right movementSpeed); } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { newPosition += (transform.right -movementSpeed); }
Answer by iR3dyPlayZ · Oct 21, 2020 at 02:26 PM
Go here https://www.youtube.com/c/SebastianLague I believe that he has a tutorial on the movement you're asking about.
Your answer
Follow this Question
Related Questions
Camera yMin postion should be restricted to player postion 1 Answer
I build a own game but i have a cam problem 0 Answers
my camera wont stay with my player after assigning the player as a target 0 Answers
Camera not following 2D character when the character reaches the ground. 0 Answers
C# Smooth Follow Space Ship 1 Answer