Issues with applying VectorForce to the player

(Changed the title to match the current point in the replies, the text below talks about my old setup of using BodyThrust)

Hey everyone, I’ve been working on making a sort of jumping ability in my game to allow players to move around quicker. I’m using BodyThrust to make the player move. I’m not using BodyForce or BodyVelocity since I want to give the player the ability to turn during the jump.

I’ve gotten everything to work BUT the direction the force is applied. I’m getting LookVector of the HumanoidRootPart’s CFrame and using that to apply force, the problem is that it only applies force in one direction instead of the way the player is facing.
This is also only a problem I’ve encountered using BodyThrust, anything else in my script that uses BodyVelocity or BodyForce uses the same method and works as I wanted it to.

Here’s a demonstration of the problem in case I wasn’t really clear enough, first jump is normal but the last two demonstrate the problem:

(physics and animations are temporary by the way)

Here’s the way I apply the BodyThrust’s force:

local thrust = Instance.New("BodyThrust")
thrust.Parent = HRP
thrust.Force = Vector3.new(HRP.CFrame.LookVector.X * 15.5, 12.75, HRP.CFrame.LookVector.Z * 15.5) * 165

I’m also tweening the force to create the drop at the end of the jump

I’ve looked everywhere on the forum and tried modifying the way I move the player, but nothing I tried worked.
Thank you for reading and considering helping me, I’m hoping this topic can help some other confused developers too.

3 Likes

VectorForce | Roblox Creator Documentation is designed to replace BodyThrust, have you given that a try? It seems to have more control over the forces involved.

1 Like

Just gave it a try and it produces a similar effect, it does control better though so I’ll keep using VectorForce.

This is what I changed it to in case you’re wondering:

local longjumpforce = Instance.new("VectorForce")

			longjumpforce.Name = "LongJumpForce"
			longjumpforce.Parent = HRP
			longjumpforce.Attachment0 = HRP.RootRigAttachment
			longjumpforce.ApplyAtCenterOfMass = true
			longjumpforce.Force = Vector3.new(HRP.CFrame.LookVector.X * 15.5, 12.75, HRP.CFrame.LookVector.Z * 15.5) * 165

Not really sure if this is worth bringing up but I’ve been experimenting for a bit and I found out that setting the RelativeTo to World makes the player go in the right direction, but disables the ability to turn. If I can’t enable the player to turn during the jump then that would make all the time I spent trying to fix this meaningless, so I need to find a different way of applying my current way of setting up the force of the VectorForce so the player can still turn, but I’ve been struggling to find a good way to handle this. If it isn’t possible then I’ll probably just use BodyVelocity and scrap turning entirely.
If anyone can help then feel free to answer, thank you to anyone who has read and is willing to help.

1 Like

Maybe try :ApplyImpulse() It should work, or body velocity.

1 Like

Sorry for the late reply but it also worked similarly to BodyThrust. But the developer site’s page on it did help me learn more about how applying forces work and I managed to come up with a solution. Thanks for telling me about this! If you didn’t then I’d probably still be stuck.

It’s been a little bit, but I did manage to come up with a solution.
I’ve replaced the BodyThrust with VectorForce (as suggested by @Scottifly). BodyThrust may also work, but I’ll be using VectorForce since I do find it more stabe.

I’m multiplying the CFrame of the HRP by CFrame.Angles in order to get an accurate effect.

This is the formula in question:

			local toapply = CFrame.new(Vector3.new(HRP.CFrame.X, HRP.CFrame.Y, HRP.CFrame.Z)) * CFrame.Angles(0, math.pi, 0)

And here’s the finished code for my jump, which uses the variable above in place of using the HumanoidRootPart’s raw LookVector:

			local LJumpTweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
			local LJumptween = tweenservice:Create(longjumpforce, LJumpTweenInfo, {Force = Vector3.new(toapply .LookVector.X * -10.5, -7.5, toapply .LookVector.Z * -10.5) * 165})

			longjumpforce.Name = "LongJumpForce"
			longjumpforce.Parent = HRP
			longjumpforce.Attachment0 = HRP.RootRigAttachment
			longjumpforce.ApplyAtCenterOfMass = true
			longjumpforce.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
			longjumpforce.Force = Vector3.new(toapply.LookVector.X * -15.5, 12.75, toapply.LookVector.Z * -15.5) * 165
			delay(0.1, function()
				LJumptween:Play()
			end)

Thank you to everyone who helped!

8 Likes