Reputation: 95
I’m starting a learning project. The idea is that you have an archer character that is static, that has a bow attached to it that shoots arrows to targets of varying difficulty. Turns out that right at the start I’m stuck. How do I make it so that the bow rotates when the player clicks and holds the mouse anywhere on the screen? So I click+hold and move left/right and the bow rotates left/right to aim the shot. I’d like to also eventually make it portable to phones (so you’d tap+hold etc).
Upvotes: 0
Views: 1623
Reputation: 8163
Stack Overflow isnt a code writing service but i will explain what you must do:
For every frame the mouse is down:
Ray
from a screen point... hint (use
camera.ScreenPointToRay
).Ray
using ray.GetPoint(distance);
.Bow.Transform.LookAt(newPoint, Vector3.Up);
.oldMousePos
to store a Vector2
location.(newMousePos - oldMousePos).normalized;
.(newMousePos -
oldMousePos).sqrMagnitude;
.Upvotes: 1