CFrame-Intergrated Revolving-axis(es) - How?
Asked by
8 years ago Edited 8 years ago
My current game in development requires the use of 'laser distributors' and 'laser receptacles', additionally paired with several more custom-made items.
My current focus is on the distributor, which requires for the 'nozzle' or 'cannon' (/'launcher') brick to revolve in an orbit around the distributor's turret brick, always sticking inside-of the hull of the the brick in question.
The nozzle/cannon brick is required to make 90-degree rotations, always having one end of the brick (which is a cylinder) inside the hull; that doesn't mean that it can't move, just that it needs to appear-to-be in the hull at all times.
My current script, which has served me very well in the making of sliding-doors and hidden-panels, derived from the Roblox Wiki Article concerning Part Sliding is seen as below:
02 | local newPos = Part.Position + Vector 3. new(- 2 , 0 , 2 ) |
06 | local Diff = newPos - Part.Position |
07 | local Mag = Diff.magnitude |
08 | local Direction = CFrame.new(Part.Position, newPos).lookVector |
10 | if Debounce then return end |
12 | for n = 0 , Mag, Increment do |
13 | Part.CFrame = Part.CFrame + (Direction * Increment) |
14 | wait( (Time/Mag) * Increment ) |
18 | script.Parent.ClickDetector.MouseClick:connect(MovePart) |
I have tried to modify it to suit my need of an additional 'rotationAxis' argument, but that has met a brick-wall. Figuratively, of course...
02 | local newPos = Part.Position + Vector 3. new(- 2 , 0 , 2 ) |
06 | local Diff = newPos - Part.Position |
07 | local Mag = Diff.magnitude |
08 | local Direction = CFrame.new(Part.Position, newPos).lookVector |
10 | local RotationAngle = Part.CFrame * CFrame.Angles(- 45 , 0 , 45 ) |
11 | local RotationAxis = RotationAngle * Direction |
14 | if Debounce then return end |
16 | for n = 0 , Mag, Increment do |
17 | Part.CFrame = Part.CFrame + ( (Direction * Increment) * RotationAxis * Mag) |
18 | wait( (Time/Mag) * Increment ) |
22 | script.Parent.ClickDetector.MouseClick:connect(MovePart) |
And bearing in mind that the Roblox Wiki's document on this is really really hard to understand, I can't fit my needs properly - hence why I came here.
To recap, the subject of assistance: Rotation Axis and Orbits: How do I create such thing?
If you have a viable solution, that is appreciated. Smiley face.
After-Note: It seems like I have solved the problem Myself. Albeit a bit 'laggy' and 'un-optimised', it serves well. You'll see my answer to the post.