Spring player forward and up when touches part

I am trying to code a block that when a player touches propels the player in a certain direction forward and up,

Below is what I have so far but does not work as propels the player the direction they touch the part, is there a better way to do this and get working?

local cd = false
script.Parent.Touched:Connect(function(hit) --script.Parent is a part, in Workspace
	if cd then return end
	cd = true
	if hit.Parent:FindFirstChild("Humanoid") then
		
		local veloc = Instance.new("LinearVelocity",hit.Parent)
		
		veloc.Attachment0 = hit.Parent.HumanoidRootPart.RootRigAttachment
		veloc.VectorVelocity = (hit.Parent:GetPivot().LookVector*5 + hit.Parent:GetPivot().UpVector*5)*5
		
		--LookVector is the direction the player is looking at - when looking straight forward, this is (0,0,-1)
		
		--UpVector is the direction which is defined as up - by default, this is (0,1,0)
		
		veloc.MaxForce = 8000
		veloc.RelativeTo = Enum.ActuatorRelativeTo.World
		game:GetService("Debris"):AddItem(veloc,2)
	end
	wait(2)
	cd = false
end)
1 Like

Do you want the player to be propelled forward in the direction of the touched part? Or in the direction the character is facing when they touch the part?

Hi, thanks for the reply, the direction of the part so it sends the player in only one direction…

Thanks

Can anyone help with this as cant understand how to get it working

Try to increase MaxForce the character need a certain high number to have enough force to make player go upward

local cd = false
local launchDir = script.Parent.CFrame.LookVector+Vector3.new(0,1,0) -- if the part changes orientation during tbe game move this into the function

script.Parent.Touched:Connect(function(hit)
	if cd then return end
	cd = true
	if hit.Parent:FindFirstChild("Humanoid") then
		local veloc = Instance.new("LinearVelocity",hit.Parent)
		veloc.Attachment0 = hit.Parent.HumanoidRootPart.RootRigAttachment
		veloc.VectorVelocity = launchDir*5
		veloc.MaxForce = math.huge
		veloc.RelativeTo = Enum.ActuatorRelativeTo.World
		game:GetService("Debris"):AddItem(veloc,2)
	end
	task.wait(2)
	cd = false
end)

1 Like

Thank you perfect and just what I needed.

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