Search Unity

How can i make the space ship fly in the sky on it's own without controlling it ?

Discussion in 'Scripting' started by benydayag, Sep 16, 2016.

  1. benydayag

    benydayag

    Joined:
    Aug 1, 2016
    Posts:
    91
    I'm using unity 3d version 5.3.5f1 personal 64 bit.

    What i want to do is that the space ship will directly move up on the Y axis i think and then start to fly around the sky by it self, not in space but in the sky so i can see the space ship from the terrain from ground but in the sky i mean in logic sky height

    In the hierarchy in the scene i have a space ship object i added it to it 3 things:

    1. RigidBody

    2. Mesh Collider

    3. Script in c#

    If i'm running the game now with the error i see the space ship make a turn when it's on ground then it's falling through the terrain.

    The script need the RigidBody but when using it when adding it to the space ship i'm getting this error:

    Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5.
    If you want to use a non-convex mesh either make the Rigidbody kinematic or remove the Rigidbody component. Scene hierarchy path "ShipUndamaged", Mesh asset path "Assets/Crash-Landed_Ship/Meshes/Ship_Undamaged.FBX" Mesh name "Ship_MintCondition"

    This is the script in c#:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MakeObjectFly : MonoBehaviour {
    6.  
    7.     public float FloatStrenght;
    8.     public float RandomRotationStrenght;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.    
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.  
    18.         GetComponent<Rigidbody>().AddForce(Vector3.up *FloatStrenght);
    19.         transform.Rotate(RandomRotationStrenght,RandomRotationStrenght,RandomRotationStrenght);
    20.    
    21.     }
    22. }
    This is a screenshot of the space ship inspector:

     
  2. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    Well the answer is pretty simple. You need to make you mesh colider convex. Remember though that Convex mesh colliders can have a maximum of 255 triangles, so for complex objects you'll need a custom mesh for the collider.

    More info about mesh colliders can be found here:
    https://docs.unity3d.com/Manual/class-MeshCollider.html
     
  3. benydayag

    benydayag

    Joined:
    Aug 1, 2016
    Posts:
    91
    Ok i turned on the Convex on the mesh collider. Now the error is gone.
    Now when i change in the script in the inspector the Float Strenght from exaple to 9 or 10 the space ship is moving up until it's gone. How do i make it to move up a bit and then start moving around from side to side or in random directions ? Like patrolling in above.
     
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    My question to you would be if you really have to simulate the ship floating through physics.
    What is the purpose of this ship? It's not the player since you want it to move on it's own, so what's it's purpose in the game?
     
  5. benydayag

    benydayag

    Joined:
    Aug 1, 2016
    Posts:
    91
    The purpose will be to make later array of space ships flying above to make atmosphere feeling like there are many space ships flying aorund. After that i will make tha the main space ship on ground will be the player where the user control it.
     
  6. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Physics calculations is not something you want to waste processing power on if the object is non-essential. if what you are looking for is to create atmosphere, most games simply fake them.

    What you have to make clear is how you want the ships to be "flying around" as you so generally put it. How high above the ground, how dense is the population of for-show ships to create atmosphere? will the player ever encounter these make-believe ships for atmosphere?
     
  7. benydayag

    benydayag

    Joined:
    Aug 1, 2016
    Posts:
    91
    About the "flying around" i mean for example 20 objects(space ships) that will fly random around the terrain area(terrain borders) and to make area of height they will fly in. For example if its the Y axis then start from 30 to 70 above ground. And later on in the game the player will be able to use one space ship on ground and take control on it and fly between the other space ships. I'm sure it's not easy buit this is the main concept.
     
  8. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17