Gravity Director SWep WIP

I’m thinking about creating a SWep that will change the DIRECTION of gravity for selected objects, or yourself. This is my first SWep, so expect it to be buggy.
If this actually makes progress, I will post pictures, and maybe a movie, if someone can film it.
I know how to make a simple SWep, but I cannot find any tutorials on making one that creates an entity when shot.
The way I see this SWep works, is that it first finds the angles perpendicular to the surface you are looking at when you fire it. It then removes the object’s gravity, and applies force to that object equal to that of the map’s gravity, in the direction you specified when you fired the gun at the surface.
I do not know how to do any of this besides the base SWep, so can someone TEACH me how I can do this in pieces, I wish to make the SWep, not you.

The first thing I want to know how to do is the perpendicular angles function.


SWEP.Author = "Copperbotte"
SWEP.Contact = "n/a"
SWEP.Purpose = "Gravity Changing"
SWEP.Instructions = "Primary changes your gravity's direction to the plane you are looking at, secondary moves it away."
SWEP.Category = "Copperbotte's SWeps"
 
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
 
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
 
SWEP.Primary.ClipSize = 8
SWEP.Primary.DefaultClip = 20
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "pistol"
 
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
 
SWEP.Sound = Sound ("weapons/pistol.wav")
SWEP.Damage = 50
SWEP.Spread = 0.02
SWEP.NumBul = 1
SWEP.Delay = 0.6
SWEP.Force = 3
 
function SWEP:Deploy()
	return true
end
function SWEP:Holster()
	return true
end
function SWEP:Think()
end
function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	if ( !self:CanSecondaryAttack() ) then return end
	
end
function SWEP:SecondaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	if ( !self:CanSecondaryAttack() ) then return end
	
end
function SWEP:Reload()
	self.Weapon:DefaultReload( ACT_VM_RELOAD )
end


this is the only code I have, besides the default cl_init.lua and init.lua. this is the shared.lua file.

its a good idea, but since your new to lua i dont know if you could make it

I think the function you are looking for is Vector:Normalize(), atleast from what I can tell.

To get the angle between you and the object -

[lua][position difference]:Angle()[/lua]

So you’d do something like

[lua]( ent:GetPos() - self:GetPos() ):Angle()[/lua]

so this creates the perpendicular angle from what you are looking at?
or makes the object move in the specified direction?

I’ll eventually make this work for players, as that was my original goal, but I do not know how to edit the screen angles, or world model angles.

While nobody was bothering to help me, I got most of the SWep working.
I can get the angles of a surface & change the player’s angles, but I am now at a wall. I do not know how to change the direction of the player’s gravity.

I was suggested to use the name Redirector instead of Director because it was mistaken for the L4D director.

Here is my code, tell me if it needs to be changed, and if you have the answer to my gravity direction problem, please tell me.


SWEP.Author = "Copperbotte"
SWEP.Contact = "n/a"
SWEP.Purpose = "Directing Gravity"
SWEP.Instructions = "n/a"
SWEP.Category = "Copperbotte's SWeps"
 
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
 
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
 
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
 
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
 
SWEP.Sound = Sound ("weapons/pistol.wav")
SWEP.Damage = 50
SWEP.Spread = 0.02
SWEP.NumBul = 1
SWEP.Delay = 0.6
SWEP.Force = 3

local SGravity = 600

function SWEP:Deploy()
	return true
end
function SWEP:Holster()
	return true
end
function SWEP:Think()
end
function SWEP:PrimaryAttack()
	local pl = self.Owner
	local HitP = pl:GetEyeTrace()
	local HitA = HitP.HitNormal
	if( HitP.HitNonWorld && HitP.Entity:IsValid()) then
		pl:SetParent( HitP.Entity )
	end
	pl.Entity:SetVelocity(HitA * (-1 * SGravity))
end
function SWEP:SecondaryAttack()
	local pl = self.Owner
	local HitP = pl:GetEyeTrace()
	local HitA = HitP.HitNormal
	if( HitP.HitNonWorld && HitP.Entity:IsValid()) then
		pl:SetParent( HitP.Entity )
	end
	pl.Entity:SetVelocity(HitA * (1 * SGravity))
end
function SWEP:Reload()
	self.Weapon:DefaultReload( ACT_VM_RELOAD )
end

I currently only have the player launched in the direction you look at, instead of changing the direction of gravity. It also does not work on the world yet.

All we need is a hack to let us use it clientside olololol

Anyway, would be awesome if source actually LET you change gravity pos code…

Multiply the player’s gravity by “.0000001”.
Push the player in the direction they are supposed to go.
Add fall damage when they hit the wall at a fast enough speed.
Done…?

Hope this helped.

I am confused on what the code is doing, why are you parenting yourself to the prop?

i’m going to add an entity with no model that rotates the player gradually and is removed when you die. (if there is a better way to do this, then please tell me)

This SWep has already proven useful when you are building a contraption and you cannot get people to stop playing with it, so you make a surface on the contraption down, and because you are parented to it, you move with it, even when the prop is flipped.

the parenting code DOES WORK when I remove the force movement line. I’ll post pics of this effect later today.

EDIT:

I always make my screenshots at the lowest resolution possible so I can use image tags and not a direct link. It also allows me to use the maximum settings with my bad graphics card.

should I show you a bigger angle?

[editline]05:58PM[/editline]

I want the force part to be squared, so it behaves like real gravity.
thanks for the info about the gravity set though.
and is there a Lua function that can remove gravity entirely?

[lua]ent:SetGravity( 0.000001 )[/lua]

0 is bugged which is why you use a small fraction value. 1 is normal gravity.

ok, thanks for the clarification.

also, what kind of tags are better: [ code] tags, or [ lua] tags?
your post is the first time I saw the use of [ lua] tags.

When your parented to something and your angle changes your mouse camera gets really messed up.

the way this works is because source isn’t supposed to make the player move to any angle, so instead of parenting the camera to the position’s angles, they just gave it a distance. This is another error I want to fix, but I do not know how to edit angles. I’ll show you a picture of this effect tomorrow.

this is the angle problem I have. Notice the height off the ground the camera is, even though i’m in the floor.

and another thing I noticed is that when you turn a prop you are parented to, your WASD movement gets fucked up, and is always oriented at the XY plane, so you can get W to make you move backwards.