Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

AI Aiming for Player?

I'm working on an AI Archer and have made a working bow, and working(almost) bow shooting script. The only problem I'm having is finding a way to find the direction to shoot the arrow in order to shoot it towards a player. The arrow shooting script basically just creates and arrow, and shoots it via

shot.Velocity = 130 * direction---(direction is what needs to be defined)

For the player's bow, I just uses mouse.Hit.lookVector for the direction. Anyone know how I might find the direction from the AI's head for example, to the player's head? Hopefully that makes sense, if you need further info, leave a comment. Thanks.

1 answer

✓ Accepted answer

The direction for a -> b is, counterintuitively, b-a

local direction = (playerHead.Position - archerBow.Position).unit

That will be the lookvector to use.

This discussion is preserved as it was. New answers, comments, and votes are closed.