How do I (Smoothly scale an object relative to it's X pos)?

0 favourites
  • 5 posts
From the Asset Store
It's here!
$4.95 USD
Creepy and nasty horror track. It's terrifying from the beginning till the end. Goosebumps guaranteed
  • TL:DR, I want the ball to know what size to be depending on it's x/horizontal position, and have it tween smoothly too as it moves back and forth horizontally between both edges of the layout.

    More details:

    I am trying to make a horizontally moving ball object (uses physics for movement) follow a certain scale or size based on it's horizontal position traveling either left or right (and tween smoothly). In the middle of the layout (static screen, no scrolling) is where the ball will be the biggest (about 75-100 pixels big). At the left and right edges of the layout is where the ball will be the smallest size/scale (about 25 pixels small). The ball travels back and forth/left and right over time during play and must be the same size at the same X position every time it travels there.

    See picture for a rough idea.

    Thanks for any help!

  • Sounds like a linear equation. If the ball sprite is 100 x 100 (when 1:1), then, it should be something like:

    Every tick -> ball.width = 100 * [here a function with ball.X (screen center) wich gives as a result 1, so it multiplies 100 by 1 to get the max size of the ball], when at the center of the screen.

    And at the left edge, where ball.X = 12,5, the same equation should give you something like:

    Every tick -> ball.width = 100 * [here the same function on ball.X (12.5 for left edge) wich gives as a result 0.25, so it multiplies the 100 by 0.25 to get your 25 pixels wide ball]

    Also, I guess Every tick -> ball.height = ball.width after the above.

    Sorry I can't give you the equation, but it should be easy to google by "finding linear equation with 2 points", those points being [screenwidth/2, 1] and [12.5, 0.25].

    Good luck!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey! I appreciate your response. I tried fiddling with your logic and looking up linear equations with 2 points. I get what you're logic is going for, I'm just still a bit of a newb and I can't quite figure out how to get the ball.X (screen center)-type function to work. Not sure what actions and assignments would need to be used for something like a screen center function or line.

    Think lerp might be involved here as well?

    Another thing is that even if I get the linear equation to work with a screen center point, I still need to be able to dial in ease in and out cause i don't want a completely linear curve.

    Thanks again!

  • The equation would be a simple expression. Look at the capx: https://www.dropbox.com/s/yd21c2v70qcck ... .capx?dl=0

  • Thanks alextro! You're right it was super simple. I just don't have the knowledge yet to do stuff like that from scratch. I really appreciate it! I spent way too much time trying to figure it out on my own. Cheers!

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