how to do something like this?
External MediaThe file OP links is this video, if you don’t want to click onto random URLs:
It’s too too late at night for me to give a more detailed answer, but:
It would be either Bones or editable meshes to achieve this effect. If it is bones, then each vertice in the mesh would have a bone. The bones are then made to move towards the blackhole via code, bringing the mesh with them.
It’s probably EditableMeshes! This is based on observation:
Each vertice is moving closer to the black hole based on it’s distance.
So, let’s set the variable dist
to each vertex’s distance from the black hole. Let’s also set a variable maxdist
to 10. At this distance, the mesh is not affected by the black hole. Each vertex’s cframe is cached in the variable initc
. The distance will be calculated using initc
to avoid any inconsistency.
Each render step, the vertex moves towards the black hole according to this formula:
local lerp = math.max(0, (maxdist - dist) / maxdist)
vertex.CFrame = initc:Lerp(blackholec, lerp)
This will not have an animation, though. To get the animation, we can use sine wave.
local lerp = math.max(0, (maxdist - dist) / maxdist)
lerp *= math.sin(tick()) * 0.5 + 0.5
vertex.CFrame = initc:Lerp(blackholec, lerp)
Likely the vertex’s animation is smoothed out with another layer of lerping, using the deltaTime of the render step. If you don’t do this, it will snap instantly to where it should be, which is unrealistic.
local lerp = math.max(0, (maxdist - dist) / maxdist)
lerp *= math.sin(tick()) * 0.5 + 0.5
local oldVertexC = vertex.CFrame
local newVertexC = initc:Lerp(blackholec, lerp)
vertex.CFrame = oldVertexC:Lerp(newVertexC, math.min(1, dt * 5))
We use main.min(1, dt * 5)
to smooth out the animation. The higher you multiply the deltaTime, the faster it will get to the target CFrame. The math.min
ensures this value doesn’t go over 1. If it did, it would overshoot when you lag or multiply too much.
uhhh
Do you have the Image/Mesh API enabled in beta features?
I don’t think there’s option to get CFrame from vertex, only option i see is EditableMesh:GetPosition(vertexId) which returns only Vector3.
Well, you should only get the position. I realize now that changing the orientation would be a bad idea.
Yep, only the way i see is only making own world space conversion, and then convert vertexes position to world space and get distances between part A to part B, and convert back to objectSpace and place to new vertex cframe.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.