- Home /
How do I disable the Character controller but keep velocity?
I'm trying to figure out some sort of way make my player able to phase through walls, but keeping the velocity whilst doing so. Untill now I've made a trigger next to the wall and when the player walks into it, his character controller just gets disabled, but then he looses his momentum, which he needs to get through the wall and is just stuck there... Is there any way to do this with the character controller, or am I going to need to use something else?
Answer by HarshadK · Sep 11, 2014 at 02:16 PM
Before you disable the character controller store the current velocity in a variable.
Then you can assign this velocity stored to you player to move him.
Once he has passed through the wall you can re-enable your character controller.
Answer by Ben-Stoneman · Sep 11, 2014 at 02:21 PM
As disabling the CharacterControllerScript causes the player to loose momentum, you will need to avoid doing this. If you don't want the player to be able to contol the character, simply put a feature in that stops the player from effecting the player, like an if statement.
if(phasing = true)
{
//Effect when player inputs
}
else //No effect when player inputs
If the player effects the momentum, then you will need to freeze the velocity until phasing is complete.
Answer by Owen-Reynolds · Sep 11, 2014 at 02:28 PM
Not really. When you use a character controller script, you don't have a velocity, in the sense of a rigidbody. The code in the character controller script (which ever one you use) does the movement, based on some of it's variables. Disabled script means disabled movement. It's like asking for a television to keep the last image after you unplug it. Only way to "keep" the velocity is to have someone else read and use those variables.
But I wouldn't bother trying to capture the velocity. What if they very slowly hit the wall. It takes them 30 seconds to slowly phase through? And if they sprint up to the wall, I think it still looks good they have to slow down into "wall phasing speed."
I'd just have them hit the trigger (and maybe they have to press the phaseWall button?) and always go through the wall at a set speed.
Your answer
