View difference between Paste ID: 43ANxFtn and kSeQ3qd6
SHOW: | | - or go back to the newest paste.
1
lp=game.Players.LocalPlayer
2
local Tool = Instance.new('HopperBin',lp.Backpack)
3
Tool.Name='MoveSun'
4
5
sky = Instance.new("Sky",game.Lighting)
6
sky.SunTextureId = "rbxassetid://188291833"
7-
sky.MoonTextureId = "rbxassetid://520140378"
7+
sky.MoonTextureId = "rbxassetid://520140377"
8
9
-- convert number (in hours) to TimeOfDay string
10
-- because TimeOfDay doesn't cast numbers as expected (3.7 -> 03:07:00 instead of 3:42:00)
11
local function ToTimeOfDay(n)
12
	n = n % 24
13
	local i,f = math.modf(n)
14
	local m = f*60
15
	local mi,mf = math.modf(m)
16
	m = tostring(math.abs(math.floor(m)))
17
	local s = tostring(math.abs(math.floor(mf*60)))
18
	return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
19
end
20
21
-- convert TimeOfDay string to number (in hours)
22
local function FromTimeOfDay(t)
23
	local signed,h,m,s = t:match("^(%-?)(%d+):(%d+):(%d+)$")
24
	s = tonumber(s)/60
25
	m = tonumber(m + s)/60
26
	h = tonumber(h) + m
27
	return h * (#signed > 0 and -1 or 1)
28
end
29
30
local function rad_sc(n)
31
	return n/(math.pi*2)
32
end
33
34
local function sc_rad(n)
35
	return n*(math.pi*2)
36
end
37
38
-- convert direction to latitude (as GeographicLatitude) and longitude (as TimeOfDay)
39
local function ToLatLon(d)
40
	d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp
41
	local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2))
42
	local lon = math.atan2(d.y,d.x)
43
	
44
	lat = rad_sc(lat)*360 + 23.5
45
	lon = ToTimeOfDay(rad_sc(lon)*24 - 6)
46
47
	return lat,lon
48
end
49
50
--[[
51
-- convert lat and lon to direction (doesn't work)
52
local function to_dir(lat,lon)
53
	lat = sc_rad((lat - 23.5)/360)
54
	lon = sc_rad((FromTimeOfDay(lon) + 6)/24)
55
56
	return Vector3.new(
57
		(math.cos(lat)*math.cos(lon)),
58
		(math.cos(lat)*math.sin(lon)),
59
		math.sin(lat)
60
	)
61
end
62
]]
63
64
local Event = {}
65
local function Disconnect(...)
66
	for _,name in pairs{...} do
67
		if Event[name] then
68
			Event[name]:disconnect()
69
			Event[name] = nil
70
		end
71
	end
72
end
73
74
local Lighting = Game:GetService("Lighting")
75
local down = false
76
77
local P = 0.02
78
local D = 16
79
local position = Lighting:GetSunDirection()
80
local velocity = Vector3.new(0,0,0)
81
local goal = Lighting:GetSunDirection()
82
83
local active = false
84
local function Activate(Mouse)
85
	position = Lighting:GetSunDirection()
86
	goal = Lighting:GetSunDirection()
87
	active = true
88
	Event.Down = Mouse.Button1Down:connect(function()
89
		down = true
90
		goal = Mouse.UnitRay.Direction
91
	end)
92
	
93
	Event.Up = Mouse.Button1Up:connect(function()
94
		down = false
95
	end)
96
	
97
	Event.Move = Mouse.Move:connect(function()
98
		if down then
99
			goal = Mouse.UnitRay.Direction
100
		end
101
	end)
102
103
	asd = game:GetService'RunService'.RenderStepped:connect(function()
104
		velocity = Vector3.new(
105
			velocity.x + P * ((goal.x - position.x) + D * -velocity.x),
106
			velocity.y + P * ((goal.y - position.y) + D * -velocity.y),
107
			velocity.z + P * ((goal.z - position.z) + D * -velocity.z)
108
		)
109
		position = position + velocity
110
		local lat,lon = ToLatLon(position)
111
		Lighting.GeographicLatitude = lat
112
		Lighting.TimeOfDay = lon
113
		--print(lon)
114
		--wait()
115
	end)
116
end
117
118
local function Deactivate()
119
	active = false
120
	down = false
121
	asd:disconnect()
122
	Disconnect("Down","Up","Move")
123
end
124
125
Tool.Selected:connect(Activate)
126
Tool.Deselected:connect(Deactivate)