Shania Posted December 30, 2016 Share Posted December 30, 2016 function makeTargetFollow ( target ) if ( target ) and ( getElementType(target) == "player" ) then local x,y,z = getElementPosition( source ) local tx,ty,tz = getElementPosition( target ) if ( getDistanceBetweenPoints3D( x,y,z,tx,ty,tz ) <= 7 ) then toggleAllControls( target, false ) setControlState( target, "forwards", true) setTimer( updateRotation, 500, 0, source, target ) end end end addEventHandler( "onPlayerTarget", root, makeTargetFollow ) function updateRotation( player, target ) if ( isElement(player) ) and ( isElement(target) ) then local x,y = getElementPosition( player ) local tx,ty = getElementPosition( target ) local rot = findRotation(tx,ty,x,y) setElementRotation ( target, 0, 0, rot ) end end function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end Link to comment
Miika Posted December 30, 2016 Share Posted December 30, 2016 So what's the problem then? Link to comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 Please read the following topic so we can help you better. Link to comment
ViRuZGamiing Posted December 31, 2016 Share Posted December 31, 2016 21 hours ago, Shania said: if t < 0 then t = t + 360 end; return t; make this return t < 0 and t + 360 or t it's shorter and ; isn't necessary (doesn't cause no harm tho) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now