Adding force to an object

Hi,
I want to make a script that creates a new part which is a sphere and also add velocity to it so that it goes into the direction the player is facing for like 2-3s before completely stopping. I never worked with this kind of stuff, I tried something but it doesn’t seem to work really.

It’s just a simple test:

local part = script.Parent

part.Velocity = part.CFrame.lookVector * 20

repeat
	
	part.Velocity += Vector3.new(0, 0, .25)
	print(part.Velocity)
	
	wait(0.01)

until part.Velocity >= Vector3.new(0, 0, 0)

It worked before but then changed directions and now it shows me an error that I am trying to compare Vector 3 to Vector 3

To apply force to an object i use a body force or a BodyVelocity, i never tried with part.velocity and never saw someone using it

2 Likes

Thanks for replying, could you show me a quick code sample of how would I use it on a part? I can’t find it on the api references page?

Yeah i think you can’t find it on api reference.

Example code:

local part = script.Parent
local Db = true

part.Touched:Connect( function()
	
	if Db == true then
		
		Db = false

		local BodyVelocity = Instance.new("BodyVelocity")

		BodyVelocity.Parent = part
		BodyVelocity.Velocity = Vector3.new(0, 50, 0)

		wait(2)

		Db = true
		
		wait(1)
		
		BodyVelocity.Parent = nil
	end
end)
2 Likes

Thank you, I didn’t realise it’s something you had to add to the part I thought it’s already in it lol.

Yeah body velocity it’s an instance. Oh and did you solved your problem?

1 Like

One last question, do you know how would I make it so that it would go towards the director the players humanoid root part is facing?

Yea I did, works great now. Just need to make it to go in the direction the player is facing.

I think yes, (don’t tested it) but if when character is added you create a little block in front of it and weld to the humanoid root part you can make:

bodyvelocity.velocity = CFrame.new(humanoidrootpart.position, littleblock.position).LookVector * 20

then the velocity will be pointing to the little block, so if the block is in front of the player the velocity will be to the direction the player is facing

1 Like

It was a popular way of applying force to BaseParts way back but the property has long been deprecated.

https://developer.roblox.com/en-us/api-reference/property/BasePart/Velocity

1 Like