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
0
Question by R-GiGgS84 · Nov 02, 2011 at 02:39 AM · fpstranslateupdownstandardassetsmobile

Move FPS up/down one level in a building

Hi there,

I am actually using Player Relative Control Prefab from the Standard Assets (Mobile) Folder and i have a 3D model that have a few storey. The problem here is i am trying to move the character (Player Relative Control) Up/Down one storey upon clicking on the GUI Button of 'Up' or 'Down' respectively. But i would need to click on the 'Down' a few time before the character will actually move down by one storey. I am using the following Code:

 character.transform.Translate(new Vector3(newPositionX, newPositionY, newPositionZ) * Time.deltaTime);

Someone can kindly advice me on what i should do to resolve this?

Thanks in advance!

Below is a sample of my problem code which should fire of when i click on the Button:

 if (GUI.Button(new Rect(10, 60, 80, 30), "Down")) {
 
                 //AutoFade.LoadLevel(null, 0, 1, Color.black);
 
                 Debug.Log("Before current position: " + character.transform.position.y);
 
                 for (int i = 0; i < floorHeightArrayList.Count; i++) {
 
                     if ((character.transform.position.y - 1) <= float.Parse(floorHeightArrayList[i].ToString())) {
 
                         /*if ((character.transform.position.y - 1) == float.Parse(floorHeightArrayList[i].ToString())) {
 
                             newPositionX = character.transform.position.x;
 
                             newPositionY = float.Parse(floorHeightArrayList[i + 2].ToString()) + 1.0f;
 
                             newPositionZ = character.transform.position.z;
 
                     
 
                             character.transform.position = new Vector3(newPositionX, newPositionY, newPositionZ);
 
                             break;
 
                         }*/
 
                         
 
                         newPositionX = character.transform.position.x;
 
                         newPositionY = float.Parse(floorHeightArrayList[i - 1].ToString()) + 1.0f;
 
                         newPositionZ = character.transform.position.z;
 
                         
 
                         //Debug.Log("newPositionY: " + newPositionY);
 
                         
 
                         character.transform.Translate(newPositionX, newPositionY, newPositionZ, Space.Self);
 
                         //character.transform.position = new Vector3(newPositionX, newPositionY, newPositionZ);
 
                         break;
 
                     }
 
                 }
 
                 Debug.Log("After current position: " + character.transform.position.y);
 
             }

                     
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by WillTAtl · Nov 02, 2011 at 03:38 AM

if you want to instantly jump one floor when clicking the button, there's no reason to multiply by deltaTime. You do that when you want to move at some steady rate over time, as in an update() function, and you multiply deltaTime by the velocity, not by a target position.

Assuming newPositionX/Y/Z are the point you want to go to one floor up/down, just remove the "*Time.deltaTime" bit entirely.

Comment
Add comment · Show 4 · 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 R-GiGgS84 · Nov 02, 2011 at 03:54 AM 0
Share

hi WillTati,

Thanks for the reply. I want the character to like slowly move up/down one level. Currently i am trying on the following codes:

character.transform.Translate(newPositionX, newPositionY, newPositionZ, Space.World);

But it don't seem to have the 'feel' of the character is move up/down.

avatar image WillTAtl · Nov 02, 2011 at 04:01 AM 0
Share

ah, sorry for the misunderstanding. I'm afraid I don't understand what's happening or what you're asking, then. Where are you using this line of code? In what function, and on what conditions?

It might help if you could add the entire function containing this line to the original question, ins$$anonymous$$d of giving just this one line!

avatar image R-GiGgS84 · Nov 02, 2011 at 04:05 AM 0
Share

Hi WillTatI,

Sorry for my poor explaination. I have attached above for the code that is suppose to fire off in a GUI Button.

avatar image WillTAtl · Nov 02, 2011 at 02:13 PM 0
Share

it sounds like you want an elevator, but without the elevator? Search UA for questions about elevators, they should be helpful, you'll just be applying the behavior to the player directly ins$$anonymous$$d of to an elevator object!

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

Why does transform.Rotate( x, y, z ) work correctly but transform.Rotate( Vector3.forward ) does not? 1 Answer

Realistic walking. 1 Answer

Moving Object up and down without player input (such as a spike that kills you) 2 Answers

shooting y axis 1 Answer

GUI begin vertical, to go Up 1 Answer


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