• 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
0
Question by Mike Wong · Nov 10, 2013 at 06:10 PM · transformfirstpersoncontroller

Why would character fly upwards with transform.position?

I tried to teleport my character with transform.position=new Vector3(x,0,z), on a collision check (so that whenever character touches something, it returns to(x,0,z)), and it works out just fine. However, when I set y!=0, such as transform.position=new Vector3(0,10,0),the character would not go to the position on top, instead it shots straight upward, with a speed of about 10/frame!!! Is there some assymetry in the y axis for the transform method? since x and z don't have this effect, while the character just pops out of screen whenever y is used....

p.s.I wonder if it's the effect of the charactercontroller? For example if it incorrectly treats this rise in height as a jump or something, it would perhaps decide to give the character a y-speed, and make it fly...?

Thank you very much!

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 3lem3n7 · Nov 10, 2013 at 06:27 PM 0
Share

Could you also post the script which is causing this problem?

avatar image robertbu · Nov 10, 2013 at 06:28 PM 0
Share

We need to see the rest of your code to see what is going on. The assignment to transform.position would all happen in a single frame, so something else is going on.

avatar image Mike Wong · Nov 10, 2013 at 06:53 PM 0
Share
 function OnControllerColliderHit (hit:ControllerColliderHit){

 if(hit.transform.name=="Cube_03to01")
     transform.position=pos01;
 if(hit.transform.name=="Cube_03to02"||hit.transform.name=="Cube_05to02")
     transform.position=pos02; 


 //......
     //a check with each zone 01-26 as possible teleport target


 if(hit.transform.name=="Cube_04to25"||hit.transform.name=="Cube_22to25"||hit.transform.name=="Cube_24to25")
     transform.position=pos25;
 if(hit.transform.name=="Cube_24to26")
     transform.position=pos26;

 //*****transform.position=new Vector3(0,1,0);******
     
 }

In fact I recorded pos01-26 in 26 zones, and between each two zones that have a connection, a pair of CubeXXtoXX is created. On collision with such a cube, the character is then transported to the target zone (whose index is deter$$anonymous$$ed by the Cube's name).

But I found that teleporting between zones in the same floor level or going down a level would work fine, but going up a level would cause the character flying...

I also tried to just replace the code with "transform.position=new Vector3(0,1,0);" on any collision and the result is the same...character only flies when y!=0

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Not working script 1 Answer

how to make a character resume after going into a random battle? 1 Answer

Transform child out of bounds 0 Answers

Editing height relative to audio levels. 0 Answers

How to glue Objects together on contact? 2 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