Jump to content

Team target


Shania

Recommended Posts

  1. function makeTargetFollow ( target )
  2.     if ( target ) and ( getElementType(target) == "player" ) then
  3.         local x,y,z = getElementPosition( source )
  4.         local tx,ty,tz = getElementPosition( target )
  5.         if ( getDistanceBetweenPoints3D( x,y,z,tx,ty,tz ) <= 7 ) then
  6.             toggleAllControls( target, false )
  7.             setControlState( target, "forwards", true)
  8.             setTimer( updateRotation, 500, 0, source, target )
  9.         end
  10.     end
  11. end
  12. addEventHandler( "onPlayerTarget", root, makeTargetFollow )
  13.  
  14.  
  15. function updateRotation( player, target )
  16.     if ( isElement(player) ) and ( isElement(target) ) then
  17.         local x,y = getElementPosition( player )
  18.         local tx,ty = getElementPosition( target )
  19.         local rot = findRotation(tx,ty,x,y)
  20.         setElementRotation ( target, 0, 0, rot )
  21.     end
  22. end
  23.  
  24. function findRotation(x1,y1,x2,y2)
  25.  
  26.   local t = -math.deg(math.atan2(x2-x1,y2-y1))
  27.   if t < 0 then t = t + 360 end;
  28.   return t;
  29.  
  30. end
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...