How can i make a physics-based swing system

Hello there! one of the characters of my game has a grappling hook ability, if you tap it you get a impulse to where it landed, which is easy, but if you hold it you start swinging, how can i make the swinging?
first i thought in using some sort of distance constraint system, but if i do that the speed wont carry over very well nor have a smooth swing

it cannot use CFrame math as it needs to update the root part’s assembly linear velocity, so the speed can be carried over in the form of momentum by my momentum script once the player leaves the swinging state

Hello there!

Tried using Roblox’s RopeConstraint? I might help with your case, since you can’t use CFrames

If that doesn’t work, i tried doing something similar on a terraria mod i was making.

The solution i found is to update the position with physic formulas.

It would be something like this

local Reach = 10
local DistanceVector = Character.HumanoidRootPart.Position - Grapple.Position

local Value = 1 -- The less you add here the more that it will streech

local Distance = DistanceVector.Magnitude
local Direction = DistanceVector.Unit

if Distance >= Reach then

local Force = Direction * (Distance - Reach) * Value

if Force < 0 the Force = 0 end

end

With tje above method you can add the force to a VectorForce that actuates on the RootPart when you grapple

Hope it helps :wink:

i did try using a ropeConstrain before, but the problem with it was that if the player holds on for too long and get past the 90° degree angle mark, it gets jittery, so i need something that can rotate the velocity
also i didnt test that code yet, but looking at it i can asume it sends the player towards the grapple point?
i’ll try design my own system for now, i think using vector:cross might work

You could use CFrame and trigonometry to create that swing effect because its something like a 0 - 150 degree ish swing. To make it speed up or slow down you’d incrementally increase what you’re adding to the angle to simulate acceleration and deacceleration

Yes it does push you towars the grapple point, that’s what makes you swing!

Just forgot to mention that you nees to put it in a loop, starting when you grapple at something.

I don’t know how vector:cross works, so i can’t help with that

interesting, gonna try that!
also vector:cross basically returns the perpendicular of 2 vectors, like, lets say you have a up vector and a forward vector, but not the right vector, if you want the right vector, you need to get the cross between the up and forward vector

1 Like