- Home /
LoadLevel() resets all input to 0! Disastrous!
Dudes!
I've built this cool and quite extensive 2D action platformer, like Super Meat Boy. Whenever the player die, I reload the scene to automatically reset all the gameMechanics.
However, against my will, all player input is set to 0.
If the player was running right, holding leftctrl for running, when the scene is reloaded he should automatically start running again.
But what happens is that he stands still, and you have to lift your fingers off the buttons and then press them again to make it register.
This is so cumbersome, and really ruins the speed and pace of the game for me.
float h = Input.GetAxisRaw("Horizontal");
control = Input.GetKey (KeyCode.LeftControl);
Are there any workarounds to this date? To manually reset everything in the scene is such an ultra cumbersome solution.
Can you somehow cash the inputs and carry them over to the next scene? I have a singleton gameState object, that can store info if someone knows how to solve this issue!
Cheers, and I hope this post will help other people with the same problem :)
"you have to lift your fingers off the buttons and then press them again to make it register"
Evidently, Input starts reading when a level loads; any input that began before that moment will not be considered. As a workaround, you could cache the player's velocity when a level ends, and re-apply it when the next level begins. But the player must still lift-and-re-press their input keys.
If you've proven to yourself that Input won't register already-pressed keys, I'm afraid that's your answer.
Its better you try to respawn the player at nearest check point rather reloading level.If level is really heavy ,$$anonymous$$y suggestion is to re-spawn player.And try to make a method which is responsible for player's movement and try calling it after player's respawn.Hope this helps Thank You Nsk
Answer by Kiwasi · Mar 09, 2015 at 05:22 AM
I don't think it can be done, not unless you rewrite the input system.
You could cheat and have a message that says "press space to start". That will force the user to take their fingers off the keys and start again.
Alternatively you could reset the level without reloading the scene.
Your answer
Follow this Question
Related Questions
How to clear input after loadlevel on android 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Clear presses from previous scene 4 Answers
Load scene on button press 4 Answers
Input resets when scene changes 1 Answer