- Home /
how to make an object move towards it's rotation a set amount as a child in 2d
So basically, I wanted to make a circle seem like it was holding a bow, and appearing aiming at the cursor whenever I click anywhere. Currently, I've got the rotation working, but it just overlaps with the player, instead of "holding" it. Then, I wanted to make it so that it moves towards it's rotation a set amount so that it looks like it is holding it (similar to how players in terraria holds bows). However, I just can't get it to work, when I adds the code it just does nothing. Here's the code:
aimTransform.eulerAngles = new Vector3(0f, 0f, -(angle -= 90f));
aimTransform.transform.position += transform.forward * Time.deltaTime * 100.0f;
yield return new WaitForSeconds(1f);
the middle line is what I'm talking about. It just does... nothing. I did however look up on Google, but a lot of then seems outdated (most of them were like 3-5 years ago). One of then mentioned using transform.up or transform.right in 2d depending on the rotation, but for me none of them works. (note: this is a re-asked question. my last question(the same question) was somehow "awaiting moderation.", so I deleted it.)
Try this:
Vector3 dir = new Vector3(0f, 0f, -(angle -= 90f));
Quaternion rotation = Quaternion.LookRotation(dir, Vector3.up);
aimTransform.rotation = rotation;`