Author Topic: setAimLocation  (Read 4868 times)

Some people wanted to know how to make a player look towards a certain location, so here's a little script I made.

EDIT: The code should work 100% accurately now. I know the code looks obscure but it made sense in my mind... look at the picture, it should make more sense.

Code: [Select]
// MADE BY RUDYMAN
function Player::setAimLocation(%obj, %pos) {
%curPos = %obj.getPosition();
%b = VectorDist(%curPos, %pos);
if( %b == 0 ) return;

%curRot = getWord(%obj.getTransform(), 6) * getWord(%obj.getTransform(), 5);

%b_pos = VectorAdd(%curPos, %obj.getForwardVector());
%a = VectorDist(%pos, %b_pos);
%c = VectorDist(%curPos, %b_pos);

%cos_theta = (%b/2) + (1 - (%a*%a)) / (%b * 2);
if( %cos_theta >= 1 ) return;
if( %cos_theta <= -1 ) {
%obj.setTransform(%curPos SPC "0 0 1" SPC (%curRot +  3.14159));
return;
}
%theta = mAcos(%cos_theta);

%curx = firstWord(%curPos);
        %cury = getWord(%curPos, 1);
%posx = firstWord(%pos);
        %posy = getWord(%pos, 1);
if( %curx < %posx ) %theta *= -1;

%slope = (%cury - %posy) / (%curx - %posx);
if(%cury - (%slope * %curx) <  getWord(%b_pos, 1) - (%slope * firstWord(%b_pos)) )
%theta *= -1;

%z = 1;
%newRot = %curRot + %theta;
if( %newRot < 0 ) {
%z = -1;
%newRot *= -1;
}

%obj.setTransform(%curPos SPC "0 0" SPC %z SPC %newRot);
}

You can make them look towards an object using that method:
Code: [Select]
function Player::aimAtObject(%this, %obj) {
   %this.setAimLocation( %obj.getPosition() );
}

How this works mathematically
« Last Edit: March 29, 2008, 02:50:37 PM by exidyne »

Tri

same as bot, you just changed it to Player instead of AI player.

No, the AIPlayer one was done in C++

Tri

all of this is C++, you prob mean binary.  But you can just take the aiplayer from v0002 and change it to look like this.

Tri do you have the remotest idea about what you're talking about?
'this' is Torque script, which is C++ derived, but not C++.
if he 'prob' meant binary, it would be ridiculous, and he meant C++ damnit. The sourcecode is C++, it is binary in a way but its C++ written.

I'm too lazy to look up the aiplayer from v0002 thing but I'm guessing you have something wrong there too considering your superb 'knowledge' of torque.

Tri

lolfu I m tried of people with the same vybe about me, in which they indicate no released mods = no scripting skill.  Binary isnt C++, C++ is binary >.>

same as bot, you just changed it to Player instead of AI player.

Being able to use the setAimLocation method with a player instead of just an aiplayer is a good thing, no need to criticize it.

Binary isnt C++, C++ is binary >.>

No it isn't. What are you on about? C++ is compiled into Machine Code which is Binary.

Yeah.  C++ is plaintext.  Notepad ftw.

TorqueScript is a scripting language interpreted by C++ in the Torque Game Engine.
« Last Edit: March 13, 2008, 09:42:46 AM by Trader »

Couldn't you use this general code idea to make an aim hack?

Zor has already developed a working auto-aim.  I'm toying with the idea myself, but I'd never release such a thing.  It'd be terrible for the community.  DMs would be ruined.

Rudyman (exidyne) already released a client-side aimbot, it got removed in the first few hours of being up though.

Wher cun I gte aembot I suk at DM :(

Rudyman (exidyne) tries to make a name for himself by reposting the hard work of people from the Garage Games forum.  It's pretty loving low.  I say develop something unique, show us you can actually code something on your own.  Grow a pair of e-balls and prove that you can actually do something useful, rather than lurking in the shadows, waiting for your chance to insult.

I'm not sure what you're so worked up about but my code is most definitely original.
If you have any evidence of the contrary, i'd love to see.
« Last Edit: March 13, 2008, 04:16:14 PM by exidyne »