Overall, I want to achieve the doppler effect on light, Redshift & Blueshift. In a nutshell, when an object heads away from you at relativistic speeds, it will appear as if the object has tinted red, and vice versa.
Would look something like this:
Light waves move to the right relative to observers.
My issue is that I’m not certain where to start, and how to code the intensity of one’s speed heading away or towards an object. I have tried using Velocity.Magnitude but that only prints out positive numbers, and no negative (heading away), which doesn’t differentiate between an object moving away or towards a part with its velocity.
This would be the relativistic doppler redshift formula for objects traveling transverse, which is what i will be using. I haven’t seen many posts talking about this in the forum, only found about unrelated raycasting and sound waves.
What you’ll want is to take the position of the point and subtract it with the position of the part in question. Magnitude will only get the distance between the two points. Also velocity is deprecated and should no longer be used for new work. Instead, you’ll want to use AssemblyLinearVelocity.
Distance is the only reason you’d want to do that. But I guess you could calculate the average with all 3 axis of the Vector3. But realistically, you’ll probably want to run your code with each axis of the Vector3.
I’ve tried it and it doesn’t really work as I expected, I tried some variations of
local Shift = rel.Position - p.Position -- rel = ball pov, p = other parts
p.Color = Color3.fromRGB(
255 / math.sqrt(1- (Shift.X^2 / c^2))
,255 / math.sqrt(1- (Shift.Y^2 / c^2))
,255 / math.sqrt(1- (Shift.Z^2 / c^2))
)
Including simplifying to
local Shift = rel.Position - p.Position -- rel = ball pov, p = other parts
p.Color = Color3.fromRGB(
255 / Shift.X
,255 / Shift.Y
,255 / Shift.Z
)
And the result I got:
This is from the red ball’s frame of reference. (Ignore the stretching/contracting map)
Increasing the velocity to the same amount for each axis results in different colors, mainly secondary colors. I assume the axis is mixed up with the colors (XYZ) + (RGB).
Another thing I’ve noticed is that all parts get shifted an equal amount of color, I’m not entirely sure what has happened but the front-facing side of the ball is supposed to receive the bluest and red for the backside.