Hi,
I have the following code that changes how the teleport work.
The current code keeps input speed, angle, height and view angle, but i want to have input speed, angle, height and center the view angle. (like original q4 teleport behavior, Center view angle = forward view). I've tried to change how the teleport work but what i've managed to do is either roll the player to have the view up side down, dis-placed or make the view totally off. So if anybody could help that would be awsome

Code:
void idPlayerStart::TeleportPlayer( idPlayer *player ) {
float pushVel = spawnArgs.GetFloat( "push", "50000" );
// Teleporters keep player's speed and deplacement vector through them (rj through a teleporter is possible)
idAngles exitAngles;
exitAngles.pitch = player->viewAngles.pitch;
if (gameLocal.isServer)
exitAngles.yaw = GetPhysics()->GetAxis().ToAngles().yaw + (player->viewAngles.yaw - player->GetPhysics()->GetLinearVelocity().ToAngles().yaw);
else
exitAngles.yaw = player->viewAngles.yaw;
exitAngles.roll = player->viewAngles.roll;
// Normalize 360
if ( ( exitAngles.yaw >= 360.0f ) || ( exitAngles.yaw < 0.0f ) ) {
exitAngles.yaw -= floor( exitAngles.yaw / 360.0f ) * 360.0f;
}
player->Teleport( GetPhysics()->GetOrigin(), exitAngles , NULL, this );
pushVel = 2000.0f;
idVec3 impulse( pushVel, 0, 0 );
impulse *= GetPhysics( )->GetAxis ( );
player->ApplyImpulse( gameLocal.world, 0, player->GetPhysics( )->GetOrigin( ), impulse );
}
void idPlayer::Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination, idEntity *src ) {
idVec3 org;
// Teleporters keep player's speed and deplacement vector through them (rj through a teleporter is possible)
// Rotation around z-axis only
idVec3 vec3_dst;
idAngles rot_angle;
/* angle calculation for future rotation to speed vector */
rot_angle = src->GetPhysics()->GetAxis().ToAngles() - GetPhysics()->GetLinearVelocity().ToAngles();
/* Rotation in progress ... (z-axis) */
vec3_dst.x = GetPhysics()->GetLinearVelocity().x * cos( DEG2RAD(rot_angle.yaw) ) - GetPhysics()->GetLinearVelocity().y * sin( DEG2RAD(rot_angle.yaw) );
vec3_dst.y = GetPhysics()->GetLinearVelocity().x * sin( DEG2RAD(rot_angle.yaw) ) + GetPhysics()->GetLinearVelocity().y * cos( DEG2RAD(rot_angle.yaw) );
vec3_dst.z = GetPhysics()->GetLinearVelocity().z;
/* ... Done */
/* Set old velocity vector but in good direction now :-) */
GetPhysics()->SetLinearVelocity( vec3_dst ) ;
SetViewAngles( angles );
legsYaw = 0.0f;
idealLegsYaw = 0.0f;
oldViewYaw = viewAngles.yaw;
// don't do any smoothing with this snapshot
predictedFrame = gameLocal.framenum;
UpdateVisuals();
teleportEntity = destination;
}
Problem solved thanks to Paril's advice

Hi,
I have the following code that changes how the teleport work.
The current code keeps input speed, angle, height and view angle, but i want to have input speed, angle, height and center the view angle. (like original q4 teleport behavior, Center view angle = forward view). I've tried to change how the teleport work but what i've managed to do is either roll the player to have the view up side down, dis-placed or make the view totally off. So if anybody could help that would be awsome

Code:
void idPlayerStart::TeleportPlayer( idPlayer *player ) {
float pushVel = spawnArgs.GetFloat( "push", "50000" );
// Teleporters keep player's speed and deplacement vector through them (rj through a teleporter is possible)
idAngles exitAngles;
exitAngles.pitch = player->viewAngles.pitch;
if (gameLocal.isServer)
exitAngles.yaw = GetPhysics()->GetAxis().ToAngles().yaw + (player->viewAngles.yaw - player->GetPhysics()->GetLinearVelocity().ToAngles().yaw);
else
exitAngles.yaw = player->viewAngles.yaw;
exitAngles.roll = player->viewAngles.roll;
// Normalize 360
if ( ( exitAngles.yaw >= 360.0f ) || ( exitAngles.yaw < 0.0f ) ) {
exitAngles.yaw -= floor( exitAngles.yaw / 360.0f ) * 360.0f;
}
player->Teleport( GetPhysics()->GetOrigin(), exitAngles , NULL, this );
pushVel = 2000.0f;
idVec3 impulse( pushVel, 0, 0 );
impulse *= GetPhysics( )->GetAxis ( );
player->ApplyImpulse( gameLocal.world, 0, player->GetPhysics( )->GetOrigin( ), impulse );
}
void idPlayer::Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination, idEntity *src ) {
idVec3 org;
// Teleporters keep player's speed and deplacement vector through them (rj through a teleporter is possible)
// Rotation around z-axis only
idVec3 vec3_dst;
idAngles rot_angle;
/* angle calculation for future rotation to speed vector */
rot_angle = src->GetPhysics()->GetAxis().ToAngles() - GetPhysics()->GetLinearVelocity().ToAngles();
/* Rotation in progress ... (z-axis) */
vec3_dst.x = GetPhysics()->GetLinearVelocity().x * cos( DEG2RAD(rot_angle.yaw) ) - GetPhysics()->GetLinearVelocity().y * sin( DEG2RAD(rot_angle.yaw) );
vec3_dst.y = GetPhysics()->GetLinearVelocity().x * sin( DEG2RAD(rot_angle.yaw) ) + GetPhysics()->GetLinearVelocity().y * cos( DEG2RAD(rot_angle.yaw) );
vec3_dst.z = GetPhysics()->GetLinearVelocity().z;
/* ... Done */
/* Set old velocity vector but in good direction now :-) */
GetPhysics()->SetLinearVelocity( vec3_dst ) ;
SetViewAngles( angles );
legsYaw = 0.0f;
idealLegsYaw = 0.0f;
oldViewYaw = viewAngles.yaw;
// don't do any smoothing with this snapshot
predictedFrame = gameLocal.framenum;
UpdateVisuals();
teleportEntity = destination;
}
Problem solved thanks to Paril's advice

Hi,
I have the following code that changes how the teleport work.
The current code keeps input speed, angle, height and view angle, but i want to have input speed, angle, height and center the view angle. (like original q4 teleport behavior, Center view angle = forward view). I've tried to change how the teleport work but what i've managed to do is either roll the player to have the view up side down, dis-placed or make the view totally off. So if anybody could help that would be awsome

Code:
void idPlayerStart::TeleportPlayer( idPlayer *player ) {
float pushVel = spawnArgs.GetFloat( "push", "50000" );
// Teleporters keep player's speed and deplacement vector through them (rj through a teleporter is possible)
idAngles exitAngles;
exitAngles.pitch = player->viewAngles.pitch;
if (gameLocal.isServer)
exitAngles.yaw = GetPhysics()->GetAxis().ToAngles().yaw + (player->viewAngles.yaw - player->GetPhysics()->GetLinearVelocity().ToAngles().yaw);
else
exitAngles.yaw = player->viewAngles.yaw;
exitAngles.roll = player->viewAngles.roll;
// Normalize 360
if ( ( exitAngles.yaw >= 360.0f ) || ( exitAngles.yaw < 0.0f ) ) {
exitAngles.yaw -= floor( exitAngles.yaw / 360.0f ) * 360.0f;
}
player->Teleport( GetPhysics()->GetOrigin(), exitAngles , NULL, this );
pushVel = 2000.0f;
idVec3 impulse( pushVel, 0, 0 );
impulse *= GetPhysics( )->GetAxis ( );
player->ApplyImpulse( gameLocal.world, 0, player->GetPhysics( )->GetOrigin( ), impulse );
}
void idPlayer::Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination, idEntity *src ) {
idVec3 org;
// Teleporters keep player's speed and deplacement vector through them (rj through a teleporter is possible)
// Rotation around z-axis only
idVec3 vec3_dst;
idAngles rot_angle;
/* angle calculation for future rotation to speed vector */
rot_angle = src->GetPhysics()->GetAxis().ToAngles() - GetPhysics()->GetLinearVelocity().ToAngles();
/* Rotation in progress ... (z-axis) */
vec3_dst.x = GetPhysics()->GetLinearVelocity().x * cos( DEG2RAD(rot_angle.yaw) ) - GetPhysics()->GetLinearVelocity().y * sin( DEG2RAD(rot_angle.yaw) );
vec3_dst.y = GetPhysics()->GetLinearVelocity().x * sin( DEG2RAD(rot_angle.yaw) ) + GetPhysics()->GetLinearVelocity().y * cos( DEG2RAD(rot_angle.yaw) );
vec3_dst.z = GetPhysics()->GetLinearVelocity().z;
/* ... Done */
/* Set old velocity vector but in good direction now :-) */
GetPhysics()->SetLinearVelocity( vec3_dst ) ;
SetViewAngles( angles );
legsYaw = 0.0f;
idealLegsYaw = 0.0f;
oldViewYaw = viewAngles.yaw;
// don't do any smoothing with this snapshot
predictedFrame = gameLocal.framenum;
UpdateVisuals();
teleportEntity = destination;
}
Problem solved thanks to Paril's advice
