Normalizing variables with maths?

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi again mathemancers!

    Okay so I need to normalize a variable.

    i.e. I have variable X and variable Y, and I want Y to always tend towards X. So if Y is greater than X, reduce Y. And if Y is less than X, increase Y.

    Normally I would of course do this using IF statements, but that's kinda infeasible (or unreasonably complicated) for what I'm currently working on and I'm really hoping there's a maths algorithm than can be used here.


  • If I have understood correctly what you want to do, then using an IF is not complicated at all. Just put this in Construct.

    Condition:   Y < X ; Action:    Set Variable Y to Y + 1

    Condition:   Y > X ; Action:    Set Variable Y to Y - 1

    For the first one, while Y is smaller than X, it adds +1 to Y each time the event is checked.

    This event runs roughly 60 times per second, so it would mean Y would be changed by roughly 60 in the course of a second. Change +1/-1 to anything else to increase/reduce the speed of change.

    If you want to set it to another value immediately, just change

    Set Variable Y to Y + 1


    Set Variable Y to <Value>

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, I think I've found a workaround for my original problem, but the reason I don't want to use IF statements is as follows:

    What I'm doing is setting a value AngleOfMotion which dictates the movement of an object. I want to set AngleOfMotion each tick using the variables AngleOfMomentum and AngleOfGravity. So what I want is for AngleOfMotion to start off as AngleOfMomentum and then move towards AngleOfGravity. But there are constantly random forces acting on the object which change the AngleOfMomentum, so I'm basically trying to figure a way to get an object to fall in a natural arc, but still react to any forces applied to it. Without using built in physics (they <img src="smileys/smiley35.gif" border="0"> everything up).

    And I confuse myself just thinking about it :P

    So I suppose what I was looking for was:

    AngleOfMotion = (Half way between AngleOfMotion and (Half way between AngleOfMomentum and AngleOfGravity))

    That's where it starts to get complex.

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