How have you used different math functions in cool ways?


  • So I just started experimenting with the various math functions and so far it's a ton of fun, and also it seems like there's a lot you can do with these from what I've been trying so far.

    All of my stuff has been very simple so far, but post/talk about any cool creations you've made by using several of these functions together.


  • Pffft, math! BAH HUMBUG.

    Good thing for me, coding totally isn't tons of math!


  • Here there is a cool but simple thing you can do with math, using math.random!

    while true do
    	wait (0.5)
    	-- You can set the wait value to any number you want so that the light changes according to the music.
    	script.Parent.Color = Color3.new(math.random(),math.random(),math.random())
    	-- This will generate a pseudo-random color and set the brick to that color.
    end
    

    Make a cool dance stage with this!


  • @Aimarekin
    PD: It's a script inside any part you would like


  • local level = p.leaderstats.Level.Value
    
    local cost = (math.ceil(math.pow((Level+1) -(math.fmod((Level+1),5)),1.1)))
    

    This was my first time experimenting with math. not much but was fun to try to figure out how to solve the problem of the required cost only going up after a certain number of levels. (like a step function but done in a different way)


  • @ari462 said in How have you used different math functions in cool ways?:

    local cost = (math.ceil(math.pow((Level+1) -(math.fmod((Level+1),5)),1.1)))

    That's kinda similar to something like this:

    for level = 1, 20 do
    	local cost = math.floor(level/4)*7
    	print("Level = "..level, "Cost = "..cost)
    end
    

    Output:

    Level = 1	Cost = 0		
    Level = 2	Cost = 0		
    Level = 3	Cost = 0		
    Level = 4	Cost = 7		
    Level = 5	Cost = 7		
    Level = 6	Cost = 7		
    Level = 7	Cost = 7		
    Level = 8	Cost = 14		
    Level = 9	Cost = 14		
    Level = 10	Cost = 14		
    Level = 11	Cost = 14		
    Level = 12	Cost = 21		
    Level = 13	Cost = 21		
    Level = 14	Cost = 21		
    Level = 15	Cost = 21		
    Level = 16	Cost = 28		
    Level = 17	Cost = 28		
    Level = 18	Cost = 28		
    Level = 19	Cost = 28		
    Level = 20	Cost = 35
    

    Using your math, it's similar.

    Level = 1	Cost = 0		
    Level = 2	Cost = 0		
    Level = 3	Cost = 0		
    Level = 4	Cost = 6		
    Level = 5	Cost = 6		
    Level = 6	Cost = 6		
    Level = 7	Cost = 6		
    Level = 8	Cost = 6		
    Level = 9	Cost = 13		
    Level = 10	Cost = 13		
    Level = 11	Cost = 13		
    Level = 12	Cost = 13		
    Level = 13	Cost = 13		
    Level = 14	Cost = 20		
    Level = 15	Cost = 20		
    Level = 16	Cost = 20		
    Level = 17	Cost = 20		
    Level = 18	Cost = 20		
    Level = 19	Cost = 27		
    Level = 20	Cost = 27
    

    It's actually kind of the same.

    Not sure if the numbers need to be like you made them.


  • @CootKitty

    Oh cool thanks! I'm still super new so don't really know the efficient ways to do things!



  • for i = 1, configFolder.AmountOfRows.Value do
    	for i = 1, configFolder.AmountPerRow.Value do
    	local clone = stone:Clone()
    	clone.Transparency = 0
    	clone.CanCollide = true
    	clone.BrickColor = colors[math.random(#colors)]
    	if clone.BrickColor == colors[14] then -- Gold
    		clone.Material = Enum.Material.Neon
    	elseif clone.BrickColor == colors[3] then -- Iron
    		clone.Material = Enum.Material.Metal
    	elseif clone.BrickColor == colors[1] then -- Coal
    		clone.Material = Enum.Material.Concrete
    	end
    	clone.Name = "Clone" ..i
    	clone.Parent = cloneModel
    	clone.Position = Vector3.new(stonePosition.x + xPosition, stonePosition.y, stonePosition.z)
    	xPosition = xPosition + 4
    	wait(configFolder.GenerationInterval.Value)
    end
    

    I used math.random to generate ores at different probability rates (it was a separate table so its not there)


  • @Rhythic Take a look at the new random number generator


  • @kingdom5 What do you mean new random number generator? Is there a new feature? I did a search but could not find any articles referencing this.


  • Somewhat what I work with. :P Nothing else comes to mind rn.

    local plr = game:GetService('Players').LocalPlayer
    repeat wait() char = plr.Character until char and char:FindFirstChild('Humanoid') and char:FindFirstChild('HumanoidRootPart')
    local hum = char.Humanoid
    local hrp = char.HumanoidRootPart
    local cam = Workspace.CurrentCamera
    local uis = game:GetService('UserInputService')
    local w,a,s,d = 0,0,0,0
    
    hum.PlatformStand = true
    hrp.Anchored = true
    repeat
    game:GetService('RunService').Stepped:Wait()
    if uis:IsKeyDown('W') then w = 1 else w = 0 end
    if uis:IsKeyDown('S') then s = 1 else s = 0 end
    if uis:IsKeyDown('A') then a = 1 else a = 0 end
    if uis:IsKeyDown('D') then d = 1 else d = 0 end
    hrp.CFrame = CFrame.new(cam.CFrame.p, hrp.CFrame.p) * CFrame.new((s-w)*5,0,(d-a)*5) * CFrame.Angles(0,0,math.rad(180)) -- Not sure if these calculations are correct; Untested.
    until nil
    

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.