How to make this fall slow?

I have this projectile script where it shoots out fast and it should fall slowly.

local function startProjectile(object, kickZone)
	local bullet = object
	
	local position1 = bullet.Position
	local position2 = workspace.PeakPoint.Position + Vector3.new(0, 0, math.random(-workspace.PeakPoint.Size.X/2, workspace.PeakPoint.Size.X/2))

	bullet.Position = position1

	local direction = position1 - position2
	local force = direction + Vector3.new(0, workspace.Gravity / 2, 0)
	
	--bullet:SetNetworkOwner(nil)
	bullet:ApplyImpulse(force * bullet.AssemblyMass)

	--game.Debris:AddItem(bullet, 5)
end
2 Likes

You could change the mass of the part after you detect when the bullet’s yAxis value is decreasing. Or you could increase workspace.Gravity (ideally you’d do the first option but do whatever suits you better).

I def think that the first idea is better than the second as workspace.Gravity affects all objects not just the part.

3 Likes

I really want to make the bullet or object only go in 2 axis which is X and Y and not the Zs because I want to achieve the 2D effect on my game.

this is the first solution yet it has a physics bug; when it falls down, it goes crazy from left and right.

local function startProjectile(object, kickZone)
	if not object then return end
	local bullet = object
	
	local position1 = bullet.Position
	local position2 = workspace.PeakPoint.Position + Vector3.new(0, 0, math.random(-workspace.PeakPoint.Size.X/2, workspace.PeakPoint.Size.X/2))

	bullet.Position = position1

	local direction = position1 - position2
	local force = direction + Vector3.new(0, workspace.Gravity / 2, 0)
	
	--bullet:SetNetworkOwner(nil)
	bullet:ApplyImpulse(force * bullet.AssemblyMass)

	--game.Debris:AddItem(bullet, 5)
end


local conns
ThrowPamato.OnServerEvent:Connect(function(Sender)
	local Character = Sender.Character
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	if not Humanoid then return end
	local kickZone = Character:FindFirstChild("kickZone")
	if not kickZone then return end
	
	local newPamato = ServerStorage:WaitForChild("Pamato"):Clone()
	newPamato.Parent = workspace
	Instance.new("Attachment", newPamato)
	
	newPamato.CollisionGroup = CG_Pamato
	for i, part in pairs(Character:GetDescendants()) do
		if part:IsA("BasePart") and part.Name ~= "kickZone" then
			part.CollisionGroup = CG_Player
		end
	end
	
	local VF = Instance.new("VectorForce", newPamato)
	VF.Attachment0 = newPamato:FindFirstChild("Attachment")
	VF.ApplyAtCenterOfMass = true
	--VF.Force = Vector3.new(0, newPamato:GetMass() * (workspace.Gravity / 0.25), 0)
	
	newPamato.Position = kickZone.Position
	newPamato.CustomPhysicalProperties = PhysicalProperties.new(0.5, 0.5, 1, 0.3, 1)
	--local Welder = Instance.new("Weld", newPamato)
	--Welder.Part0 = newPamato
	--Welder.Part1 = kickZone
	
	conns = newPamato.Touched:Connect(function(hit)
		local e = task.spawn(function()
			while newPamato do
				if newPamato.AssemblyLinearVelocity.Y >= 0 then
					VF.Force = Vector3.new(0, 0, 0)
				else
					VF.Force = Vector3.new(0, newPamato:GetMass() * (workspace.Gravity / 0.6), 0)
				end
				task.wait()
			end
		end)
		if hit.Name == "Floor" then
			--newPamato:Destroy()
			conns:Disconnect()
			task.cancel(e)
		end
	end)
	
	startProjectile(newPamato, kickZone)
end)
1 Like

Maybe you could spawn a thread (task.spawn) after the bullet is shot. You could make it wait a bit then gradually decrease the AssemblyLinearVelocity to your desired preferences.

How can I achieve the gradually decreasing? tbh, I really don’t know what I should change in my script as this is my first time handling physics in Roblox.

This is what I did:

local conns
local function startProjectile(object, kickZone)
	if not object then return end
	local bullet = object
	
	local position1 = bullet.Position
	local position2 = workspace.PeakPoint.Position + Vector3.new(0, 0, math.random(-workspace.PeakPoint.Size.X/2, workspace.PeakPoint.Size.X/2))

	bullet.Position = position1

	local direction = position1 - position2
	local force = direction + Vector3.new(0, workspace.Gravity / 2, 0)
	
	
	local VF = Instance.new("VectorForce", bullet)
	VF.Attachment0 = bullet:FindFirstChild("Attachment")
	VF.ApplyAtCenterOfMass = true
	
	conns = bullet.Touched:Connect(function(hit)
		local e = task.spawn(function()
			while bullet do
				if bullet.AssemblyLinearVelocity.Y >= 0 then
					VF.Force = Vector3.new(0, 0, 0)
				else
					VF.Force = Vector3.new(0, bullet:GetMass() * (workspace.Gravity / 0.6), 0)
				end
				task.wait()
			end
		end)
		if hit.Name == "Floor" then
			--newPamato:Destroy()
			conns:Disconnect()
			task.cancel(e)
		end
	end)
	
	bullet:ApplyImpulse(force * bullet.AssemblyMass)
end

Though it works, still I want to achieve the 2-axis direction only of the trajectory of the bullet.


in this video, you can see the slow falling of the bullets

You could add something like this to your code:

-- Pretend like this is the code that is fired when the bullet is shot
task.spawn(function()
task.wait(whatever)
while task.wait(0.1) do
bullet.AssemblyLinearVelocity -= 5
-- Something like this
end
end)

To be honest, I’m not that good at math or anything that involves physics (real life and Roblox). I don’t really work with VectorForces and Roblox “physics objects” often either. This is just really what I think would work, if it doesn’t, I could take another look.

To achieve that you can use a LinearVelocity, here’s how to do it step by step

  1. Add an Attachment to the object
  2. Change the WorldPosition of the Attachment to the AssemblyCenterOfMass of the object
  3. Add a LinearVelocity to the object
  4. Change the Attachment0 of the LinearVelocity to the Attachment
  5. Change the VelocityConstraintMode of the LinearVelocity to Line
  6. Change the MaxForce of the LinearVelocity to inf or a very big number
  7. Change the LineDirection of the LinearVelocity to the axis that you want the part to be locked on
3 Likes

Add a bodyForce (I KNOW ITS DEPRECATED) and set its maxforce to inf and force to this.
Or just use vector force and stuff. (if your not dumb like me)

local force = direction + Vector3.new(0, bullet:GetMass()*workspace.Gravity / 2, 0)
1 Like

is this correct?

local function startProjectile(object : Part, kickZone)
	if not object then return end
	local bullet = object

	local position1 = bullet.Position
	local xOffset = math.random(-workspace.PeakPoint.Size.X/2, workspace.PeakPoint.Size.X/2)
	local position2 = Vector3.new(position1.X + xOffset, position1.Y, position1.Z)

	bullet.Position = position1

	local direction = position1 - position2
	local force = direction + Vector3.new(0, workspace.Gravity / 2, 0)
	
	
	local Att = Instance.new("Attachment")
	Att.Parent = bullet
	Att.WorldPosition = bullet.AssemblyCenterOfMass
	
	local LV = Instance.new("LinearVelocity", bullet)
	LV.Attachment0 = Att
	LV.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
	LV.MaxForce = math.huge
	LV.LineDirection = Vector3.new(1, 1, 0)
	
	
	bullet:ApplyImpulse(force * bullet.AssemblyMass)

Your code logic seems fine. Have you tested it? see this post btw How do you use linear velocity - #3 by elomala

I don’t know why the bullet won’t go up by using the ApplyImpulse?

Update: I changed the vector of LinearVelocity in to this 0, 1, 1. now it only goes diagonal

Maybe set the velocity manually?