Making Ball Move in Only Two Dimensions

I’m trying to make a 2.5D soccer ball (it’s actually a cylinder on its side so that it looks like a soccer ball head on) that can only move on the X and Y axis. It will be able to move left and right, up and down, but not back and forth. I have tried many things, but nothing has seemed to work.

I have put a bodygyro into the soccer ball so that it won’t flop over.

I have tried changing the CFrame of the soccer ball to match where it should be in a while loop. I have tried to use legacy movers and constraints to no avail.

Here is the closest thing I have to perfection:

while wait(0.1) do
	local ball = workspace:WaitForChild('GameInteraction'):WaitForChild('Ball')
	local pos = ball.CFrame.p -- Line 3
	ball.CFrame = CFrame.new(pos.X,pos.Y,75)
	local ori = ball.Orientation.X
	print(ori) -- Line 6
	ball.CFrame = ball.CFrame * CFrame.Angles(ori,math.rad(-90),0) --this line
end

The only problem with this script is that the ball’s X axis is 0, because on line 4, the CFrame is reset, and so is the orientation. Here is a video:
robloxapp-20200808-0122129.wmv (2.7 MB) The gray thingy kicks the ball

I thought that I could fix this by putting line 5 between lines 3 and 4:

while wait(0.1) do
	local ball = workspace:WaitForChild('GameInteraction'):WaitForChild('Ball')
	local pos = ball.CFrame.p -- Line 3
	local ori = ball.Orientation.X
	ball.CFrame = CFrame.new(pos.X,pos.Y,75)
	print(ori) -- Line 6
	ball.CFrame = ball.CFrame * CFrame.Angles(ori,math.rad(-90),0)
end

The code above instead resulted in a bunch of weird stuff happening with the soccer ball. It was shaking all around. Here is a video of it happening:
robloxapp-20200808-0131442.wmv (3.8 MB)

Edit: The problem that I had in post #4 was solved in post #5 by @darthbl0xx

2 Likes

BodyPosition!!!

That’s the first thing that comes to my mind. Put a BodyPosition object in the soccer ball, and modify its MaxForce property so that it only applies force on the Z axis.

The only time you would need a script in this situation is if you needed to change the ball’s position on the Z axis in-game. Otherwise, this should work code-free.

Hope this helped!

1 Like

Send me a link to the game once it’s complete please

This worked perfectly at keeping the ball where it needs to be!

Sure thing!

There is another problem, though. When the ball is turning and it goes over 90 deg, it flips over. Here is a video of it happening:
robloxapp-20200810-1416265.wmv (1.0 MB)

Edit: This post solved in post #5

Are you using any kind of script on your ball, still?

I made my own soccer cylinder to try and replicate the bug, but it didn’t come up. I’m guessing it has something to do with code or another object inside your ball.

While messing around with it, though, I found something else. I had to use a BodyAngularVelocity object to keep the ball from tipping over or spinning around. Set the AngularVelocity property to (0, 0, 0) and apply force on two axes, but not the third. You may have to mess around with the axes to figure out which one is the right one for your ball, but other than that it should work just as smoothly as BodyPosition.

1 Like

Thanks, this worked perfectly! I would mark this as the solution, but unfortunately, I can only mark one.