BGE Python (Noobie Question)

Hello, I am trying to make a script where an object will constantly scale up, the starting size, ending size, and growth rate should be configurable from owners’ properties. Any help will be appreciated :smiley:

That’s a pretty simple task:)

Here’s an example of how to do this:
scaleExample.blend (414 KB)

and this is the script, but this script assumes your always going to be scaling evenly on all axis’s:


def init(cont):
    obj = cont.owner 
    obj["startingSize"] = obj.worldScale[0] 
    
def scaleObject(cont):
    obj = cont.owner 


    growthRate = obj["growthRate"]
    startingSize = obj["startingSize"]
    endingSize = obj["endingSize"]
    
    if startingSize > endingSize: 
        if growthRate > 0:           
            growthRate = -growthRate 


        if obj.worldScale[0] > endingSize:
            sx = obj.worldScale[0] + growthRate
            sy = obj.worldScale[1] + growthRate
            sz = obj.worldScale[2] + growthRate
            obj.worldScale = ([sx,sy,sz])
    
    if endingSize > startingSize: 
        if growthRate < 0:           
            growthRate = -growthRate 
            
        if obj.worldScale[0] < endingSize:
            sx = obj.worldScale[0] + growthRate
            sy = obj.worldScale[1] + growthRate
            sz = obj.worldScale[2] + growthRate
            obj.worldScale = ([sx,sy,sz])

If you want an explanation of the script let me know:)

you can do this with

  • a scale action,
  • an action actuator in property mode
  • a property to set the actuators frame
  • logic to increase this property

I would suggest to round the ‘increasing’ startingSize, since you are dealing with float values.

startingSize = round(obj["startingSize"], 3)

You see what I mean if you would change growthRate to some higher value like 0.1 for example.