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 Commander Quackers · Nov 03, 2013 at 07:03 PM · movementbugflying

Is there any flying bug scripts out there?

Hey everyone! I've had Unity for about a month now, and I figure it's time to make my first game. It's going to be more of a simulation game than a regular game, but it's going to basically be about this robotic fly in a modern-day living room. However, I'm still just learning Javascript, and I don't have the ability to create a code as of right now that allows the fly to "fly," move forward, backwards, left and right.

So far I've got this, but it's very choppy/not smooth as I would like it. The game is a simulation game and I would love it to have a nice, smooth feel to it. #pragma strict

 var walkspeed: float = 5.0;
 
 function Start() {
 
 
 
 }
 
 function Update() {
 
     rigidbody.freezeRotation = true;
 
     if (Input.GetKey("space")) rigidbody.AddForce(0, 2, 0);
     if (Input.GetKey("d")) transform.Translate(Vector3(-1, 0, 0) * Time.deltaTime * walkspeed);
     if (Input.GetKey("a")) transform.Translate(Vector3(1, 0, 0) * Time.deltaTime * walkspeed);
     if (Input.GetKey("w")) transform.Translate(Vector3(0, 0, -1) * Time.deltaTime * walkspeed);
     if (Input.GetKey("s")) transform.Translate(Vector3(0, 0, 1) * Time.deltaTime* walkspeed);
     
 }


The flying is triggered by pressing the space bar and the rest is just wsad movement, I just found this script somewhere on the forums and edited a little bit. So back to the question, is there anyone that has a better script out there for flying bug movement? Or, can you please edit this one to improve it?

Any help is greatly appreciated, and thank you in advance!

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 Commander Quackers · Nov 05, 2013 at 09:11 PM 0
Share

Sorry to bump, but this is still troubling me.

There anyone out there who can help?

avatar image highend · Nov 06, 2013 at 12:20 AM 0
Share

i think this is what you are looking for if you want to make it your self link text

change the var (everywhere, not just at the top) in something like :velocityup add an extra var like velocityup, only now down, make the number -8 for example, you can change it to what ever you want make the var gravity : float = 0; ins$$anonymous$$d of 20.0;

remove the if statement about grounding inlcuding the starting { and the ending }

add an extra button like: if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; (where jumpspeed should be velocityup now) change it to the keys you want for the flying so you wil get for example if(Input.Get$$anonymous$$ey("q")) moveDirection.y = velocitydown or up, what ever you want

1 Reply

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

Answer by aldonaletto · Nov 06, 2013 at 01:24 AM

AddForce works more smoothly in FixedUpdate, and you don't have to freeze rotations every Update. You can also simplify a lot the code with Input.GetAxis:

 var walkspeed: float = 5.0;
  
 function Start() {
     rigidbody.freezeRotation = true;
 }
  
 function FixedUpdate(){
     if (Input.GetKey("space")) rigidbody.AddForce(0, 2, 0);
 }
 
 function Update() {
     var dirX = Input.GetAxis("Horizontal"); // read A/D keys
     var dirY = Input.GetAxis("Vertical"); // read W/S keys
     transform.Translate(Vector3(dirX, 0, dirY) * walkspeed * Time.deltaTime);
 }
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

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

Objects cloning on movement? 1 Answer

User Scripts not showing in "Add component - scripts" 6 Answers

Variable Script "movement" 2 Answers

Airplane Script Control 1 Answer

Saving/ Loading Script Weird Bug 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