Turn entity

Discuss programming in the QuakeC language.
Post Reply
Stealth Kill
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Turn entity

Post by Stealth Kill »

Hi,

I made a weapon attached a weapon to the player.
But it doesn´t turn left or right.

here is my code

void() attachment =
{
local vector vec;
local vector org;
local entity weapon;
makevectors(self.angles);
org = self.angles;
weapon = spawn();
weapon.movetype = MOVETYPE_NONE;
setmodel(weapon, "progs/w_ak47.mdl");
setsize(weapon, '0 0 0', '0 0 0');
setorigin(weapon, self.origin);
makevectors(self.view_ofs);
weapon.solid = SOLID_NOT;
weapon.frame =1;

weapon.nextthink = time + 0.05;
weapon.think = SUB_Remove;
};
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Try this:

Code: Select all

void() WeaponFollowThink =
{
  self.origin = self.owner.origin + '0 0 16';
  self.angles = self.owner.v_angle;
  self.angles_x = -self.angles_x; // silly Quake bug with angles and v_angle
  self.velocity = self.owner.velocity;

  // update again next frame
  self.nextthink = time;
};

void() attachment =
{
local vector org;
local entity weapon;
org = self.origin + '0 0 16';
weapon = spawn();
weapon.owner = self;
weapon.movetype = MOVETYPE_NOCLIP;
weapon.solid = SOLID_NOT;

setmodel(weapon, "progs/w_ak47.mdl");
setsize(weapon, '0 0 0', '0 0 0');
setorigin(weapon, org);
weapon.velocity = self.velocity;

weapon.angles = self.v_angle;
weapons.angles_x = -weapon.angles_x; // silly Quake bug with angles and v_angle
weapon.frame =1;

weapon.nextthink = time;
weapon.think = WeaponFollowThink;
};

I haven't tested the code, but it should fix some things. That will make the weapon follow you by updating its velocity, angle, and origin every frame. I don't know why you would have it delete iself in 0.05 seconds but that would require you to keep spawning a new entity (which I don't recommend).

There are two other ways to do this that might be much better.

1) Create a .entity for .visualweapon and set up that .visualweapon when the player spawns. Create a function that updates .visualweapon's velocity and origin, then call that function from both playerpostthink and playerprethink in client.qc. This will make the weapon update *much* smoother, though net play will still be jittery for the client holding the weapon (it won't follow his view perfectly because of the lag). This is a bit of an advanced option however, and if you want help we can provide code snippets.

2) If you're using an engine that supports either .viewmodelforclient (if you only want the player holding the weapon to see it) or MOVETYPE_FOLLOW (for all players to see it, possibly combined with .nodrawtoclient), then use one of those instead.

I hope that helps!
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Stealth Kill
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Post by Stealth Kill »

Thank you :)
It work´s but without subremove it says packet overflow :lol:
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

That's because you're respawning the weapon every single frame or every single time you attack. You need to spawn it only once.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Stealth Kill
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Post by Stealth Kill »

Another problem.

I want to make it only visible for modelindex_player and tried with this line

modelindex_player = weapon.modelindex;

it doesn´t work.
Post Reply