Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by nowhereman · Dec 31, 2010 at 06:21 PM · charactercontrollerteleportmomentum

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jason B · Dec 31, 2010 at 07:07 PM 0
Share

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.

avatar image nowhereman · Dec 31, 2010 at 07:27 PM 0
Share

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?

avatar image YoshieMaster · Jan 01, 2011 at 08:08 AM 3
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges