ID:165802
 
My first attempt at making a projectile system was of course to make dense objects. Then call Bump() for when they come in contact with something dense, but i also wanted it to pass through other projectiles, so i did something simple like this example

obj
projectile
Bump(atom/A)
if(isobj(A))
src.loc=A.loc


Which would work if there isn't alot of projectiles at a high rate, but my game has a team system and you can't be hurt by people on your own team. So i want to be able to pass through my team fire without it becoming sluggish which it did, so i scrapped the dense projectile idea.

Now i try to do a different method(seems odd even to me) where I check turf/Entered as my projectile moves along and do a loop through the the turf for mobs,objs, ect. Then del the projectile, apply damage, and ect. Now im in love eveything is working smooth as can be(team mates pass through smoothy). Then i decided to do a accuracy test where I take three guys have them shoot at one spot. Then take another guy(from the other team with inf Hp) then have him walk in the middle of the fire and disappointedly I noticed that some projectiles randomly passed through me.
Well if your still with me and not bored, what would be the best way to go about making a projectile system that has these features. Im not asking for a hand out just direction
or example thanks in advance

1 Pass through your own team mates smoothly
2 Pass through other projectiles smoothly
3 Your own teams able to pass through your fire without it becoming sluggish
4 Accuracy simply hitting the target without having lag or movement allowing it to pass through randomly

One way I've used when I wanted projectiles to pass through is override Move() for your projectiles (using non-dense objects), and after calling the parent, check the bullets location for anyone (or anything) it may possibly hit. As far as not hitting teammates, a simple check would take care of that. For the accuracy, and bullets missing sometimes, just add a prob() check. Don't forget to check and make sure it's not actually hitting something dense (like a wall, or a trashcan for instance) otherwise it'll just fly across the map indefinitely, and could error out when it reaches the end of the map.
Lemme see...

mob/var/list/team = new //team variable
mob/verb/Fire() //Shoot!
var/obj/projectile/O = new/obj/projectile(src.loc)//C'mere!
O.owner = src //I own you
walk(O,src.dir,O.delay) //Go!
obj/projectile
var
damage = 5 //damage for projectile
delay = 1 //bigger delay, more slowness
owner = null //owner variable
New()
..()
spawn(10) //Lets wait a second
if(src) //If I'm still here..
del(src) //Delete me!
Bump(atom/A) //CRASH
if(ismob(A))
var/mob/M = A //set a mob variable as the atom hit so it has mob vars
var/mob/Z = src.owner //Set owner as a variable
if(M == Z) //Just in case you hit yourself...
return //then STOP... and wiggle wit it.
if(M in Z.team) //if person hit is on your team
src.loc = M.loc //just keep swimming.. just keep swimming,swimming,swimming
else
M.hp -= src.damage //ouch hurt them!
del(src) //delete projectile
if(M.hp <= 0) //Are they dead? NOooOOooo
M.Death() //Call your death proc or whatever
else if(istype(A,/obj/projectile/)) //Hit another projectile?
src.loc = A.loc //Just keep swimming... just keep swimming.. ok you know it
else //Not a mob or a projectile?
del(src) //Delete it then!


Try that.. it fires.. I tested that much lol didn't test the team thing and hitting other projectiles
In response to Detnom
Thanks Detnom ill look into overiding Move() and see what i can come up with i hope it works. VcentG thanks, but ill already have a similar system and the problem is when you teammates bunched up or get in a line it become sluggish if you try to pass there line of fire, even with the projectiles only moving there loc.

Dont be shy continue to post other ideas, im looking to make the best system i can
In response to Solee
I took Vcents and cleaned it up, because I couldn't stand seeing that code there. Terrible for people to use, because it would die in many ways, and has alot of things to fix. Here's the fixed up version, made my way:
mob/var/list/team = new
mob/proc/Damage(Damage as num)
if(!Damage) return
src.health-=Damage
if(src.health<1) src.Death() //self explanatory

mob/verb/Fire()
var/obj/projectile/O = new/obj/projectile(usr.loc,usr)
obj/projectile
var
damage = 5
delay = 1
mob/owner
New(Loc,mob/Owner)
if(!Owner) return
owner=Owner
..()
dir=Owner.dir
walk(src,dir,delay)
spawn(10) del(src)
Move()
..()
var/turf/T=loc
if(!T||T.density) del src
for(var/obj/O in T) if(O.density) del src
for(var/mob/M in T)
if(M==owner||M in owner.team) continue
if(prob(25)) continue
M.Damage(damage)
del src
In response to Detnom
Weeeeell, best not to give perfect codes or people just copy and paste and say "Yay, I added it!" when its "Yay, I copied what he did and put it in my game".. but whatever works right? lol
In response to VcentG
Sigh sadly overiding Move() has the same effect as Entered(). I notice its only when you walk towards the projectiles that they randomly pass through you or if you move back in forth rapidly, which kinda puts you in Limbo with what turf you are on I guess. Looks like my only option is to slow down rate of fire, which is something i really don't want to do unless someone knows how to fix my problem.