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 sanghai · Sep 20, 2011 at 06:15 AM · airplane

Need Help for AirPlane Script

I have written below script for the Airplane this script allows airplane to move right or left and up and down but I want air plane to move forward and back also ......May I get help for the same....

using UnityEngine; using System.Collections;

public class MoveAirPlane: MonoBehaviour {

 public float    _init_x                 = 0.0f;         //inital x position
 public float    _init_y                 = 0.0f;         //initial y position
 public float    _horizontal_extent      = 20.0f;        //max horizontal distance achieved on each side
 public float    _vertical_extent        = 10.0f;        //max vertical distance achieve on each side
 public float   varspeed = 50.0f;
 
 // Use this for initalizing setting
 /*void initSettings()
 {
     
 }*/
 
 // Use this for initialization
 void Start () {
 
     //    initSettings();
 }
 
 
 // Update is called once per frame
 void Update () {
     
     Quaternion temp_rotate0 = new Quaternion((Input.GetAxis("Vertical") / 4) * -1, 0.0f, (Input.GetAxis("Horizontal") / 4) * -1, 1.0f);
      //set the new rotation with a tween so that the craft returns back to normal in a slow motion
     transform.rotation = Quaternion.Lerp(transform.rotation, temp_rotate0, 0.05f);
     //0.05f will limit the rotation to maximum 45 degrees on each side, 1 will make it 90
             
     
     transform.position = new Vector3(Mathf.Clamp(transform.position.x, _init_x - _horizontal_extent, _init_x + _horizontal_extent), 
                                         Mathf.Clamp(transform.position.y, _init_y - _vertical_extent, _init_y + _vertical_extent), transform.position.z);
 
   transform.Translate(Input.GetAxis("Horizontal") * 50, Input.GetAxis("Vertical") * 50, 0, Space.World);    
     
     rigidbody.AddForce(0,0,5 * varspeed);
     
     }

}

Comment
Add comment · Show 4
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 timsk · Sep 20, 2011 at 08:10 AM 1
Share

Could you just apply the same logic for X and Y to the Z axis ?

avatar image sanghai · Sep 20, 2011 at 08:18 AM 0
Share

O ya I just need to do it for z axis ..I am so dumb !!! Thanks a lot

avatar image timsk · Sep 20, 2011 at 08:22 AM 1
Share

glad to help :D. annoying that this question shall remain flagged as unanswered....

avatar image sanghai · Sep 20, 2011 at 09:34 AM 0
Share

timsk I am new to unity answers what should I do to say its correct answers ...

1 Reply

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

Answer by timsk · Sep 20, 2011 at 09:56 AM

apply the same logic you have for the X and Y axis to the Z axis.

(I'm pretty new as well, just mark this as the correct answer i guess)

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 sanghai · Sep 20, 2011 at 10:26 AM 0
Share

This is what I have done .... Check this code but listen I just want it to move forward and not the backward... Only want " _init_z + _foward_extent " to work and not the $$anonymous$$us one then what should I write ins$$anonymous$$d of that ?

 transform.position = new Vector3($$anonymous$$athf.Clamp(transform.position.x, _init_x - _horizontal_extent, _init_x + _horizontal_extent), 
                                         transform.position.y, 
                                         $$anonymous$$athf.Clamp(transform.position.z, _init_z - _forward_extent, _init_z + _forward_extent));
avatar image timsk · Sep 20, 2011 at 10:42 AM 0
Share

well the way i would do it is define my own input and not give it a negative button. For instance verticals input has positive "W" and negative "S". I haven't actually tried this, but it seems like it should work.

avatar image sanghai · Sep 20, 2011 at 10:44 AM 0
Share

I got it ... .Thanks $$anonymous$$athf.Clamp(transform.position.z, _init_z, _init_z + _forward_extent));

avatar image timsk · Sep 20, 2011 at 10:51 AM 0
Share

good to hear :)

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

Script Execution Order removes scripts on apply 1 Answer

Can I make an array of scripts? 3 Answers

How to start with camera and Airplane for the game ? 1 Answer

Objectives based on object appear. 2 Answers

How To Add A FX When I Teleport. 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