Apply forces to the humanoidRootPart

Hello! I’m trying to apply a force to the player but i see no difference, the main part is that i have a ball attached to the player and I want to apply a force to create a drift, so if the player input A or D the force will apply in the opposite direction to make a drift movement, but i dont know if im doing good or not.
Here my code:

local function ApplyDriftForce(direction)
	local forceMagnitude = 1000 -- Ajusta la magnitud de la fuerza según sea necesario para el efecto de derrape
	local oppositeForce = Instance.new("VectorForce")
	oppositeForce.Force = direction * forceMagnitude
	oppositeForce.Parent = player.Character.HumanoidRootPart
	wait(1) -- Puedes ajustar la duración de la fuerza para el derrape aquí
	oppositeForce:Destroy() -- Eliminar la fuerza después de cierto tiempo
end

ApplyDriftForce(Vector3.new(-Xdirection, 0, -Zdirection)) --Depending on direction

I anyone can help me or provide example ill appreciate! Thanks! :smiley:

You have to apply the VectorForce to an Attachment. Make an attachment and parent it to the HRP of the Character and then do oppositeForce.Attachment0 = AttachmentInsideHRP. That should do it

1 Like

Also since your dealing with physics you need to set the NetworkOwnership.

I did this but still don’t notice the force applied

local function ApplyDriftForce(direction)
	local forceMagnitude = 1000 -- Ajusta la magnitud de la fuerza según sea necesario para el efecto de derrape
	local oppositeForce = Instance.new("VectorForce")
	local attachment = Instance.new("Attachment")
	attachment.Parent = player.Character.HumanoidRootPart
	oppositeForce.Force = direction * forceMagnitude
	oppositeForce.Parent = player.Character.HumanoidRootPart
	oppositeForce.Attachment0 = attachment
	wait(1) -- Puedes ajustar la duración de la fuerza para el derrape aquí
	oppositeForce:Destroy() -- Eliminar la fuerza después de cierto tiempo
end

This worked (modify it as per needs)

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

local function ApplyDriftForce(direction)
	local forceMagnitude = 1000 -- Ajusta la magnitud de la fuerza según sea necesario para el efecto de derrape
	local oppositeForce = Instance.new("VectorForce")
	oppositeForce.Force = direction * forceMagnitude
	
	--> Attachment
	local Attach = Instance.new("Attachment")
	Attach.Name = "ForceAttachment"
	Attach.Parent = Character:WaitForChild("HumanoidRootPart")
	oppositeForce.Parent = Attach
	oppositeForce.Attachment0 = Attach
	wait(1) -- Puedes ajustar la duración de la fuerza para el derrape aquí
	oppositeForce:Destroy() -- Eliminar la fuerza después de cierto tiempo
end

ApplyDriftForce(Vector3.new(-500, 0, 0)) --Depending on direction

1 Like

I think im getting it, Im gonna try to modify some values and see how it looks like :smiley:

made a parabola and now kinda works better with the movement, thanks! here the code:

local function ApplyDriftForce(direction, key)
	local oppositeForce = Instance.new("VectorForce")
	local forceMagnitude = 30000 
	oppositeForce.Force = direction * forceMagnitude *4
	--> Attachment
	local Attach = Instance.new("Attachment")
	Attach.Name = "ForceAttachment"
	Attach.Parent = player.Character:WaitForChild("HumanoidRootPart")
	oppositeForce.Parent = Attach
	oppositeForce.Attachment0 = Attach
	
	rotation = player.Character.HumanoidRootPart.Orientation.Y
	Xdirection = -math.sin(math.rad(rotation))
	Zdirection = -math.cos(math.rad(rotation)) 

	wait(.1)
	oppositeForce:Destroy()
end
1 Like

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