How to make moving object move with another player controlled object?
ivanmerga
Member Posts: 3
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
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
Basically i want the centre of the shields pattern to always be positioned at the centre of the ship
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.