How can I invert an axis

Firstly a big thank you to everyone who has helped me learn by posting a question on this forum. This is my first, hope I'm not covering old ground.
Basically what I want to do is change the colour of an actor depending on another actors movement along the y Axis.
I have a sub descending in the scene. As it gets deeper I want another actor that covers the screen to darken by increasing the opacity (Alpha).
I currently have a game attribute (int) DEPTH. which is used to display the subs depth and also to darken the actor, Constrain (self.colour.alpha) to (game.Depth). problem is it works in reverse. the scene starts in total darkness but as the sub descends it starts to get lighter and the subs depth reads in minus figures.
I thought there may be an easy way to flip the axis so it increases as the sub descends but i cant figure it out.
Thanks in advance.

Best Answer

Answers

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Try converting the depth to a percentage number based on it's position from the screen height i.e.

    ((100 / screen.height) * game.depth)

    let's say that gives you 70%

    Take 70% away from 100% to get the difference

    (100 - ((100 / screen.height) * game.depth))

    That gives you 30%

    That's the alpha number to use with a formula like this:

    self.colour.alpha = (1 / 100) * (100 - ((100 / screen.height) * game.depth))

    I'm sure it can be written nicer than this.

    I've not got GameSalad open to test it but it looks right with a calculator.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    @Manto1 won't that make it lighter the further it goes down (the higher the depth number)?

    I realise my example won't work if your depth isn't actually the y position on the screen.
  • MantoManto Member Posts: 796
    @KevinCross I understood that it currently works fine, but needs to be reversed.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited August 2013
    Two more examples without converting them to percentages which isn't actually necessary

    If you're basing it on the y position between 0 and screen height:

    self.alpha = 1 - (game.Depth / screen.height)

    If you're basing it on the position between a min and max depth i.e. 0 to 400 depth

    self.alpha = (game.Depth / game.Max Depth)

    These should create a higher alpha number (i.e. darker image) the further it goes down.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2013

    Hi @Bottle_O_Mook

    Respect to the other guys' solutions; here's my take on it: make sure your attribute Depth is a real attribute.

    Work out the drop from top to bottom, for instance if the sub starts at 280 and drops to 30, then the max. drop is 250 (which I'll use for the following example).

    Add the following to your rules:

    Constrain Attribute scene.Depth to self.Position.Y
    Constrain self.Color.Alpha to 1/250+(scene.Depth/250)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • Bottle_O_MookBottle_O_Mook Member Posts: 2
    Hey All. Thanks for the quick responses.
    I tried Manto1 approach first as it seemed the quickest one to integrate into what I had already and sure enough it did the trick as the sub descended the scene grew darker,thanks heaps.
    As I had it though the scene didn't grow completely dark until I reached 0 so using some ideas from Gyroscope I changed a few things.
    now Sub has:
    Constrain Attribute scene.depth to: self.position.Y-6000
    And actor that changes Alpha has:
    Constrain Attribute self.colour.alpha to: 1-(scene.depth/1000)
    This now means that the scene gradually darkens within the first 1000 and the remainder of the scene takes place in the dark requiring the player to switch on the Subs lights which is exactly what I wanted.
    So thanks again to all.
Sign In or Register to comment.