VectorForce based movement system giving me a headache

I’m going to start this post out by saying this: I am NOT a good coder. Not in the slightest. Most of my code is a hodge-podge of code from other places I’ve seen, and while I myself can look at code and go “yeah, I can tell what this does,” my application of this knowledge is terrible. So please be patient with with me, okay? I’m just trying my best here, and this post is proof it wasn’t enough.

Basically, I’m trying to make an easy-to- use parkour system. I got one to work pretty well with BodyVelocity, but I learned later that I probably shouldn’t use it since it’s deprecated, along with the fact there was a wall-clinging bug that was unintended. I was trying to find a solution and I stumbled into VectorForce, which was apparently better for things like momentum and such. I thought: oh, perfect! But I think that it might be a bit out of my pay grade now.

I have non-stop tried to get this to work for three days, and nothing I do can fix it. The issue at the core is that I cannot for the life of me get the character to move. I got them to move once, but I had to put so much velocity on it to move about 2 studs a second on the ground, and then the moment you jumped you’d enter the nth dimension. I redid the code several times with the best of my knowledge, and nothing has been working.

I tried twice to not use VectorForce, but every time I just end up coming back to it since it feels like it’s the closest I’ve gotten to what I wanted. Both times I went to try linear velocity, but both times failed for one reason or another, mostly feeling jank in comparison. I feel like I’m going insane now, like it’s a cursed relic beckoning me.

My formatting probably sucks, but I have a module script running this in ReplicatedStorage,

local ForceController = {}

local characterRefs = {} -- Stores per-character force objects
local debug = true

function ForceController.Init(character)
	
	local hrp = character:WaitForChild("HumanoidRootPart")

	if characterRefs[character] then return end

	local attachment = Instance.new("Attachment")
	attachment.Name = "ForceAttachment"
	attachment.Parent = hrp

	local vectorForce = Instance.new("VectorForce")
	vectorForce.Name = "MainVectorForce"
	vectorForce.Attachment0 = attachment
	vectorForce.RelativeTo = Enum.ActuatorRelative.World
	vectorForce.Force = Vector3.zero
	vectorForce.Parent = hrp

	characterRefs[character] = {
		HumanoidRootPart = hrp,
		Attachment = attachment,
		VectorForce = vectorForce
	}

	if debug then print("ForceController initialized for", character.Name) end
	
end

function ForceController.ApplyForce(character, forceVector, duration)
	
	local data = characterRefs[character]
	
	if not data then return end

	local vf = data.VectorForce
	vf.Force = forceVector

	if debug then
		
		print("Applied force to", character.Name, forceVector, "for", duration or 0.2)
		
	end

	if duration and duration > 0 then
		
		task.delay(duration, function()
			
			if vf and vf.Parent then
				
				vf.Force = Vector3.zero
				
				if debug then print("Force reset for", character.Name) end
				
			end
			
		end)
		
	end
	
end

function ForceController.ZeroForce(character)
	
	local data = characterRefs[character]
	
	if data then
		
		data.VectorForce.Force = Vector3.zero
		
	end
	
end

return ForceController

and the actual movement code is in a local script in StarterCharacterScripts.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local usi = game:GetService("UserInputService")

local player = Players.LocalPlayer
local character = script.Parent.Parent

local ApplyForceEvent = ReplicatedStorage:WaitForChild("ApplyForceEvent")

usi.InputBegan:Connect(function(input, gpe)
	
	if gpe then return end

	if input.KeyCode == Enum.KeyCode.Space then
		
		local jumpForce = Vector3.new(0, 2500, 0)
		ApplyForceEvent:FireServer(jumpForce, 0.15)
		
	end

	if input.KeyCode == Enum.KeyCode.LeftShift then
		
		local hrp = character:WaitForChild("HumanoidRootPart")
		local dashDir = hrp.CFrame.LookVector * 4000
		
		ApplyForceEvent:FireServer(dashDir, 0.1)
		
	end
	
end)

Ideally, what I WANT it to do is to just have slight acceleration and deceleration while moving, to NOT have the dash mechanic (one of the code pieces I looked at just had it in there and I never took it out), and to feel like a less technical parkour game. That’s it.

I’m at my wit’s end with this, and I already had to wait 3 days just to gain access to actually post this, so sorry if I seem short. I’m just so tired.

1 Like

The issue here is using VectorForce. To my knowledge, VectorForce is similar to pushing someone already moving, increasing their speed. Since you have no initial velocity nothing will happen. In the above linked doc page VectorForce recommends using LinearVelocity through the following line:

Because the VectorForce constraint applies constant force and acceleration, very high speeds may result if no other forces are involved. If you want to maintain a more steady velocity over time, use a LinearVelocity constraint.

With minimal tweaks I believe your script should work as intended using LinearVelocity rather than VectorForce.

To address you saying you’re a bad coder, don’t beat yourself up over it. You’re taking the time to learn, and create things. Everyone starts somewhere, and you’ll get to a good point in no time.

As for having to wait to access devforum, for the future if you are having issues where you are getting no reply or you can’t access help there are many resources available such as LLMs (e.g. ChatGPT, Gemini), off platform help channels (e.g. Discord), and the Roblox Documentation.

2 Likes

You know, I did have a feeling when I found no solution to this seemingly easy to spot issue maybe this wasn’t the way to go. I’m actually glad, because VectorForce has given me a headache.

I also have been using as many resources as possible, including different LLMs, but I didn’t realize there was a Discord to help me out with things outside of this. I thought this was the only way to get help. But honestly, I’m somewhat glad I went through all that tedium anyway since I can now make posts here at all.

I’ll try to get it to work with LinearVelocity and see if that’s better. Thanks for the advice! Thank you for also being kind about it, I saw a huge debate the other day about OOP and it kind of scared me what kind of environment this could be- glad I didn’t attract that crowd.

Hey! All good, sometimes it just takes a fresh pair of eyes. Congratulations and welcome to the devforum. I wouldn’t get bogged down by all the debates over OOP or other issues unless you feel it’s important for your learning journey or a related project. While some debates set standards for larger projects, learn to code the way you feel works for your projects. If that includes learning OOP go ahead, if not continue as you are going. As for the discords, with the intention of not wanting to lead others off platform I won’t link them here but large communities like HiddenDevs is where I’d start. Roblox’s unofficial discord server also has a dev-help channel (despite being quite busy :rofl:) Best of luck in your programming journey.

Hey, thanks so much for the help in the end, I’ll be sure to check that place out!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.