Help with vectorforce

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

this is what i have so far but its not that good.
image

Any help is appreciated

2 Likes
jump_force.Force = total_force*character_mass

jump_force.Force = Vector3.zero

maybe jump_force and character_mass isnt a variable. try sending the full script if you didnt already?

1 Like

local skateboard = params[3]

		---------------- 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

1 Like

i changed the jump code at the bottom, 5 is meant to be the jump height

1 Like

did you do an Instance.new() or did you just place it on the skateboard directly?

1 Like

I’m not sure why that matters, but yes I did use instant.new as u can see in the code

Great! since you can delete the instance when its about a secend.

and try experimenting this.

if its too strong. then reduce it. if its too weak. then increase it

1 Like

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

great idea but i think it will probbably take time. same for mine

1 Like

You should use velocity control instead of forces for a jump.

Also, generally, should also use applyimpulse instead of using a force for a very short amount of time (which can be inconsistent).

I would recommend creating a LinearVelocity for about 0.1 seconds on the client, which will override the CharacterController’s ground sticking force.

1 Like