//try to translate C code into lua // https://wiki.srb2.org/wiki/A_AttractChase if P_AttractLua return end rawset(_G, "P_AttractLua", function(source, dest, nightsgrab) //pretty quick copy & paste made by luigi budd --[[ HOW TO USE: P_LookForPlayers(mobj_t actor, fixed dist, boolean allaround, boolean tracer?) if mobj.tracer P_AttractLua(mobj, mobj.tracer, boolean nightsgrab?) end Fill out P_LookForPlayers as normal, then once a tracer is found, call P_AttractLua. Usually used by rings. --]] local dist local ndist local speedmul local vangle local tx = dest.x local ty = dest.y local tz = dest.z + (dest.height/2) // Aim for center local xydist = P_AproxDistance(tx - source.x, ty - source.y) if ((not dest) or (dest.health <= 0) or (not dest.player) or (not source.tracer)) return end // change angle source.angle = R_PointToAngle2(source.x, source.y, tx, ty) // change angle dist = P_AproxDistance(xydist, tz - source.z) if (dist < 1) dist = 1 end if (nightsgrab and source.movefactor) source.movefactor = $ + (FRACUNIT/2) if (dist < source.movefactor) source.momx = 0 source.momy = 0 source.momz = 0 P_TeleportMove(source, tx, ty, tz) else vangle = R_PointToAngle2(source.z, 0, tz, xydist) source.momx = FixedMul(FINESINE(vangle >> ANGLETOFINESHIFT), FixedMul(FINECOSINE(source.angle >> ANGLETOFINESHIFT), source.movefactor)) source.momy = FixedMul(FINESINE(vangle >> ANGLETOFINESHIFT), FixedMul(FINESINE(source.angle >> ANGLETOFINESHIFT), source.movefactor)) source.momz = FixedMul(FINECOSINE(vangle >> ANGLETOFINESHIFT), source.movefactor) end else if nightsgrab speedmul = P_AproxDistance(dest.momx, dest.momy) + FixedMul(8*FRACUNIT, source.scale) else speedmul = P_AproxDistance(dest.momx, dest.momy) + FixedMul(source.info.speed, source.scale) end source.momx = FixedMul(FixedDiv(tx - source.x, dist), speedmul) source.momy = FixedMul(FixedDiv(ty - source.y, dist), speedmul) source.momz = FixedMul(FixedDiv(tz - source.z, dist), speedmul) end // Instead of just unsetting NOCLIP like an idiot, let's check the distance to our target. ndist = P_AproxDistance(P_AproxDistance(tx - (source.x+source.momx), ty - (source.y+source.momy)), tz - (source.z+source.momz)) if (ndist > dist) // gone past our target // place us on top of them then. source.momx = 0 source.momy = 0 source.momz = 0 //i might need to translate this too // https://github.com/id-Software/DOOM-iOS/blob/master/code/prboom/p_maputl.c //P_UnsetThingPositionLua(source) P_TeleportMove(source, tx, ty, tx) //P_SetThingPositionLua(source) //don't need to translate the commented functions, since this works fine enough for me! end end)