Re: TDExplosives that collide with actors
First note: I wasn't sure if you were after the bounce specifically, or if you wanted them to impact as well. As it stands, this script will make them bounce off, but will not impact. You can probably re-tool it to... apply forces, or wounds, or gib itself on contact. Who knows. But anyway, this at least will bounce off, as tested with the ronin stone and pineapple grenade. I'd expand it myself if I hadn't spent the better part of a day just mucking through it.If someone better at lua than me wants to go through and make this not horrible and kludgey, go ahead.
Just put this into your favourite text editor, save it as <<Something>>.lua (insert name, I used NadeCollide.lua, but what ever) in an appropriate .rte folder, and add ScriptPath = Path/To/Script/<<Something>>.lua to your TDExplosive.
Code:
function Create(self)
self.checking = 0;
self.bounceloss = 0.3; -- Velocity is negatively multiplied by this, so a stone going right at a velocity of 15 u/s would end up going left at a velocity of 4.5 u/s (using the value of 0.3 for bounceloss).
self.kludge = Vector();
self.usekludge = false;
end
function Update(self)
if self.checking <= 0 then
for actor in MovableMan.Actors do
local distcheck = SceneMan:ShortestDistance(self.Pos,actor.Pos,true).Magnitude
if distcheck < 50 then
local actorAhead = SceneMan:CastObstacleRay(self.Pos, self.Vel, self.kludge, Vector(), self.ID, self.Team, 128, 0);
if actorAhead > 0 then
self.checking = 2;
if actorAhead < self.Vel.Magnitude / 2 then self.usekludge = true end;
break
end
end
end
elseif self.checking > 1 then
self.checking = self.checking - 1;
if self.kludge == true then
self.Pos = self.Pos + self.kludge;
end
else
if self.Vel.Magnitude >= 1 then
if math.abs(self.Vel.X) - math.abs(self.Vel.Y) > 2 then
self.Vel.X = self.Vel.X * -self.bounceloss;
elseif math.abs(self.Vel.X) - math.abs(self.Vel.Y) < 2 then
self.Vel.Y = self.Vel.Y * -self.bounceloss;
else
self.Vel = self.Vel * -self.bounceloss;
end
end
self.checking = 0;
end
end