How do I make it so that when the player shoots a bullet, and it hits an NPC, they can see where they shot the NPC at? I want to do something like the game Hunting Season; here is a screenshot from it:
This can be accomplished pretty easily using vectors by storing the relative hit position, hit object, bullet direction, and bullet origin after hitting the target. Here’s an example of what you could do:
-- below are variables depending on your own code for handling the gun(s)/hits, set accordingly
local bulletDirection = Vector3.new(1,0,0) -- set to unit vector of the bullet's direction
local bulletSpeed = 100 -- speed of the bullet in studs/s
local bulletOrigin = Vector3.new(0,20,0) -- set to position the gun was fired from
local hitObject = part -- set to part the bullet hit
local hitPosition = bulletHitPosition - part.Position -- gets the relative position to the hit
-- determined variables
local distance = (hitPosition - bulletOrigin).Magnitude -- distance bullet travelled in studs (straight line)
local travelTime = distance/bulletSpeed -- seconds it took to hit from origin
print("distance:",distance)
print("travel time:",travelTime)
-- visual line "arrow" of impact
local arrowLength = 5
local arrowThickness = 0.2
local line = Instance.new("Part")
line.Anchored = true
line.CanCollide = false
line.Size = Vector3.new(arrowThickness,arrowThickness,arrowLength)
line.CFrame = CFrame.lookAt(part.Position + hitPosition - bulletDirection*arrowLength*0.5, part.Position + hitPosition) -- basically, set the origin position to the bullet hit position moved back in the bullet's direction by half the arrow length (in the center of the arrow's tip and tail), and face the z axis towards the bullet hit position to correctly rotate the arrow
line.Color = Color3.new(1,0,0)
line.Parent = workspace
Hopefully this helps! Let me know if you have any questions.