Clamp help?

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Anyone have any idea why the expression:

    clamp(Player.Value('Xcomp'), cos(Player.Value('Vector')) * -200, cos(Player.Value('Vector')) * 200)

    is returning -200 as soon as Player.Value('Xcomp') goes below zero?

    cap here if you need:

    W and S to move, player looks at the mouse

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What happens when cos(global('Vector')) returns -1?

  • I'm assuming it would return 200 unfortunately

    Not sure how I would do this, but still the current problem is that for some reason, as soon as Xcomp is a negative, BOTH Xcomp and Ycomp variables get messed up

  • I think I fixed it:

    clamp(Player.Value('Xcomp'), abs(cos(Player.Value('Vector')) * global('MaxSpeed')) * -1, abs(cos(Player.Value('Vector')) * global('MaxSpeed')))

    Absolute value ftw

  • I can't really look at the .cap right now, so I'll just do some guesswork.

    I am assuming the Xcomp and cos(Vector) get into negative values when facing left, right? In that case, you have the following case:

    clamp(Xcomp,200,-200). This is erroneous, try making sure the min and max values are correctly set.

    I'd suggest something like this:

    cosV = cos(Vector)

    minSpeed = min(cosV*-200, cosV*200)

    maxSpeed = max(cosV*-200, cosV*200)

    clamp(value, minSpeed, maxSpeed)

    That way, the minimum and maximum values will be correctly ordered. Let me know how it goes.

  • In theory that looks like it should work, I even made a little text box display those values to make sure they were the inverse of each other at all times, which they were, the minimum one was always a negative and the other, always a positive.

    Yet when I move my player around using that method, he now moves MEGA twitchy, basically when Xcomp goes from a negative to a positive, he then goes max speed in the positive direction, and vice versa when going from positive to negative. It doesn't make sense!

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