How can I scale using python?

Can somebody tell me how can I scale an object using python, I need to set the scaling factor in X,Y and Z separatedly for an object but I want a way to do something like this:

UPKEY = Increase Z scaling
DOWNKEY = Decrease Z scaling
LEFTKEY = Decrease X scaling
RIGHTKEY = Increase X scaling
AKEY = Increase Y scaling
ZKEY = Decrease Z scaling

can somebody help me please?

Hmm. There isn’t a function to set scale but there is a property that doesn’t say is read only so you would probably:


cont = GameLogic.getCurrentController()
owner = cont.getOwner()
upkey = cont.getSensor("upkey")
downkey = cont.getSensor("downkey")
leftkey = cont.getSensor("leftkey")
rightkey = cont.getSensor("rightkey")
akey = cont.getSensor("akey")
zkey = cont.getSensor("zkey")

if upkey.isPositive():
    owner.scaling[2] += .1
elif downkey.isPositive() and owner.scaling[2] > .1:
    owner.scaling[2] -= .1
if leftkey.isPositive():
    owner.scaling[0] += .1
elif rightkey.isPositive() and owner.scaling[0] > .1:
    owner.scaling[0] -= .1
if akey.isPositive():
     owner.scaling[1] += .1
elif zkey.isPositive() and owner.scaling[1] > .1:
     owner.scaling[1] -= .1

That’s untested code. Make sure the names of the sensors are spelled exactly the same as those listed. If you want to hold down a key and have it keep scaling just add an always sensor. I don’t know if it negative scales so I put the limit in there.

I can’t have it working, i made all excactly like you wrote, but nothing happens, and there is no one error in the console :frowning: but thanks anyway

I heard a rumour that incorrectly calibrated orientation matricies happen to scale objects.

You could set up an IPO that scales the object. Control it with a property driven IPO actuator.

Or if you want for the orientation matrix, multiply the current orientation matrix with this matrix:

S 0 0
0 S 0
0 0 S

where S is the scaling factor (1 = 100%)

There should be some python scripts around that have a function for matrix multiplication.
If you do not have any rotation set to your orientation matrix would look like this:

1 0 0
0 1 0
0 0 1

you can just replace this current matrix with the above one.

I hope this helps

Sorry about that. It was probably read only, then. Yeah, you’ll have to use the orientation matrix, then. You could use a scaling ipo if you didn’t mind scaling all 3 at the same time. Or you might could try 3 ipos and blending them somehow. You can tie an ipo to a property, but I’ve already written my code for the day that doesn’t work.