Why does my ball not collide with the cups or any other parts nearby?

So basically I’m currently making a cup pong system that whenever I click with my mouse around here and there the ball goes in that direction and it follows a certain trajectory which I have defined in my code.

But here’s the issue even though CanCollide is true, the ball while moving doesn’t collide with anything at all or doesn’t fling with the edges of the cups or anything like that.

I know the issue might be the RunService but how else would I make the ball move if there is no RS involved.
I have taken the eq.s of motion of the ball from this guide given by @EgoMoose Basketball shooting

Here is the code

local t = 1;
	local mouse = game.Players.LocalPlayer:GetMouse();
	local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart");
    local bball = game.Workspace.Pong.Balls.Part;
	local rs = game:GetService("RunService").RenderStepped;
	 
	mouse.Button1Down:Connect(function()
		    local g = Vector3.new(0, -game.Workspace.Gravity, 0);
	        local x0 = bball.CFrame * Vector3.new(0, 0, 0)
		 
		    
		    local v0 = (mouse.Hit.p - x0 - 0.25*g*t*t)/t;
		 
		    local c = bball:Clone();
		    c.CanCollide = false;
		    c.Anchored = true;
		    c.Parent = game.Workspace;
	
		 
		    
		    local nt = 0;
		    while (nt < t) do
			        c.CFrame = CFrame.new(0.5*g*nt*nt + v0*nt + x0);
			        nt = nt + rs:Wait();
	   	    end
		end)

It seems that the ball isn’t colliding with anything because it’s moving by CFrame, so it doesn’t even acknowledge any collidable parts and just goes through everything. Basically, it’s “teleporting” bit by bit to move instead of actually moving.

You can probably use constraints for your problem, but I’m currently not sure how to apply them with your script. I’ll get back to you if I figure it out (which I can’t guarantee). Meanwhile, you can experiment with constraints. You could also try searching through the toolbox to find similar examples, like grenades (just watch out for ones that use Part.Velocity, as that’s a deprecated method).

Also this probably doesn’t matter anyway but you said the ball is collidable but your script shows it’s set to not collidable so I’m confused?

2 Likes

Hey Denny thanks for replying, you are right actually I just noticed that, however alternatively I used this at the moment and this should work however all this is doing is just changes its CFrame and I dont see the ball actually moving

local t = 1;
local mouse = game.Players.LocalPlayer:GetMouse();
local ball = game.Workspace.Pong.Balls.Part;

mouse.Button1Down:Connect(function()
	print("button pressed")

	local g = Vector3.new(0, -game.Workspace.Gravity, 0);
	local x0 = ball.CFrame * Vector3.new(0, 0, 0)

	
	local v0 = (mouse.Hit.p - x0 - 0.5*g*t*t)/t;

	
	local c = ball:Clone();
	c.Velocity = v0;
	c.CFrame = CFrame.new(x0);
	c.CanCollide = true;
	c.Parent = game.Workspace;
end)```

Actually I just tested your script and it seems to work:

ThrowGIF

Note that the ball is cloned and thrown from where the original ball is located. Also make sure the ball isn’t anchored, or at least do c.Anchored = false in your script under the c variable. You can also delete the c.CFrame = CFrame.new(x0) line since it’s actually moving by physics now, not CFrame.

Also, while this seems to work, I wouldn’t recommend doing it this way, as the Velocity property on parts is deprecated. You can still use this solution, but I wouldn’t recommend using it in the future and would try to find an alternative way to do it.

1 Like

Yeah it was the Anchored property that was causing the issue thanks for helping me figure it out! :slight_smile: