subtracting from vertex color eventually becomes white?

in my code I only subtract from a vertex color value, and somehow it’s going -> darker -> darker ->darker ->white.

what am I doing wrong?

note I tried checking if the value was negative and setting it to zero, and I tried checking to make sure the new value would be lower than the old… I am confused.


import bge
from mathutils import Vector


def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    Collision = cont.sensors['Collision']
    
    if Collision.positive:
        for objects in Collision.hitObjectList:
            
            if objects!=own['Owner']:
                if 'Boom' in own:
                    if 'Map' in objects:
                        print('HitMap')
                        mesh = objects.children[0].meshes[0]
                       
                        for v_index in range(mesh.getVertexArrayLength(0)):
                            vertex = mesh.getVertex(0, v_index)
                            V2 = objects.worldPosition+(objects.worldTransform * vertex.XYZ)
                            D2 = own.worldPosition-V2
                            if D2.magnitude<15:
                                D2X = D2.copy()
                                D2X+=-objects.worldOrientation.col[2]
                                D2X/=2
                                vertex.XYZ=vertex.XYZ+(objects.worldTransform.inve  rted()*(D2X*(15-D2.magnitude))*-.1)       
                                
                                      
                                R=(vertex.r-abs((15-(1*D2.magnitude))*.025))
                                # this should not allow the value to go up right?
                                if R<vertex.r:    
                                    vertex.r-=abs((15-(1*D2.magnitude))*.025)
                                
                                
                                G=(vertex.g-abs((15-(1*D2.magnitude))*.025))
                                if G<vertex.g:
                                    vertex.g-=abs((15-(1*D2.magnitude))*.025)
                                
                                
                                B=(vertex.b-abs((15-(1*D2.magnitude))*.025))
                                if B<vertex.b:    
                                    vertex.b-=abs((15-(1*D2.magnitude))*.025)
                                
                                if vertex.r<0.0:
                                    vertex.r=0.0
                                if vertex.g<0.0:
                                    vertex.g=0.0
                                if vertex.b<0.0:
                                    vertex.b=0.0    
                                    
                        objects.children[0].reinstancePhysicsMesh()                 
                            
                Vec2 = own.getVectTo(objects.worldPosition)
                objects.applyForce(Vec2[1]*own['Impact']*100)
                if not own['Owner'].invalid:
                    objects.applyForce((0,0,own['Owner'].localLinearVelocity.z*10),0)
    if 'Next' in own:
        added =bge.logic.getCurrentScene().addObject(own['Next'],own,0)
        added['Owner']=own['Owner']
    own.endObject()


main()



if vertex.r < 0.0

vertex.r will never be less then 0.0, it will jump back to 1.0.
Perform that check for each color before you apply the color to the vertex.
So check if R < 0.0 not vertex.r

Thanks! that worked great !

ask for permission not for forgiveness in this case I guess :smiley: