22.5 C
New York
Sunday, July 27, 2025

vector – Pseudo-3D Parallax Shifting


everybody. I’m engaged on a recreation that depends fairly considerably on “faking” 3D by utilizing completely different parallaxing and polygonal rework strategies. In a present instance, I’m engaged on a fan with tilted blades, that spins alongside the x-axis. I first set up a base set of 3D factors (Vector3) for a blade (principally the UV, however translated to the place the blade must be on the backside of the spin, and with Z values of zero):

#Set up 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 gap from the axis of spin to the within of every blade.) This fan has 4 blades, so I iterate by way of them with a “for” loop. I clone the bottom set of factors as soon as for every blade, as every has its personal distinctive angle in regards to the fan’s axis of rotation. I then iterate by way of the 4 factors for every set, rotating every alongside the blade’s lengthwise axis to “tilt” it, then once more alongside the fan’s axis of rotation to “spin” it:

for f in 4:
    
    var cloneBladePoints = bladePoints.duplicate()
    
    #Rotate the bottom polygon
    
    for i in cloneBladePoints.dimension():
        
        #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 airplane
        
        cloneBladePoints[i] = Vector2(cloneBladePoints[i].x,cloneBladePoints[i].y)

Every blade is a Polygon2D node,the polygon of which accepts an array of 2D factors, so I flatten every of the factors alongside the XY axis. I then apply every blade’s set of factors 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 opposite 3 blades)

This all coalesces to do that:

(animated)
https://imgur.com/a/V1iJ9yf

My query is that this: how do I correctly apply parallax to this fan? (fan blades seem larger when “nearer” to the viewer, and smaller when “additional away, transferring digital camera to proper of fan makes you see its entrance airplane, and many others.” The system is successfully a one-point perspective, with a vanishing level on the middle of the digital camera.
Apologies if this can be a duplicate query, I actually do not even know what I might seek for in on the lookout for this answer. Additionally, my code positively is not optimum, I plan on cleansing stuff up as soon as I’ve gotten it working.

This is the total code, for reference:

BladeTiltVec = Vector2.RIGHT.rotated(BladeTilt)

var curPropVec = PropAngleVec

#Set up 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 bottom polygon
    
    for i in cloneBladePoints.dimension():
        
        #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 airplane
        
        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 subsequent blade
    
    curPropVec = curPropVec.rotated(PI/2)

Thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles