Gravity Gun help

Discuss programming in the QuakeC language.
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Gravity Gun help

Post by Ghost_Fang »

If anyone has played half life 2, im sure you remember the gravity gun. I'm trying to make a simple quake style gravity gun. So you can pick up various objects. But with my current code the object warps the the maps's center. What did i do wrong?

Code: Select all

void() item_hold =
{
		makevectors (other.v_angle);
        traceline (other.origin , (other.origin+(v_forward * 300)) , FALSE , other);
        setorigin (self, trace_endpos);
		self.movetype = MOVETYPE_NONE;
		self.owner = other;
		self.think = item_hold;
        self.nextthink = time + 0.01;
};

Code: Select all

void() grav_grab =
{

local entity oldself; 

	if (trace_ent.th_grabbed) 
	{
	oldself = self; 
	other = self; 
	self = trace_ent; 
	self.th_grabbed(); 
	self = oldself;
	}
};

Code: Select all

void() Fire_Grav =
{
	local	vector	source;
	local	vector	org;

	makevectors (self.v_angle);
	source = self.origin + '0 0 16';
	traceline (source, source + v_forward*64, FALSE, self);
	if (trace_fraction == 1.0)
		return;
	
	org = trace_endpos - v_forward*4;

	if (trace_ent)
	{
		if (trace_ent.classname == "world")
			return;
		grav_grab();
	}
	grav_frames();
};

each object has
self.th_grabbed = item_hold;
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Post by mankrip »

It's because the center of entities aren't at their origins, so you gotta offset it.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Post by Ghost_Fang »

alright, well then what would the function look like for offsetting?
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

Center of the world is at '0 0 0' which tells me that your hold function isnt seeing the trace_endpos. You really dont have to define a th_grabbed for each entity, since self is global and you are swapping oldself and passing the grabbed object to that function as self, you can use parameters for the hold function, as hold_me(self, origin);

Even so, you could do all this within one function and just modify the movetype/velocity of trace_ent from within Fire_Grav. But MOVETYPE_NONE wouldnt be what I would use.
Last edited by r00k on Sat Sep 04, 2010 5:09 pm, edited 1 time in total.
Sajt
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Post by Sajt »

What does "grav_frames()" do? It is being called when you grab the world.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Post by Ghost_Fang »

r00k wrote:you can use parameters for the hold function, as hold_me(self, origin);

Even so, you could do all this within one function and just modify the movetype/velocity of trace_ent from within Fire_Grav. But MOVETYPE_NONE wouldnt be what I would use.
Hmm... forgive me, but im not entirely sure what you mean by that. Where i got this idea was simply the flashlight tutorial, it spawns a lightsource at the end of a given traceline. And i figured i could modify it to change the position of the entity hit by the traceline to the position where the lightsource would be. So maybe i butchered it too much, so maybe if you give me pointers based of the flashlight tutorial here it might be better.

@Sajt
grav_frames are the firing animations. Its being called in Fire_Grav();
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Gravity Gun help

Post by Baker »

Ghost_Fang wrote:If anyone has played half life 2, im sure you remember the gravity gun. I'm trying to make a simple quake style gravity gun. So you can pick up various objects. But with my current code the object warps the the maps's center. What did i do wrong?
RuneQuake Plus had a gravity gun.

Source:

http://www.quake-1.com/quakec-gallery/RQP_0.5.4.zip

A very lethal and annoying weapon to fight against.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Post by Ghost_Fang »

Thanks! but um, dumb question: whats it called in the qc? I looked and none of them seem to be able to grab something. Airgun? Hook? Shrapnel gun? which weapon is it?
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Post by Ghost_Fang »

[sarcasm] Dont everyone answer my question at once ok? [/sarcasm] I'm just kidding. But after playing with the code somemore (and never finding the grav gun in runequake plus). I figured out wat was wrong. I was calling upon self (the grabber) as the oldself (as a LOCAL entity) and it wasnt carrying over to the new function i called if (trace_ent).

So now right now I can grab and hold an entity only if i hold down the fire button. What would be the easiest why to make it toggle?

How would i be able to reset the objects physics? I want it MOVETYPE_TOSS, and thats how the items starts out, but when i let go they float.

Here is my code:

Code: Select all

void() Fire_Grav =
{
	local	vector	source;
	local	vector	org;
	local entity oldself;

	makevectors (self.v_angle);
	source = self.origin + '0 0 18';
	traceline (source, (self.origin+(v_forward * 200)) , FALSE , self);
	
	if (trace_fraction == 1.0)
		return;
		
	
	org = trace_endpos - v_forward*4;
	
	if (trace_ent)
	{
		if (trace_ent.classname == "world")
			return;
			
			oldself = self; 
			self = trace_ent;
			other = self;
			
		traceline (oldself.origin, (oldself.origin+(v_forward * 150)) , FALSE , self);
        setorigin (self, trace_endpos);
	}
	
};
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

Ghost_Fang wrote:[sarcasm]
How would i be able to reset the objects physics? I want it MOVETYPE_TOSS, and thats how the items starts out, but when i let go they float.
Haven't checked your code, but you may try to call droptofloor() after setting movetype.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Post by Ghost_Fang »

well im not sure when to call it. cause what happens is that objects origin is set to the end of my traceline so i dont think the object technically "knows" that its being grabbed, so when would i tell it "ok you can fall now"?
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Ghost_Fang wrote:Thanks! but um, dumb question: whats it called in the qc? I looked and none of them seem to be able to grab something. Airgun? Hook? Shrapnel gun? which weapon is it?
Search for the word "gravity" in the source.

If you are going to be coding, you should have something that can do an easy text search. I use TextPad 5: Search --> Find in folder

The weapon can't grab on to something, it shoots a ball with an attractive gravitational field. I didn't mess around enough with Half Life 2 or whatever game had the gravity gun or whatever it was called that let you remotely manipulate objects to be thinking that was what you wanted to achieve.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Post by Ghost_Fang »

Baker wrote: Search for the word "gravity" in the source.
Oh ok, I was just wondering if it was a literal gravity gun or it was called something else but with the same effect.

If it doesnt pick up items I don't think I'll bother just yet. I think I have a way to fix all the problems now.

I THINK:

That I have to hold the fire button because the traceline is only getting called when I fire. So what i could do is call the traceline function in like weaponframe or playerprethink or something. Would that work?

I could have the firing traceline toggle a float on the object, and if the object's "i am grabbed float" is true then stay on the player's constant traceline. Anf firing at it again will disable it and call upon "droptofloor()" as frag.machine has mentioned.

I am going to try it now, please comment if you have any objections to this because you know something i dont on how and why this wont work.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Ghost_Fang wrote:Oh ok, I was just wondering if it was a literal gravity gun or it was called something else but with the same effect.
The gravity gun in Rune Quake Plus is a literal gravity gun shooting a gravity ball that attracts players and rockets and such, not a "grabber gravity gun" like in HL2.
I am going to try it now, please comment if you have any objections to this because you know something i dont on how and why this wont work.
Someone else will have to step in, my overall QuakeC knowledge is pretty weak.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

Baker wrote:The gravity gun in Rune Quake Plus is a literal gravity gun shooting a gravity ball that attracts players and rockets and such, not a "grabber gravity gun" like in HL2.
Sounds more like the gravity well from SDQ.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Post Reply