No announcement yet.

Selecting things, handy for RTS.

  • Filter
  • Time
  • Show
Clear All
new posts

    Selecting things, handy for RTS.

    i made this so i have to press E to pick stuff up.

    class SelectorGun extends InstantFire;

    function Actor Fire(Pawn P)
    local vector X, End, Start,HitLocation, HitNormal;
    local Actor Other;
    local rotator tempRotation;
    local int range;
    range = 75;
    tempRotation = AdjustAim(P.location,0);
    Start = P.Location;

    X = Vector(tempRotation);
    End = Start + range * X;
    return P.Trace(HitLocation, HitNormal, End, Start, true);

    it works so if your in need of something that works like this, there you go. Create it in your pawn class, look at your target, call fire and it will return that actor to whatever variable you declared for it. B sure to make your actor, bBlockActors=true.

    you really didnt explain what the use of this code is. do you mean pick up things like pickups, or pick up real world objects, such as karma actors, etc. my guess is the first, but you really should elaborate a bit, otherwise no one in need of such code will ever know what youre talking about.

    but of course, thanks for sharing.

    also, if it is infact pickups youre talking about, there are much better ways, heh.


      His function return an actor and is issued by a Pawn.

      Example :

      if you are the pawn P and you re aiming at something and call that function you will get the actor you re aiming at...

      what will you do with this result is up to you !

      Pickup, destroy,write his name on the screen, etc.

      I repeat this function only return the actor the pawn is aiming at...


        Yes, it would return any actor that the pawn is looking at.

        I do it differently. My method returns whatever actor the mouse corss-hair is over on the screen. It does not depend on having your own pawn. This also means you can select anyting on the screen, anywhere, as long as your mouse is over it.

        I use the interaction class's ScreenToWorld function. Here is the code:

        mouseLoc.X = cursorX;
        mouseLoc.Y = cursorY;
        mouseDir = ScreenToWorld(mouseLoc, pOwner.Pawn.Location, pOwner.Pawn.Rotation);
        mouseDir = Normal(mouseDir);
        tStart = pOwner.Pawn.Location;
        tEnd = tStart + mouseDir * 8000;
        other = pOwner.Trace(hitLoc, hitNorm, tEnd, tStart, true);
        First, I put the cursor x and y coordinates into a vector; mouseLoc. Then I use the ScreenToWorld function to grab the normal vector that is pointing in the direction that mouse cross is at. Note that I use the pawn location and rotation, but you dont need to if you dont have a Pawn, you can just use the camera location and rotation.

        Then I use the mouse direction to get the end vector, and use trace to get the actual object that the trace hits.

        With this code, you can select any actor.

        edit: I dont know how accurate the OP's code is in selecting exactly what you want. I have noticed another version that wasn't all that accurate. This code, however, is 100% accurate. You will hit exactly what you're mouse cross-hair is over on the screen.

        One more note: this code should be inside the intereaction class, but it can be outside too as long as you have a reference to your interaction class; but since the interaction class does not exist server-side, its best to stick this inside the interaction class.