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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Make character follow path "loosely"? (i.e. able to strafe)

Discussion in 'Editor & General Support' started by spvn, Mar 1, 2015.

  1. spvn

    spvn

    Joined:
    Dec 10, 2013
    Posts:
    80
    I'm researching on making characters follow a path and thus far all the solutions I can find such as iTween and SeekSteer involve setting a specific set of waypoints for the gameobject to follow.

    Is there anyway that I can still allow some left and right strafing control (and maybe jumping) over the character while still following a general path? The idea is that I'm trying to create a first person "on-rails" game where the character goes through various corridors (which might involve left and right turns) but he is still able to strafe to the left or right (to dodge things) while going down these corridors.

    Not sure if I phrased my question well enough, hope someone can point me in the right direction. Thanks!
     
  2. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    You explained two movements. Easiest way would be to have a general (centered) path and another controller for strafing/jumping.
    Your character would sit on another empty gameobject(let's say movementController) which would follow this path. On movementController you would have another script in which you can decide if your character is jumping or is shifted from it's original centered position.
     
  3. spvn

    spvn

    Joined:
    Dec 10, 2013
    Posts:
    80
    But how would I handle it when the player is not exactly along the path? Won't it try to go back to the path (i.e. center of the corridor) instead of simply continuing to move straight forward?

    to clarify, the effect I'm looking for is something similar to this sonic game:


    Though of course I'm making more of a first person runner type game rather than such a fast paced third person game with changing camera angles. I just need to know how to move my character along a fixed corridor while allowing him to move freely left and right within this corridor.
     
  4. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    Just depends on how you want it to react. Should the character stay at the new position or always go back to the center.

    First the movementController with your character on top would follow the path straight forward. For visualization let's say movementController is a black box rectangle. This rectangle is the box in which your character moves left/right and jumps. Your character is completely detached from your forward movement which is done by the black box that faithfully follows the path.

    Then depending on what you need you can for example have 3 positions in the movementController for left/center/right position or a limited maximum shift value(which you check when you add/substract during a keypress).
    so movementController would have these possible values if shift value is for example 10.
    |(-10)-----(0 center)-----(10)|

    After a keypress you can lock into another position and have your character shifted to the new position on movementController. You just have to check if the new position value is within your minimum/maximum shifted position else the new position should be the minimum/maximum value. If the character should always return to center there is no need to save the locked position.