# playMaker

### Author Topic: Change Direction / Math Operator Question  (Read 565 times)

#### Kodagames

• Junior Playmaker
• Posts: 52
##### Change Direction / Math Operator Question
« on: October 30, 2018, 07:48:33 PM »
I have an NPC moving in the X direction with a speed variable set to 1. When it collides with an object I need its speed variable to be -1 so that it moves in the other direction.

I can hard code this with another variable and have it set to -1 with something like Set Float Value but if I have different enemies set at different speeds (5 to -5) that will also collide with this object it wouldn't work.

How would I do the math / use actions and variables to make this happen?

#### Athin

• Full Member
• Posts: 135
##### Re: Change Direction / Math Operator Question
« Reply #1 on: October 31, 2018, 12:54:54 AM »
Just simply have the speed variable get multiplied by -1 when it trips the trigger.  So as long as you need it to go the exact speed in the opposite direction, it will work.

#### Kodagames

• Junior Playmaker
• Posts: 52
##### Re: Change Direction / Math Operator Question
« Reply #2 on: October 31, 2018, 06:28:33 AM »
Doh... Now that you told me it makes perfect sense Anything multiplied by 1 is anything (weather negative or positive).
Thank you so very much!
« Last Edit: October 31, 2018, 01:26:35 PM by Kodagames »