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

Need help, projectile script falls ontop of me not sure why?

My projectile script shoots a shadow ball thingy to the mouse, the mousepos is fired over from a localscript. It works well but sometimes it just falls on your head? help appreciated.

https://gyazo.com/90441ec262916cbbd19e76cc27157d42

local shadow = game.ServerStorage.MAGICKS:WaitForChild("Shadow")
local shadowDMG = 60

game.ReplicatedStorage.shadowService.OnServerEvent:Connect(function(player, mouse, origin)
	local character = player.Character
	local newShadow = shadow:Clone()
	newShadow.CFrame = character.HumanoidRootPart.CFrame
	
	local shadowVelocity = Instance.new("BodyForce")
	shadowVelocity.Force = (mouse.Position)
	shadowVelocity.Parent = newShadow
	


	newShadow.Parent = workspace
	
	local touchCon
	
	touchCon = newShadow.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name ~= player.Name then
				hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - shadowDMG
				if touchCon ~= nil then touchCon:Disconnect() end
				newShadow:Destroy()
			end
		end	
	end)
	
	wait(4)
	if touchCon ~= nil then touchCon:Disconnect() end
	newShadow:Destroy()
end)


1 answer

The force of your shadowVelocity should be the direction from either the character to the mouse position or the camera to the mouse position (your choice). This would be done like so...

local POWER = 10
local character = LocalPlayer.Character

local force = (mouse.Hit.Position - character.PrimaryPart.Position).Unit * POWER

or

local POWER = 10
local camera = workspace.CurrentCamera

local force = (mouse.Hit.Position - camera.CFrame.Position).Unit * POWER

The (pos1 - pos2).Unit gets a unit vector that points in the direction of pos2 to pos1. This vector is very small, so to make it a usable force you would want to add a scalar (power) to it.

1 comment

0

So instead of starting the shadow from the humaniod root part cframe, I started it from the character primary part position. I tried using the subtraction thingy with the force but it made it so it always fell of your head i tried boosting the unit power up but still to no avail

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