Scale object in one direction (SOLVED)

I want to change the scale.x of an object to the right. When you change the X scale, the object expands from center to the left and to the right and i want to expand the object only from the left to the right.

I’m guessing that you’re talking about a game object with a sprite, and you’re scaling the game object? When you add a sprite to a game object it will by default be centred around origo. When you scale the game object the sprite will become wider and extend further to the left and right of the centre. If you instead want it to expand from left to right you need to move your sprite so that it’s left edge is at 0.

1 Like

Hi @britzl,

could you explain this a little bit more in detail? :slight_smile:
No matter how I position the sprite it will always scale to left and right - any ideas what I do wrong?

function update(self, dt)
    go.set("#middle", "scale.x", 20)
end

Thanks a lot and sorry for bumping this old thead!

Hi @zugende!

In your example, you are scaling the sprite itself, and since it is a local scale, you’ll notice it scales “to the left and right”

You need to offset the sprite relative to its parent, lets say to 64,0,0 (if your sprite is 128 pixels wide), and then scale the parent game object instead with go.set_scale(".", vmath.vector3(2, 1, 1)) and you should see it being scaled away from the position of the parent game object.

1 Like

Awesome! Thanks for the fast reply. It worked!
Makes sense to scale the “parent” GO instead of the sprite itself.

2 Likes