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
0
Question by hitory · Jun 02, 2011 at 03:18 AM · raycastraygroundaltitude

altitude checking from ground

I'm working on a small game, I've everything done, its an helicopter game and I don't want the helicopter to fly higher than a certain amount of units from the ground (an irregular terrain) To do so, I want the helicopter to ray cast a ray that ignores all layers except the "ground" one and if the ray is larger than a certain amount of units I want the player to be unable to fly higher than that, the up movement is controlled with the space bar and its a force movement.

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
1
Best Answer

Answer by Dreamer · Jun 02, 2011 at 03:56 AM

First set your irregular terrain to a layer "Terrain" (no other objects in this layer. Let's say the layer id is 1. (last parameter of Raycast function)

 var height_limit:float=3000;
 
 function GetHeliHeight:float(){
  var hit : RaycastHit;
  var heli_pos:float=GameObject.Find("Helicopter").transform.position;
  hit = Physics.Raycast (heli_pos, Vector(0,-1,0),1);
  return (Vector3.Distance(heli_pos, hit.collider.transform.position));
 }
 
 function HeliControl(){
  if(GetHeliHeight>=height_limit)
  //can't move up
  else
  //can move up
 }

Now you know roughly how to implement?

Comment
Add comment · Show 2 · 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 BeatCord · Jun 02, 2011 at 04:04 AM 0
Share

(I'm hitory) Thanks It works :D You're awesome

avatar image Dreamer · Jun 02, 2011 at 04:11 AM 0
Share

Am I? hahaha~

avatar image
0

Answer by Jesse Anders · Jun 02, 2011 at 03:51 AM

That's more of a statement than a question :)

I'm assuming though that the question is how to go about restricting the helicopter's altitude - is that correct? If so, here's one possible solution: when the helicopter is 'over altitude', apply a downward force proportional (with the proportion determined by a constant coefficient) to the difference between the current altitude and the maximum desired altitude.

Note that this will allow the helicopter to go a bit over altitude (how far will be determined by the constant force multiplier), so if you need a hard limit, you might need to use another method.

Comment
Add comment · Show 1 · 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 BeatCord · Jun 02, 2011 at 03:59 AM 0
Share

(I'm hitory Really i just hated that username) Thanks, what I posted above was the statement, I just want to know how to type that statement into a C# script, Its my first time using ray-cast so I don't know how to make it XD

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to tell what platform you're on. 1 Answer

Layermask doesn't seem to work 2 Answers

Using raycasting to make a character NOT move off a platform 1 Answer

ray direction to quaternion 0 Answers

Why in Unity3D RaycastHit. textureCoord always return 0,0 after building the project? 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