Question by
ErtyumPX · Aug 16, 2019 at 11:51 PM ·
rotationgameobject
Rotating an object by the sides
I'm new in unity and im trying to have some fun with a stickfigure. I'm trying to make the arms of stickfigure to follow my mouse position but it always getting rotate by the center of the arm. I attached the part of my stickman with HingeJoint2D and i want to rotate the arm by the joint point.
I tried these codes on the arm but as i said it rotated by its center.
void Update ()
{
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
difference.Normalize();
float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotationZ + 180);
}
stickfigure-question.jpg
(56.3 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612210742im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotating the player with mousePosition problem. 0 Answers
How to create a rotating floor upon player collision with object? 0 Answers
After Rotating a Prefab, Transform.Position of children is inaccurate 1 Answer
Apply the Camera Rotation Y to Player Gameobject Y 0 Answers
How to rotate my gameObject using Joystick control? 1 Answer