Announcement

Collapse
No announcement yet.

Lock on a bot

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

    Lock on a bot

    Hi,
    I'm trying to make a mutator;
    I took the camera out (3rd person view) and now I need to lock on an enemy. It works like this when u face 2 or more in your radius (you will have a small (invisible) radius around your character) and when you press the lock key your character will lock on one of them (close one) and when you strafe your character will turn around the enemy (it works like an auto face)
    and again you press lock key you will have the ability to change the enemy you lock on...
    Thanks for your answers...

    #2
    In your PlayerController, you have to play around with PlayerCalcView and its CameraLocation and CameraRotation vars; And dont forget to set ViewActor to the one that you are focusing;

    I cant give more details, as I am at my job, and I dont have the code here

    Comment


      #3
      Thanks for the reply...
      I'm still trying things but I think I've a problem with detection if the enemy is in radius or not...

      Comment


        #4
        Code:
        /* RadiusActors() returns all actors within a give radius.  Slow like AllActors().  Use CollidingActors() or VisibleCollidingActors() instead if desired actor types are visible
        (not bHidden) and in the collision hash (bCollideActors is true)
        */
        native(310) final iterator function RadiusActors  ( class<actor> BaseClass, out actor Actor, float Radius, optional vector Loc );
        You are using this function right??

        Comment


          #5
          Here is some code from a project that I have stopped working on. I think it might be similar to what you are looking to do. This code is in the player controller, I didnt include the third-person camera code or anything (if thats what your trying to do, but it should work with first person too ). Anyways, there is this function TurntowardNearestEnemy() in playercontroller that is empty which gets called in UpdateRotation. Here is part of what I did to make a lock on button. Hope you can make use of this or that it helps you with your code.

          Code:
          var pawn closestEnemy; 				//The Closest Enemy in FOV
          var bool bFoundTarget; 				//If Found a target
          var rotator TurnToEnemy;			//Rotation needed to Turn To Enemy
          
          
          function bool TurnTowardNearestEnemy()
          {
             	local pawn p;
             	local vector direction, EnemyDirection,x,y,z;;
          	local float distance, EnemyDistance;
          	local rotator rotChange;
          
             	//Checks if there is a ClosestEnemy and get the direction to check
             	//if in view
          	if( closestEnemy != none )
             	{
          		//Get the pawns rotation
          		GetAxes( pawn.Rotation, x, y, z );
          
          		EnemyDirection = closestEnemy.Location - pawn.Location;
          
          		//Normalize the vector
          		EnemyDirection = Normal( EnemyDirection );
          
          		if( !(EnemyDirection dot x > 0.6) || !(pawn.LineOfSightTo( closestEnemy )))
          		{
          			closestEnemy = none;
          		}
          	}
          
          	//If closestEnemy is dead or not in view release him
          	if( closestEnemy != none && closestEnemy.Controller == none )
             	{
             		closestEnemy = none;
             	}
          
                  //If no target found
          	if( !bFoundTarget )
          	{
          		//Run through all the pawns
          		foreach AllActors(class'pawn', p)//, LockOnRange, Location)
          		{
          			//If pawn doesnt equal none and is not dead
          			if( p != pawn && p.Controller != none )
          			{
          				//Get the pawns rotation
          				GetAxes( pawn.Rotation, x, y, z );
          
          				direction = p.Location - pawn.Location;
          
          	                        distance = VSize(direction);
          
          				//Normalize the vector
          				direction = Normal( direction );
          
          				//If line of sight and field of view
          				if( direction dot x > 0.6 && pawn.LineOfSightTo( p ))
          				{
          					//If no closestEnemy, p is it by default
          					if( closestEnemy == none )
              		                        {
          						closestEnemy = p;
          					}
          					else
          					{
          						EnemyDirection = closestEnemy.Location - pawn.Location;
          						EnemyDistance = VSize(EnemyDirection);
          
          						//Check who is closest
          						if( distance < EnemyDistance)
          						{
          							closestEnemy = p;
          							EnemyDirection = direction;
          						}
          					}
          				}
          			}
           		}
          	}
          
          	//If closestEnemy still exists
          	if( closestEnemy != none && closestEnemy.Controller != none )
          	{
          		//We found a target
          		bFoundTarget = true;
          
          		//Works YAY!!!
          		TurnToEnemy = Rotation;
              	        rotChange = rotator(EnemyDirection) - Rotation;
          		TurnToEnemy += rotChange;
          
          		//Debug
                          //		ClientMessage( "Enemy: " $ closestEnemy.GetHumanReadableName() $
                          //			                        "  Dist: " $ string(distance) $
                          //						"  DirRot: " $ string(rotChange) $
                          //						"  Dir: " $ string(direction) );
          
          		//Turn to the Enemy
          		DesiredRotation = TurnToEnemy;
              	        bRotateToDesired = ( DesiredRotation != Rotation );
          	}
          
              return true;
          }

          Comment


            #6
            Wow man thanks for all your gr8 replies I thought I never would be able to do this (yesterday night I went to bed at 6a.m. with none of my goals accomplished) again thanks a lot.
            BTW I want to ask you a little thing if we can modify the animation sets (putting new animations like rightpunch or right kick)....

            Comment


              #7
              It's possible to do so. Most of the TC's out there have their own animation sets. Whether you can do it is up to how much time and effort you want to put into it.

              Comment

              Working...
              X