Announcement

Collapse
No announcement yet.

Know when an actor overtake another actor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Know when an actor overtake another actor

    Hi,

    I working on a game mode look like savage street racing where the pilot who take the lead choose the way to go and, if another pilot overtake the leader, it take the lead etc... (discovered long time ago in NFS Underground 2 called "Outrun")

    I looking for a way to detect when a car overtake another car, I have try some things like an half-sphere in front of all car and set the one, without anyone in front of him, to the leader... but I have meet some trouble when 2 car are face to face. I also try to set some spline in the game but spline have direction, so if the leader engage the street in the wrong way, it become the last and between the crossing from one street to another, 2 pilot have the lead in the same time...

    Has you can see, I'm lack of idea to do this well, if someone have an idea or a suggestion, I'll take it!

    Thanks

    #2
    Perhaps have a moving "finish line" that is oriented to the street spline and keeps track of the direction it is moving.

    Intersections and branch roads will be problematic though and perhaps you should handle them differently with a trigger box that when entered is drawing the finish line relative to the lead car velocity temporarily.
    Last edited by GarnerP57; 07-26-2019, 05:15 AM.

    Comment


      #3
      Your suggestion gave me an idea that half work and I think I have to dig this way: I have created an actor that automatically attach to the front of the car when "end overlap" trigger of a very large box collision is fired. If a player overtake this player, he fire the trigger and got the actor, the player who have the actor attached is the leader. That don't work if other player arrives from front but I feel I'm on the good way!

      Thanks for the help GarnerP57

      Comment


        #4
        Just keep in mind that working with collision and triggers can cause some errors like if the overtaking car somehow misses or teleports through the trigger. A regular check projecting a squared distance to the "finish line" might be more robust. If the vector from your car to the finish line dotted with the finish line direction is negative and your velocity dotted with the lead car velocity is positive then you must be in the lead and the finish line should now follow you.

        I haven't tested it but that is where I would start.
        Last edited by GarnerP57; 07-26-2019, 07:09 AM.

        Comment


          #5
          Originally posted by GarnerP57 View Post
          Just keep in mind that working with collision and triggers can cause some errors like if the overtaking car somehow misses or teleports through the trigger. A regular check projecting a squared distance to the "finish line" might be more robust. If the vector from your car to the finish line dotted with the finish line direction is negative and your velocity dotted with the lead car velocity is positive then you must be in the lead and the finish line should now follow you.

          I haven't tested it but that is where I would start.
          I'm not familiar with dot node, i'm not sure to understand and I don't know that collision and trigger can be so buggy... I will dig with the dot node, but your suggestion is pretty hard to understand to me, but I think I understand the idea, I don't have the skill (yet) to apply it, so, can I ask for an exemple ?

          I have tryed this, but the result is very strange: https://i.imgur.com/SnrDh2f.jpg (this bp is for the finish line) and I think I'm probably doing it wrong.

          Comment


            #6
            Dot product compares Vector A with Vector B. It will be positive if the vectors are in the same direction and negative if opposite. Zero means the Vectors are perpendicular.

            Collision works pretty good and are not buggy in themselves but it can be difficult to manage all edge cases that might occur and if you need to do some calculations to cover the edge cases then the collider becomes almost irrelevant. I am not saying you should always avoid colliders just that you need to be aware of this.

            GetDotProductTo returns if the other Actor is in front or behind the Actor relative to its orientation. What you need is if the Actor is ahead relative to its motion aka velocity since the car might not be moving in the direction it is facing if it is drifting or spinning.

            A road spline would help having a general direction of where "ahead" really is and to orient the "finish line" relative to the spline direction.

            If you don't want to use a road spline then the "finish line" could simply be permanently oriented to the velocity of the lead car which has to be used anyway for intersections and branching roads.

            Comment


              #7
              Ok, I understand better now, I perform some test and I meet same problems with player come from front of leader, this player take the lead when crossing the leader. And it's hard to use spline because player can choose the way they want!

              My new idea with collision box solve, for the moment, all the case I imagine:

              I create 2 collision box in my Finish Line (I call it Leader Marker), 1 placed front of the leader car, the second behind it. When a car overtake the leader, this car overlap the box behind first, and the leader marker's bp add this car in an array, then, the car overlap the front box (I use end overlap for this box), the BP check if this car has already overlapped the other box, if yes, this car become the new leader, if not, that probably mean that this car come from front, and it not become the new leader.

              For this gamemode, I will precise to players that they have to overtake on the same road, if not, they not take the lead (to avoid a lot of edge cases ).

              That will work fine for a prototype, probably not for a more serious project, if this become a serious project, I will probably reconsidering this aspect and also working with other dev and not working only with BP!

              Thanks for your explanation for dot product, very interesting!

              Comment


                #8
                You're welcome. There is always multiple solutions to a problem and yours can be as good as mine. I'm happy you made it work.

                Comment

                Working...
                X