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;
};
Turn entity
Try this:
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!
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.
-
- Posts: 83
- Joined: Fri Dec 29, 2006 12:34 pm
-
- Posts: 83
- Joined: Fri Dec 29, 2006 12:34 pm