BodyVelocity better than Velocity in the properties?

I’m working on an arena where if the Client lands in the pit, their character bounces up into the air with the addition of losing a life from their heart. Primarily, I’m just focusing the bouncing part.

I’ve been tinkering with the Velocity in the properties and I’ve got say that it doesn’t really do so well. Sometimes the Roblox’s physics engine can’t comprehend how high the character should really be going up.

So I’ve create this chunk a code where it inserts a BodyVelocity within a character for only a quarter of a second, then destroys that said velocity.

I’ve gotta say, the results are pretty differential and I’m preferring BodyVelocity over the Property one. I wish this DevForum would allow me to post videos for me to show, but alas it still has problems with Quicktime for me.

Basically, I’m just wondering if this script is impractical:

LocalScript in StarterGui

local RemoteEvent = script.Events:WaitForChild("Bounce")
local debounce = true

local Player = game.Players.LocalPlayer
game.Workspace:WaitForChild(Player.Name)
 
game.Workspace.BouncePart.Touched:Connect(function(hit)
	if debounce then
		debounce = false
		
		RemoteEvent:FireServer() -- Fire remote
		
		debounce = true
 	end
end)

RemoteScript

local RemoteEvent = script.Parent.EventsFolder:WaitForChild("Bounce")

RemoteEvent.OnServerEvent:Connect(function(Player)
	
	local Vel = Instance.new("BodyVelocity")
	Vel.Parent = Player.Character.Torso
    Vel.Name = "BounceVelocity"
    Vel.MaxForce = Vector3.new(0,math.huge,0)
	Vel.P = math.huge
	Vel.Velocity = Vector3.new(0,100,0)
	
	wait(.25)
	
	for _, v in pairs(Player.Character.Torso:GetDescendants()) do --Just in case there's too many velocities being created
		if v:IsA("BodyVelocity") then
			v:Destroy()
		end
	end
end)

Will I be facing some performance issues by doing this rather than doing trusting the Velocity within the Part properties?

EDIT: Realized this is more of a #help-and-feedback:code-review question rather than a #help-and-feedback:scripting-support question.

1 Like

Creating a new instance will always have more of a performance impact than changing the property directly; that being said, you don’t seem to be relying on it that much so it should be negligible.

BodyVelocity I think is less responsive than manually setting velocity or CFrame properties - I’m not sure why that would affect how velocity is set (difference in a frame at most) but surely there are some internals in BodyVelocity that give you the desired outcome…

In larger servers though it might have an impact. Instead of creating and destroying the BodyVelocity every time you need it, why not create one for every player that joins, and parent it to the torso when they need it? Then unparent it when you no longer need it, and when they leave you can destroy it. That might help in terms of scalability

1 Like

I’m intrigued with the idea of only creating a new instance when absolutely necessary and just keeping it parented. Thanks 8)

1 Like

Just a heads up, this has memory implications. Depending on your bottleneck (memory vs. performance) you would want to consider either option :slight_smile:

1 Like