Limit Force

0 favourites
  • 6 posts
From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • 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)


  • 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.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Limiting the output value should be quite easy with   max(500, 5 * distance (whateve))

  • <img src="smileys/smiley9.gif" border="0" align="middle" /> sometimes I think I know what I am doing and then I am reminded I don't ! <img src="smileys/smiley9.gif" border="0" align="middle" />

    Joannak - Thankyou.

  • 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.

  • Thanks for the replies guys, the max() function is exactly what I was looking for!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)