Here’s what I’m trying to achieve: Make Player Jump to a certain Position, with an arc.
While it is fairly simple to achieve this with parts, but it don’t seem to work for HumanoidRootParts?
local p1 = workspace.A.Position
local p2 = workspace.B.Position
direction = p2 - p1
force = direction + Vector3.new(0,game.Workspace.Gravity*.5,0)
while true do
task.wait(3)
local cl = game.Workspace.Part:Clone()
cl.Position = p1
cl.Parent = game.Workspace
cl:ApplyImpulse(force*cl.AssemblyMass)
end
Start = HumanoidRootPart.Position
End = Vector3.new(50,2.1,0)
Direction = End - Start
Force = Direction + Vector3.new(0,game.Workspace.Gravity*0.5,0)
UIS.InputBegan:Connect(function(Input,IsTyping)
if Input.KeyCode == Enum.KeyCode.K then
HumanoidRootPart:ApplyImpulse(Force*HumanoidRootPart.AssemblyMass)
end
end)
The problem is that Humanoids have a custom physics system when the player is on the ground. You can mitigate this by forcing the player to jump before applying a velocity:
if Input.KeyCode == Enum.KeyCode.K then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
-- wait a bit to ensure the Humanoid actually starts being
-- affected by physics before we try and give it any velocity
task.wait(0.1)
HumanoidRootPart:ApplyImpulse(Force*HumanoidRootPart.AssemblyMass)
end
So I changed the script, and tested it out, and this is the result: https://gyazo.com/cc064153057bba9be9d65083ce28fade
It looks like States like Freefall and Fallingdown some how deletes all forces applied to player, so I work around it by enabling PlatformStand, but another problem occurs:
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
Humanoid.PlatformStand = true
-- wait a bit to ensure the Humanoid actually starts being
-- affected by physics before we try and give it any velocity
task.wait(0.1)
HumanoidRootPart:ApplyImpulse(Force*HumanoidRootPart.AssemblyMass)
task.wait(2)
Humanoid.PlatformStand = false
https://gyazo.com/1a89483c015c549b93375b516adf6df1
As you can see, from the gif, the Impulse over shoots on the Z Axis by a weird amount, and sometimes even on the X Axis too.
I also thought of maybe Disabling Player’s Control(since the force just oddly disappears when player regains control) can be another work-around, replacing PlatformStand, but it did not work.
Maybe you could try using ControllerManagers? They are fully physics-based, so I would assume that applying a velocity is just as simple at changing the velocity of any other part.
Example scripts:
Even though it’ll be a bit more work to implement them, I think it’ll be worth it for a more physics-based game.