How would I go about creating a brick that launches whatever touches it toward the brick's LookVector?

The idea is essentially a cannon, and the cannon balls are the player characters, which are actually balls. I tried using velocity, but it didn’t work out.

Velocity should work, may I see a code snippet?

I don’t understand CFrames yet, so I didn’t bother to include the LookVector code.

Debounce = false

script.Parent.Touched:Connect(function(Ball)

if Debounce == false then
	Debounce = true
		Ball.Velocity = Vector3.new(0,100,0)
	wait(.5)
	Debounce = false
end	

end)

Technically that should add upwards velocity,
Are any errors thrown?

There are none.

Sadly as I am overseas I don’t have access to studio, I hope that someone can fix your script.

Your script seems fine, why not just replace Vector3.new(0,100,0) with script.Parent.CFrame.LookVector?


Debounce = false

script.Parent.Touched:Connect(function(Ball)
	if Debounce or not Ball:FindFirstChild("BodyVelocity") then return end
	Debounce = true
	Ball.BodyVelocity.Velocity = script.Parent.CFrame.LookVector
	wait(.5)
	Debounce = false
end)

script.Parent.CFrame.LookVector * velocitySpeed

Roblox directional vectors have a magnitude of approximately 1. You want to times them by a high value, like 100 if you want the characters to actually be shot out. You should also delete the BodyVelocity shortly after adding it, or the player will shoot out indefinitely. It would be better to do add and remove the BodyVelocity on the client, because its possible that there will be more lag when adding the velocity, than when removing it, so players will be flung for variable amounts of time, rather than a precise 0.5 seconds.

2 Likes

It is launching it in the right direction, but after a second the ball just stops and falls to the ground.

(This is for the client, server side it doesn’t work at all.)

Is network ownership set to the client who is changing the velocity? If not, setting velocity from the client will only work if the player is the closest player to the object, and it is within a certain distance. When the ball is pushed out of that certain distance, physics will go back to either the server or another client, and it will stop midair.

Yes, the network ownership is set to the ball.

Just to be clear, you mean network ownership is set to the part with the BodyVelocity right? Do you mind showing what the script looks like now?

Hello, asking a question four years later, lol. How would I do this, except without lookvector mattering. In other words, the brick simply launches players upwards a lot. Im very new to scripting!