Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local M = game.Players.LocalPlayer:GetMouse();
- function Part(Orientation)
- local P = Instance.new("Part", workspace);
- P.Anchored = true;
- P.CFrame = Orientation;
- P = nil;
- end
- M.Button1Down:connect(function()
- if (M.Target) then
- local Surface = M.TargetSurface;
- local HitPosition = M.Hit.p
- local WorldSpaceNormalIdVector = Vector3.FromNormalId(Surface);
- local ObjectSpaceSurfaceDirection = M.Target.CFrame:vectorToWorldSpace(WorldSpaceNormalIdVector);
- -- ObjectSpaceSurfaceDirection is the direction the target surface is facing
- local Up = Vector3.new(0,1,0);
- if (math.abs(ObjectSpaceSurfaceDirection.Y) >= .99) then
- Up = M.Target.CFrame:vectorToWorldSpace(Vector3.new(1,0,0));
- print("Target surface faces world-space 'up.' Switching world-space 'up.'");
- end
- local PerpDirection = ObjectSpaceSurfaceDirection:Cross(Up);
- -- Create manual CFrame for part to "lay" on the surface.
- local FrontAxis = ObjectSpaceSurfaceDirection:Cross(PerpDirection);
- local Orientation = CFrame.new(HitPosition.X, HitPosition.Y, HitPosition.Z,
- PerpDirection.X, ObjectSpaceSurfaceDirection.X, -FrontAxis.X,
- PerpDirection.Y, ObjectSpaceSurfaceDirection.Y, -FrontAxis.Y,
- PerpDirection.Z, ObjectSpaceSurfaceDirection.Z, -FrontAxis.Z
- );
- Part(Orientation);
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement