• 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 KR33M · Jun 02, 2013 at 01:27 AM · collisionflight

Making a Flying Object Collide With Terrain & Assets

Hello everyone,

I have seen many variables of this question asked on the forums, but very few of them have answers, and the ones that do are a little too complex or vague for my simpleton brain.

I am working on a flight prototype.

I have one piece of terrain, all at default settings. - Terrain has a collider, not a trigger.

I have one rectangular cube (the flying object) (see script below). - Has a box collider, not a trigger.

I have one Main Camera with the default Smooth Follow Script (to follow the Jet).

I have one larger cube, aka Mountain, on top of the terrain. - Has a box collider, not a trigger.

I'm using this script for the flying object which I discovered on the internet:

 // JavaScript Document - flying-tank3.js
 
 var rotateSpeed = 50.0;
 var speed = 100.0;
  
 function Update() {
 var transAmount = speed * Time.deltaTime;
 var rotateAmount = rotateSpeed * Time.deltaTime;
  
 if (Input.GetKey("up")) {
 transform.Rotate(rotateAmount, 0, 0);    
 
 }
 if (Input.GetKey("down")) {
 transform.Rotate(-rotateAmount, 0, 0);    
 }
 if (Input.GetKey("left")) {
 transform.Rotate(0, -rotateAmount, 0);
 }
 if (Input.GetKey("right")) {
 transform.Rotate(0, rotateAmount, 0);
 }
 
 if (Input.GetKey ("a")) {
 transform.Rotate(0, 0, rotateAmount);
 }
         
 if (Input.GetKey ("d")) {
 transform.Rotate(0, 0, -rotateAmount);
 }
 
 if (Input.GetKey ("s")) {
 transform.Translate(0, 0, transAmount);
 }
         
 if (Input.GetKey ("w")) {
 transform.Translate(0, 0, (transAmount * 2));
 }
 
 }

Why can I fly through the Terrain and Mountain? Is my script overriding the collision or are my collisions not set up properly? I've watched many videos on collision and I just can't seem to crack this.

Thank you for reading this long ass question.

KRM

Comment
Add comment · Show 5
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 syclamoth · Jun 02, 2013 at 01:40 AM 0
Share

Yes, your script is overriding collisions. You require a non-kinematic rigidbody to use the built-in physics engine.

avatar image robertbu · Jun 02, 2013 at 01:42 AM 1
Share

In addition to the Rigidbody that @syclamoth mentions, you need to move your objects through Rigidbody.AddForce() rather than Transform.Translate() if you want the objects to use the physics engine correctly.

avatar image KR33M · Jun 03, 2013 at 06:08 AM 1
Share

Thanks very much @syclamoth and @robertbu. I wasn't able to figure out the coding right away, but I am reading the sections in the manual now.

I played around with the rigidbody inspector settings and found a bandaid solltion, though I'm not sure exactly which setting is making it work anymore. I'm putting it here in case another person like me comes along.

$$anonymous$$ass - 10 Drag - 100 Angular Drag - 50 No Gravity, Is Not $$anonymous$$inematic, No Interpolation Set Continuous Dynamic. No Constraints.

Now, when I collide with the mountain I just stop and park on it ,or bounce a little.

avatar image syclamoth · Jun 03, 2013 at 06:10 AM 0
Share

Try using rigidbody.AddForce for your movement functions. That will make it a bit more natural, but a lot harder to control.

avatar image KR33M · Jun 04, 2013 at 12:30 AM 0
Share

I'm trying to learn how to do that now, seems I need to use vector something or other. Pretty new at this! But thanks.

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

3rd person Flying with Collision problems 1 Answer

Flying collision 0 Answers

Why does a collider make my vehicle fly away? 2 Answers

How to prevent a thrown object from rotating but not effect the physics of its collision? 0 Answers

Returning Force/Direction to zero 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