Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

RTS Unit/ship movement through 3D space.

Discussion in 'Scripting' started by athaun, Apr 7, 2020.

  1. athaun

    athaun

    Joined:
    May 2, 2019
    Posts:
    2
    Background:
    • I am working on a space RTS, and my task is to implement unit selection and movement in 3D space (including changing Y positioning).
    • The units are space ships, therefore have acceleration, deceleration, turning radius, etc.
    • I need the ability to move multiple units in a selection, without them all colliding with eachother
    • they need to be able to navigate waypoints.
    What I have done:
    • implemented a system that gets coordinates based on user input (returns a Vector3)
    • move the ship/unit in a straight line from its current position to the new position using Vector3.MoveTowards:
    Code (csharp):
    1. selectedUnit.transform.position = Vector3.MoveTowards(selectedUnit.transform.position, newPosition, step);
    • Tried using the unity standard assets plane AI controller, I can't get it working, and it is very large and bloated for my purposes
    My problem:
    I don't know how to implement a natural looking ship movement that gets the ship from point A to point B in 3D space.

    Does anybody have any pointers to help me along my way? I am stumped...
    I am new to unity and C#, but I have programmed in Java for quite some time.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What type of movement are you even looking for?

    Most movies, TV shows, and games show space ships moving as if they are fixed wing aircraft moving in atmosphere or boats on the water, as this looks more natural to viewers even though it is entirely unrealistic (Star Wars, Star Trek, etc). You'd do that by turning the ship X number of degrees per second towards the direction you intend on the ship moving, while you move forward on the ship's Z axis. This will look like a car making a U turn for example, instead of rotating in place until facing the correct direction, or even worse instantly snapping to the correct direction. Then the ship slows down as it approaches the destination.

    A more realistic approach (Battlestar Galactica 2004 to an extent) would have ships rotating without affecting their momentum until they apply additional thrust. So you apply thrust to accelerate into a rotation, then apply reverse thrust to end the rotation. As you move forward you apply thrust to accelerate towards the destination, then halfway through the trip your turn the ship around and apply thrust in the opposite direction until reaching the target, where you should come to a full stop. This probably isn't a great choice for an RTS though, as players probably expect their units to be more responsive when they need to redirect them after they are already moving somewhere else.

    Many RTS games implement formations, where units nearby will form up into some pattern (often user selectable) as they move to the destination. This helps prevent units walking into a grouped enemy one at a time just to get insta-popped by focus fire.
     
    Last edited: Apr 8, 2020
  3. athaun

    athaun

    Joined:
    May 2, 2019
    Posts:
    2
    I think the first approach sounds better in my case, and it sounds reasonably simple to implement. Thanks
     
    Joe-Censored likes this.