How do I change speed in crouch (platform)?

0 favourites
  • 5 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • Sorry, another stupid newbie question but hopefully a simple one.

    I am trying to halve movement speed while crouched but I'm not having much luck with the expression.

    The imageHeight expression works correctly. The Platform.MaxSpeed does not but I think I have the right expression since the following DOES work:

    "PlayerCapsule.Platform.MaxSpeed*100"

    It work fine (with 100x the max speed) but I can't seen to divide MaxSpeed. With either /2 or *0.5 set, I simply lose the ability to move after I crouch. Any suggestions?

  • ok i think the problem is that everytime you click arrow while player on floor it keep getting slower so you need something to fix that.

    you can use boolean variable, the problem i can't know what should i do because i can't see the capx

  • The reason you lose the ability to move is because your dividing the max speed by 2 every frame the condition is true. Max speed is a variable, so when you divide it by 2, next time you access it it will be then halved value, not the original. The reason image-height/2 works is because it's a constant. Had you used .height instead your player would shrink infinitely.

    To fix this you have a few options:

    1. create a variable called originalMaxSpeed and set it to the max speed you want as a base. Then set max speed to originalMaxSpeed/2.

    2. Set the max speed to the base amount every frame, then affect it as the event sheet progresses. Since it will get reset on every frame, then it won't accumulate like it's doing now.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1. create a variable called originalMaxSpeed and set it to the max speed you want as a base. Then set max speed to originalMaxSpeed/2.

    Thanks for the explanation! That makes sense and for now, I was able to solve it with the method above. Though I'd like to find a way to have the originalMaxSpeed vairable driven by or otherwise tied to the MaxSpeed variable of PlayerCapsule(platform) object.

  • There isn't a purpose to doing that though, since you want the MaxSpeed variable of the behavior to change according to constantly true events. Where you would modify the real max speed you should just change originalMaxSpeed. If you want to use the actual variable (there isn't really a purpose to this), you should use another eventing paradigm. What that means (basically) is setting up the character with states, so that upon entering "crouched", his max speed changes once (not every frame like it does now), and then it gets set back to the original only once he exits that state. In my experience, this method is much more prone to bugs depending on the complexity of your system. It's much safer coding practice to reset the maxspeed every frame, then change it when things are true. Imagine a waterfall, where game frames are the water. Now, when it flows straight the max speed is its base value. However, when the player is crouched, a funnel diverts the flow of the water to half of it's original value. when the crouching events are true it would set a state "crouched" for the player to 1. Then, whenever crouched=1 it would "create the funnel" (setting the speed to half of it's original). however the frame when crouched goes back to 0 would mean the waterfall returns to it's full force.(the original speed returns.). The reason you would want a state called crouched is so that you can checked whether the player is crouched further down the line for other events. Let's say he can only go invisible while he is crouched, then all you would have to check is if crouched=1, instead of checking whether he is on the ground, and holding down button. Just giving you some insight to a more complex scenario where you would want a solid foundation for more complex logic.

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