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 rOBY GAMES · May 04, 2014 at 08:26 AM · axispersonflyx axis

Character to fly in axis X

Hello to all.

In my character I have the First Person Controller. I want the character to get up in the air going up on the Y axis Now everything works ok thanks alo script Aldonaletto below. The problem lies in the fact that the character salt, but can not get it right and to the left of it seems to be locked. I tried to change all the values ​​but nothing. I ask for a help from someone more experienced maybe Aldonaletto by itself. How could I go up and then move to the right and left forever in flight? Thank you.

var cMotor: CharacterMotor; // reference to the CharacterMotor script

 function Start(){ // get the CharacterMotor script at Start:
     cMotor = GetComponent(CharacterMotor);
 }
  
 function Update(){ // move player upwards while F is pressed
     if (Input.GetKey("f")){
        cMotor.SetVelocity(Vector3.up*1.5);
     }
 }
  
 // This do-nothing function is included just to avoid error messages
 // because SetVelocity tries to call it
  
 function OnExternalVelocity(){
 }
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
1
Best Answer

Answer by NoseKills · May 04, 2014 at 10:03 AM

We can't see how SetVelocity works, but if it works as supposed you should define the velocity and modify it based on key presses and finally pass it to the SetVelocity(). Something like this:

     function Start(){ // get the CharacterMotor script at Start:
         cMotor = GetComponent(CharacterMotor);
     }
     
     function Update(){ // move player upwards while F is pressed
 
         var velo:Vector3 = Vector3.zero;
         //vertical velocity
         if (Input.GetKey("f")){
             velo = Vector3.up;
         }
         else if (Input.GetKey("v"))
         {
             velo = Vector3.down;
         }
 
         //horizontal velocity
         if (Input.GetKey("z")){
             velo += Vector3.left;
         }
         else if (Input.GetKey("x"))
         {
             velo += Vector3.right;
         }
     // normalize velo so it's length is 1. Otherwise we will move faster diagonally
         cMotor.SetVelocity(velo.normalized * 1.5);
     }
Comment
Add comment · Show 3 · 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 rOBY GAMES · May 04, 2014 at 10:38 AM 0
Share

Really good. Thanks to work. Now I have to fix the controller because when I press w walk slow. Thank you.

avatar image rOBY GAMES · May 04, 2014 at 11:00 AM 0
Share

Sorry again Nose$$anonymous$$ills.

When you are at the top and then release the keys, the character falls slowly, slowly. How can I disable the Down to lower the character normally? Thank you.

avatar image NoseKills · May 04, 2014 at 08:07 PM 0
Share

I guess the character has a rigidbody that makes the character fall due to gravity ? This Update function sets the velocity as Vector3.zero when no keys are pressed so there has to be something else making the character fall.

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

21 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 avatar image avatar image avatar image avatar image

Related Questions

Make ball flip around cube... 0 Answers

RPG scripts 2 Answers

Horizontal axis seperate inputs 0 Answers

Mouse look and character model? 1 Answer

Touch and move in any axis 0 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