I want to create a game like flappy bird, but to do that I need the right physics.
I want to first make it so that when I apply an Impulse force (ApplyImpulse) when the player presses a key, that the “forces” don’t “add-up” and the player starts to move faster and faster.
Furthermore, I want it so that when the player is freefalling it can have the same jump effect equal to if the player didn’t have the force of gravity on them.
Video of the player going higher and higher as the forces add up. It looks like im jumping but its really the impulse force.
Video of the gravity forces having to be cancelled before the player can go up again
The only idea that I have is to somehow reset the velocity/force to zero before applying the force but I don’t know how to do that.
And for the gravity issue I think you have to cancel out the gravity’s force but I don’t know how to get that force and what to use to cancel it out
here i whipped out a demo for you thing.rbxl (40.8 KB)
local jumpVel: number = 50
local lp = game:GetService('Players').LocalPlayer
local uis = game:GetService('UserInputService')
type char = typeof(script:WaitForChild('R6')) --R6 is a dummy character
local hrp: BasePart
local function updateHrp(ch: char)
ch:WaitForChild('Humanoid').JumpPower = 0
hrp = ch:WaitForChild('HumanoidRootPart', 5)::any
end
lp.CharacterAdded:Connect(updateHrp) --will update the HRP on respawn
updateHrp(lp.Character or lp.CharacterAdded:Wait())
uis.InputBegan:Connect(function(k, gp)
if gp then return end
if k.KeyCode == Enum.KeyCode.Space and hrp and hrp.Parent then
local vel: Vector3 = hrp.AssemblyLinearVelocity
hrp.AssemblyLinearVelocity = Vector3.new(vel.X, jumpVel, vel.Z) --override the Y component
end
end)