Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

Trace length?

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

  • Trace length?

    So I know that normally traces return the actor hit.

    But what I'm looking for is a way to get the length until it hits something.

    Basically, I am setting up strafing for my AI, and want to make sure it's not trying to strafe into a wall or similar, then set the distance to strafe a bit lower than that.

    Code:
       //local Actor traceHit;
       local vector HitLocation, HitNormal;
       local vector Start;
       local vector End;
       local vector ViewRotation;
       local int StrafeDistance, TraceLength;
    
       if(Rand(2) == 1)
       {
          ViewRotation = Vector(Pawn.GetViewRotation());
          ViewRotation.Yaw += 90 * DegToUnrRot;
          Start = Pawn.GetPawnViewLocation();
          End = Pawn.GetPawnViewLocation() + (ViewRotation * 2000);
    
          //traceHit = Trace(HitLocation, HitNormal, End, Start, true);
          StrafeDistance = TraceLength + 500;
    
          DrawDebugLine(Start, End, 255,0,0,false)
       }
    But I need to get the length of the trace between start and the first hit surface. (Not just the point I set when I define the trace)
    I thought of just doing a VSize on the location of the trace start and the hit actor's location, however, that would be too inaccurate, especially if the actor hit is big or is offset from it's pivot point.


    Edit: Oh god, I'm retarded. I'll just use the HitLocation....

  • #2
    For those who ask the same question,

    Code:
    HitTraceLength = VSize(StartTraceLocation - HitLocation);

    Comment


    • #3
      I know that, sometimes the solution becomes obvious just by discussing it with yourself.

      Comment


      • #4
        Yeah, I don't know how many times I've stopped myself from posting once I've had the issue put to words.

        Comment


        • #5
          So This is me thinking out loud at work w/ out a compiler. I really hate trial and failure so I am going to justify this post as maybe someone else needs help with traces also.

          Originally posted by Graylord View Post

          Code:
             //local Actor traceHit;
             local vector HitLocation, HitNormal;
             local vector Start;
             local vector End;
             local vector ViewRotation;
             local int StrafeDistance, TraceLength;
          
             if(Rand(2) == 1)
             {
                ViewRotation = Vector(Pawn.GetViewRotation());
                ViewRotation.Yaw += 90 * DegToUnrRot;
                Start = Pawn.GetPawnViewLocation();
                End = Pawn.GetPawnViewLocation() + (ViewRotation * 2000);
          
                //traceHit = Trace(HitLocation, HitNormal, End, Start, true);
                StrafeDistance = TraceLength + 500;
          
                DrawDebugLine(Start, End, 255,0,0,false)
             }
          I am also interested in doing this, but I am not drawing my trace from a pawn. How can I start a trace from an actor?
          Can I do a " Start = rotation - 32768; " within the actor I do my trace from to get my angle? How do I set my distance? It seems like the OP code is taking the pawn camera turning it 90 degrees and then multiplying * 2000. Where as I just have an angle so far, and multiplying it would just result in more rotation.


          Part 2:
          I do not understand trace very well.
          Code:
          traceHit = Trace(HitLocation, HitNormal, End, Start, true);
          Sending HitLocation and HitNormal, to the trace function before it is even known what they are?
          Does the Trace function reset these class variables once it does the trace? It returns an actor.
          Maybe I just don't understand "out vector's"?


          Im pretty sure I can get the distance from this:
          Originally posted by Solid Snake View Post
          Code:
          HitTraceLength = VSize(StartTraceLocation - HitLocation);

          Comment


          • #6
            Originally posted by Slamm View Post
            So This is me thinking out loud at work w/ out a compiler. I really hate trial and failure so I am going to justify this post as maybe someone else needs help with traces also.



            I am also interested in doing this, but I am not drawing my trace from a pawn. How can I start a trace from an actor?
            Can I do a " Start = rotation - 32768; " within the actor I do my trace from to get my angle? How do I set my distance? It seems like the OP code is taking the pawn camera turning it 90 degrees and then multiplying * 2000. Where as I just have an angle so far, and multiplying it would just result in more rotation.


            Part 2:
            I do not understand trace very well.
            Code:
            traceHit = Trace(HitLocation, HitNormal, End, Start, true);
            Sending HitLocation and HitNormal, to the trace function before it is even known what they are?
            Does the Trace function reset these class variables once it does the trace? It returns an actor.
            Maybe I just don't understand "out vector's"?


            Im pretty sure I can get the distance from this:
            1.You can simply set your distance manually if you like. Just take vectors and give them a static value (vect(10,0,0)) . If you set your End variable equal to that vector I just gave you and you kept the Start vector as the pawns location, you would trace in the X direction 10 units. Usually you want to make sure it makes it outside of the collision cylinder though, hence the get functions for the cylinder specs.

            2. You pass the Hitlocation and HitNormal because they are out varaibles (when changed within the function, they change the actual variable outside of the function as well). When you pass it the empty variable, it simply saves the hit location and hit normal to those variables so you can use them again for calculation after you call trace.

            Comment


            • #7
              Originally posted by Slamm View Post
              So This is me thinking out loud at work w/ out a compiler. I really hate trial and failure so I am going to justify this post as maybe someone else needs help with traces also.



              I am also interested in doing this, but I am not drawing my trace from a pawn. How can I start a trace from an actor?
              Can I do a " Start = rotation - 32768; " within the actor I do my trace from to get my angle? How do I set my distance? It seems like the OP code is taking the pawn camera turning it 90 degrees and then multiplying * 2000. Where as I just have an angle so far, and multiplying it would just result in more rotation.


              Part 2:
              I do not understand trace very well.
              Code:
              traceHit = Trace(HitLocation, HitNormal, End, Start, true);
              Sending HitLocation and HitNormal, to the trace function before it is even known what they are?
              Does the Trace function reset these class variables once it does the trace? It returns an actor.
              Maybe I just don't understand "out vector's"?


              Im pretty sure I can get the distance from this:
              1.You can simply set your distance manually if you like. Just take vectors and give them a static value (vect(10,0,0)) . If you set your End variable equal to that vector I just gave you and you kept the Start vector as the pawns location, you would trace in the X direction 10 units. Usually you want to make sure it makes it outside of the collision cylinder though, hence the get functions for the cylinder specs.

              2. You pass the Hitlocation and HitNormal because they are out varaibles (when changed within the function, they change the actual variable outside of the function as well). When you pass it the empty variable, it simply saves the hit location and hit normal to those variables so you can use them again for calculation after you call trace.

              Comment


              • #8
                Makes a lot of sense thanks.

                Comment


                • #9
                  Ok, Stuck at work again trying to theory craft.

                  The problem I think I am having: Inconstant hit location, on the Z axis.

                  The Short: Every time I trace with this, I output the Start.Z value and the End.Z value. The Start.Z value is always correct. The End.Z value is not always correct.


                  The Long:
                  Ive got a floating actor that moves on the X and Y planes going back and forth zapping the "ground" with traces as described in the above posts. My trial level is the default New Map Night level with the cube removed. Ive removed the Vsize function instead running "Start.Z - End.Z = int Trace length". Because that's all I'm worried about is the Z change. I output the resultant Trace Length to a log and most times it is 231, as expected. Sometimes it is off by ~50 or more.

                  Looking at what its tracing against in the editor, it is a flat plane, there is no where for a ~50uu error in this trace.
                  Outputting the vector .z component to the log, I can see that when the value is a float, there is some variation in the hitlocation, but these are usually smaller than 1 / 100th Unreal Unit of a difference.


                  I have a few graphical elements telling me it is tracing to the correct locations, not the least of which is the debug line In the OP's code.
                  Much Obliged for any help.

                  Comment


                  • #10
                    I'm not sure where your 50uu deviation is coming from, maybe you could post the latest code.

                    I've been working on a tutorial for Trace() this week, will post it after the weekend. It's quite long and indepth.

                    Comment


                    • #11
                      :rolleyes

                      Comment


                      • #12
                        I fixed the problem. My initial thought was that was that it was a cpu glitcher.

                        I cleaned up my log so that I could see when I logged out all my start.z and end.z variables they were all exactly what they should be. But when I went in to check the assigned value based on the start.z and the end.z a few of them were wonkey. But it was only on the corners of the grid that were getting wacky assignments.

                        The bulk of the code was assigning a value based on the .z components of the start and end vectors. Where I shot myself in the face was that I forgot to change the cornering bit to do the same thing, it was assigning a value based on Vsize(start - Hitlocation). Which was not at all accurate.

                        I guess the oddity remains though, that my spawner is basically teleporting to the center of each chess square and tracing down to see how far away it is. X and Y values for the spawner and the location should be parallel and unchanging*, yet the Vsize(start - hitlocation) seem to reflect more of a change than that.

                        *The spawner only moves on X and Y and never on Z while the ground it was zapping was a flat plane.

                        Comment


                        • #13
                          The results from trace should be accurate and predictable. If you're still encountering odd results it may be the settings you're using, or something else is interfering with it.

                          Comment


                          • #14
                            Fixed it again. Either Lovindadonks didn't get it, or (and this is far more likely) I didn't understand what Lovindadonks was trying to say Here:

                            Originally posted by lovindadonks View Post
                            1.You can simply set your distance manually if you like. Just take vectors and give them a static value (vect(10,0,0)) . If you set your End variable equal to that vector I just gave you and you kept the Start vector as the pawns location, you would trace in the X direction 10 units.
                            I am tracing from an actor, not sure if this is different for pawn.
                            I had my trace starting at "location" and ending at vector 0,0,-2550. Because I wanted to trace directly down. Well I was not getting what I wanted to. For one the debug lines had an angle to them. Initially, when they just hung around for a split second, I thought it was a product of perspective. Once I turned the DrawDebugLine True flag to false, I could clearly see that it was angled.

                            My fix is as so:

                            Code:
                                    local vector HitLocation;
                            	local vector HitNormal;
                            	local vector Start;
                            	local vector End;
                            	local vector EndDistance;
                            	
                                    local int HitTraceLength;
                            	
                            	EndDistance.z = 2550;
                            
                                            Start = location;
                            		End = Start;
                                         //Below because Im not smart enough to get "End.z = End.z - 2550;" to compile
                            		End.Z = End.z - EndDistance.z;
                            		 
                            		Trace(HitLocation, HitNormal, End, Start, true);
                            My debugging starts with my absolute faith that UDK only does what it is told, so I am obviously giving it bad instructions.

                            Comment


                            • #15
                              Start = location;
                              End = location;
                              End.Z -= 2550;

                              Comment

                              Working...
                              X