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. Dismiss Notice

Best Approach for controlling player speed but use waypoint system for pathing?

Discussion in 'Scripting' started by UnSkiLd, Oct 2, 2016.

  1. UnSkiLd

    UnSkiLd

    Joined:
    Mar 4, 2015
    Posts:
    20
    I have a task where I need to have predefined paths for my player (waypoint system) but the speed that player uses to get to these waypoints are going to be dynamically given via arduino.

    I have used a waypoint script that was posted in the forums a while back:
    https://forum.unity3d.com/threads/a-waypoint-script-explained-in-super-detail.54678/

    It is working as expected however each time it hits a waypoint there is a noticeable pause before it turns to the next waypoint and continues. Do all waypoint systems do this pause before continuing?

    So my main question would be if I used this script (and I can get the pause removed) would it be a good design to implement code that would read from the arduino during the Update() method and set the players speed or should I use something else entirely?

    Thanks
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Depends on the game. If the character turning plays no part in the game or player experience, I'd say remove turning entirely and have the player simply snap to the designated facing direction.

    If your game is top down 2d, the waypoint script you have linked is excessive.
     
  3. UnSkiLd

    UnSkiLd

    Joined:
    Mar 4, 2015
    Posts:
    20
    Thanks for the reply Laperen. I apologize for not giving more details this is a 3d game and right now I am having my character 'walk' around a circular track (race track). I setup waypoints (spheres) for it to follow using that script noted above so turning is essential unfortunately.

    Right now I have to set a preset speed to this script, however, ultimately the speed will be set using data from arduino.

    Have you used any other way point systems? Do they all pause at each way point, turn, then move again? I am hoping to modify this script to make it more of a fluid motion like normal. Any suggestions or more information I can provide?
     
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Turning is not a property of using waypoints. The waypoint script you are using setup that way. Since you're making a racing game, it would be better for you to look into racing game AI. I don't recall any of them using waypoints.
     
  5. UnSkiLd

    UnSkiLd

    Joined:
    Mar 4, 2015
    Posts:
    20
    Fair enough, let me ask this then. This isn't really a racing game, just using a track for a proof of concept at the moment. I am using a way point to keep the character within the track while it moves, so the user (me) will not be controlling the character's direction but just the speed the character is going in. I use the waypoint as a way to tell the character where to go. Does that make sense?

    I will check out the racing AI and see if that might shed some light though. Thanks again for the reply.
     
  6. UnSkiLd

    UnSkiLd

    Joined:
    Mar 4, 2015
    Posts:
    20