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

Part rotation affects part position?

Asked by
thebayou 441 Moderation Voter
6 years ago

This kinda expands off of my last post. So basically I have this script that automatically sets the Position of a part and its orientation after doing some calculations, but for some reason setting the Rotation of the part would also deal collateral damage and mess up the Position-al component.

Version 1 (commented)

Code:

01local runService = game:GetService("RunService")
02 
03local parachute = script.Parent
04local base = parachute:WaitForChild("Base").Value
05local dragBF = base:WaitForChild("Drag")
06 
07local resistanceCoefficient = 10
08local parachuteDistance = 10
09 
10runService.Heartbeat:Connect(function(step)
11 
12    -- Compute the parachute's drag force
13    local drag = -base.Velocity * resistanceCoefficient
14 
15    -- Compute position and rotation of parachute
View all 33 lines...

BTW I did try setting the rotation by multiplying by CFrame.Angles but that didn't yield any better results

Output:

10, 54.5970306, 0
20, 54.5970306, 0 0, 0, 0
30, 54.7103844, 0
40, 54.7103844, 0 0, 0, 0
50, 54.7820587, 0
60, 54.7820587, 0 0, 0, 0
7...

Version 2 (uncommented)

Code:

01local runService = game:GetService("RunService")
02 
03local parachute = script.Parent
04local base = parachute:WaitForChild("Base").Value
05local dragBF = base:WaitForChild("Drag")
06 
07local resistanceCoefficient = 10
08local parachuteDistance = 10
09 
10runService.Heartbeat:Connect(function(step)
11 
12    -- Compute the parachute's drag force
13    local drag = -base.Velocity * resistanceCoefficient
14 
15    -- Compute position and rotation of parachute
View all 33 lines...

Output:

10, 54.5970306, 0
20, -3.40282347e+38, 0 0, 0, 0
30, 54.6886597, 0
40, -3.40282347e+38, 0 0, 0, 0
50, 54.7569809, 0
60, -3.40282347e+38, 0 0, 0, 0
7...

So what's happening here? How is the Rotation of the part adversely affecting the Position??

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Set CFrame instead of Rotation. To do this, set the part's CFrame to it multiplied by CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))

So if you want to rotate a part, let's say 90 degrees, on x axis, you would do it like this:

1part.CFrame = part.CFrame * CFrame.Angles(math.rad(90), 0, 0) --you dont need to rad(0)
0
Read the bolded part of my question: BTW I did try setting the rotation by multiplying by CFrame.Angles but that didn't yield any better results, but I'll try again to see if anything changed thebayou 441 — 6y
Ad

Answer this question