[SELF SOLVED] Formula for adding 1 for each increment of set number

I bet my title is wrong but idk how to translate it to english

I want to add 1 each time distance between two points is increments of some other number

For example i have camera width 9 and i add to it camera width /3
CameraWidth()+(CameraWidth()/3)
Which would be 12
Now i have distance between camera center and mouse cursor

And so now for each that 12 add 1 to some variable
Where i check that distance between camera center and cursor
So
12 = 1
24 = 2
36 = 3
and so go on
I bet there is some formula for that but i can’t figure it out
Any ideas?

1 Like

Deduced it myself

(DistanceBertweenTwoPositons) / CameraWidth()+(CameraWidth()/3)

Now each 12 will give me + 1

If i wanna reduce something that have 100 value
I would do set to 100 - ((DistanceBetweenTwoPositons) / (CameraWidth()+(CameraWidth()/3)))

Further i get that 100 value will get closer to 0

1 Like

That should work, but I think the modulo expression (mod()) may also help. I believe it checks if the second parameter is a divisor of the first., And returns a 1 if no remainder, a 0 if remainder.

So basically you’d have an event that is
Conditions:
Compare two numbers of modulo(yourdistance+camera,12) = 1
Trigger once

Actions
set the variable Multiplier to (yourdistance+camera/12)

If your distance is 12, the variable is set to 1. If your distance is 15, the variable is unchanged. If your distance is 24, the variable is set to 2. Etc.

Just another option.

1 Like

mod(#,#) returns the remainder of the 1st number divided by the 2nd unless the 1st number is less than the 2nd number and then it returns the 1st number. It’s great for looping numbers like keeping an angle within 360 like mod(angle,360)
0,7 = 0
1,7 = 1
7, 7 = 0
8,7 = 1
9,7 = 2

2 Likes

@Keith_1357
@Silver-Streak

Thx i did know about mod and it was 1st thing i did try
But it simply did not work for me for whatever reason

I was trying to make sound go lower further i get away from sound source with camera

Which works now perfectly fine
For me this did work
GlobalVariable(SoundsVolume) set to 100 - ((DistanceBetweenPositions(CameraCenterX(),CameraCenterY(),Sounds.X(),Sounds.Y())) / (CameraWidth()/70))

And now in sound volume i simply put GlobalVariable(SoundsIVolume)

And result (sound is buggy due to how i make units fire which is on certain frame of animation but volume control works perfectly fine)
Move units close to building and use WASD to move camera or drag it with any mouse button

Yeah i do not get sound from 1st bullet because object group i am referring to does not exist YET (before 1st shot) so no volume can be set but i can’t care less about it
Since overall mechanism works flawlessly

OK volume control do works flawlessly
But playing sound actually don’t
It is bugged as hell
I need 2 sounds to be playing for it to even work
For example 1 bazooka or pistol unit won’t trigger sound
You need at least 2 of them to fire at same time for it to even work
Machinegun units work solo because they fire fast enough
I gonna fix it later but damn

OK i found out that i made mistake of going for variable and then using it for volume

i should put this (and now i did)

100 - ((DistanceBetweenPositions(CameraCenterX(),CameraCenterY(),Sounds.X(),Sounds.Y())) / (CameraWidth()/70))
Directly in volume of sound that is playing
And now i am not missing any sound

Only buggy sound due playing it on animation frame left to fix

1 Like