How do I make a ball curve?

Hello, I am guesti

I am working on a football game where you can kick the ball and it curves. I have tried this:

local function spawnCurve(force)
			if plr.PwrData.Curve.Value == "Right" then
					if force then
						wait(0.10)
					for i = 0, 0.25, 0.01 do
						force.Velocity = force.Velocity - Vector3.new(2.5, 0, 0)
						print(force.Velocity)
					end
				end
			end

And it does not curve. Please let me know

You can use BĂ©zier Curves to make the ball curve.

3 Likes

Hell no thats a terrible way. Very Imprecise.

What I would do is have a max “curve offset”.
You could just lerp between 0 and the max curve offset(would be magnitude), then mutliply this lerped value by your vector.

You could also use a Catmull rom or natural spline, but those are very complex 11 row 11 collumn rotational matrixes and a nightmare to work with.

I have no idea what this means.

If you really can’t do all the maths, Egomoose has already done something similar (except with basketballs) which you can repurpose for your own game.

1 Like

Before you try doing curves, you should do straight shots (Which you probably have, since youre asking for curves). Curves could act as an extension of straight shots. Add a VectorForce to the ball for the curve, and along with the normal straight shot calculation, you would have to calculate a curve to put into the vectorforce to act on the X axis.

You could achieve this by modeling the curve via a tween first, which is what I did when working on my current football game project. Then make the calculations using the tweened example as a guide. The curve value should be entered like ; yourVectorForceName = Vector3.new(0, CURVEVALUE, 0) and it should go left or right depending on if it is positive or negative.

To make it fullproof, get the curve value magnitude then, get the base straight shot direction in the X - Axis, Make a function that can return its direction; (For example, if Normal Shot X direction is -3, the direction is negative, so to the east, and should return -1, or “east”, or “negative” or something similar just to know what direction) then just multiply that to the curve magnitude. If you found this helpful or have any questions feel free to ask.

3 Likes

1 Like

Like this for modeling the tween

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.