Targeting Actors Manually with Expression Editor....
sillylaughter
Member Posts: 3
We have three actors: Player, Door1, and Door2.
Is there a way on key press to check and see which door the player is overlapping and change the x and y coordinates of the player to the other door? In other words, if Player overlaps with Door1, set self.position.x = door2.position.x? It seems like I should be able to manually add door2.position.x as the value for the Players new coordinates, but this crashes when I try it. Is the syntax wrong? Is it doable? Can someone provide the syntax if this is not the way to do it? (I don't want to use a global game variable.)
Thanks for any help!
Sherry
Is there a way on key press to check and see which door the player is overlapping and change the x and y coordinates of the player to the other door? In other words, if Player overlaps with Door1, set self.position.x = door2.position.x? It seems like I should be able to manually add door2.position.x as the value for the Players new coordinates, but this crashes when I try it. Is the syntax wrong? Is it doable? Can someone provide the syntax if this is not the way to do it? (I don't want to use a global game variable.)
Thanks for any help!
Sherry
Comments
In the door actors, have the following rule:
When [all] conditions: actor collides/overlaps with actor [player] AND key [keyname] is down
.....Change Attribute game.doorX to self.position.X
.....Change Attribute game.doorY to self.position.Y
In the player actor, have the following rule:
When [all] conditions: actor collides/overlaps with actor [door] AND key [keyname] is down
.....Timer after 0.1 second (this is to allow the active door to set the game attributes first)
..........Change Attribute self.position.X to game.doorX
..........Change Attribute self.position.Y to game.doorY
Be aware that rules like this can cause "looping" issues where the condition is true and then as soon as the player moves to the other door, the condition is true again (immediately) and the player just flashes back and forth between doors. You can usually alleviate this by either changing the position when the key is then UP or by adding a timer or boolean that helps to control when swapping positions is allowed.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User