Attack indicator rotateAround player
hi,
i want to make an attack indicator for my 2D project. but i can't make it rotate the way i want. I want it to rotate around the player at the position of the mouse. (pic 1) I know I have to use transform.rotation but not sure how.
I want to control this rotation with my Right analog stick (PS4 Controller). so i use my left stick to move the player around, using the old unity input system. ( i don't quite undestand the new input system) and want to use the right stick to rotate the attack indicator and show where to attack.
then my 2nd question is: How do I instantiate an trigger area at the point the indicator is pointing to? Is this easily done by making a child of the indicator so it rotates with it?
Please help !
Romek
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AttackIndicator : MonoBehaviour { public Transform Player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
faceMouse();
// transform.RotateAround(Player.transform.position, Vector3.forward, angle * Time.deltaTime);
}
public void faceMouse()
{
Vector3 mouseposition = Input.mousePosition;
mouseposition = Camera.main.ScreenToWorldPoint(mouseposition);
Vector2 direction = new Vector3(
mouseposition.x - Player.position.x,
mouseposition.y - Player.position.y
);
transform.up = direction;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.RotateAround(Vector3.zero, Vector3.forward, angle * Time.deltaTime);
}
} enter code here`
Your answer
Follow this Question
Related Questions
Add force to rotate perpendicular to an object on Unity 2D 0 Answers
Move Object error with Input.GetAxis; 1 Answer
Unity 2D Character gets stuck in collider 0 Answers
Movement is jittery on Unity Remote,Movement jittery on a mobile device 0 Answers
The sample rate doesn't show up in the animation window 1 Answer