2D TopDown rotating a gun according to its parent position, ON MOBILE, not PC,
Before thinking anything, its not for windows. If it would have been for Windows it would have been pretty easy... I am making it for mobile.
I have a player that can go Left or Right, Up or Down, using a JoyStick ( if you are not familiar with how one works, is gives the horizontal value ( from 1 to -1 ) and same for vertical, based on those I am moving my player ).
Now, I added a gun to the player, as its child. Beforehand, the player does NOT rotate, it simply changes position, therefore my child will not rotate after its parent, but only change position accordingly.
THE BIG PART... How on earth am I supposed to rotate the gun according to the players position? One is a quaternion and one is a vector. Also, I can not make a "directionToFace", in order to use Quaternion.LookRotation();
This is how I am moving my player :
hor = js.Horizontal;
ver = js.Vertical;
if (hor > 0) //WALK RIGHT
{
Vector3 rightMove = new Vector3(hor * sens * Time.deltaTime, 0.0f, 0.0f);
transform.position += rightMove;
ar.SetFloat("Horizontal", hor);
ar.SetBool("isIdle", false);
}
if(hor < 0) //WALK LEFT
{
Vector3 leftMove = new Vector3(hor * sens * Time.deltaTime, 0.0f, 0.0f);
transform.position += leftMove;
ar.SetFloat("Horizontal", hor);
ar.SetBool("isIdle", false);
}
if(hor == 0) //MAKING SURE IT GOES BACK TO "IDLE"
{
ar.SetBool("isIdle", false);
}
if(ver > 0) //WALK UP
{
Vector3 upMove = new Vector3(0.0f, ver * sens * Time.deltaTime, 0.0f);
transform.position += upMove;
ar.SetFloat("Vertical", ver);
ar.SetBool("isIdle", false);
}
if (ver < 0) //WALK DOWN
{
Vector3 downMove = new Vector3(0.0f, ver * sens * Time.deltaTime, 0.0f);
transform.position += downMove;
ar.SetFloat("Vertical", ver);
ar.SetBool("isIdle", false);
}
if (ver == 0) //MAKING SURE IT GOES BACK TO "IDLE"
{
ar.SetBool("isIdle", true);
}
I am working on this part for so darn long, its easier to make the AI lmao. Anyone? Thanks!
,
Your answer
Follow this Question
Related Questions
Lock Rotation of Object between 2 points, which is looking at the direction the mouse is pointing 1 Answer
Rotation issue when selecting a new waypoint. 0 Answers
Rotating weapon in top-down 2D 0 Answers
can't figure out top down 2D rotation (noob) 0 Answers
Problem with projectile rotation - 2D 0 Answers