Making projectiles target a player but keep moving if they miss?

Basically i want projectiles to target something, but if they miss they keep moving. I was thinking I could probably do it with BodyVelocity but I’m not sure how.

example of what i’m talking about (its timestamped for you):

Should be easy enough with tween … target the direction where they are at the moment and play() …
Stop the tween if it hits or if it goes off screen.

wouldn’t it just stop automatically upon reaching the goal?

Not if you didn’t give it a goal and just a direction to move in.

can you send an example? I’m not sure how i’d do that

1 Like

Based on the video, you’d just need the direction from the projectile to the player.

local humanoidRootPart = humanoidRootPart
local projectile = projectile
local projectileSpeed = 50 -- how many studs/second projectile moves

-- to get the direction between two objects, subtract the origin position from the goal position
-- in this case, the origin is the projectile's position and the goal position is the humanoidRootPart position
local direction = (humanoidRootPart.Position - projectile.Position)
projectile:ApplyImpulse(direction.Unit * projectileSpeed)
2 Likes

This would work also … I was thinking tween as you could do just as you see in that video with some tween codes. Not really that hard to work with basically a animation sub language. So it’s just what you need for that. Tween is a big subject, however … you’ll need to study up on that. Well worth the time to put into it.

2 Likes

It mostly depends on the use case on what you’re trying to achieve here, the video you’ve shown has Projectiles starting out slow, but progessively over time it starts to become faster

You got multiple options to choose from here:

  • Creating a set path for the Part to follow via TweenService
  • Using Physics that’ll interact upon collision with the object (This would probably be your best bet)

Either way, you’d have to reference the Target’s HumanoidRootPart to be able to rotate the Projectile to its desired angle where you want it to move from cause without a Target you wouldn’t be able to reference where the Projectile is going

What you would be looking for is the LinearVelocity Class Object instead :wink: as BodyVelocity would now be deemed as
a deprecated instance

I would personally look into 1 of my older posts, that completely explains how you’d handle Projectiles using Physics & how a basic concept about it could work :wink:

All you’d have to do, is create both an Attachment for the Projectile, and a LinearVelocity for that Attachment to hook onto

The only difference that you’d need to change is to remove the while not Exploded do loop involved with it, as I specifically focused on making a tracking projectile & it can easily be removed by commenting out that specific loop

local RS = game:GetService("RunService")

local MaxSpeed = 25
local Exploded = false
local MainTarget = workspace:WaitForChild("Dummy")

local Part = script.Parent

local PartConnection
local function Touched(Hit)
	local Target = Hit.Parent
	
	if not Target then return end
	
	local Hum = Target:FindFirstChildOfClass("Humanoid")
	
	if Hum ~= nil then
		PartConnection:Disconnect()
		
		Exploded = true
		
		for _, Part in pairs(Target:GetDescendants()) do
			if Part:IsA("BasePart") then
				Part:BreakJoints()
			end
		end
		
		local Explosion = Instance.new("Explosion")
		Explosion.Position = Part.Position
		Explosion.Parent = workspace
		
		Part.Explode:Play()
		Part.Anchored = true
		Part.Transparency = 1
		
		Part.Explode.Ended:Wait()
		
		Part:Destroy()
	end
end

PartConnection = Part.Touched:Connect(Touched)

Part.CFrame = CFrame.new(Part.Position, MainTarget.HumanoidRootPart.Position)
Part.LinearVelocity.VectorVelocity = Part.CFrame.LookVector * MaxSpeed

--while not Exploded do (This is only if you want the Projectile to lock onto a target)
	--Part.CFrame = CFrame.new(Part.Position, MainTarget.HumanoidRootPart.Position)
	--Part.LinearVelocity.VectorVelocity = Part.CFrame.LookVector * MaxSpeed
	--RS.Stepped:Wait()
--end
5 Likes

This looks interesting … many links also.

BézierTweening | Simple tweening along bezier curves

I ment @ WinterFire