Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Rotating a frame so it's in perspective?

Asked by 7 years ago

Okay, this question is more of a request for ideas on equations etc. that will basically rotate a frame into perspective, e.g:

http://prntscr.com/bdaje7

to this:

http://prntscr.com/bdajho

(this is in PS, but you get the idea)


My only idea for this to set/tween the size and position in some way as well as the rotation. I attempted it, but it didn't work very well.

Here is my code if you want it (although it's not very important):

wait(1)
local f = script.Parent.Frame
local num = 80
local num2 = .25
local t = 0.025
local pos = UDim2.new(0,(num*t)*5,0,(num*t)*8)

print(num*t)

f:TweenSizeAndPosition(f.Size - UDim2.new(0,0,0,(num*t)*10),f.Position-pos,"InOut","Quad",num*t,true)
for i = 1,num do
    f.Rotation = f.Rotation + num2
    wait(t)
end

Thank you! Any help with this would be greatly useful!

~TDP

0
I don't believe it's possible to form a trapezium like that with a single Roblox frame. This will be very complicated. gskw 1046 — 7y
0
Yes. I agree. My only other idea is creating multiple triangles and basically animating it - which will take forever since it's like 300 lines of code per frame. TheDeadlyPanther 2460 — 7y

1 answer

Log in to vote
1
Answered by
EgoMoose 802 Moderation Voter
7 years ago

This is a fun question because there are quite a few possible answers! There are two ways I can think of off the top of my head.

The first is to use a lot of vertical frames and math to scale them based on the perspective/depth etc. I personally wouldn't use this method because it would require me to do more work than I have to.

The second way, which is what I'll give an example of, is to simply triangulate your shape and draw it with triangles. I used this module to triangulate and this article to draw 2D triangles. I then used WorldToScreenPoint to get the corners of one of the surfaces on the shape just for ease of testing/showing how it works.

local camera = game.Workspace.CurrentCamera;
local screen = script.Parent; -- screengui
local cleanup = screen:WaitForChild("cleanup"); -- something we can put the drawn triangles in and clear the next frame

local triangle = require(script:WaitForChild("triangle")); -- for drawing 2D triangles
local delaunay = require(script:WaitForChild("delaunay")); -- for 2D trianglation

function get2DPoints(part)
    local points = {};
    for x = -1, 1, 2 do
        for y = -1, 1, 2 do
            local p3 = (part.CFrame * CFrame.new(part.Size/2 * Vector3.new(x, y, 1))).p;
            local p2 = camera:WorldToScreenPoint(p3);
            table.insert(points, p2);
        end;
    end;
    return points;
end;

local part = game.Workspace.Part;

function update()
    cleanup:ClearAllChildren(); -- clear prev stuff
    local points = get2DPoints(part);
    local tris = delaunay.triangulate(unpack(points)); -- triangulate the shape
    for _, tri in next, tris do
        -- params: parent, colour, pointa, pointb, pointc
        triangle(cleanup, Color3.new(), unpack(tri));
    end;
end;

game:GetService("RunService").RenderStepped:connect(update);

This is what it looks like

0
So the gif shown is what it would look like when put in use? TheDeadlyPanther 2460 — 7y
0
Yes EgoMoose 802 — 7y
Ad

Answer this question