How do I change speed in crouch (platform)?

Get help using Construct 2

Post » Sun Jul 01, 2012 9:32 pm

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.
[/URL]

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?
B
5
Posts: 20
Reputation: 1,015

Post » Sun Jul 01, 2012 9:43 pm

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
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Sun Jul 01, 2012 9:45 pm

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.
Davioware2012-07-01 21:45:56
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Sun Jul 01, 2012 10:47 pm

[QUOTE=Davioware]
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.

[/QUOTE]

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.
B
5
Posts: 20
Reputation: 1,015

Post » Mon Jul 02, 2012 1:43 am

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.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests