Issue with multiple keys being pressed
Hey guys,
I'm controlling an actor using key input (left button down makes actor go left etc) - I'll eventually replace these with on screen buttons but I'm pretty sure this issue will still arise.
Essentially, I when left button is down, my actor goes left, when right is down he goes right. When neither is down, he stops. All working fine.
I want the player to be able to quickly change direction, so if they're pressing left, but then press right, right will take over and change the direction. For some reason, this only works one way.
If I'm holding down left, the actor moves left. If I keep holding down left and press right, he goes right. If I then release right, whilst left is still down, he goes back left. Perfect.
However, when I press right, he moves right, but pressing left he just keeps going right. The rules are the same for both buttons, so not sure what's going on.
If anyone can figure it out I'd be very grateful. I've posted my behaviours below - the trigger movement behaviour is for something else and isn't interfering. Also, I've tried this with nested rules as shown, and with the rules separated out, so that's not it.
Comments
the nest which you exclude is causing the behaviour you describe tough
don't have "left" as "else" of "right"
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
and "not moving" also not as "else" of "left"
just if none of the two keys are pressed change or interpolate motion to 0
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
In your current version
if you keep holding "right" your code never reaches "no movement" .
but the other way round "left" is turned of by hitting "right"
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
having three separate rules
Left
Right
No Movement
would be the cleanest solution
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
Hey @BigDave, thanks for the help! This certainly removes the issue mentioned, but now when two keys are pressed, the actor doesn't move. So when I'm pressing right, then press left, the actor just stops, instead of moving left. And vice versa.
I'm trying to keep it relatively fluid, so pressing right, then pressing left (whilst still pressing right) would result in the actor moving left. And vice versa. Otherwise the controls don't feel as responsive.
I've tried putting duplicating the left rules and putting them in the right otherwise along with the right key in the right otherwise, but this doesn't solve the issue.
I assume this is possible but I can't work out the combination of rules and behaviours!
So keeping one key "down" should always be overwritten by pressing the later one.
I see.
I attached one solution I think there could be many ways of doing it.
https://www.dropbox.com/sh/y36jzzql0inuiar/AACDW3Ss2ZJ1LqPdS2p5313xa?dl=0
PS: I use interpolate over 0.05 secs to change the linear x movement to 0.
Instead of changing the motion to 0.
Basically it functions as a smooth temporarily constraint, its more reliable to really stop the movement.
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
Thanks for this @bigdave! Super helpful. And great tip on the quick interpolate, the not stopping instantly been bugging me.