You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make an npc that shoots at a player.
What is the issue? Include screenshots / videos if possible!
The issue is I don’t know how to calculate the direction of which the raycast will be done at.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Not much.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local RightVector = ShootPos.CFrame.RightVector
local Direction2 = -RightVector * 1000
-- the reason why it's right vector is because thats the front of the gun. Lookvector gets the side.
This is the code that calculates the direction. But it doesn’t directly shoot at the direction of the player which is what I want. If you want the full code then simply ask below.
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
you have to while true do on players humanoid root part and some complex calculating stuff, just search on YouTube how to make starring at player npc I’m not such a good teacher myself
In order to get the direction from NPC to the Player get the unit vector of the difference between their positions.
-- position of the target Player
local playerPosition = Player.Character.HumanoidRootPart.Position
local gunPosition = ShootPos.Position
-- Use this direction variable for the raycast function
local direction = (playerPosition - gunPosition).Unit
local rayLength = 500 -- the length of your bullet ray in studs
local raycastResult = workspace:Raycast(gunPosition, direction * rayLength)