K
K
Kuusandr2019-11-20 16:29:56
Algorithms
Kuusandr, 2019-11-20 16:29:56

The control of the GG jump to the side slips by pressing two keys. How to remake the management of the GG?

In the game I use the control of the GG by pressing the keys.
By pressing to the right, to the left - the GG moves, respectively, to the right, to the left. When you press right + up, left + up, the hero makes a jump right + up, left + up. If you do a check on the flag cocked by the key press (release) handler, then the delay between the user pressing the key to the right and the key up jumps. For me, as a user, the delay seems to be minimal, but for a computer it is noticeable and the algorithm for checking a bunch of conditions skips all checks and, as a result, instead of jumping right (left), the GG starts moving right (left).
How can the situation be resolved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2019-11-20
@dollar

Option 1 (stupid)
Add a delay of 200ms before the hero starts moving left and right from the keys. This is done simply. At the moment of pressing, we remember the current time with an accuracy of milliseconds.
And the movement condition is as follows: the key to the right is clamped AND the clamping time is more than 200 ms
When pressing the up key, make a jump even in motion. Actually, it is even more correct than not doing it. That is, if the hero walks long enough to the right (several seconds), and then the player suddenly presses up, then the hero should not ignore the press, but jump right + up. Isn't it logical? Then the problem will resolve itself.
If you simultaneously press right + up - this is some kind of special combo, then you can, similarly to the first option, track the time of pressing to the right and allow the user to perform this combo within this delay.
That is, when you press the key to the right, you need to remember the current time.
And when you press the up key, the condition is checked.
The condition is: the up key is pressed AND the right key was pressed less than 200 ms ago
Similar to the previous option, but you still need to roll back the hero's coordinates to the position where he pressed the right key. After all, this combo is considered only from a place?
To avoid sharp rollbacks, you need to adjust not the starting coordinate of the jump, but the end point of the jump. Let's say the hero is jumping on a parabola. We calculate where he should have hit if he had jumped from the point where he pressed the key to the right. Then we recalculate what trajectory should be so that the player from the current coordinates would get to the same point. More precisely, we consider the initial speed and direction to hit this target.
If the hero in a jump can change the direction of acceleration with arrows, then you need to approach the game designer and ask what to do in this case. After all, in the end it all depends on his idea, what feelings he wanted to evoke in the player.

X
xmoonlight, 2019-11-20
@xmoonlight

1. Asynchronously, you need to poll the keyboard and set flags in variables before calculating the frame.
2. When calculating a frame, put everything together and correctly create the GG displacement vector.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question