Part rotation affects part position?
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:
01 | local runService = game:GetService( "RunService" ) |
03 | local parachute = script.Parent |
04 | local base = parachute:WaitForChild( "Base" ).Value |
05 | local dragBF = base:WaitForChild( "Drag" ) |
07 | local resistanceCoefficient = 10 |
08 | local parachuteDistance = 10 |
10 | runService.Heartbeat:Connect( function (step) |
13 | local drag = -base.Velocity * resistanceCoefficient |
16 | local chutePos = base.Position + base.Velocity.Unit * parachuteDistance |
17 | local d = base.Position - parachute.Position |
18 | local hXY = math.sqrt(d.X^ 2 + d.Y^ 2 ) |
19 | local hXZ = math.sqrt(d.X^ 2 + d.Z^ 2 ) |
20 | local hYZ = math.sqrt(d.Y^ 2 + d.Z^ 2 ) |
22 | local rotZ = math.asin(d.X/hXY) |
23 | local rotY = math.asin(d.Z/hXZ) |
24 | local rotX = math.asin(d.Y/hYZ) |
26 | parachute.Position = chutePos |
29 | print ( tostring (chutePos)) |
30 | print ( tostring (parachute.CFrame.p).. " " .. tostring (parachute.Rotation)) |
BTW I did try setting the rotation by multiplying by CFrame.Angles
but that didn't yield any better results
Output:
2 | 0 , 54.5970306 , 0 0 , 0 , 0 |
4 | 0 , 54.7103844 , 0 0 , 0 , 0 |
6 | 0 , 54.7820587 , 0 0 , 0 , 0 |
Version 2 (uncommented)
Code:
01 | local runService = game:GetService( "RunService" ) |
03 | local parachute = script.Parent |
04 | local base = parachute:WaitForChild( "Base" ).Value |
05 | local dragBF = base:WaitForChild( "Drag" ) |
07 | local resistanceCoefficient = 10 |
08 | local parachuteDistance = 10 |
10 | runService.Heartbeat:Connect( function (step) |
13 | local drag = -base.Velocity * resistanceCoefficient |
16 | local chutePos = base.Position + base.Velocity.Unit * parachuteDistance |
17 | local d = base.Position - parachute.Position |
18 | local hXY = math.sqrt(d.X^ 2 + d.Y^ 2 ) |
19 | local hXZ = math.sqrt(d.X^ 2 + d.Z^ 2 ) |
20 | local hYZ = math.sqrt(d.Y^ 2 + d.Z^ 2 ) |
22 | local rotZ = math.asin(d.X/hXY) |
23 | local rotY = math.asin(d.Z/hXZ) |
24 | local rotX = math.asin(d.Y/hYZ) |
26 | parachute.CFrame = CFrame.new(chutePos) |
27 | parachute.Rotation = Vector 3. new(rotX, rotY, rotZ) |
29 | print ( tostring (chutePos)) |
30 | print ( tostring (parachute.CFrame.p).. " " .. tostring (parachute.Rotation)) |
Output:
2 | 0 , - 3.40282347 e+ 38 , 0 0 , 0 , 0 |
4 | 0 , - 3.40282347 e+ 38 , 0 0 , 0 , 0 |
6 | 0 , - 3.40282347 e+ 38 , 0 0 , 0 , 0 |
So what's happening here? How is the Rotation
of the part adversely affecting the Position
??