Inside3D!
     

Turn entity

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Stealth Kill



Joined: 29 Dec 2006
Posts: 83

PostPosted: Sat Feb 07, 2009 4:33 pm    Post subject: Turn entity Reply with quote

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;
};
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sat Feb 07, 2009 6:53 pm    Post subject: Reply with quote

Try this:

Code:

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.
Back to top
View user's profile Send private message MSN Messenger
Stealth Kill



Joined: 29 Dec 2006
Posts: 83

PostPosted: Sun Feb 08, 2009 11:00 am    Post subject: Reply with quote

Thank you Smile
It work´s but without subremove it says packet overflow Laughing
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sun Feb 08, 2009 6:08 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message MSN Messenger
Stealth Kill



Joined: 29 Dec 2006
Posts: 83

PostPosted: Thu Feb 19, 2009 7:10 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group