Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I generate unique vector3 values based on playerID?

Asked by
chrono2 189
7 years ago
Edited 7 years ago

Well, this got moderated for being too vague last time, so hopefully I can word it a bit better...

I want to create a weird sort of... Aura system, for use in anime games like Bleach or Dragon Ball. But I want to ensure that each player has a totally unique aura colour, for reasons I'll go into later for the sake of brevity.

To accomplish this, I'm essentially just going to toss a vector3 value into the player's client or their character or somewhere, and have any aura particle effects read it to determine their colour; if the value is 0, 0, 0, the player will have an aura particle emitter in their torso whose colour value is 0,0,0.

So, now I've got a system where I can freely change the aura colour of a person. Brilliant. But like I said, I want to ensure that each one is unique, so my idea was to generate them based on playerID, as each player has their own ID number. So is there any way to actually accomplish this? The only thing I've thought of is using maths, like...

playerID = game.Players.LocalPlayer.UserId
character = game.Players.LocalPlayer.Character
function gencolor()
local VectorColor = Instance.new(Vector3Value)
VectorColor.Parent = character.Torso

local value1 = playerID - [insert some arbitrary long number here]
local value2 = playerID - [insert some arbitrary long number here]
local value3 = playerID - [insert some arbitrary long number here]
if value1 >255 then 1 = 255
if value2 > 255 then 2 = 255
if value3 > 255 then 3 = 255
VectorColor.Value = Vector3.new(1 , 2 , 3)
end

Or something along those lines. But then as new players arrive to play the game, they'd find that they all have pure white auras as the number subtracted from their value is too small.

If this isn't an option, is there any way to easily generate unique colours on a player-by-player basis?

The reason that I want every player to have a unique colour assigned to them is so that you can almost identify a person from long range based on the colour or "feel" of their aura alone. Two people might have similar colours, but no two will be identical.

2
Well, why did you use Vector3Values? Why not use Color3Values? Since you are going to be setting a color to them. KingLoneCat 2642 — 7y
0
Because I forgot they existed. I'm too lazy to update this, but for future answerers and commenters, consider it changed. chrono2 189 — 7y
0
Just save a random Color3 to new players using DataStores. User#11440 120 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

Procedural generation

I don't know what procedural means to you, but procedural generation simply means that data is generated by an algorithm rather than being predetermined. This algorithm can be the algorithm for a pseudorandom number generator, perlin noise, or even some obscure algorithm that just gets the magnitude of the vertex over the lips.


Noise

Perlin noise will always generate the same values, given the same input. This is because the generator is functional. An example of how to use it in this context might for example be

Color.Value = Color3.fromHSV(math.noise(UserId*10,UserId,UserId*.001),1,1)

HSV is used in this context to give a full range of colours from a simple algorithm.


Random generation (seeded)

Because the random generator can take a seed, and will always generate the same sequence of numbers from the seed, you can use the UserId as the seed.

math.randomseed(UserId)
Color.Value = Color3.new(math.random(), math.random(), math.random())

Similar UserIds will produce similar colours in this case however, so you may want to test whether the numbers produced are diverse enough for your playerbase.


Tick generation (saved)

This generates the colour randomly based on when they joined, and this will not produce the same colours every time a player joins so you will need to save their colour in a DataStore. I am simply leaving this here for completeness.

Color.Value = Color3.fromHSV(tick()%1,1,1)

Alternatively, you can use the fractional part of the tick to seed the random number generator

math.randomseed((tick()%1)*1e16)
Color.Value = Color3.new(math.random(), math.random(), math.random())

However as mentioned you will need to save this.

Ad

Answer this question