Locking On code... please help
by Dylan Sale · in Torque Game Engine · 01/28/2003 (4:53 am) · 5 replies
Hay. I wrote some C++ code for making the player "lock on" to a position that was determined be the scripts.
Basically, I wrote a function called updateLockOn() that was run in the Player::processTick() function.
This worked by getting the position and then changing the mRot.z variable to point in the direction of the target.
I also added some code so that the server extracts the position out of the scripts and stored it in
Point3F mLockedOnPos;
Now, I then changed writePacket() (i dont know if thats the exact name) and packUpdate() and their related unpacking methods to transmit the mLockedOnPos to the client.
So, heres how it works:
1) weapon sets a variable called %obj.target, this stores the target object.
2) server uses Con::evaluatef("%d.target.getPosition();", scriptThis()); to find the position, and then stores it in mLockedOnPos using sScanf();
3) the position is sent to the client
4) the client and server player objects are rotated to always point at the target.
Now, this works but it movement of the lockon position is pretty laggy (ie the player strafes left then the view rotates to point at the target, and when the target is moving, the lock position jitters behind it).
Any ideas why?
At first I thought it was a problem with the client lagging behind the server. But this was done on a single computer with bots. I have implemented interpolation of the point after reading a post from last year about it, and that seems to be implemtented sucessfully, but the problem still remains.
Sorry for the longish post.. hope someone out there knows what is wrong :)
PS I did notice that the name above the bots (you know the green one) does the same thing (it lags behind them when they move).
Basically, I wrote a function called updateLockOn() that was run in the Player::processTick() function.
This worked by getting the position and then changing the mRot.z variable to point in the direction of the target.
I also added some code so that the server extracts the position out of the scripts and stored it in
Point3F mLockedOnPos;
Now, I then changed writePacket() (i dont know if thats the exact name) and packUpdate() and their related unpacking methods to transmit the mLockedOnPos to the client.
So, heres how it works:
1) weapon sets a variable called %obj.target, this stores the target object.
2) server uses Con::evaluatef("%d.target.getPosition();", scriptThis()); to find the position, and then stores it in mLockedOnPos using sScanf();
3) the position is sent to the client
4) the client and server player objects are rotated to always point at the target.
Now, this works but it movement of the lockon position is pretty laggy (ie the player strafes left then the view rotates to point at the target, and when the target is moving, the lock position jitters behind it).
Any ideas why?
At first I thought it was a problem with the client lagging behind the server. But this was done on a single computer with bots. I have implemented interpolation of the point after reading a post from last year about it, and that seems to be implemtented sucessfully, but the problem still remains.
Sorry for the longish post.. hope someone out there knows what is wrong :)
PS I did notice that the name above the bots (you know the green one) does the same thing (it lags behind them when they move).
About the author
#2
One other thing I wonder: whats the point of having a Point3f for a position to lock onto, if you really just want to lock onto any random object in the game? Perhaps a pointer to a Shapebase would work better, that way you dont have to delve into the scripting engine. I mean, you're just gonna call getPosition() on it anyway, right?
hope that helps some
but hey, its 3am here, who knows what I'm thinking.
01/29/2003 (12:38 am)
hmm. thought I saw something in the camera class about setting a point or an object that the camera will lock on. I also wonder: where are you calling the script that grabs the current location of the target obj? Seems as how it should go in the Player's interpolateTick method, so that every frame drawn will have the correct position, as far as the client knows.One other thing I wonder: whats the point of having a Point3f for a position to lock onto, if you really just want to lock onto any random object in the game? Perhaps a pointer to a Shapebase would work better, that way you dont have to delve into the scripting engine. I mean, you're just gonna call getPosition() on it anyway, right?
hope that helps some
but hey, its 3am here, who knows what I'm thinking.
#3
yep. I tried this already, still doesnt work. :(
Actually there are set rules in the scripting language to determine who it locks on to (it has to be the closest player within a certain angle of the muzzel vector), so its not random. I though of making a pointer to the player object, but i couldnt figure out how to convert a script object (which is really just a number) to its engine counterpart, if i could *wink wink* then that'll be SUPER SWEET. Then the engine would jut interpolate it all for me and I'd just have to call getPosition() on it ever frame.
I did in fact try something like this, but my problem was that the server and the client have different player objects (the real one and the ghost, respectively).. so how would this work.. would I need to track both, or do they have some way of linking them...
Am I even near the right track?
... I'll look into that camera code... It might be usefull, at the moment I stole the AIPlayer code for looking at a position.
Anyone else got any ideas?
01/29/2003 (12:53 am)
Cool, thanks for replying.Quote:
Seems as how it should go in the Player's interpolateTick method
yep. I tried this already, still doesnt work. :(
Quote:
if you really just want to lock onto any random object in the game? Perhaps a pointer to a Shapebase would work
Actually there are set rules in the scripting language to determine who it locks on to (it has to be the closest player within a certain angle of the muzzel vector), so its not random. I though of making a pointer to the player object, but i couldnt figure out how to convert a script object (which is really just a number) to its engine counterpart, if i could *wink wink* then that'll be SUPER SWEET. Then the engine would jut interpolate it all for me and I'd just have to call getPosition() on it ever frame.
I did in fact try something like this, but my problem was that the server and the client have different player objects (the real one and the ghost, respectively).. so how would this work.. would I need to track both, or do they have some way of linking them...
Am I even near the right track?
... I'll look into that camera code... It might be usefull, at the moment I stole the AIPlayer code for looking at a position.
Anyone else got any ideas?
#4
Check out cSetControlObject() in player.cc.
That's a simple example that should suit your purpose pretty much exactly.
The active ingredient is : Sim::findObject(...).
01/29/2003 (1:54 am)
Well hell, Of Course there's an easy way to get an object out of the script engine.Check out cSetControlObject() in player.cc.
That's a simple example that should suit your purpose pretty much exactly.
The active ingredient is : Sim::findObject(...).
#5
01/29/2003 (2:11 am)
cool, ill look into it... If this works I will declare today National Paul Day. :)
Torque Owner Dylan Sale
"We will no longer spank the monkey. The monkey will spank us!" - Jay