[SOLVED]A fan system and BodyVelocity, need help

Hello,

This is my first topic on the Developer Forum.

I’m currently creating my game, an Obby, with a time system, etc… I want to warn you that I’m still a novice in programming and that I’m trying to learn, I think with some basics, but they are consolidated.
For the traps, I thought about a fan that pushes the players, after several researches I found a solution, but I can’t understand very well how it works, “BodyVelocity”. I found the one thanks to (Pushing fan player - #2 by GalaxyGourmet) and (How to Use BodyVelocity).

So I started to find out more about BodyVelocity and I understood something about it.

Here’s my code:

local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Velocity = Vector3.new(-1,0,0)
BodyVelocity.P = math.huge
BodyVelocity.MaxForce = Vector3.new(math.huge,0,0)
BodyVelocity.Parent = part.Parent.HumanoidRootPart
wait(2.5)
BodyVelocity:Destroy()

On this page one of them, @fego2015, has a system that I would be interested in, so I’m asking you, if you can make me a script that would do the same thing as @fego2015, and if possible also, if you could explain to me what the three following properties of “BodyVelocity” correspond to:

  • .Velocity
  • .P
  • .MaxForce

I think I understood Velocity, that to prohibit or not, the movement on the axis, but I don’t know more.

So I would like my fan to push the player in one direction, and that the player can always move forward, backward, “counter” this force.

Thanks for all.

3 Likes

Here are the properties of BodyVelocities.

I’m gonna make a fan demo for you, give me a sec.

1 Like

https://developer.roblox.com/en-us/api-reference/class/BodyVelocity/index.html

1 Like

Thanks, for the property, i see it before, but, for example, the MaxForce, how many force our character make basicly ? because i don’t know, what i should set here.

I usually set MaxForce to Vector3.new(math.huge, math.huge, math.huge) which puts a lot of force on the character. It prevents other forces from changing the characters direction.

Ok thanks, i waiting for your demo, a big thanks again x)

Ok, I finished the demo!

Here’s the place: Warcraft945 - Fan System - Roblox. It’s uncopylocked, so you can download it.

Here’s the code for those who want to see it:

-- << Variables >>
local fanHitbox = workspace["Industrial Stand Fan "].Propeller.Hitbox
local debounceTracker = {}

-- << Functions >>
local function applyVelocity(character)
	local BV = Instance.new("BodyVelocity") -- Create the BodyVelocity
	
	BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BV.P = 500
	BV.Velocity = fanHitbox.CFrame.LookVector * 70 -- This will push the player away from the fan
	
	BV.Parent = character:FindFirstChild("HumanoidRootPart")
	
	game.Debris:AddItem(BV, 3) -- Destroy the BodyVelocity after 3 seconds
end

local function removeVelocity(character)
	character.HumanoidRootPart.BodyVelocity:Destroy()
end

-- << Connections >>
fanHitbox.Touched:Connect(function(hit)
	if debounceTracker[hit.Parent] then return end -- Make sure the character hasn't already been pushed back
	
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local Character = hit.Parent
		debounceTracker[Character] = true
		
		applyVelocity(Character)
	end
end)

fanHitbox.TouchEnded:Connect(function(hit)
	if debounceTracker[hit.Parent] then
		debounceTracker[hit.Parent] = nil
		removeVelocity(hit.Parent)
	end
end)
1 Like

Thanks u very much, i will closed the topic, so, thanks again, have a good day

1 Like