# Face weapon in the right direction that the player is facing!

Member Posts: 3
edited February 2017

I am working on a basic attack in which the player will use a weapon to attack the bad guys. It uses the same attack as a sword except the weapon is not actually a sword but it's an electric shock of lightning. However, I'm trying to face the weapon in the right direction the player is facing. Everytime I face to the left the weapon always keeps facing to the right and doesn't flip horizontally whenever I press a key to attack. I've followed most of the steps I found on other posts here on the forums but it doesn't seem to be working for me. I've already created a boolean Game attribute and rules to the player that goes like this:

Rule: If "A" receives a key press...
Change attribute: game.BasicWeapon To: True
Otherwise... Change attribute: game.BasicWeapon To: False

Group:
Constrain Attribute: game.PlayerX To: self.PositionX
Constrain Attribute: game.PlayerY To: self.PositionY

Here are rules made to the weapon:

Rule: If game.BasicWeapon is True...
Constrain attribute: self.positionX To: game.PlayerX
Constrain attribute: self.positionY To: game.PlayerY
Otherwise... self.positionY To: -100

Animation

Play Sound

The weapon is a separate actor which will be an arm shooting out the electric shock of lightning from his finger and I tried to constrain it to my player. Here's how it looks like: https://postimg.org/image/i4c3vbgsn/

• Member Posts: 3
edited February 2017

Here are the rules I have set up on my player:
https://postimg.org/image/5g7q9gdib/

• Member Posts: 1,182

I'm guessing
when you constrain position it will always go to that position relative to player.

You need two constrain rules. On for each side then and check position.

If player is left constrain to player position x -100

If player position right constrain to player position x+100

• Member Posts: 3

@Toque said:
I'm guessing
when you constrain position it will always go to that position relative to player.

You need two constrain rules. On for each side then and check position.

If player is left constrain to player position x -100

If player position right constrain to player position x+100

I just recently figured it out myself and it works. I just had to make another boolean and use a rule that goes "If "A" key is pressed and flip horizontal is False" and then made another rule that says "If "A" key is pressed and flip horizontal is True."

Not sure if your method works too but thanks for helping. I think that's all for now!!

• Member Posts: 1,182

@CyberHax5100 said:

@Toque said:
I'm guessing
when you constrain position it will always go to that position relative to player.

You need two constrain rules. On for each side then and check position.

If player is left constrain to player position x -100

If player position right constrain to player position x+100

I just recently figured it out myself and it works. I just had to make another boolean and use a rule that goes "If "A" key is pressed and flip horizontal is False" and then made another rule that says "If "A" key is pressed and flip horizontal is True."

Not sure if your method works too but thanks for helping. I think that's all for now!!

I wasn't sure of what you were doing but yes that works awesome!!! I do the same thing as well like that.