A bug with player viewangles based on se Created 6 years ago2018-01-29 08:20:45 UTC by crystallize crystallize

Created 6 years ago2018-01-29 08:20:45 UTC by crystallize crystallize

Posted 6 years ago2018-01-29 08:34:20 UTC Post #338722
Hello TWHL.
I hope you'll help me to sort out this trouble I'm having.
The thing is, I'm a noob coder and I'm trying to make Sonic Adventure/Soul Reaver-like camera and controls, I've stuck at the very beginning though.

First what I did was going to server camera code and skipping that chunk of code that softens up camera movement: now difference between hmtarget and camera origin is written into pev->angles right away, we've got an instant rotation.

Then on client side, IN_JoyMove to be precise, I had to get camera angles.
(I tried making a custom message from server, then I tried GetEntityByIndex( viewEntityIndex ), the effect was the same)

To achieve this kind of controls I have to take an angle given by input device and transform it from the coordinates based on camera axis to global coordinates, it can be done either by rotating a 3d vector or simply adding two yaw values, I tried both.

The thing is I kinda got what I needed, but making player to go pure 90 degree to the side (and remember that camera follows him) doesn't really make him run a perfect circle around the camera as one would expect, I'm getting a gradual spiral instead.

Yaw value calculated for the player is wrong by from 60 degrees (right under the camera) to about zero when he's a few hundred units away. I wonder is it engine architecture issue or I've ran into some kind of basic geometrical law.

https://www.youtube.com/watch?v=_hEam9Uk_fs
Posted 6 years ago2018-01-30 16:38:15 UTC Post #338733
How are you setting the angles on the server side? You need to use pev->fixangle to force the engine to set a particular angle, and both pev->angles and pev->v_angle need to be set to be correct.
Posted 6 years ago2018-01-31 15:43:40 UTC Post #338745
I just did
pev->angles = UTIL_VecToAngles( m_hTarget->pev->origin - pev->origin );
and comented the rest of FollowTarget.
Posted 6 years ago2018-01-31 17:16:13 UTC Post #338746
Then you should try setting fixangle to 1 right after that, it should tell the engine to set exactly that angle.
Posted 6 years ago2018-02-01 02:21:28 UTC Post #338749
Ok I'll try fixangle (and ef_nointerp). But doesn't that line I broght up above is doing exactly that, calculating vector between camera and its target, converting it to angles and immediately applying them to camera without any smooth transition?
Posted 5 years ago2018-04-12 16:45:07 UTC Post #339295
Well it doesn't work.
pev->avelocity.x = dx * 40 * gpGlobals->frametime;
pev->avelocity.y = dy * 40 * gpGlobals->frametime;
pev->fixangle = TRUE;
pev->effects = EF_NOINTERP;
if (!(FBitSet (pev->spawnflags, SF_CAMERA_PLAYER_TAKECONTROL)))
Now to client side. If we do this:

gEngfuncs.SetViewAngles( (float *)viewentity->angles );
gEngfuncs.Con_Printf( "yawdiff cam,pl = %f\n", viewentity->angles[1]-player->curstate.angles[1]);

We can see that these angles just aren't the same despite the fact that we just copied them over. The difference can be as big as half a degree for player about 300 units from camera.
Posted 5 years ago2018-04-22 15:06:05 UTC Post #339410
Tried the same with client-side camera, still no luck. The issue seems to be how player's movement direction is defined by his viewangles (obviously) but they are only updated after being sent to server which adds 1 frame-long lag. Every frame client is dealing with player's incorrect viewangles from previous frame which probably creates this bug.
I thought, may be I'll delay as many values as possible for 1 frame and apply them there. I assumed how 1 frame equals going through client's main loop anew and going through V_CalcThirdpersonRefDef from the beginning so I calculated some values at the end of the function and applied them at the beginning, but the issue remained.
You must be logged in to post a response.