Turn players view toward an entity

Discuss programming in the QuakeC language.
Post Reply
Mexicouger
Posts: 514
Joined: Sat May 01, 2010 10:12 pm
Contact:

Turn players view toward an entity

Post by Mexicouger »

I am trying to create a sort of aimbot type thing. My success is little to nothing. I examined bot code, but couldn't seem to apply it.

How can I miraculously change the players view via a vector?(No mouse input)
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

Yeah, i have the same question for my waypoint system...
GiffE
Posts: 170
Joined: Sun Oct 08, 2006 3:39 pm
Location: USA, CT
Contact:

Re: Turn players view toward an entity

Post by GiffE »

Mexicouger wrote:I am trying to create a sort of aimbot type thing. My success is little to nothing. I examined bot code, but couldn't seem to apply it.

How can I miraculously change the players view via a vector?(No mouse input)
For it to be done smoothly this should be done in csqc.

You would have to do something similar to ChangeYaw except it changes your view angles.

So you set an ideal view angle to (vector ideal_view) then every frame (or 0.1 sec) you turn from your current angle toward the ideal one by some turn speed.
Take a look at the qc version of changeyaw commented out in ai.qc

The biggest problem your going to face is if your doing this with ssqc your going to have to write the viewangles repeatedly and it wont give you a smooth result.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

Yeah, you can't always do it smoothly via ssqc.
Note that a few engines will automatically smooth out angles if you fixangles them in each PlayerPreThink (including both FTE and DP). Also note that such angles are often limited to 256 graduations, even if interpolated.

CSQC gives a way to avoid the graduations. It also means your angles will be correct despite prediction. If you're not using prediction, using an engine with setangles interpolation, and are using an engine with extended WriteAngles protocols (player-angles-only like QW will be just as corse), then csqc for this is overkill.
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

Wazat had some turret code at one point that would turn a stationary turret towards a vector... http://forums.inside3d.com/viewtopic.ph ... ght=turret
you might be able to adapt that to the player pov.
blubswillrule
Posts: 68
Joined: Mon Oct 04, 2010 9:08 pm
Location: Lincoln, California

Post by blubswillrule »

sorry for reviving this thread, but it's never too late to help somebody out :)

I don't know if you still want something like this, but I was able to get something to happen along the lines of aim assist, it seems a little buggy though, ont to mention it wont run on psp because of some WriteDest: Not a client error, but hey, it's my first (2nd if lightning lines count) time messing with writebytes, which I still have no idea what they do and how they work, all I know is that it works :P

anyways, here's the code...

Code: Select all

//this guy basically finds the best monster or thing that is in front of it to aim at
entity() find_infront_zombie =
{
	local entity what;
	local entity best;
	local float bestdist;
	bestdist = 1000000;
	
	
	what = findradius(self.origin, 1000);
	while(what)
	{
		if(what.classname == "monster_knight" || what.classname == "doggy"||what.classname == "RADIO" || what.classname == "teddy")
		{
			if(infront(what))
			{
				if(visible(what))
				{
					if(vlen(what.origin - self.origin) < bestdist)
					{
						best = what;
						bestdist = vlen(what.origin - self.origin);
					}
				}
				
			}
		}
		what = what.chain;
	}

	return best;
};

// this is the actual function that is called to start the aim assist
void() aim_assist =
{
	local entity what;
	what = find_infront_zombie();
	if(what == world)
	{

		//if there's nothing to aim at
		return;
	}
	
        // and this is where a whole lotta' luck came into play, basically messing around with different things got it to work.

	local vector new_ang;
	
	new_ang = self.v_angle + normalize((what.origin + '0 0 10')- self.origin) * 2; 
	
	new_ang = vectoangles(new_ang - self.v_angle);



	//using writebytes seemed like the only way to make the angles affect the player

	WriteByte (MSG_ONE, 10);

	
	WriteAngle (MSG_ONE,new_ang_x);
     	WriteAngle (MSG_ONE, new_ang_y);
     	WriteAngle (MSG_ONE,self.v_angle_z);
	
	
};
enjoy! perhaps haha
ps, I call this function in a zoom function

pps, you may want to edit the function infront() by changing the line from "if ( dot > 0.3)" to "if ( dot > 0.99)", this will make it only auto aim if you are aiming near the goal entity.

like I said before, this is a little bit buggy, and I have no idea why it crashes on the psp.
A truly rewarding experience for an AI coder: watching your ai navigate the map... makes all the time invested in the code worth it :)
daemonicky
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

Post by daemonicky »

blubswillrule : There should also be at least something like

Code: Select all

if you already have target then 
         dont do this
else
          find new target
to avoid jumping from target to target. I am sorry if You already have it there, I haven't look hard enough to see it. :)
Think, touch, movetype, solid, traceline ...
blubswillrule
Posts: 68
Joined: Mon Oct 04, 2010 9:08 pm
Location: Lincoln, California

Post by blubswillrule »

However sometimes there is something better in front of you to aim at than your last target :P

but yeah, I get what you're saying ;)
A truly rewarding experience for an AI coder: watching your ai navigate the map... makes all the time invested in the code worth it :)
Post Reply