Correctly changing the angle of a monster?

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

Correctly changing the angle of a monster?

Post by Ghost_Fang »

I have a monster sending out a traceline, and when the traceline is interupted by a wall i want the monster to face the wall at the correct angle. ive tried many combinations of vectoangles and trace_plane_normal. Is their something i didn't do right?


traceline (self.origin + '0 0 20', self.origin + '0 0 20' + v_forward*50, TRUE, self);
if(vlen(self.origin + '0 0 20' - trace_endpos) < 30)
{
self.angles_y = vectoangles(trace_plane_normal);
}
taniwha
Posts: 401
Joined: Thu Jan 14, 2010 7:11 am
Contact:

Re: Correctly changing the angle of a monster?

Post by taniwha »

You're assigning a vector to a float (I suggest getting a good qc compiler, one that lets you know when you've messed up like that (qfcc does, and I think fteqcc does).

Anyway, you'll need a vector temp:

Code: Select all

local va = vectoangles(trace_plane_normal);
self.angles_y = va_y;
Note, however, that I make no guarantee that you'll get the results you want (in fact, I believe you won't). Quake surface normals can point either way: out of the wall, or into the wall. You'll need to do a dot product of the trace vector with the plane normal to find out whether you need to negate the normal before converting it to angles.
Leave others their otherness.
http://quakeforge.net/
Ghost_Fang
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Re: Correctly changing the angle of a monster?

Post by Ghost_Fang »

And how would i do this?
taniwha
Posts: 401
Joined: Thu Jan 14, 2010 7:11 am
Contact:

Re: Correctly changing the angle of a monster?

Post by taniwha »

Code: Select all

local float dot;
dot = v_forward * trace_plane_normal;
if (dot > 0)
    // plane normal goes into the wall
else if (dot < 0)
    // plane normal comes out of the wall
else // dot == 0
  // how did we hit the wall?
vector1 * vector2 in qc gives the dot product of two vectors.

I very strongly suggest reading up on vector math. Wikipedia is a good place to start.
Leave others their otherness.
http://quakeforge.net/
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Correctly changing the angle of a monster?

Post by mankrip »

taniwha wrote:I very strongly suggest reading up on vector math. Wikipedia is a good place to start.
I am slowly learning vector math through Quake. I've got a ton of books on vector math, but for some reason learning through books feels disgusting to me. I usually learn by practicing first, and then checking out the books to see if there's anything else about the subject. I do feel that I'm being lazy and dumb, though.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
taniwha
Posts: 401
Joined: Thu Jan 14, 2010 7:11 am
Contact:

Re: Correctly changing the angle of a monster?

Post by taniwha »

mankrip: maybe I should have been more explicit, but I didn't mean to read exhaustively. What you're doing is more or less how I got it: play a bit, read a bit, repeat. However, without a bit of reading, it's very difficult to understand just what information a dot product or cross product gives you. It's for that reason I recommend doing some reading.
Leave others their otherness.
http://quakeforge.net/
Post Reply