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 8 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):

01wait(1)
02local f = script.Parent.Frame
03local num = 80
04local num2 = .25
05local t = 0.025
06local pos = UDim2.new(0,(num*t)*5,0,(num*t)*8)
07 
08print(num*t)
09 
10f:TweenSizeAndPosition(f.Size - UDim2.new(0,0,0,(num*t)*10),f.Position-pos,"InOut","Quad",num*t,true)
11for i = 1,num do
12    f.Rotation = f.Rotation + num2
13    wait(t)
14end

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 — 8y
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 — 8y

1 answer

Log in to vote
1
Answered by
EgoMoose 802 Moderation Voter
8 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.

01local camera = game.Workspace.CurrentCamera;
02local screen = script.Parent; -- screengui
03local cleanup = screen:WaitForChild("cleanup"); -- something we can put the drawn triangles in and clear the next frame
04 
05local triangle = require(script:WaitForChild("triangle")); -- for drawing 2D triangles
06local delaunay = require(script:WaitForChild("delaunay")); -- for 2D trianglation
07 
08function get2DPoints(part)
09    local points = {};
10    for x = -1, 1, 2 do
11        for y = -1, 1, 2 do
12            local p3 = (part.CFrame * CFrame.new(part.Size/2 * Vector3.new(x, y, 1))).p;
13            local p2 = camera:WorldToScreenPoint(p3);
14            table.insert(points, p2);
15        end;
View all 32 lines...

This is what it looks like

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

Answer this question