Saving the AIM vector of a player correctly

Hey facepunch,

I don’t know if I am drunk or just stupid atm, but I got a little problem saving the AIM direction of the player.

What I want:

i.e
I press primary fire and that saves the AIM direction, so I could spawn props sorted on a line straight in this direction.

The props spawn after each another in the direction of the old AIM vector (like a Wall), nevertheless the player is moving again and changed his AIM direction.

What I YET don’t want to happen:
If I define the AIM vector for each prop spawning, it changed and when I walk I get a curvy Wall.

A bad paint sample for better understanding:
(This is what I want)

http://img6.imagebanana.com/img/i65ef08q/sample.PNG


	function SWEP:CliffAttack( tarpos ) -- acts when primary fire is pressed. TarPos is aim hitpos.
		for i = 1,6 do
				local cliff = ents.Create("prop_dynamic")
				cliff:SetPos( tarpos )
				
			if (cliff:IsInWorld() == true) then
			
				--cliff:SetModel("models/props_wasteland/rockcliff01k.mdl")
				cliff:SetModel("models/PG_props/pg_obj/pg_crystal.mdl")
				cliff:SetColor(255,255,255,255)
				cliff:SetCollisionGroup( COLLISION_GROUP_NONE)
				cliff:PhysicsInit( SOLID_VPHYSICS )
				cliff.AutomaticFrameAdvance = true
				cliff:DrawShadow( false )
				cliff:SetPhysicsAttacker(self)

				cliff.heigth = math.abs(cliff:OBBMaxs().z - cliff:OBBMins().z)
				cliff:SetPos( Vector(tarpos.x, tarpos.y, tarpos.z /*+ (cliff.heigth / 2 + 1)*/))
				cliff:SetAngles(Angle(0, math.random(0,360), 0))

				cliff:Spawn()
				cliff:Activate()
				
				constraint.NoCollide(cliff, GetWorldEntity())
				
				cliff:ResetSequence(cliff:LookupSequence("grow_fast"))
				cliff:SetCycle( 0 )
				
				local stop_sounds = {
					"physics/concrete/boulder_impact_hard1.wav",
					"physics/concrete/boulder_impact_hard2.wav",
					"physics/concrete/boulder_impact_hard3.wav",
					"physics/concrete/boulder_impact_hard4.wav", }
					
				--self:GetPhysicsObject():SetVelocity((self:GetUp() * 900))
				
				timer.Simple(0.1, function()
					for _,tar in ipairs(ents.FindInSphere(cliff:GetPos(),100)) do
						if (ValidEntity(tar) && tar:IsNPC() && tar:IsOnGround()) then
							tar:SetVelocity(Vector(0, 0, 8000))
							tar:TakeDamage(5000,self:GetOwner(), self)
						end
					end
					cliff:EmitSound(table.Random(stop_sounds), 100, 100)
				end)
				timer.Simple(10, function()
					cliff:ResetSequence(cliff:LookupSequence("die"))
					cliff:SetCycle( 0 )
				end)
			else
				cliff:Remove()
			end
		end
	end

6 props spawning like a wall.

bump. No one got an idea?

I didn’t test this but I tried:

[lua]
SWEP.CliffSounds = {

"physics/concrete/boulder_impact_hard1.wav",
"physics/concrete/boulder_impact_hard2.wav",
"physics/concrete/boulder_impact_hard3.wav",
"physics/concrete/boulder_impact_hard4.wav"

}

function SWEP:CliffAttack(hitpos)

if !self.Owner:GetVar("CliffInfo") then self.Owner:SetVar("CliffInfo");end --If this var doesn't exist, then create it.

local CliffInfo = self.Owner:GetVar("CliffInfo"); --Define CliffInfo.

if #CliffInfo >= 6 then return; end --If there are more than six cliffs within our var then don't run this! (A hacky method fo' sho')

local OffSet = 20; --In theory, you change this to make the next spawned cliff either closer or farther away.
local model = "models/PG_props/pg_obj/pg_crystal.mdl";

local CliffInfo[1] = ents.Create("prop_physics");
		
	CliffInfo[1]:SetPos( Vector(hitpos) );
	CliffInfo[1]:SetAngles( Angle(0, math.random(0,360), 0) );
	CliffInfo[1]:SetModel( model );
	
CliffInfo[1]:Spawn();
CliffInfo[1]:EmitSound( table.Random(self.CliffSounds), 100, 100 );		

for _, ent in ipairs( ents.FindInSphere(CliffInfo[1]:GetPos(),100) ) do

	if ValidEntity(ent) then
	
		ent:SetVelocity( Vector(0, 0, 8000) );
		ent:TakeDamage( 5000,self.Owner, self );
			
	end
	
end
			
for i = #CliffInfo, 6 do 
	
	timer.Simple( i / 2, function()
	
		local I = i + 1;
		local CliffInfo* = ents.Create("prop_physics");  
		
			CliffInfo*:SetPos( CliffInfo*:GetForward() * OffSet ); --Get the last cliffs forward and multiply it by the offset previously defined!
			CliffInfo*:SetAngles( Angle(0, math.random(0,360), 0) );
			CliffInfo*:SetModel( model );
			
		CliffInfo*:Spawn();
		CliffInfo*:EmitSound( table.Random(self.CliffSounds), 100, 100 );
		
		for _, ent in ipairs( ents.FindInSphere(CliffInfo*:GetPos(),100) ) do

			if ValidEntity(ent) then
	
				ent:SetVelocity( Vector(0, 0, 8000) );
				ent:TakeDamage( 5000,self.Owner, self );
			
			end
			
		end
	
	end);
	
end

self.Owner:SetVar("CliffInfo", CliffInfo);
self:CliffsRemove();

end

function SWEP:CliffsRemove()

local CliffInfo = self.Owner:GetVar("CliffInfo");

for key, ent in pairs( CliffInfo ) do
	
	timer.Simple(key + 5, function()
	
		ent:Remove();
		table.remove(CliffInfo, key);
		
	end);
	
end

self.Owner:SetVar("CliffInfo", CliffInfo);

end[/lua]

In theory, from what I think you’re trying to do, is getting the forward angle of the ‘Cliff’ and set the next cliffs position based on that. There will be a few logical bugs that I can think of atm, one is getting the correct forward, doing a math.random for the spawn angle might mess it up. Try and define a local using http://wiki.garrysmod.com/?title=Player.GetAimVector and set your cliff angles based on that. Anything else is beyond me atm for the lack of ability to test what I’ve coded.