sine function
Moderator: InsideQC Admins
9 posts
• Page 1 of 1
sine function
silly question, but I'm stupid and tired, my brain isn't working. Is there a sin() function in qc? I'm pretty inept at programming generally, so I don't know what I'm supposed to be looking for.
I want to spawn monsters at random points on a circle on the x/y plane around an entity. They can't spawn too close to the origin of the entity, otherwise they'll telefrag it. So I was thinking something like:
Does that make sense? Any help appreciated.
I guess it doesn't even really need to be a circle, just far enough outside the entity's hitbox that the new entity doesn't cause problems.
I want to spawn monsters at random points on a circle on the x/y plane around an entity. They can't spawn too close to the origin of the entity, otherwise they'll telefrag it. So I was thinking something like:
- Code: Select all
newent.origin_x = ent.origin_x + (sin(angle) * minDistFromEnt);
newent.origin_y = ent.origin_y + (cos(angle) * minDistFromEnt);
Does that make sense? Any help appreciated.
I guess it doesn't even really need to be a circle, just far enough outside the entity's hitbox that the new entity doesn't cause problems.
-

sp4x0r - Posts: 16
- Joined: Mon Jul 21, 2008 11:48 am
There's no sin() or cos() function in standard QuakeC (although they do exist in DP and probably in FTE as built-ins, too). If you want to make a fully portable code, I'd suggest you to make something like:
a) make the central point entity face a random direction (randomize self.angles_y);
b) make it to fire a traceline from its origin to a destination at a random number of units from its origin (check the shotgun fire function in weapons.qc for examples of how to do that);
c) use trace_endpos as the spawn coordinates for your new entity;
d) restore self.angles_y (optional).
This approach has the advantage of make sure your destination won't be a solid spot. Of course, you'll still need to check if there's enough room for your about to spawn entity.
a) make the central point entity face a random direction (randomize self.angles_y);
b) make it to fire a traceline from its origin to a destination at a random number of units from its origin (check the shotgun fire function in weapons.qc for examples of how to do that);
c) use trace_endpos as the spawn coordinates for your new entity;
d) restore self.angles_y (optional).
This approach has the advantage of make sure your destination won't be a solid spot. Of course, you'll still need to check if there's enough room for your about to spawn entity.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
- Code: Select all
local vector v;
v_y = angle;
makevectors(v);
newent.origin = ent.origin + v_forward * minDistFromEnt;
is basically equivelent
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Spike wrote:
- Code: Select all
local vector v;
v_y = angle;
makevectors(v);
newent.origin = ent.origin + v_forward * minDistFromEnt;
is basically equivelent
^^^ What Spike said.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
courtesy of FrikaC http://www.inside3d.com/frikbot/qc/mathlib.qc
-

Error - InsideQC Staff
- Posts: 865
- Joined: Fri Nov 05, 2004 5:15 am
- Location: VA, USA
mathlib.qc is if you need sin(). But you don't, you want makevectors. makevectors does for you what you wanted to do with sin and cos, so using mathlib would be redundant and wasteful (since mathlib uses makevectors to generate sin/cos anyway).
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.
- Sajt
- Posts: 1215
- Joined: Sat Oct 16, 2004 3:39 am
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest

