How to make moving object move with another player controlled object?

ivanmergaivanmerga Member Posts: 3
edited November -1 in Working with GS (Mac)
First post so go easy on me : )

I have an object that is moving up and down the screen using a timer to change the x and y selfmotion values (adapting a how to tutorial from here). Now what i would like to do is have this object continue to follow this pattern as well as move with the player controlled object.

Imagine the already moving object as a shield in front of a ship, it moves 50 pixels up the screen then 100 back down. Now at the moment if the ship moves 80 pixels up the screen the object is no longer in front of the ship, this is what i want to change.

The ships x and y location are global attributes (im sure this is the correct path to take when making the other object follow the ship).

Any help would be appreciated im sure this is a simple fix i simply cannot get my head around it!

Thanks in advance

Comments

  • VoidedSkyVoidedSky Member Posts: 1,095
    do you want the "shield" to stay in front of the ship?
  • ivanmergaivanmerga Member Posts: 3
    i want the shield object to move in a set pattern up and down (so the ship is not always covered by the shield), i also want the shield object to move when the ship moves. At the moment when i've tried to set this up the shield continues running its up and down pattern but the ship can move so far up or down that the shield does not protect it anymore.

    Basically i want the centre of the shields pattern to always be positioned at the centre of the ship
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    In the shield create an integer attribute called backandforth.

    Then have a timer set for every and set the amount of time to whatever you want. Within the timer have:

    change attribute self.backandforth to (self.backandforth+1)%2

    This will cause this variable to cycle between 0 and 1 every amount of time you put in the timer.

    Then have a rule when self.backandforth = 0

    interpolate self.positionY to game.shipY+50

    OTHERWISE

    interpolate self.positionY to game.shipY-50

    This will cause the shield to move to 50 above the ship and then 50 below the ship.
  • VoidedSkyVoidedSky Member Posts: 1,095
    haha, I bet that took u 5 minutes, I was slowly getting there. lol, well, there you go ivanmerga.
  • ivanmergaivanmerga Member Posts: 3
    yes guys thanks a lot for the info, i had not even thought to use 'interpolate'. This defo worked out for me now :D
Sign In or Register to comment.