Help with Cape Simulation Physics

Hey there again fellow Roblox Developers, I am here again trying to solve another problem I can’t wrap my head around, so why not use someone elses head… so straight to it.

I’ve made progress towards my gliding mechanics, and I was able to apply gravity, momentum etc etc…
but I wanted to add something a little extra to the player’s character… a CAPE

x.com… Voila, this guy has done it beautifully, so I decided to do some research and I came across Verlet Integration by EgoMoose, and I was able to follow along and understand at least %40 of what’s being explained and all in all I was able to make my classes with their corresponding methods

Constraint Class

local c = {}

c.new = function(p1, p2, d)
    local self = setmetatable({}, {__index = c})
    self.point1 = p1
    self.point2 = p2
    
    self.restDist = d
    self.canBreak = false
    self.breakDistance = 5
    
    self.line = Instance.new("Part")
    self.line.Size = Vector3.new()
    self.line.Anchored = true
    self.line.CanCollide = false
    self.line.BrickColor = BrickColor.new("Really black")
    
    self.mesh = Instance.new("BlockMesh", self.line)
    self.mesh.Scale = Vector3.new(0.2, 0.2, 0.2)
    
    return self
    
end

function c:solve()
    if self.point1 and self.point2 then
        local difference = (self.point1.Position - self.point2.Position)
        local distance = difference.magnitude
        local scalar = (self.restDist - distance) / distance
        local translation = difference * 0.5 / scalar
        
        if not self.point1.anchored then
            self.point1.position = self.point1.position + translation
        end
        
        if not self.point2.anchored then
        self.point2.position = self.point2.position - translation
        end
        
        if self.canBreak and (self.point1.position - self.point2.position).magnitude > self.restDist + self.breakDistance then
            self:Destroy()
        end
        
    end
end



return c

Point Class

local Point = {}
local Gravity = workspace.Gravity

Point.new = function(V3)
    local self = setmetatable({}, {__index = Point})
    self.Position = V3
    self.PriorPosition = V3
    self.Velocity = Vector3.new()
    self.Acceleration = Vector3.new()
    self.Anchored = false
    
    return self
end

function Point:Update(dt, damp)
    if not self.Anchored then
        self.Acceleration = Vector3.new(0, -Gravity, 0)
        self.Velocity = self.Position - self.PriorPosition
        self.PriorPosition = self.Position
        self.Position = self.Position + (self.Position - self.PriorPosition) + self.Acceleration * dt^2
    else
        self.Velocity = Vector3.new()
        self.Acceleration = Vector3.new()
        self.PriorPosition = Vector3.new()
    end
end

return Point```

but my problem is, I have no clue how to apply this in the way that I'd be able to have collision and cape physics.

TL:DR Im trying to make a cape and I used EgoMooses formulas but Idk how to apply them to get the cape going, please help if you can thank you!
5 Likes

I am pretty sure that all of this can be accomplished by using HingeConstraint. Have you tried using Roblox constraints before doing this?

1 Like

Well, in my opinion there is a workaround for this. Personally, I would use several beams connected to each other with constraints. I think this would be the most efficient way of doing this.

2 Likes

Is there a particular reason for why you want to use Verlet Integration? If you are still learning and beginning to develop, I would instead opt for a simpler approach that gives you satisfactory results. Perhaps using a beam and a part that is constrained to follow behind the players back?

(If for some reason you really want to continue with Verlet Integration, then you need to create points that represent your cape. Apply constraints to these points such that they are bound in a way where they can represent the fabric of your cape)

1 Like

So I used to have a place file floating around with an example. Not sure what ended up happening to that. Regardless, only a few days ago I was playing around with Verlet capes again so luckily I have something for you.

Although there are ways to handle actual collision with verlet I do not recommend them. Verlet can be expensive and collision just adds to that. Instead I’ve found the best thing to do for capes is to instead draw them with beams and then use the the zOffset property to ensure the cape is drawn in front of the character.

Without zOffset:

With zOffset:

All the code you’d need to do that is in here, but it’s pretty much what you’ve posted with the exception of a beam triangle drawing class.

cape.rbxl (21.7 KB)

Hope that helps!

40 Likes

Dude thank you sooo much! I never thought about these other options, honestly thought Verlet was the way to go and I wanted to challenge myself to get better, but I tend to jump the gun alot and go for abstract approaches… nonetheless thank you.

3 Likes