Porting from UnrealScript to GLua

Hello. I’m trying to port Razor Blade code from Unreal Tournament to Gmod. I need this function:


simulated function HitWall (vector HitNormal, actor Wall)
	{
		local vector Vel2D, Norm2D;

		NumWallHits++;
		if ( NumWallHits > 6 )
			Destroy();

		if ( NumWallHits == 1 ) 
		{
			Vel2D = Velocity;
			Vel2D.Z = 0;
			Norm2D = HitNormal;
			Norm2D.Z = 0;
			Norm2D = Normal(Norm2D);
			Vel2D = Normal(Vel2D);
			if ( (Vel2D Dot Norm2D) < -0.999 )
			{
				HitNormal = Normal(HitNormal + 0.6 * Vel2D);
				Norm2D = HitNormal;
				Norm2D.Z = 0;
				Norm2D = Normal(Norm2D);
				if ( (Vel2D Dot Norm2D) < -0.999 )
				{
					if ( Rand(1) == 0 )
						HitNormal = HitNormal + vect(0.05,0,0);
					else
						HitNormal = HitNormal - vect(0.05,0,0);
					if ( Rand(1) == 0 )
						HitNormal = HitNormal + vect(0,0.05,0);
					else
						HitNormal = HitNormal - vect(0,0.05,0);
					HitNormal = Normal(HitNormal);
				}
			}
		}
		Velocity -= 2 * (Velocity dot HitNormal) * HitNormal;  
		SetRoll(Velocity);
	}

I tried something and this is what I got:


ENT.NumWallHits = 0

function ENT:PhysicsCollide(data,phys)
	local Vel2D, Norm2D
	local Velocity = phys:GetVelocity()
	local HitNormal = data.HitNormal

	self.NumWallHits = self.NumWallHits +1	
	self:EmitSound("weapons/ut99/BladeHit.wav")
	
	if self.NumWallHits > 6 then
		self:Remove()
	end
	
	if self.NumWallHits == 1 then
		Vel2D = Velocity
		Vel2D.Z = 0
		Norm2D = HitNormal
		Norm2D.Z = 0
		Norm2D:Normalize()
		Vel2D:Normalize()
		if Vel2D:Dot(Norm2D) > -0.999 then
			local hn = HitNormal + 0.6 * Vel2D
			hn:Normalize()
			Norm2D = HitNormal
			Norm2D.Z = 0
			Norm2D:Normalize()
			if Vel2D:Dot(Norm2D) > -0.999 then
				if ( math.random(0,1) == 0 ) then
					HitNormal = HitNormal + Vector(0.05,0,0);
				else
					HitNormal = HitNormal - Vector(0.05,0,0);
				end
				if ( math.random(0,1) == 0 ) then
					HitNormal = HitNormal + Vector(0,0.05,0);
				else
					HitNormal = HitNormal - Vector(0,0.05,0);
				end
				HitNormal:Normalize();
			end
		end
	end
	phys:SetVelocity(Velocity - 2 * (Velocity:Dot(HitNormal)) * HitNormal)
end

But it works weird, blade stops after hit. Is there anyone who can help?

You are using > if Vel2D:Dot(Norm2D) > -0.999 then when the Unreal uses <

You are referencing Z instead of z in the Vectors.

I’m not noticing anything else right off hand.

Then it doesn’t work at all, though I dunno if it should

Is there a difference?

Actually, I thought there would be; apparently not. My mistake. The __index function on the meta-table, like Angle, must only take the first character and string.lower it. Angle you can use .yaw, etc…