local Effect local Offset = self.Vel*(20*TimerMan.DeltaTimeSecs) -- the effect will be created the next frame so move it one frame backwards towards the barrel
-- smoke forward for i = 1, 4 do Effect = CreateMOSParticle("Side Thruster Blast Ball 1", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end
for i = 1, 1 do Effect = CreateMOPixel("Glow Explosion Huge", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end for i = 1, 2 do Effect = CreateAEmitter("Explosion Trail 1") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end
-- smoke up for i = 1, 5 do Effect = CreateMOSParticle("Tiny Smoke Ball 1", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(-2,2), -RangeRand(7,11))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end
-- smoke down for i = 1, 5 do Effect = CreateMOSParticle("Tiny Smoke Ball 1", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(-2,2), RangeRand(7,11))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end end
function Update(self) if self.Life:IsPastSimMS(5) then if SceneMan:FindAltitude(self.Pos, 500, 1) < 5 then self.penetrating = true end end self.ToSettle = false local Effect local Offset = self.Vel*(20*TimerMan.DeltaTimeSecs) -- the effect will be created the next frame so move it one frame backwards towards the barrel
-- smoke trail for i = 1, math.floor(self.Vel.Magnitude*0.045) do Effect = CreateMOSParticle("Tiny Smoke Trail " .. math.random(3), "Coalition.rte") if Effect then Effect.Pos = self.Pos - Offset * i/8 + Vector(RangeRand(-2,2),RangeRand(-2,2)) Effect.Vel = (self.Vel + Vector(RangeRand(-10,30),RangeRand(-10,10))) / 20 MovableMan:AddParticle(Effect) end end local Vector2 = (Vector(25,0):GetXFlipped(self.HFlipped)):RadRotate(self.RotAngle); local Vector3 = Vector(0,0); local Vector4 = Vector(0,0); self.ray = SceneMan:CastObstacleRay(self.Pos, Vector2, Vector3, Vector4, self.RootID, self.Team, 128, 0); local gap = SceneMan:ShortestDistance(self.Pos, Vector3, true) local length = gap.Magnitude if length <= 5 then self.penTimer:Reset() self.penetrating = true end if self.penetrating == true then if self.penTimer:IsPastSimMS(60) then self:GibThis() end end
for i = 1, self.dots do local checkPos = self.Pos + Vector(self.Vel.X,self.Vel.Y):SetMagnitude((i/self.dots)*self.raylength); if SceneMan.SceneWrapsX == true then if checkPos.X > SceneMan.SceneWidth then checkPos = Vector(checkPos.X - SceneMan.SceneWidth,checkPos.Y); elseif checkPos.X < 0 then checkPos = Vector(SceneMan.SceneWidth + checkPos.X,checkPos.Y); end end local terrCheck = SceneMan:GetTerrMatter(checkPos.X,checkPos.Y); if terrCheck == 9 or terrCheck == 10 or terrCheck == 11 then self:GibThis(); end end
end
as u maybe can see this is supposed to check if the round this .lua is attached to is close to something, aka going through it (high gib impulse limit, mass and strong deep material etc) and initiate a timer
my problem is, this is really, really unreliable
some rare times it fails to set off, and if i make the length requirement lower, it's even more sensitive, and sets off quicker (wut? shouldnt that mean it has to be even closer (wait more time) before setting off)
i've also tried to make it so that it only initiates the timer to gib itself once it's gotten OUT of the thing it touched - by making another length check, and only setting the timer off if the length is above a certain amount
this was met with tons of unreliability and i could make no sense of it
so what the heck is going on here?
EDIT: this is basically the gun right now
Last edited by Hoovytaurus on Sun Jan 22, 2017 10:30 am, edited 1 time in total.
Sat Jan 21, 2017 10:30 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: shoddy ray stuff
Well, to start with, SceneMan:GetTerrMatter only applies to terrain, not MOs. Another issue is that your projectile might be moving fast enough that it covers a larger distance per frame than the ray.
Sun Jan 22, 2017 12:44 am
Hoovytaurus
Joined: Mon Dec 21, 2015 9:30 am Posts: 89
Re: shoddy ray stuff
CaveCricket48 wrote:
Well, to start with, SceneMan:GetTerrMatter only applies to terrain, not MOs. Another issue is that your projectile might be moving fast enough that it covers a larger distance per frame than the ray.
the terrmatter stuff is just to check for dirt - i want it to penetrate concrete and other things but not act like a gunpowder-powered digger. surprisingly, that part works flawlessly. the part above, with the obstacle ray, is the one that is unreliable
should i increase ray length, then? its shot out with a velocity of 170, which is pretty fast i suppose but i dont think it moves 25 pixels a frame, does it?
Sun Jan 22, 2017 10:16 am
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: shoddy ray stuff
Took a closer look - looks like while the obstacle ray is 25 pixels long, you're only checking if the projectile is within 5 pixels of an obstacle, so your ray is effectively only 5 pixels.
If you want to have a longer, more reliable ray/distance check while still having the projectile detonate up close, you could try teleporting the projectile closer before detonation.
Sun Jan 22, 2017 4:53 pm
Hoovytaurus
Joined: Mon Dec 21, 2015 9:30 am Posts: 89
Re: shoddy ray stuff
CaveCricket48 wrote:
Took a closer look - looks like while the obstacle ray is 25 pixels long, you're only checking if the projectile is within 5 pixels of an obstacle, so your ray is effectively only 5 pixels.
If you want to have a longer, more reliable ray/distance check while still having the projectile detonate up close, you could try teleporting the projectile closer before detonation.
well the point of this script is to initiate a boom-timer upon it penetrating sometimes
for example, if there is a guy hiding in a bunker, i can fire through the wall and have the round explode just after penetrating, rather than on the surface, or not at all and just plowing through the guy instead
im not sure what teleporting it would achieve here
to elaborate, the problem is that sometimes it seems to detonate instantly upon it touching a wall, sometimes it works well, and sometimes it completely fails to detonate, even when in circumstances where it should (ive seen it get stuck in a very thick concrete wall and just sit there, encased in concrete without exploding - and the timer is shorter than the time it took to settle!)
maybe i could use the second bit of the code to achieve it since it's rather reliable, but then i'd have to manually add in every material i want it to act that way to
Sun Jan 22, 2017 5:22 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: shoddy ray stuff
Okay so, this script is supposed to detect an obstacle (MO or terrain), and then start a timer. Then, when the timer finishes, it explodes.
Is it possible infinitely restarting the timer, for the scenario where it's embedded in walls and not doing anything?
Sun Jan 22, 2017 5:49 pm
Hoovytaurus
Joined: Mon Dec 21, 2015 9:30 am Posts: 89
Re: shoddy ray stuff
CaveCricket48 wrote:
Okay so, this script is supposed to detect an obstacle (MO or terrain), and then start a timer. Then, when the timer finishes, it explodes.
Is it possible infinitely restarting the timer, for the scenario where it's embedded in walls and not doing anything?
i was gonna write no then i took a look at the code, yeah that might be possible
would putting a length less than 5 AND self.penetrating == false check work to fix that? then it can only reset once
ill go check right now and test over and over again, as one does
EDIT: ok so i had a look
firing horizontally through walls goes pretty well, havent had one dud
firing at a direct, downwards into the ground, seems to produce most duds
firing at a pretty horizontal angle towards the ground makes it prematurely detonate, penetrating even less than expected even if you factor in the fact that it has to go through more ground thanks to the angle
firing through very thin walls or corners fails to set off the timer and will produce a dud, until it plows into something else
Sun Jan 22, 2017 6:19 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: shoddy ray stuff
Out of curiosity, what are the dimensions of the sprite of the projectile?
I'm wondering if the premature detonation (when firing at a mostly horizontal angle into the ground) is due to the terrain check? Are you testing on dirt ground or concrete/scrap ground?
Producing a dud through corners and very thin walls is probably due to the 5 pixel length check - if the projectile is traveling faster than 5 pixels per frame, it would effectively have "holes" in its detection, and be able to miss thin walls.
Firing directly into the ground and getting duds - if this is before adding the self.penetrating check to "if length <= 5 then", it sounds like it's infinitely resetting the timer. - if this is after adding the self.penetrating check, then that's strange, and would ask what you have set for the projectile's RestThreshold.
Sun Jan 22, 2017 7:33 pm
Hoovytaurus
Joined: Mon Dec 21, 2015 9:30 am Posts: 89
Re: shoddy ray stuff
CaveCricket48 wrote:
Out of curiosity, what are the dimensions of the sprite of the projectile?
I'm wondering if the premature detonation (when firing at a mostly horizontal angle into the ground) is due to the terrain check? Are you testing on dirt ground or concrete/scrap ground?
Producing a dud through corners and very thin walls is probably due to the 5 pixel length check - if the projectile is traveling faster than 5 pixels per frame, it would effectively have "holes" in its detection, and be able to miss thin walls.
Firing directly into the ground and getting duds - if this is before adding the self.penetrating check to "if length <= 5 then", it sounds like it's infinitely resetting the timer. - if this is after adding the self.penetrating check, then that's strange, and would ask what you have set for the projectile's RestThreshold.
i am testing it on concrete ground, firing it into dirt produces instant detonation - as expected and properly working, no worries there
so the only way to fix that is to make the length - or lack or it - bigger? perhaps if i also increase the timer this could make it more reliable without necessarily messing up the intended timing
the dimensions of the round itself are 23 long and 5 thick
there is no restthreshold defined - at the time of making this i knew there was something like that but failed to remember. what should i set it to?
Sun Jan 22, 2017 7:43 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: shoddy ray stuff
Set your RestThreshold to a negative number, this will keep it from settling. -500 or something. After that, mess around with your timer delay and ray check length, see if you can get something workable. With the self.penetrating check before resetting the timer, it shouldn't produce duds (outside of not properly detecting small terrain).
Sun Jan 22, 2017 7:55 pm
Hoovytaurus
Joined: Mon Dec 21, 2015 9:30 am Posts: 89
Re: shoddy ray stuff
CaveCricket48 wrote:
Set your RestThreshold to a negative number, this will keep it from settling. -500 or something. After that, mess around with your timer delay and ray check length, see if you can get something workable. With the self.penetrating check before resetting the timer, it shouldn't produce duds (outside of not properly detecting small terrain).
i will try just that and report back in an edit
does 20 if-requirement on the length stuff sound good? how fast is "170" anyway?
EDIT: ok this is very interesting
i have tested and i commented out the self.epentrating == true from the altitude check
it stopped working completely, as if the obstacle ray was doing nothing at all
i set length to less than 40, which should be foolproof, but it still seems to straight up not work
it throws no errors. what's going on?
Sun Jan 22, 2017 8:02 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
local Effect local Offset = self.Vel*(20*TimerMan.DeltaTimeSecs) -- the effect will be created the next frame so move it one frame backwards towards the barrel
-- smoke forward for i = 1, 4 do Effect = CreateMOSParticle("Side Thruster Blast Ball 1", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end
for i = 1, 1 do Effect = CreateMOPixel("Glow Explosion Huge", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end for i = 1, 2 do Effect = CreateAEmitter("Explosion Trail 1") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end
-- smoke up for i = 1, 5 do Effect = CreateMOSParticle("Tiny Smoke Ball 1", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(-2,2), -RangeRand(7,11))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end
-- smoke down for i = 1, 5 do Effect = CreateMOSParticle("Tiny Smoke Ball 1", "Base.rte") if Effect then Effect.Vel = self:RotateOffset(Vector(RangeRand(-2,2), RangeRand(7,11))) Effect.Pos = self.Pos - Offset MovableMan:AddParticle(Effect) end end end
function Update(self) if self.Life:IsPastSimMS(5) then if SceneMan:FindAltitude(self.Pos, 500, 1) < 5 then self.penetrating = true end end self.ToSettle = false local Effect local Offset = self.Vel*(20*TimerMan.DeltaTimeSecs) -- the effect will be created the next frame so move it one frame backwards towards the barrel
-- smoke trail for i = 1, math.floor(self.Vel.Magnitude*0.045) do Effect = CreateMOSParticle("Tiny Smoke Trail " .. math.random(3), "Coalition.rte") if Effect then Effect.Pos = self.Pos - Offset * i/8 + Vector(RangeRand(-2,2),RangeRand(-2,2)) Effect.Vel = (self.Vel + Vector(RangeRand(-10,30),RangeRand(-10,10))) / 20 MovableMan:AddParticle(Effect) end end local Vector2 = (Vector(40,0):GetXFlipped(self.HFlipped)):RadRotate(self.RotAngle); local Vector3 = Vector(0,0); local Vector4 = Vector(0,0); self.ray = SceneMan:CastObstacleRay(self.Pos, Vector2, Vector3, Vector4, self.RootID, self.Team, 128, 0); local gap = SceneMan:ShortestDistance(self.Pos, Vector3, true) local length = gap.Magnitude if length <= 40 and self.penetrating == false then self.penTimer:Reset() self.penetrating = true end if self.penetrating == true then if self.penTimer:IsPastSimMS(200) then self:GibThis() end end
for i = 1, self.dots do local checkPos = self.Pos + Vector(self.Vel.X,self.Vel.Y):SetMagnitude((i/self.dots)*self.raylength); if SceneMan.SceneWrapsX == true then if checkPos.X > SceneMan.SceneWidth then checkPos = Vector(checkPos.X - SceneMan.SceneWidth,checkPos.Y); elseif checkPos.X < 0 then checkPos = Vector(SceneMan.SceneWidth + checkPos.X,checkPos.Y); end end local terrCheck = SceneMan:GetTerrMatter(checkPos.X,checkPos.Y); if terrCheck == 9 or terrCheck == 10 or terrCheck == 11 then self:GibThis(); end end
end
Sun Jan 22, 2017 8:32 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: shoddy ray stuff
It looks like self.penetrating is not actually set to some initial value anywhere in the script, if I'm reading it correctly.
Since you commented out the self.penetrating = true from the altitude section, self.penetrating is a null value during the ray length check, not false.
Put a self.penetrating = false in your Create() block and test with the self.penetrating in the altitude section commented out.
Sun Jan 22, 2017 8:40 pm
Hoovytaurus
Joined: Mon Dec 21, 2015 9:30 am Posts: 89
Re: shoddy ray stuff
CaveCricket48 wrote:
It looks like self.penetrating is not actually set to some initial value anywhere in the script, if I'm reading it correctly.
Since you commented out the self.penetrating = true from the altitude section, self.penetrating is a null value during the ray length check, not false.
Put a self.penetrating = false in your Create() block and test with the self.penetrating in the altitude section commented out.
ahhhhhh
a bug in coding is 1% actually doign something wrong and 99% overlooking things huh? thanks i will try it out and edit in results
edit: absolutely brillaint man it all works!
thank you so much for all this, you are the best dude
i hope this will make it on the workshop or this forum soon... if i get around to polishing my older things haha
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum