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

How do I make the Union part still?

Asked by 9 years ago

I put the Union part with the other part and clicked it to move, but apparently when it touches the part, it like goes up and turns to have free space. But I want it to stand still and not move at all. Here is the link for what script BlueTaslem made if you want me to add it to make the Union part still. I just want to know how do I make the Union part still while it rotates and still stand still even though it touched the part.

Link: https://scriptinghelpers.org/questions/19967/why-does-this-script-doing-something-different-than-i-expected-and-can-you-fix-it-like-i-said

Sorry about that. @BlueTaslem, thanks for helping me. I hope everyone understands. Again, I want the Union to stand still while it rotates even though it touched the part. The Union touched the part and it like goes up to the empty space area to rotate the rest. Please help.

0
Anchor the part? DragonSkyye 517 — 9y
0
I did, it still did the same RobotChitti 167 — 9y
0
then the script must be changing its position somehow, or its another roblox bug >:( dragonkeeper467 453 — 9y
0
0
It's not a ROBLOX bug, it's because he's using Rotation, which will move the part upwards if it intersects another part. It's how ROBLOX handles collisions. I'll post an answer in a sec. Spongocardo 1991 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

So considering that this is the following code in question:

for t = 0, 4.8, 0.03 do
    wait(0.03)
    local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45
    cover.CFrame = home
    cover.Rotation = Vector3.new(v, 0, 180)
end

In ROBLOX, when Rotation is edited, ROBLOX checks if the part is intersecting another part and if it is, it will move the part upwards to stop this. To fix this, we need to use CFrame to negate the effect of ROBLOX moving the part up, but how do we use CFrame when we're trying to change the rotation?


The answer is CFrame.Angles. CFrame.Angles is a method that allows you to specify angles (in radians) to rotate the CFrame by said angle.

Rotation is a Vector3, but we're specifying angles in degrees when using Rotation, which we'll need to convert to radians in order for it to work as intended, but how do we make an angle in degrees into radians?

Well, there's a neat function called math.rad which takes a number that should be an angle in degrees and converts it into radians.

Overall, your script should now look like this:

for t = 0, 4.8, 0.03 do
    wait(0.03)
    local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45
    cover.CFrame = home * CFrame.new(math.rad(v), 0, math.pi) --Math.pi in radians is equal to half a turn, or 180 degrees.
end

I hope my answer helped you. If it did, be sure to accept it.

Ad

Answer this question