Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Shantred · Jul 20, 2011 at 09:46 PM · first-person-controllerfalling-through-floorreset-position

Moving first person controller via script

Hello, I'm new to using unity and am looking forward to getting my hands dirty, but first I'm following along with a short tutorial series.

I'm at a point where I'm writing a small script "catch" a player when they fall off the edge of the terrain, and move them to the starting location. However, the script is not actually moving the player.

Here's the code (javascript):

 function Update () 
 {
     if ( transform.position.y < -50 ) {
         transform.position.y = 2;
         transform.position.x = 0;
         transform.position.z = 0;

         //Send verification to console
         print ( "Player fell, resetting to start." );
     }
 }

When I hit play and run the player off the edge, I can see the code firing off in console, but I just keep falling. I've attached the script to the player fab and can see it in inspector when I click the player. Can anyone see what I've done wrong?

Comment
Add comment · Show 2
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 aldonaletto · Jul 20, 2011 at 10:19 PM 0
Share

Are you using the standard First Person Controller which comes with Unity? I mean the Standard Assets/Character Controllers/First Person Controller.

avatar image Shantred · Jul 20, 2011 at 10:27 PM 0
Share

yes, Loaded it exactly like that.

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by aldonaletto · Jul 20, 2011 at 10:52 PM

There's nothing wrong with your code. I've just tested it in a project which uses the First Person Controller, and it worked as expected. But I tested a hypothesis: I attached the script to Graphics, a First Person Controller's child, and the player fell continuously, while the Graphics child was "jumping" to the initial position each time the limit was reached. Could it be your problem? Check if the script is attached to the First Person Controller or to one of its children (Graphics or Main Camera).

Comment
Add comment · Show 2 · 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
avatar image Shantred · Jul 20, 2011 at 11:29 PM 0
Share

You had it, thank you. I had it attached to the graphic, not the actual controller itself.

avatar image aldonaletto · Jul 21, 2011 at 12:59 AM 0
Share

I made a similar mistake some time ago - it's highly frustrating, because you look to the script, change the instructions order, look again, place debug instructions, and nothing seems to make sense!
By the way, please click the "check" button below the voting thumbs in my answer to signal it solved the problem, so it can help others with similar issues.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Crosshair? How? 6 Answers

how do I move the 1st person controller by dragging the mouse 1 Answer

C# Crouch script problem 1 Answer

Can't get 1st person controller to stay on a platform. 2 Answers

how to use the dual joystick from the prefab and how can i put it in my first person controller? 4 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