Page 1 of 2

Getting a script object to point at the player?

Posted: Tue Apr 29, 2003 2:03 am
by matt_moh
I made a script object out of brushes that looks like a gun and was wondering if it was possible to get the "gun" to turn and point at the player as he moves around, kind of like how a tank turret moves. Is there any simple way to get the gun to work? I don't have any advanced 3d graphic tools or the money to buy them, so making my own model is out of the question. If there is no simple way to make my gun work, I did come up with a complicated idea involving trigonometric ratios. If I have to resort to this, is it possible to put a command in my script that calculates the inverse cosine of a variable?

Posted: Tue Apr 29, 2003 6:00 am
by jv_map
I think it can be done pretty easily. First calculate a vector to the target, e.g.

local.vec = local.target.origin - self.origin

Then make the script_object rotate to that vector:

self rotateto local.vec
self speed 15
self waitmove

I don't know if this would change the pitch of the object as well. If it does, just force the z coord of the vector to be 0.

Posted: Tue Apr 29, 2003 10:17 pm
by matt_moh
Great! Thanks alot, but what do I have to do to change the z coord of the vector?

Posted: Wed Apr 30, 2003 12:34 am
by nuggets
local.vec[2] = 0

although if the player isn't on the ground floor it'd be a bit strange

Posted: Fri May 09, 2003 8:19 pm
by matt_moh
Well, after finishing another project, I finaly got to test out the gun. It doesn't work. What happens is that the gun, instead of pointing at the player, spins around in a apiral motion and ends up pointing at the ground. I tried changing the values of each of the three coordinates of the vector to zero, but it still does not work. These are the exact lines of my script:

cannon_aim: //threaded by a trigger_multiple in the bsp

$car1_turret1 thread turretmove
//$car1_barrel1 thread barrelmove
end

turretmove:
local.target = $player
local.vec = local.target.origin - self.origin
local.vec[2] = 0
self rotateto local.vec
self time 2
self waitmove
end

Hmmm

Posted: Sat May 10, 2003 7:27 am
by jv_map
Try:

Code: Select all

cannon_aim: //threaded by a trigger_multiple in the bsp

$car1_turret1 thread turretmove
//$car1_barrel1 thread barrelmove
end

turretmove:
local.target = $player
local.vec = local.target.origin // now is a location instead of a direction
local.vec[2] = 0
self rotateto local.vec
self time 2
self waitmove
end

Posted: Sat May 10, 2003 12:13 pm
by nuggets
or...

cannon_aim
$car1_turret1 thread turretmove
end

turretmove:
local.angles = (vector_toangles ($player.origin - self.origin))
self speed 15
self rotateto $player
self waitmove
end

lookat

Posted: Sun May 11, 2003 7:44 am
by tltrude
Can't you use the "lookat" command somehow? To me, it looks like your threads will only find the player one time and stop. I think he wants it to follow the player's movements.

Posted: Sun May 11, 2003 8:49 am
by jv_map
Well I don't think the turret gun script_object has an eye bone :roll:

But you could always modify the script so that it traces the player (just put it in a while loop).

Posted: Sun May 11, 2003 1:36 pm
by bdbodger
nuggets whouldn't that just give you the angles from the object to the player? maybe you could make two spript origins and put one at the base of the gun and one at the end of the gun . After that you could use the use the vector_toangles ($origin1 $origin2) to find the direction of the gun and then use that to point the gun at the player?

eye bone

Posted: Sun May 11, 2003 10:42 pm
by tltrude
You would have to bind an "eye bone" to the gun pivit point--a script origin.

There are some pretty cool things in the vehicles_thinkers.scr script. It uses commands like "vector_within" and "vector_length" for the tanks turrets. I guess the AI tanks don't have have "eye bones" either!

Here is something that might work from the turnto.scr script:

// parameters:
// local.target - target aiming at (can be anything which has an origin)
start local.target:
self turnto local.target

Posted: Sun May 11, 2003 11:13 pm
by nuggets
yes yes no no and yes no!!!

i don't know about the order but from what i've read some of it's right and some wrong

when a gun will be facing the player it won't move, therefore irrelevant of the position origin or whatever you want to call it, it will only be moving around the angles it needs to move to

attaching an eye to a gun?? what the hell are you thinking man, it's like giving a person wheels so you can use the drive command

Mg42

Posted: Sun May 11, 2003 11:21 pm
by tltrude
An mg42 can track players without an AI standing by it. At least I do think before posting my thoughts.

Posted: Sun May 11, 2003 11:35 pm
by nuggets
more information would b grateful... :roll:

and another thing i 4got 2 mention before, with a trigger multiple it will follow the player whenever the player is in the trigger multiple... which will stop unnecessary scripting calling when the player isn't in sight of the "gun" / possibly an mg42

Test_map

Posted: Mon May 12, 2003 4:36 am
by tltrude
I made a test map for it and got the gun working, but it is still weird. It rotates on all axis and flips around if you move along the north wall (past 0 angle). It also seems to point at the top of the player's head. Here is a zip with the bsp, map file, and script:

http://pages.sbcglobal.net/tltrude/Temp/auto_gun.zip

I added two origins at both ends of the barrel, as per bdbodger suggestion, to get it working like it is now. It should probably be made so that only the barrel moves up and down with changes in the player's elevation. In other words, the rotation and the elevation should be seperate movements.

I do understand why "lookat" and "turnto" wont work now. Those commands can not be used with "scriptSlaves" like a script_object--that's what the console said anyway.