Hello, I’m trying to find a way to me able to not only decelerate the balls speed faster but also a way to be able to adjust the speed of deceleration. Here I have a football/soccer ball which is being exerted a force on by BodyVelocity (I do not plan to switch to VectorForce, though I have tried it too same problem). However, the speed at which it decelerate is catastrophically small and I would like to find a better way to decelerate the ball much faster and be able to adjust it to my likings. here’s a video of the ball being exerted a force upon;
As you can see it barely slows downs. I’m currently using mouse position for the velocity. If anyone could suggest ways to help with this problem then that would be extremely helpful. I would like a way to reduce the velocity all the way to an idle state or 0
If you want a dramatic way to slow down the ball or at least have more control over its velocity, I would recommend using heartbeat to update the velocity while its not being controlled by a player.
Since it only affects the X and Z axis, you can just run:
local connection = game:GetService("RunService").Heartbeat:Connect(function(dt)
local f = .98*(dt*60) -- .98 is friction, 60 is assumed rate the server runs on ( I forgot what it was )
script.Parent.AssemblyLinearVelocity *= Vector3.new(f, 1, f) -- ignore Y axis
end)
-- disconnect the connection when a player receives the ball --
The results are decent, feel free to adjust the friction as you see fit. One additional thing is you would want to apply different friction values depending if its in the air or on the ground, or even the material of the ground if you wish.
This solution is not that accurate to how friction works, but its a quick answer that gets similar enough results.
EDIT: I assumed the script was inside the ball, but obviously you can replace script.Parent with whatever variable you have for the ball.
I’ve been using your method and so far it seem decent, however I was wondering of a way to detect if the ball is in the air or not. I’m currently using workspace:GetPartBoundsInBox but i’m not sure how to detect if the ball is in the air or not.
You can either use Raycasting, or GetPartBoundsInBox, or better yet GetPartBoundsInRadius.
The last option returns a list of parts that would collide with a given position and radius. If you take the current velocity and position, and determine where it will be in the next frame, you can predict what will hit with it, how it can bounce/reflect, and whether or not its in the air.