everyone. I am working on a game that relies pretty substantially on "faking" 3D by using different parallaxing and polygonal transform techniques. In a current example, I am working on a fan with tilted blades, that spins along the x-axis. I first establish a base set of 3D points (Vector3) for a blade (basically the UV, but translated to where the blade should be at the bottom of the spin, and with Z values of zero):
#Establish base polygon
var bladePoints = [
Vector3(-BladeHalfSize.x,CoreRadius,0),
Vector3(BladeHalfSize.x,CoreRadius,0),
Vector3(BladeHalfSize.x, (CoreRadius + (BladeHalfSize.y * 2)),0 ),
Vector3(-BladeHalfSize.x,(CoreRadius + (BladeHalfSize.y * 2)),0 )
]
(CoreRadius is the distance from the axis of spin to the inside of each blade.) This fan has four blades, so I iterate through them with a "for" loop. I clone the base set of points once for each blade, as each has its own unique angle about the fan's axis of rotation. I then iterate through the four points for each set, rotating each along the blade's lengthwise axis to "tilt" it, then again along the fan's axis of rotation to "spin" it:
for f in 4:
var cloneBladePoints = bladePoints.duplicate()
#Rotate the base polygon
for i in cloneBladePoints.size():
#Tilt Blade
cloneBladePoints[i] = cloneBladePoints[i].rotated(Vector3.DOWN,-BladeTilt)
#Rotate Blade about Core
cloneBladePoints[i] = cloneBladePoints[i].rotated(Vector3.RIGHT,curPropVec.angle())
#Apply Parallax
#???
#Flatten to XY plane
cloneBladePoints[i] = Vector2(cloneBladePoints[i].x,cloneBladePoints[i].y)
Each blade is a Polygon2D node,the polygon of which accepts an array of 2D points, so I flatten each of the points along the XY axis. I then apply each blade's set of points to its corresponding blade polygon:
#Apply Stuff to blade
var blade = $NuSprite/Blades.get_child(f)
blade.polygon = PoolVector2Array(cloneBladePoints)
blade.z_index = 4.0 * curPropVec.y
blade.modulate.v = 0.75 + (curPropVec.y / 4.0)
(rinse/repeat with the other 3 blades)
This all coalesces to do this:
(animated) https://imgur.com/a/V1iJ9yf
My question is this: how do I properly apply parallax to this fan? (fan blades appear bigger when "closer" to the viewer, and smaller when "further away, moving camera to right of fan makes you see its front plane, etc." The system is effectively a one-point perspective, with a vanishing point at the center of the camera. Apologies if this is a duplicate question, I honestly don't even know what I would search for in looking for this solution. Also, my code definitely isn't optimal, I plan on cleaning stuff up once I've gotten it working.
Here's the full code, for reference:
BladeTiltVec = Vector2.RIGHT.rotated(BladeTilt)
var curPropVec = PropAngleVec
#Establish base polygon
var bladePoints = [
Vector3(-BladeHalfSize.x,CoreRadius,0),
Vector3(BladeHalfSize.x,CoreRadius,0),
Vector3(BladeHalfSize.x, (CoreRadius + (BladeHalfSize.y * 2)),0 ),
Vector3(-BladeHalfSize.x,(CoreRadius + (BladeHalfSize.y * 2)),0 )
]
for f in 4:
var cloneBladePoints = bladePoints.duplicate()
#Rotate the base polygon
for i in cloneBladePoints.size():
#Tilt Blade
cloneBladePoints[i] = cloneBladePoints[i].rotated(Vector3.DOWN,-BladeTilt)
#Rotate Blade about Core
cloneBladePoints[i] = cloneBladePoints[i].rotated(Vector3.RIGHT,curPropVec.angle())
#Apply Parallax
#???
#Flatten to XY plane
cloneBladePoints[i] = Vector2(cloneBladePoints[i].x,cloneBladePoints[i].y)
#Apply Stuff to blade
var blade = $NuSprite/Blades.get_child(f)
blade.polygon = PoolVector2Array(cloneBladePoints)
blade.z_index = 4.0 * curPropVec.y
blade.modulate.v = 0.75 + (curPropVec.y / 4.0)
#Rotate to next blade
curPropVec = curPropVec.rotated(PI/2)
Thank you!
