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

How do I make body velocity push a brick in the direction the torso is facing?

Hi, i was wondering. How do you make it so that the BodyVelocity thing fires out the object in accordance to the Torso ??

Example, the brick is created. You create a BodyVelocity and assign the velocity. This does not work, and I thought it would:

local BodyVelocity = Instance.new("BodyVelocity") BodyVelocity.Parent = power local multiplier = 50 local pos = CFrame.new(0,0,-multiplier) * (torso.CFrame.lookVector * 1) BodyVelocity.velocity = pos

1 answer

Credit to UserOnly16Characters for making me explain my code

Credit to Spongocardo for pointing out an error



When I tested that then it worked perfectly, in the correct tool setting of course.

The code I used(localscript in hopperbin in starterpack);


local plr = game.Players.LocalPlayer --Get the player

--Make a function to add force to the object, relative to the torso
function push(obj,torso)
	local BodyVelocity = Instance.new("BodyVelocity",obj)
	local multiplier = 50 --How much force to push them by
	--Mulitply the force on the negative Z axis(pushing back), from the torso's lookVector
	local pos = CFrame.new(0,0,-multiplier) * (torso.CFrame.lookVector * 1) 
	--Apply the force
	BodyVelocity.velocity = pos
end

--When the hopperbin is selected, or if it was a tool the term would be 'Equipped'
script.Parent.Selected:connect(function(mouse)
	--When they left click
	mouse.Button1Down:connect(function()
		--Get the part their mouse is on
		local brick = mouse.Target
		--Check if the brick is anchored or not
		if not brick.Anchored then
			--Call the function to add the BodyVelocity
			push(brick,plr.Character.Torso)
		end
	end)
end)

And perhaps you could credit me next time you decide to post code of mine(:

5 comments

2

It would be nice if you could explain how the script works so people who are new to SH could learn from it.

0

It's the same script, just in a tool setup.

0

But you're right(:

1

I think you were meant to comment on line 3. :P

0

Thx

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