Turn only if moving forward

  • December 8, 2016 at 13:02 #16895
    Kirill Pervushyn
    Participant

    Hello.
    We have a car – object that has finite radius of turn (not infinitely small).
    We teached it to turn by curve when it moves, but when it stays on the spot it still goes right where the waypoint says – no turning happens.

    What we want to have:
    1) Unit has the Turn-Sector in front of him – the angle where velocity vector can be applied. Let’s say it is 45 degrees left and 45 degrees right from unit’s forward
    2) If direction to waypoint lays within this sector (let’s say 30 degrees) then velocity vector is applied normally
    3) But if direction to waypoint goes out of this sector (135 degrees) then velocity vector is applied at maximum allowed degree from the Turn-Sector (45 degrees).

    This naturally occurs while unit is on move as it cannot change velocity vector fast.
    But if initial velocity vector was 0, then after waypoint appeared new velocity vector is applied right in its direction.
    So the question is: how we achieve behaviour descried in 1)-3) ?
    Thanks in advance

    December 8, 2016 at 13:14 #16897
    Geminior
    Keymaster

    In the Steerable Unit component all steering input is gathered and passed on to an implementation of the IMoveUnits interface. The default implementation just moves the unit according to the desired velocity.

    So what you need to do is write your own implementation of IMoveUnits, where you implement the logic you described. Implement it as a MonoBehavior and attach it to the unit.

    You can find examples of IMoveUnits implementations in both the Steerable Unit component itself, and in the examples project.

    December 8, 2016 at 18:19 #16906
    Kirill Pervushyn
    Participant

    It worked!
    Now we’ll teach unit to use reverse when he is in front of the wall – I guess we implement it in IMoveUnits as well.
    Thank you, Geminior

    December 9, 2016 at 12:41 #16925
    Geminior
    Keymaster

    You can also implement reversing as a steering component that will kick in when the unit is in front of a wall.
    If you do that just give it a priority above that of the basic locomotion, e.g steer for path and only produce output when the conditions for reversing are met.

You must be logged in to reply to this topic.