# Limit Force

Get help using Construct 2

### » Wed Jan 22, 2014 2:07 am

Hey,

I'm making a game where the user can shoot a ball.
The balls velocity increases the further away the mouse is from the cannon when they click.

Although, I want the balls velocity to increase up to a certain point.

So when they click I want to do something like this:
If the distance from cannon is > 500, then force = 500 else force = distance

But the only way I can see doing this is by making a variable and then assigning that the distance and then using that variable to check that the distance isn't over 500 and then assign a force based on that result.

What is the appropriate approach for this?

Right now my event is
Apply force distance(ball.X, ball.Y, Touch.X, Touch.Y) * 5 toward (Touch.X, Touch.Y)

Thanks!
B
4
Posts: 14
Reputation: 228

### » Wed Jan 22, 2014 9:20 am

I can see nothing wrong with

theforce= distance(ball.X, ball.Y, Touch.X, Touch.Y)
if theforce>500 then theforce=500
apply theforce at angle

sort of thing

But if you want it in 1 event then something like

apply ( (distance(ball.X, ball.Y, Touch.X, Touch.Y)<500)*( distance(ball.X, ball.Y, Touch.X, Touch.Y)))+( ( distance(ball.X, ball.Y, Touch.X, Touch.Y)>=500)*500) at angle

(I think the first method would probably run faster and is easier to read.)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Wed Jan 22, 2014 9:33 am

Limiting the output value should be quite easy with   max(500, 5 * distance (whateve))

https://www.scirra.com/manual/126/system-expressions
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

### » Wed Jan 22, 2014 9:49 am

sometimes I think I know what I am doing and then I am reminded I don't !

@Joannak - Thankyou.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Wed Jan 22, 2014 10:35 am

Caveat.

On some systems max() and min() behave just the opposite way one would expect, and I've not tested this to be sure which one is right.

Otoh, that kind of mistake is usually quite easy to spot.
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

### » Wed Jan 22, 2014 11:44 am

Thanks for the replies guys, the max() function is exactly what I was looking for!
B
4
Posts: 14
Reputation: 228