I don’t really ask many questions here so it would be sad if this gets deleted like all my other scripting support questions because they were not answered.
Anyways, I am making a physics based movement system using apply impulse but the issue is that apply impulse stacks and I do not want that because it makes the player go unrealistically fast.
A topic that I viewed here:
Is close to the solution but the user is using body velocity which are not too physics based because I need gravity. I won’t code gravity because, yet again, it is unrealistic.
My question is:
- How can I limit apply impulse?
My code:
local Character = script.Parent
local Humanoid:Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local HRP:BasePart = Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local oldvelocity = Vector3.zero
local speed = 16
local currentspeed = speed
local jumpheight = 7
local function KD(Key)
return UIS:IsKeyDown(Enum.KeyCode[Key])
end
local function GetMass()
local mass = 0
for _,v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") then
mass += v:GetMass()/v.CurrentPhysicalProperties.Density
end
end
return mass
end
local maxy = 0
RS.RenderStepped:Connect(function(dt)
local x = KD("A") and -1 or KD("D") and 1 or 0
local z = KD("W") and -1 or KD("S") and 1 or 0
local _,y_rot,_ = Camera.CFrame:ToOrientation()
local dir = CFrame.Angles(0,y_rot,0)*CFrame.new(Vector3.new(x,0,z).Unit)
local velocity = dir.Position*(currentspeed)*GetMass()
currentspeed = speed+math.abs((HRP.AssemblyLinearVelocity.Y/(4+math.pi)))
HRP:ApplyImpulse(velocity)
oldvelocity = velocity
end)
I also tried using deltatime but that just slows stuff by a lot.
I tried to explain this as briefly and accurately as I can.
Detail
I am trying to code a physics based movement system using applyimpulse on the humanoid root part but applyimpulse will not stop stacking. I really do not want that because it makes my character go extremely fast. I was previously using humanoid:moveto which did kind of worked but it just felt yet again unrealistic. So is there a way to make it physics based with velocity? Or realistic with humanoid:moveto?
I also do not want to use linearvelocity as gravity and collisions are not really simulated while using linearvelocity which I obviously, yet again, do not want.