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

Offset by rotation?

Asked by
Vulcain 10
10 years ago

I'm terrible with math, so please help me with this.

Say I have a part, I want to clone it and place the clone on top of the part, but at an angle (x axis).

( So, I'm basically creating an arc of on top of a part. )

local rotation = 15; 

local part = workspace.Part:clone(); 
local cf = part.CFrame; 
part.Parent=workspace; 

p.CFrame=cf * CFrame.Angles(math.rad(rotation), 0,0) * CFrame.new(0,0,0); -- What do I do here to make it fit smoothly on top of the other part, and to offset by the rotation so there aren't any cracks?

This should be pretty simple. I'm just terrible at math/logic. :P

1 answer

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

I hope I got your question right: You want to move the part to the top of another part and THEN rotate it?

In that case, you need the following

-The size of the part and the other part -The other parts CFrame -The angle

Use:

local YDiff = otherpart.Size.y/2 + part.Size.y/2
local angle = 30
part.CFrame = otherpart.CFrame * CFrame.new(0, YDiff, 0) * CFrame.Angles(math.rad(angle), 0, 0)

Explanation:

CFrames are offsets. Normally, you would say a = b * c = c * b (order of multiplications don't matter). For CFrames the order DOES matter. (Because it has a rotation matrix, and by multiplying matrices the order does matter!)

You have to think in offsets. You first want to move it up to the brick and then rotate it. If you rotate first and THEN move it up, you will see that it will get offsetted in the "direction" you aimed it at.

0
That's not what I wanted, no. Basically, I'm making an arc of the same part, starting from the top of the part. Rotating it by an angle makes a big crack in the middle of the two parts. I want to make it smooth, with scripting. Vulcain 10 — 10y
0
Aha! No offense, but this wasn't really clear in your question. I'm editing this answer. jobro13 980 — 10y
0
No wait, I still don't understand your question. You are trying to create the arc on top of a part? Could you sketch what you mean and post a picture of it somewhere? I can randomly start throwing some code at you but it will be a shot in the dark if I don't know what you want exactly. jobro13 980 — 10y
0
Say there's one single part in the workspace. I want to clone that part, and rotate it by the variable named Angle. (On the X axis.) Then, I want to move this clone so that it fits perfectly on top of the part it was cloned from. So if I do this with a for loop, I could make an arc from the starting part. Or, I could make it into a circle. Vulcain 10 — 10y
View all comments (2 more)
0
Okay, this is quite hard to do. As I take it, the only variable I am allowed to use is the "original" brick and the angle you want to rotate too? Also, this function would, if you would run it so every "spot" has a brick - always shows as a circle? jobro13 980 — 10y
0
Yeah, it'd show a circle at the angle I type in. It's really more for arcs than circles, but I'd be able to edit the for loop enough to make an arc rather than a circle. Vulcain 10 — 10y
Ad

Answer this question