Random width/height and proportions...

This forum is currently in read-only mode.
From the Asset Store
Take your creativity to new heights with over 410+ files.
  • I want to create copies of the same object with random sizes, but I don't want their proportions to be distorted.

    I tried;

    *set height*

    35 + (random 20)

    *set width*

    40 + (random 20)

    35 and 40 are the original dimensions. The problem is that unless both random numbers are the same the image either looks squished or stretched.

    Is there a way to generate a random number and then add/subtract that number to another value?

    (could it be done with global or private variables? that's the only way I imagine it would work but I'm not entirely sure how to do it in this case...)

    -thanks!

  • You probably should use some basic math for this.

    35/40 is 0.875... your ratio basically.

    Then set sprite.width to 40 + random(X)

    and in the following action you set sprite.height to sprite.width*0.875.

    That should work. Remember you will not really get random sizes this way since you're only adding a random number to the size. You should use + random(X) - random(X) or something. Unless you want only bigger versions of course.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you Pixel, I'll give that a try.

  • (never mind... my project .cap is working perfectly now! )

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)