i was attempting to make a combat system and was wondering how i would knock a player back, while into the air, before coming back down. i tried using linear velocity, but it’s terrible at getting it off the ground. i’m using it in relitive to A0 and LineVelocity btw.
i dont want to use any deprecated methods, either. i know bodyvelocity would work here, but i dont want to use it for that preference.
whats the best way to do this?
please give a small code sample to show me how this would be used, im new.
I’m assuming you mean that the player stays in the air until the attacked player falls back down- correct me if I’m wrong.
Anyways,
Use LinearVelocity and the Attacked player’s negative LookVector to send them flying backwards after you have hit them (I’m assuming you have hit-detection already scripted)
Just anchor your player’s HumanoidRootPart for a couple of seconds, and then unanchor it.
Sorry that this was rushed, but my brain is fried after coding for, like, 5 hours.
local targetPosition = Vector3.new(50, 5, 20)
local force = targetPosition * Part.AssemblyMass
Part:ApplyImpulse(force)
so basically :ApplyImpulse() makes a force on the part which will take him to that Position in one second and we multiply it by the Mass because of some Boring physics things
Velocity would probably give you the best control over the throw, I think the reason it doesn’t end up lifting the character off the ground is because the character has multiple parts, you should try adding every part’s velocity in the character and gravity should give you that arc you want.
function ThrowPlayer(Character,ThrowValue)
for i,v in Character:GetDescendants() do
if v:IsA("BasePart") then
v.AssemblyLinearVelocity += ThrowValue
end
end
end
Applying it on every part of the character guarantees the same amount of velocity change on every part of the character every time. You could definitely apply it only on the humanoid root part but the throw now matters on how many parts there are in the character.