Mouse Part Physics?

There is this mobile game I’m recreating and it’s called, “Rise Up”. The objective is to protect the balloon with your cursor from flying objects and prevent it from touching the balloon. The game features objects (how do I say this?) being “flung” when making contact. You’ll see what I mean.

local function mousePace() --// Runs infinitely
	local position = Vector2.new(mouse.X, mouse.Y)
	local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
	
	local normalizedPosition = position / size
	camera.CFrame = playerBalloon.Balloon.CFrame * ballonCFrame
	
	playerBalloon:SetPrimaryPartCFrame(playerBalloon:GetPrimaryPartCFrame() * CFrame.new(0,elevateby,0))
	elevation = elevation + elevateby
	
	TweenService:Create(playerPartMouse.Head, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear), {CFrame = CFrame.new((normalizedPosition.X * 30) - 15, (-normalizedPosition.Y * 19) + 19 + elevation, 0) * CFrame.Angles(0,math.rad(90),0)}):Play()
	
	mouse2.TargetFilter = mouseIgnoreList
end

In the video above me, I attempt to throw the object, but it’s not doing it in a good manner. For the cursor, it tweens to the mouse position every second. Is there a solution to this?

3 Likes

So if I’m understanding correctly, you want the physics parts to be more responsive to being hit? If so, then try tinkering around with CustomPhysicalProperties. Decrease density and increase elasticity, which will affect the mass and ‘bounciness’ of parts respectively.

2 Likes

Exactly. I haven’t really explored the world of physics in roblox, but I’ll give it a shot. It does look like it’s moving a little, but it doesn’t necessarily work.

I believe it’s the limit to the CustomPhysicalProperties. Is there a way to hack it?

Edit 2: I have low gravity on, so that may be the case?

Interesting. I’ll try messing around with physics and let you know what I find.

1 Like

It might be the part cursor, and how it’s repetitively tweening to the mouse’s position, but hey, that’s just me.

Save the mouse’s position every frame, and before saving it, whenever a part collides with the mouse, use the difference between the saved position and the current one and add the difference to the Part.AssemblyLinearVelocity property.

I am too lazy to make the entire code, so here is what you need to keep in mind.

local mousehit = vector3 new 0,0,0
while frame:wait() do
    if colliding with part then
        for every part you collide with, do
            part.linear velocity += mousehit - mouse.hit.position
       end
    end
     mousehit = mouse.hit.position
end
1 Like

When you mean “use the difference” do you mean like magnitude?

You could multiply the velocity by the magnitude if you want, or you could use vector3 values.

1 Like

Thank you so much! Both the CustomPhysicalProperties and the velocity contributed. I wish I can solution both solutions but I can’t. Here’s the code every time the mouse cursor hits a part:

for i, v in pairs(playerPartMouse.Detail:GetTouchingParts()) do
	if previousPartCFrame ~= nil then
		v.AssemblyLinearVelocity = v.AssemblyLinearVelocity * (previousPartCFrame.Position - mouse.Hit.Position).Magnitude / 1000
	end
end


A little odd, but works fine.