Results 1 to 22 of 22
  1. #1

    Default Problem offsetting a directional trace.

    So, I have set up a simple strafe for my AIController.
    What I was doing was simply, randomly choose a direction to go in, trace to see if there's anything in the way, then subtract the size of the pawn away from the distance to walk, so it doesn't get stuck on a obstacle.

    While it takes the pawn's size into account for direct collisions, this method does not take tangental collisions into account.
    So what I have now expanded it into is three traces, one in the middle, one on the right side of the pawn's collision, and one on the left side of the pawns collisions, with a tiny bit of overshoot, just to be on the safe side.
    I then send the pawn to the the location of the trace that's the shortest distance (as that means it would collide with whatever the shortest trace hit, if it went for any of the others).

    However, I seem to have done something wrong when offsetting the trace to the left and to the right of the AI's view direction, as the debug lines are all over the place and the AI seems to have no clue on where to go now.
    It's a bit too fast for me to be able to tell exactly what is going on.

    I believe the middle trace still works as it is basically the same as the original (it is the one without the Left and Right nominators in it's variables).

    Code:
       local Actor TraceHit, TraceHitLeft, TraceHitRight;
       local vector HitLocation, HitNormal, HitLocationRight, HitNormalRight, HitLocationLeft, HitNormalLeft;
       local vector Start, LeftStart, RightStart;
       local vector End, LeftEnd, RightEnd;
       local vector ViewRotToLoc;
       local rotator ViewRotation;
       local int TraceLength, TraceLengthLeft, TraceLengthRight;
    
       ViewRotation = Pawn.GetViewRotation();  
    
       ViewRotToLoc = Vector(ViewRotation);
       Start = Pawn.GetPawnViewLocation();
       End = Pawn.GetPawnViewLocation() + (ViewRotToLoc * 2000);
    
       LeftStart.Y = Start.Y + 160;
       LeftEnd = LeftStart + (ViewRotToLoc * 2000);
    
       RightStart.Y = Start.Y - 160;
       RightEnd = RightStart + (ViewRotToLoc * 2000);
    
       TraceHit = Trace(HitLocation, HitNormal, End, Start, true);
       TraceHitLeft = Trace(HitLocationLeft, HitNormalLeft, LeftEnd, LeftStart, true);
       TraceHitRight = Trace(HitLocationRight, HitNormalRight, RightEnd, RightStart, true);
    
       if (TraceHitLeft != None)
       {
          TracelengthLeft = VSize(LeftStart - HitLocationLeft) - 500;
       }
       Else
       {
          TracelengthLeft = 2000;
       }
    
       if (TraceHitRight != None)
       {
          TracelengthRight = VSize(RightStart - HitLocationRight) - 500;
       }
       Else
       {
          TracelengthRight = 2000;
       }
    
       if (TraceHit != None)
       {
          Tracelength = VSize(Start - Hitlocation) - 500;
       }
       Else
       {
          Tracelength = 2000;
       }
    
       If (TraceLength == 2000 && TraceLengthLeft == 2000 && TraceLengthRight == 2000)
       {
          StrafeToLocation = End;
          DrawDebugLine(End,Start,0,255,0,TRUE);
          DrawDebugLine(LeftEnd,LeftStart,0,255,0,TRUE);
          DrawDebugLine(RightEnd,RightStart,0,255,0,TRUE);
       }
       Else If (TraceLength <= TraceLengthLeft && TraceLength <= TraceLengthRight)
       {
          StrafeToLocation = Start + (ViewRotToLoc * TraceLength);
          DrawDebugLine(End,Start,255,0,0,TRUE);
          DrawDebugLine(LeftEnd,LeftStart,0,255,0,TRUE);
          DrawDebugLine(RightEnd,RightStart,0,255,0,TRUE);
       }
       Else If (TraceLengthLeft <= TraceLengthRight)
       {
          StrafeToLocation = LeftStart + (ViewRotToLoc * TraceLengthLeft);
          DrawDebugLine(End,Start,0,255,0,TRUE);
          DrawDebugLine(LeftEnd,LeftStart,255,0,0,TRUE);
          DrawDebugLine(RightEnd,RightStart,0,255,0,TRUE);
       }
       Else
       {
          StrafeToLocation = RightStart + (ViewRotToLoc * TraceLengthRight);
          DrawDebugLine(End,Start,0,255,0,TRUE);
          DrawDebugLine(LeftEnd,LeftStart,0,255,0,TRUE);
          DrawDebugLine(RightEnd,RightStart,255,0,0,TRUE);
       }
    }
    There's a lot more to it, but this is the parts relevant to the issue.

    Any help would be greatly appreciated!
    Last edited by Graylord; 06-08-2012 at 08:31 PM.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  2. #2

    Default

    Look into using the Extent parameter in the trace, it will let you use a box to trace instead of a line: http://forums.epicgames.com/threads/...in-Trace%28%29

  3. #3

    Default

    Cheers, I'll have a look, that should take care of rare instances of overhead collisions as well.

    Though I wouldn't mind knowing what I did wrong for future reference.
    Last edited by Graylord; 06-11-2012 at 02:11 AM.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  4. #4

    Default

    Sorry, I am not sure how to use it, I might be using it right, as it is, but I am not sure how to use a DebugBox to display it.

    This is what I have at the moment:
    Code:
       local Actor TraceHit;
       local vector HitLocation, HitNormal;
       local vector Start;
       local vector End;
       local vector ViewRotToLoc;
       local rotator ViewRotation;
       local int TraceLength, TraceLengthLeft, TraceLengthRight;
    
       ViewRotation = Pawn.GetViewRotation();  
    
       ViewRotToLoc = Vector(ViewRotation);
       Start = Pawn.GetPawnViewLocation();
       End = Pawn.GetPawnViewLocation() + (ViewRotToLoc * 2000);
    
       TraceHit = Trace(HitLocation, HitNormal, End, Start, true, Vect[100.f, 100.f, 0.f]));
    
       if (TraceHit != None)
       {
          Tracelength = VSize(Start - Hitlocation) - 500;
          StrafeToLocation = Start + (ViewRotToLoc * TraceLength);
       }
       Else
       {
          StrafeToLocation = End;
       }
       DrawDebugLine(StrafeToLocation,Start,0,255,0,TRUE);
       DrawDebugLine(End,StrafeToLocation,255,0,0,TRUE);
       DrawDebugBox(Start, End, 0, 255, 0, True);
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  5. #5
    God King
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    4,133

    Default

    It's recommended to use the same value for each component of the extend vector, i.e. 100,100,100. It's a world-axis aligned box, so your best bet to hit something without knowing the exact alignment is to just make it square.

    And you should use Vect(100,100,100) with round brackets.
    Our Loop, which art in source code, hallowed be thy keyword.
    Thy condition come, thy instruction be done, in RAM as it is in cache.
    Increment us this day our daily counter,
    and forgive us our typos, as we also have forgiven our compilers.
    And lead us not to the nullpointer but deliver us from bugs.
    For thine is the API, the GUI, and the CLI while(true).
    Semicolon;
    Please don't send me questions about how to do something in the UDK via PM. That is better discussed in the forums and we only have limited PM storage.

  6. #6

    Default

    Alright cheers.

    But how about the DrawDebugBox? I'd like to visualize the the trace so that I can see what is going on.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  7. #7

    Default

    Hi, don't mean to nag, but anyone?
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  8. #8
    MSgt. Shooter Person
    Join Date
    Mar 2010
    Posts
    249

    Default

    Free Bump!

  9. #9
    Redeemer
    Join Date
    Jul 2011
    Location
    London, UK
    Posts
    1,789

    Default

    Well i don't really know how a draw debug box should look as i never tried it before i tried it now this way
    Code:
    DrawDebugBox(Hitlocation,vect(100,0,0),255,0,0,true);
    first parameter needs a vector i used hitlocation but you can use start it should work, second parameter expects a vector extent thing i just wrote 100,0,0 didn't bother calculating, third one is a byte for the red channel so the line or box whatever you call it will be red in this case, the fourth parameter is the the G Byte which is for the green channel and the fifth parameter is the B Byte which is for the blue channel, the fifth one is a bool variable it's whether you want persistant lines or not,

    btw the way you did it isn't a good way, you need to write the drawdebugbox inside the if TraceHit!=none
    Last edited by reinrag; 06-14-2012 at 08:48 AM.

  10. #10

    Default

    I'm not really having issues understanding the separate variables of the DrawDebugBox, but I am unsure of how to use it to represent the extruded trace.

    Quote Originally Posted by reinrag View Post
    btw the way you did it isn't a good way, you need to write the drawdebugbox inside the if TraceHit!=none
    No.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  11. #11
    Redeemer
    Join Date
    Jul 2011
    Location
    London, UK
    Posts
    1,789

    Default

    Alright as you wish if it works for you the way you did it i can't argue any further,
    by the way i do not get what you mean, what exactly do you want to do ? please explain a bit more if you can,

  12. #12

    Default

    Well, the entire point of the thread is that I have setup a trace over an area, I'd like to display that trace using DrawDebugBox, but I am not sure how as they use different variables.

    I know how to setup a DrawDebugBox and I know how to do an extruded trace, but I do not know how to make the the DrawDebugBox equal to the Extruded Trace.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  13. #13
    Redeemer
    Join Date
    Jul 2011
    Location
    London, UK
    Posts
    1,789

    Default

    I got no idea sorry about that, i guess it could be possible but i can't figure out how or which way to do it,

  14. #14

    Default

    Oh well, Thanks for trying.

    I think I'll be fiddling around with the 3 way trace instead in the meantime.
    Any suggestions what I did wrong there? It's in the first post.

    The documentation says to use regular traces if you can get away with it, and I certainly don't need extreme accuracy.
    Last edited by Graylord; 06-15-2012 at 03:51 PM.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  15. #15

    Default

    Any suggestions why the traces are off?

    The traces seem to be in the right position in the axis I am intending them to be.

    However, they spawn at 0 in the z axis by what I can tell.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  16. #16

    Default

    Alright, I've fixed the issue with the traces being at 0, but I've located another issue messing it up.

    The directions use the world pivots, I need to use the local ones, how can I do this?
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  17. #17
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,920

    Default

    The extent parameter is a vector defining the width, height and depth of the box. You should be able to plug the same values in as you use for the trace extent. Both the box and the trace extent are axis aligned to the world, and the trace extent values should be uniform (all the same value, i.e. 50,50,50, or 64,64,64) to give the best results.

    However, it won't show the swept path of the trace. What you can do is interpolate over the path of the trace drawing several boxes to approximate that.

    Code:
    function DrawTracePath( Vector start, Vector end, Vector extent )
    {
        local int i, subdivisions;
    
        subdivisions = 10;
    
        for( i = 0; i <= subdivisions; ++i )
        {
            DrawDebugBox( VLerp(start, end, (1.0 / subdivisions) * i), extent, 255, 0, 0, false );
        }
    }

  18. #18

    Default

    Cheers, but I think I'm going to stick to doing multiple traces.

    I just need to know how to do the offsets I'm doing here local rather than world.:
    Code:
      ViewRotToLoc = Vector(ViewRotation);
       Start = Pawn.GetPawnViewLocation();
       End = Pawn.GetPawnViewLocation() + (ViewRotToLoc * 2000);
    
       LeftStart = Start;
       LeftStart.Y +=  160;
       LeftEnd = LeftStart + (ViewRotToLoc * 2000);
    
       RightStart = Start;
       RightStart.Y -= 160;
       RightEnd = RightStart + (ViewRotToLoc * 2000);
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  19. #19
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,920

    Default

    Use a cross product, or GetAxes().

    Code:
    local Vector x, y, z;
    
    GetAxes(ViewRotation, x, y, z);
    
    LeftStart = Start - y * 160;
    LeftEnd = Start - y * 2000;
    
    RightStart = Start + y * 160;
    RightEnd = Start + y * 2000;

  20. #20

    Default

    Thank you so much!

    It is now working perfectly!
    Code:
       ViewRotToLoc = Vector(ViewRotation);
       Start = Pawn.GetPawnViewLocation();
       End = Pawn.GetPawnViewLocation() + (ViewRotToLoc * 2000);
    
       GetAxes(ViewRotation, LocalX, LocalY, LocalZ);
    
       LeftStart = Start - LocalY * 160;
       LeftEnd = LeftStart + (ViewRotToLoc * 2000);
    
       RightStart = Start + LocalY * 160;
       RightEnd = RightStart + (ViewRotToLoc * 2000);
    
       TraceHit = Trace(HitLocation, HitNormal, End, Start, true);
       TraceHitLeft = Trace(HitLocationLeft, HitNormalLeft, LeftEnd, LeftStart, true);
       TraceHitRight = Trace(HitLocationRight, HitNormalRight, RightEnd, RightStart, true);
    I think I may be having the same issue with some other parts of my coding, some things using local where others use world. But I can't quite tell, is there any easy way to tell?

    Is viewrotation local? Are bonerotations local, are socket rotations local? What about their locations? How can I tell?
    Last edited by Graylord; 06-24-2012 at 11:21 AM.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  21. #21

    Default

    Hmm, I got another issue, how about offsetting it on multiple axes at once?
    Code:
          GetAxes(ViewRotation, LocalX, LocalY, LocalZ);
    
          Start = Pawn.GetPawnViewLocation() + (LocalZ * 480) + (LocalY * SMPawn_Base(Pawn).CamOffsetDistance);
          End = Start + (Vector(Pawn.GetViewRotation()) * 50000);
    I tried offsetting it in two directions like this, but the LocalY offset ends up being in the world axis (the Z might be as well, I am not sure since the world and local Z always is the same).
    Last edited by Graylord; 06-25-2012 at 05:01 PM.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  22. #22

    Default

    Sorry, It was due to a mistake on my part. I have used ViewRotation so much in so many situations, I started believing it was a native value, rather than one I had made myself.

    I never actually set the viewrotation.

    Everything is working perfectly now, thanks everybody for all your help!
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.