How to rotate object based on cursor position
I want to create an AirStrike ability for a RTS game. Before the planes launch, I want to set the position and rotation of the "Strike Zone". I have this code, where I can rotate the object, but not on the mouse position.
Here is the code: public class AirStrikeAbility : MonoBehaviour { public float rotSpeed = 20;
public GameObject camera;
public bool mousePressed = false;
// Update is called once per frame
void Update()
{
if (mousePressed == true)
{
camera.GetComponent<RTSCameraController>().enabled = false;
}
}
private void OnMouseDown()
{
mousePressed = true;
}
private void OnMouseDrag()
{
float rotX = Input.GetAxis("Mouse Y") * rotSpeed * Mathf.Deg2Rad;
transform.RotateAround(Vector3.up, -rotX);
}
private void OnMouseUp()
{
mousePressed = false;
camera.GetComponent<RTSCameraController>().enabled = true;
}
}
Answer by junk_rat_angel · Aug 11, 2021 at 09:30 PM
What do you mean by rotate based on cursor position? Its hard to visualize your problem or what your trying to accomplish from the details here
Your answer
Follow this Question
Related Questions
Why do custom hardware cursors only work in exclusive mode? 0 Answers
MouseOver 1 Answer
How can I make my cursor to follow more faster? (there's too much delay) 0 Answers
Is it possible to make a cursor using right stick axis of an xbox controller? 0 Answers
Determine which of two rotation options is less rotation 2 Answers