- Home /
Stop player momentum carrying over when using a 'portal'?
(ha. just noticed the title made a referance, i did not intend for that to happen...)
So I'm using these teleporter type objects in my platformer game, that, when you step inside them they translate the player object 200 units up to another set of platforming objects (it's a long story why i do this, but it's the key game mechanic and i need to keep it intact). While the player is being moved, i turn off the player controller script and camera look scripts (i'm using the prefab first person controller scripts), and turn them back on when the player finished being moved.
The problem is, the player seems to regain all the momentum it carried when it entered the portal, which means that if they were moving fast enough or had leaped into the portal, they end up falling off the platform after being teleported. Would anyone know of a way to stop this from happeneing? the script is a little over my head, and i've tried to understand it, but i have had no luck =/
EDIT: I found a variable in the CharacterMotor script named velocity (it's a Vector3), which seems to be storing the velocity when the charactermotor script is disabled. It's under a class CharacterMotorMovement and has the @System.NonSerialized. If I got rid of @System.NonSerialized, can i access this variable and how? Sorry, I don't have a lot of scripting experience and my attempts
GetComponent(CharacterMotor2).CharacterMotorMovement2.velocity.x=0;
aren't working, I get a NullReferenceException: Object reference not set to an instance of an object
Are you talking about the downward momentum (since CharacterControllers basically will infinitely accelerate downward during a Simple$$anonymous$$ove)? If you are, you'll have to find a way to ground the player before being teleported, so that the momentum resets.
Ah, that's interesting, didn't know that. Although I'm talking about both downward and side to side. Although this gives me an idea. Could i potentially add in some script that says wait till the player has grounded before moving them?
Clearly you didn't listen to GLaDOS when she said "...understand how a portal affects forward momentum, or to be more precise, how it does not. $$anonymous$$omentum, a function of mass and velocity, is conserved between portals. In layman's terms, speedy thing goes in, speedy thing comes out." You should learn to think with portals.
Answer by nowhereman · Dec 31, 2010 at 08:34 PM
Figured it out >.< I was disabling the character motor script entirely, instead of using the static variable canControl. When i use the canControl variable instead, the script keeps running and does not store the movement velocities and such.
Although I am still curious, how would I have accessed the velocity in the script?
Your answer
![](https://koobas.hobune.stream/wayback/20220613093449im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Need help with script, one time touch to the screen = synchronize camera with face 0 Answers
How to make a cooldown on a script 1 Answer
Null Reference Exception with GetComponent() while component is attached 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers