• 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 Ouija · Aug 07, 2013 at 12:11 PM · bounds

Engine shut on/off at bounds

I have been playing with this project file http://forum.unity3d.com/threads/43984-Unity-testproject-a-little-flightsim

I would like to add a box(or bounds) that the airplane can fly around inside. Once it goes outside the bounds, the airplane engine shuts off. If you go back inside(glide back inside) the bounds, the engine turns back on.

The bounds should possibly work like this link below:

http://answers.unity3d.com/questions/509590/enabledisable-box-bounds.html

By holding down shift in the game it stalls the plane engine, perhaps accessing that could help?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Xtro · Aug 07, 2013 at 02:15 PM

You must use a box collider and it must be marked as trigger. Then you can use OnTrigger events in your plane script.

Enable the engine in OnTriggerEnter Disable the engine in OnTriggerExit

Comment
Add comment · Show 7 · 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 Xtro · Aug 08, 2013 at 02:25 AM 0
Share

Did it help?

avatar image Xtro · Aug 08, 2013 at 03:48 AM 0
Share

I'm here to help if you can supply enough info about what you've done and what's wrong with it. Supply me info as much as you can. Screenshots or whatever...

avatar image Xtro · Aug 08, 2013 at 04:59 AM 0
Share

zip it maybe ? screenshots will be very helpful too.

avatar image Xtro · Aug 08, 2013 at 01:24 PM 0
Share

I can look at this when I'm home. 8 hours later :(

avatar image Xtro · Aug 09, 2013 at 04:53 AM 0
Share

Like the collision event, you must handle the trigger enter and exit events to detect the fly zone collider. It's too late here for me to write the code. I must sleep. :(

Show more comments
avatar image
1

Answer by bubzy · Aug 09, 2013 at 05:41 AM

     //Limiting to playfield
     
     //Here i wrap the airplane around the playfield so that you cannot fly under the landscape
     if (transform.position.x >= 900.0) transform.position.x = 0;
     else if (transform.position.x <= -900.0) transform.position.x = 900.0;
     else if (transform.position.z >= 900.0) transform.position.z = 0;
     else if (transform.position.z <= -900.0) transform.position.z = 900.0;
     
     //Here i limit the height
     if (positiony > 1000) transform.position.y = 1000;

this section deals with limiting the playfield. you can modify this section to do what you want,

 //Limiting to playfield
 
 //Here i wrap the airplane around the playfield so that you cannot fly under the landscape
 if (transform.position.x >= 900.0) //TURN OFF ENGINE
 else if (transform.position.x <= -900.0) //TURN OFF ENGINE
 else if (transform.position.z >= 900.0) //TURN OFF ENGINE
 else if (transform.position.z <= -900.0) //TURN OFF ENGINE
 

you can limit the size, so the playfield (900 to -900) could still count, and the plane will fly inside a smaller playfield.

personally I would use a global variable for this to make easier modification.

 var playField : float 900.0f;
 var engineZone : float 800.0f;
 if (transform.position.x <= -engineZone) //TURN OFF ENGINE
 if (transform.position.x <= -playField) transform.position.x = playField;


not working code, but I hope you get the idea.

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 Ouija · Aug 09, 2013 at 07:40 AM 0
Share

Hey bubzy, I have actually thought about that, but its not good for what I need. Doing it that way limits me to one giant box. I am trying to achieve something different. I want to be able to place a variety of boxes around the map that you fly navigate inside, if you fly outside of them the engine turns off. See the difference? perhaps I should have stated this before haha. Thanks for your effort though, seriously!

so yeah quick recap for yourself and anyone else reading. I need a box with some kinda bounds script (i've started a forum for the bounds here: http://answers.unity3d.com/questions/509590/enabledisable-box-bounds.html)

the airplane script needs to be modified to shut the engine off when outside these bounds. :) sorry for writting so much, just trying to paint a clear picture for you all!

To me the answers seems to be a trigger on the box that the script n the airplane can read? turn it on and off that way?

avatar image Ouija · Aug 13, 2013 at 08:54 PM 0
Share

Hey bubzy, I gave your answer a thumbs up! what you wrote here actually is correct, so it deserves some respect haha. Just in case someone finds this your answer might be useful!

Peace

avatar image bubzy · Aug 14, 2013 at 09:46 AM 0
Share

glad you could use it :)

avatar image Ouija · Aug 14, 2013 at 04:43 PM 0
Share

lol I didnt use it, It's not what I was looking for, But what you wrote there does actually work if someone else was looking for something similar. But in my case its not exactly what I needed. But who knows it might help someone out.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Is a Bounds Aligner Tool even a feasible idea? 1 Answer

Get bounds.size of a game object in an LODGroup? 1 Answer

Getting the mesh component of an object 1 Answer

Change Collider Bounds at Run-time 0 Answers

Keeping track of spawn positions with Bounds.Intersects 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