Search Unity

Navigation / Movement in 3D space

Discussion in 'Navigation' started by 1druid1, Feb 3, 2016.

  1. 1druid1

    1druid1

    Joined:
    Dec 7, 2015
    Posts:
    12
    Hi All

    I am just new to Unity and programming but I have made my way through a lot of tutorials and have created a couple of basic games, 2D shooter / simple RTS game.

    I am now looking into more advanced material and what I am currently try to do is creat a space based RTS game, sort of a mix between EVE and Homeworld and X3 Albion Prelude.

    However moving objects in 2D is easy as you have a ground plane for your coordinates but for the life of me I just cant work out how to do 3D movements.

    Any helpfull advice or tips on this area would be great, some examples from programmers who have already implemented this type of feature would be great.

    Cheers

    Druid
     
  2. browne11

    browne11

    Joined:
    Apr 30, 2015
    Posts:
    138
    3D is actually much easier then 2d with Unity I found at first. Most of 2d I had to create all the movement and scripts for that functionality.

    Unity has a bunch of scripts you can download in the standard assets package. I suggest downloading that and looking at it.

    For 3d you need a terrain or a plane. The easiest way to start is use cubes and add mesh agents to them. Bake your terrain and attach some movement scripts to your cubes and mess around. You will learn a ton just doing that.

    Youtube search : unity movement and you'll find a crap ton of stuff :)
     
  3. 1druid1

    1druid1

    Joined:
    Dec 7, 2015
    Posts:
    12
    HI All

    Still really struggling with this, just cant seem to find an answer but there seems to be a few Unity members who have created or are creating a space based RTS, so looking towards your knowledge for some help. It would be appreciated.

    Cheers

    Druid
     
  4. pixxelbob

    pixxelbob

    Joined:
    Aug 26, 2014
    Posts:
    111
    Druid. There are plenty of examples of moving in 3D space.
    The only difference is you have three axis of movement instead of two.

    Depending on if you're using physics for movement or you're just using fixed positioning. Methods you'll be interested in are:

    Transform.Translate(x,y,z);
    RigidBody.AddRelativeForce(x,y,z,type);

    If you can explain a bit more about the specifics of the issue you're struggling with maybe we can help further.

    You may need to broaden your search, if you're looking to find a complete space RTS ready to go you're going to be disappointed. There are loads of flight sim tutorials on the web & youtube which you could possibly use as a base to build your ship movement.
    https://www.google.co.uk/webhp?sour...=2&ie=UTF-8#q=unity+flight+controller&tbm=vid

    The standard assets even come with a flight controller & full working example.
    I suggest you get the unity standard assets and example project.

    A quick search on the unity asset store will give you a few systems others have developed you can use as a base. One is even 100%
    https://www.assetstore.unity3d.com/en/#!/search/page=1/sortby=relevance/query=flight&plane
     
    Last edited: Feb 9, 2016
  5. 1druid1

    1druid1

    Joined:
    Dec 7, 2015
    Posts:
    12
    Hi pixxelbob

    Thanks for the reply, at the moment I dont have internet access with my PC that has unity on, so I am using the library so I cant download any unity assets.

    As far as what I am struggling with is the basic point and click movement, in my ground based RTS that I created the point and click is easy as I have a ground plane so my units move to the position on the ground plane clicked.

    Since there is no ground plane in a Space RTS, I am struggling to capture specific points to move the units to.

    I have played with flight controls for a space ship and this works great as I either use the keyboard or mouse to move around using forces / velocity and movement, but a simple point and click so the unit will to that position just eludes me.

    Cheers

    Druid
     
  6. pixxelbob

    pixxelbob

    Joined:
    Aug 26, 2014
    Posts:
    111
    Ok, Well I suggest you look into ScreenPointToRay
    Something like this might help you get started.

    Code (CSharp):
    1. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    2. // create a horizontal plane
    3. Plane plane = new Plane(Vector3.up, Vector3.zero);
    4. float distance = 0; // Distance from ray origin (which is camera's near plane)
    5. // if the ray hits the plane...
    6. if (plane.Raycast(ray, out distance)){
    7.   //move the targetGameObject (your ship or whatever) to the position
    8.   targetGameObject.transform.position = ray.GetPoint(distance);
    9. }
     
  7. zy7294

    zy7294

    Joined:
    Jul 15, 2015
    Posts:
    2
    Hi, Druid
    I love Homeworld too.
    I'm also making a game like want you said and want to know HOW.

    Currently I am making a research about it and realized that the points like these below:

    1. Navigation - Unity's NavMesh can't work it .You need to find a way to do the path-finding in 3D-space(Such as Nav Volume?). How to make an efficient way to keep the FPS is the problem.

    2. Movement - You can learn the Steering Behaviors(Including Seek, Flee, Arrival, Avoidance, etc...) to implement it. The hardest part is Avoidance in crowd simulation, this is almost can not be perfect.

    Sorry for my poor English.
     
  8. yanuaris

    yanuaris

    Joined:
    Oct 16, 2015
    Posts:
    61
    I'm also facing this and i'm implementing it in my AI.

    mine is more in platforming 3d spaces...