Trying to make dart go straight

so my dart’s velocity is so weird; idk how to improve it. when i click to shoot; my dart kinda freezes at where i want it to shoot from; but mainly my dart drops to the ground but i want it to go completely straight to the mouse position.

i appreciate any help; ty guys!

script:

	local function createDartVelocity()
		local DART_VELOCITY = 50
		local duration = 5
		
		local newForce = Instance.new("VectorForce", dartClone)
		newForce.Force = Vector3.new(0, workspace.Gravity*dartClone.PrimaryPart:GetMass(),0)
		dartClone.PrimaryPart.AssemblyLinearVelocity = CFrame.new(c:WaitForChild("HumanoidRootPart").Position, mousePos).LookVector*DART_VELOCITY
	end
	
	createDartVelocity()

Maybe you need more force by accounting for the other parts in your dart. Is it just the primary part? That’s the only force of gravity you’re countering.

1 Like

hey Alex, thanks for ur help!!!

u could be right lowkey. ill try adding more force in a second.

these are my parts in the dart:
image

Maybe just calculate the total mass of the whole dart, then multiply it by gravity and use 1 vector force. Also, be sure to apply it at the center of mass. Given there are multiple parts, the dart might rotate on you.

1 Like

Some things:

  1. You need to use the mass of the entire dart assembly when calculating the force required to counter gravity. You can get the assembly mass using BasePart.AssemblyMass (e.g. dartClone.PrimaryPart.AssemblyMass instead of :GetMass()).
  2. BasePart:ApplyImpulse() is recommended over directly setting the velocity (source). For your code, that change would look like:
local velocityDirection = CFrame.new(c:WaitForChild("HumanoidRootPart").Position, mousePos).LookVector
local dartMass = dartClone.PrimaryPart.AssemblyMass
local impulse = velocityDirection*dartMass*DART_VELOCITY
dartClone.PrimaryPart:ApplyImpulse(impulse)
  1. The freezing looks like a more complicated issue having to do with the network ownership and replication. I would need to see the code where you create the darts (e.g. if the darts are given velocity on the client or server) for more details on that. The TL;DR: is that the most optimal way is to have a “projectile buffer” of projectiles created on the server with client network ownership that the client can then use when they need to shoot a projectile. That results in zero latency for the client.
1 Like

hey Bends!!

thanks a million for your help. i got it to work. i used this:

instead of this:

and it worked perfectly after that. thanks for giving me a code example for the impulse that was a lot more intuitive. as for the freezing, i’ll have a look at it the next day but thanks for your help! :slight_smile:

	local function createDartVelocity()

		local function CalculateMassofDart()
			local totalMass = 0

			for _, part in ipairs(dartClone:GetChildren()) do
				if part:IsA("MeshPart") then
					totalMass = totalMass + part.AssemblyMass
				end
			end

			print("massofDart: "..totalMass)
			return totalMass
		end

		local DART_VELOCITY = 50
		local duration = 5

		local massofDart = CalculateMassofDart()
		local gravityForce = Vector3.new(0, -gravity * massofDart, 0)
		local velocityDirection = CFrame.new(blowgunEndCFrame.Position, mousePos).LookVector
		local impulse = velocityDirection*massofDart*DART_VELOCITY
		dartClone.PrimaryPart:ApplyImpulse(impulse)

		print("Gravity Force: ", gravityForce)
		print("velocityDirection: "..tostring(velocityDirection))
		print("impulse: "..tostring(impulse))
		
	end

	createDartVelocity()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.