Keep Object From Moving on Y Axis (Random Y position)

I'm creating an endless runner illustrate in the image bellow:

The buildings spawn in a random y position and has a move rule for the x axis.

The problem I'm having is that whenever the character lands on the building, the building moves down.

I've already tried marking the fixed rotation, change the drag and density attributes, but none of them work.

The last try was to create the following rule to my buildings:

Change attribute -> game.yposition to self.yposition
constrain attribute -> self.yposition to game.yposition

It doesn't work because every time a building is spawned it changes all the other buildings y position.

I know you guys will help me out with this. :)

Cheers.

Comments

  • BBEnkBBEnk Member Posts: 1,764

    easy way, did you try constraining self position to self position.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @BBEnk said:
    easy way, did you try constraining self position to self position.

    To clarify, that would be Constrain Attribute self.Position.Y to self.Position.Y. As you noticed, you can't use a single game attribute for multiple attribute values. But you can constrain an attribute to itself in order to force it to not change.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956
    edited December 2014

    Create a real attribute within the building actor. Call it "MyY".

    Add the following statement to the building actor.

    Change attribute self.MyY to self.posY

    Make another rule,

    If self.posY < self.MyY
    constrain attribute self.posY to self.MyY

  • joaosjcjoaosjc Member Posts: 19

    I tried this too!! Didn't work :(

    It seems that it if there is another event that changes the actor y position, this code does not have the power to prevent it from moving.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Can you post a screenshot of your actual rules?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • colandercolander Member Posts: 1,610

    @Rabid Parrot said: Create a real attribute within the building actor. Call it "MyY".

    Add the following statement to the building actor.

    Change attribute self.MyY to self.posY

    Make another rule,

    If self.posY < self.MyY constrain attribute self.posY to self.MyY

    Everything Rabid Parrot said except the last bit I would not have the rule just the constrain attribute self.posY to self.MyY and make sure the building actor has fixed rotation. If they are all self attributes it should work.

  • jorkosjorkos Member, PRO Posts: 353

    don't use constrain. just set the Y value when the object is spawned with a change attribute. change the y value just before you spawn. it's that easy.

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @joaosjc also try unchecking Moveable for your spawned buildings.

    Lovely graphics, BTW. :smile:

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

  • joaosjcjoaosjc Member Posts: 19

    @Rabid Parrot said:
    Create a real attribute within the building actor. Call it "MyY".

    Add the following statement to the building actor.

    Change attribute self.MyY to self.posY

    Make another rule,

    If self.posY < self.MyY
    constrain attribute self.posY to self.MyY

    Actually, it worked. Tks. I was creating the "Y" attribute in the game. Haven't though about creating it in the actor. After I created the attribute myY, changed it to the spawn moment y position, and constrain the character position to it, it worked. Many tks

  • joaosjcjoaosjc Member Posts: 19

    @gyroscope said:
    Hi joaosjc also try unchecking Moveable for your spawned buildings.

    Lovely graphics, BTW. :smile:

    tks :)

Sign In or Register to comment.