So i’ve been wondering on how i could use vectorforce to mimic jump physics. Not requesting an alternative for vectorforce, I just want to know how to code it so it can mimic jumping
---------------- Animations -----------------------
playing_animation = true
local sk_idle = default_anims["Skateboard Idle"]
local sk_left = default_anims["Skateboard Left"]
local sk_right = default_anims["Skateboard Right"]
local sk_fall = default_anims["Skateboard Fall"]
local sk_ring = default_anims["Skateboard Ring"]
sk_idle:Play()
sk_left:Play()
sk_right:Play()
sk_fall:Play()
sk_ring:Play()
---------------- Math Operations ----------------------
local clamp = math.clamp
local cframe_new = CFrame.new
local cframe_angles = CFrame.Angles
local math_abs = math.abs
---------------- Variables --------------------------------------
local character_mass = 0
local interactive_objects = {map}
local raycastParams = RaycastParams.new()
local leg_length = humanoid.HipHeight
local loop_function
local jump_function
local current_velocity = Vector3.zero
local jumping = false
---------------- Initialize ---------------------------------------
character_mass = root.AssemblyMass
for i, v in pairs(map:GetDescendants()) do
if v:IsA("BasePart") then
if v.CanCollide == true then
table.insert(interactive_objects,v)
end
end
end
raycastParams.FilterDescendantsInstances = interactive_objects
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.IgnoreWater = true
---------------- Movers ----------------------------------------
local force_point = Instance.new("Attachment",root)
force_point.Name = "SkateboardForcePoint"
local lift_force = Instance.new("VectorForce",force_point)
lift_force.Name = "LiftForce"
lift_force.Attachment0 = force_point
lift_force.ApplyAtCenterOfMass = true
lift_force.RelativeTo = Enum.ActuatorRelativeTo.World
lift_force.Force = Vector3.zero
local jump_force = Instance.new("VectorForce",force_point)
jump_force.Name = "JumpForce"
jump_force.Attachment0 = force_point
jump_force.ApplyAtCenterOfMass = true
jump_force.RelativeTo = Enum.ActuatorRelativeTo.World
jump_force.Force = Vector3.zero
---------------- Humanoid/Character Options ---------------------
humanoid.PlatformStand = true
rotation_settings = {MaxTorque = 0}
---------------- Apply Forces -----------------------------------
local function apply_forces(delta)
current_velocity = root.AssemblyLinearVelocity
----------- Lift Force --------------------------------------
local ground = workspace:Shapecast(root,root.CFrame.UpVector*-(leg_length),raycastParams)
if ground then
local g_force = Vector3.new(0,workspace.Gravity,0)
local f_force = Vector3.new(0,-current_velocity.Y,0)*(1/delta)
local d_force = Vector3.new(0,leg_length-ground.Distance,0)*(1/delta)
local total_force = g_force+f_force+d_force
lift_force.Force = total_force*character_mass
else
lift_force.Force = Vector3.zero
end
end
loop_function = update.Heartbeat:Connect(apply_forces)
jump_function = humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
local ground = workspace:Shapecast(root,root.CFrame.UpVector*-(leg_length+0.5),raycastParams)
if ground and jumping == false then
local frame_time = task.wait()
local j_force = Vector3.new(0,math.sqrt(2*workspace.Gravity*5),0)*(1/0.1)
local total_force = j_force
jump_force.Force = total_force*character_mass
lift_force.Enabled = false
task.wait(0.1)
jump_force.Force = Vector3.zero
lift_force.Enabled = true
end
end)
This is for a skateboard script, the character mass is accurate and jump_force works, its just not jumping the same height as if i were to use humanoid jump
im trying to mathematically make an equation to mimic jump physics using impulse time, jump height and force. even if i were to do that, that seems really crude and could cause problems