Announcement

Collapse
No announcement yet.

Help with a Trace problem

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

    Help with a Trace problem

    I was wondering if some of you out ther could help me out. I have created a basic weapon. The only thing I want to do is perform a trace to spawn something on an object I am looking at. So basically if I were shooting across the room it would spawn the item across the room on that wall. What is happening is that I am spawning something directly where I am standing at eye level. Please take a look at my code and let me know what you see. Also I am going to post the log so you can see the values. I don't know that much about vector math so I haven't quite figured out where the erro is. Also it is important that this remain in the ProjectileClass instead of an InstantFire weapon. Thanks for your help.

    class GunFire extends ProjectileFire;

    var() float TraceRange;

    simulated function PlayFiring()
    {

    local vector HitLocation, HitNormal, Start, End;
    local vector X, Y, Z;
    local rotator Aim;

    log("function PlayFiring has been called");

    Start = GetFireStart(X, Y, Z);
    log("Start="@Start);

    Aim = GetPlayerAim(Start, AimError);
    log("Aim="@Aim);

    X = vector(Aim);
    log("X="@Aim);

    End = Start + TraceRange * X;
    log("End="@End);
    log("TraceRange="@TraceRange);

    trace(HitLocation, HitNormal, End, Start, true);

    spawn(class'Gun.GunPickup',,,HitLocation);

    }

    simulated function Rotator GetPlayerAim( vector StartTrace, float InAimError)
    {
    log("function GetPlayerAim has been called");
    return Instigator.Location + Instigator.EyePosition() + X*Instigator.CollisionRadius;
    }

    simulated function vector GetFireStart(vector X, vector Y, vector Z)
    {
    log("function GetFireStart has been called");
    return Instigator.Location + Instigator.EyePosition() + X*Instigator.CollisionRadius;
    }

    function Rotator AdjustAim(vector Start, float InAimError)
    {
    log("function AdjustAim has been called");
    return Instigator.Controller.Rotation;
    }


    defaultproperties
    {
    TraceRange=64856.00
    AmmoClass=class'Gun.GunAmmo'
    ProjSpawnOffset=(X=25.00000,Y=8.000000)
    bLeadTarget=False
    bWaitForRelease=True
    bModeExclusive=False
    FireAnimRate=1.500000
    FireRate=0.250000
    AmmoPerFire=-1
    ProjectileClass=Gun.GunWave
    BotRefireRate=0.300000
    }

    The following is the log. I used the weapon 3 times in different locations to get some different numbers.

    ScriptLog: START MATCH
    ScriptLog: Fabricate gun.gunpickup
    ScriptLog: function AdjustAim has been called
    ScriptLog: function PlayFiring has been called
    ScriptLog: function GetFireStart has been called
    ScriptLog: Start= -156.90,826.95,-296.32
    ScriptLog: function GetPlayerAim has been called
    ScriptLog: function AdjustAim has been called
    ScriptLog: Aim= 65402,37451,0
    ScriptLog: X= -0.90,-0.43,-0.1
    ScriptLog: End= -58588.25,-27304.22,-1141.94
    ScriptLog: TraceRange= 64856.00
    ScriptLog: function AdjustAim has been called
    ScriptLog: function PlayFiring has been called
    ScriptLog: function GetFireStart has been called
    ScriptLog: Start= -293.42,670.48,-296.06
    ScriptLog: function GetPlayerAim has been called
    ScriptLog: function AdjustAim has been called
    ScriptLog: Aim= 736,33250,0
    ScriptLog: X= -1.00,-0.05,0.07
    ScriptLog: End= -64919.52,-2305.68,4276.58
    ScriptLog: TraceRange= 64856.00
    ScriptLog: function AdjustAim has been called
    ScriptLog: function PlayFiring has been called
    ScriptLog: function GetFireStart has been called
    ScriptLog: Start= -611.94,950.38,-296.32
    ScriptLog: function GetPlayerAim has been called
    ScriptLog: function AdjustAim has been called
    ScriptLog: Aim= 1123,45822,0
    ScriptLog: X= -0.31,-0.94,0.11
    ScriptLog: End= -20862.39,-60269.77,6654.46
    ScriptLog: TraceRange= 64856.00


    Any help at all would be greatly appreciated. This thing is driving me crazy. Thanks.

    #2
    Code:
    class GunFire extends ProjectileFire;
    
    var() float TraceRange;
    
    simulated function PlayFiring()
    {
        local Vector StartTrace;
        local Rotator Dir;
        local Vector X, End, HitLocation, HitNormal;
        local Actor Other;
    
        StartTrace = Instigator.Location + Instigator.EyePosition();
        Dir = AdjustAim(StartTrace, AimError);
    
        X = Vector(Dir);
        End = StartTrace + TraceRange * X;
    
        Other = Weapon.Trace(HitLocation, HitNormal, End, StartTrace, true);
    
    	if(Other == None)
    		HitLocation = End;
    	Spawn(class'XWeapons.FlakAmmoPickup',,,HitLocation);
    }
    
    defaultproperties
    {
    	TraceRange=64856.00
    	AmmoClass=class'Gun.GunAmmo'
    	ProjSpawnOffset=(X=25.00000,Y=8.000000)
    	bLeadTarget=False
    	bWaitForRelease=True
    	bModeExclusive=False
    	FireAnimRate=1.500000
    	FireRate=0.250000
    	AmmoPerFire=-1
    	ProjectileClass=Gun.GunWave
    	BotRefireRate=0.300000
    }

    Comment


      #3
      I made the changesand it still isn't working. I still get the same thing. It spawns exactly where I am standing. I just don't get it. I have looked at the code all through the different weapons and most of it is similar to a certain extent. If you would like I can email you exactly what I have. I wouldn't think it would be a problem in any of the other files I have because I have nothing in them besides defaultproperties. I appreciate your respons. Is what you posted something that you currently have working. Thanks.

      Comment


        #4
        What I posted worked for me when I did a quick test. You might want to log both hitlocation and instigator.location to see if they are truely the same.

        Comment


          #5
          Are you using UT2004 or 2003. I don't know if it would matter. Just curious. Thanks.

          Comment


            #6
            ut2004 but that should not matter

            Comment


              #7
              I think my problem may be in one of the other gun files. I don't have anything in them except the default properties. I am wondering if one of the defalut properties or something like that is the problem. Exactly what files are required in order to create something simple like this. Also is their any type of referance that you know of that will tell you the minimul default properties that need to be set. Thanks a lot for your help. Oh also I was wondering if you would mind if I emailed you directly. I just wanted to ask before actually oing that. Thanks again for your help.

              Comment


                #8
                Apparently I didn't quite test it fully. Here is the problem I am having now. I set the TraceRange to 400. What is happening is that I can only get them to spawn correctly when I am look pretty much straight up and straight down. It has a little bit of play, roughly a few degrees, but thats it. But I definately can't spawn anything correctly when I look were somone would normally look which is right in fornt of you. Ok the other proble is that for somereason they spawn correctly when nothing is hit byt the trace. They will spawn directly 400 units away. so I know the End Point is working correctly to an extent. But t still has to be almost straight up or straight down. Otherwise it spawns right on top of me. I have the code set exactly the way you wrote. Any suggestions. I don't know much about vector math so I am a little confused on that. But I am slowly learning it. Who knows by the time I get this figured out I might know what all of it means. Thanks for your help. Hopefully you can see something obvious that I don't.

                Comment


                  #9
                  OK. I have done a little more troubleshooting and I think what the problem actually is is that the traces is running but it is colliding with me. So therefore the Spawn is spawning at my location. Not exactly my location, but almost. So I was looking through some other code and I noticed that they use the following:

                  StartTrace = Instigator.Location + Instigator.EyePosition() + X*Instigator.CollisionRadius;

                  So I was trying to use that and I noticed that my X never got initialized. So on their code they use a call to GetViewAxes and send it three vecotrs. So I looked a little deeper to see what it is doing and it makes since. So when I call it like so

                  Gun.GetViewAxes(X, Y, Z)

                  I get an error for Bad Command or Expression. But when I make a call to it inside of Gun.uc it passes. The GetViewAxess function is actually in Weapon. Now I looked through all the other code and it doesn't appear that they have anything special in theirs.

                  So for the hell of it I decided to call it as Weapon.GetViewAxes(X, Y, Z) and Guess what? IT WORKED? Kindof. It does exactly what I want it to do except that I notice it doesn't spawn everywhere. If I aim at the floor it won't spawn and it seems that if I aim at static meshes it won't spawn. Is their anyway around this. Thanks again for your help.

                  Comment


                    #10
                    It is probable trying to spawn the item part way inside of the terrain so try adding a tiny offset into it.
                    Spawn(class'XWeapons.FlakAmmoPickup',,,HitLocation +vect(0,010));

                    Comment


                      #11
                      OK I added the offset and it works great. The last problem I have is that the trace doesn't deal with swtatic meshes. When it hits one it just doesn't spawn anything. Do you think this is another offset problem that I may need to tweak or does it have something to do with the static mesh properties. Thanks again for your help.

                      Comment

                      Working...
                      X