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