• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Ruckrova · Dec 03, 2014 at 09:08 AM · terrainscript error

Unwanted teleporting when the player hits the ground

I have a problem with one of these three scripts that is make the position of the player teleport unexpectedly when they hit the terrain to the 0 0 0 position but im not sure of the position , I think it is in the eagleFlying Script but I don't know why if you can please take a look. Also I hit the flatten button by accident and had to build the terrain up again could this have effected it ?

eagleFlying- modified

 // Use this for initialization
 void Start () {
     Debug.Log("eagleFlying added to: " + gameObject.name);
 }
 
 // Update is called once per frame
 void Update () {
     
     // chase camera 
     
     Vector3 moveCamTo = transform.position - transform.forward * 5.0f + Vector3.up * 2.0f;
     float bais = 0.96f;
     Camera.main.transform.position = Camera.main.transform.position * bais + 
         moveCamTo * (1.0f-bais);
     Camera.main.transform.LookAt (transform.position + transform.forward * 60.0f );
     
     transform.position += transform.forward * Time.deltaTime * speed;// make this a public float 
     
     speed -= transform.forward.y * Time.deltaTime * 50.0f;
     
     if (speed < 5.0f) {
         speed = 5.0f;
     }
     
     else if (speed > 100.0f) {
         speed = 100.0f;
     }
     
     
     transform.Rotate (Input.GetAxis ("Vertical"), 0.0f, -Input.GetAxis("Horizontal") );
     
     float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight( transform.position );
     
     if (terrainHeightWhereWeAre > transform.position.y) {
         
         // input the landing here 
         transform.position = new Vector3 (transform.position.x,
                                           terrainHeightWhereWeAre,
                                           transform.position.z);
     }
     
 }

}

LandFly - modifited

//Need a new script called LandFly and to check the key are call Fly [F] and Land [L]

using UnityEngine; using System.Collections;

public class LandFly : MonoBehaviour {

 public eagleFlying eagleFlying;
 public CharacterMotor characterMotor;
 
 // Use this for initialization
 
 void Start()
 {
     eagleFlying = GetComponent<eagleFlying>();
     characterMotor = GetComponent<CharacterMotor>();
 }    
 
 void Update()
 {
     if(Input.GetButtonDown("Fly"))
     { 
         eagleFlying.enabled = true;
         characterMotor.enabled = false;    
     }
     else
     {
         if(Input.GetButtonDown("Land"))
         { 
             eagleFlying.enabled = false;
             characterMotor.enabled = true;    
         }
     }        
 }

}

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Randomizing tile textures 2 Answers

How to programmatically embed data into 2d terrain through color + heightmap data? 0 Answers

renderning quality on far away objects 2 Answers

Remove Terrain's reflection 2 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