Teleporting Issue

KO_Games

Member
Hi,

In my game, I am currently coming across an issue every so often when trying to teleport my dead character to the start of the level. I'm using the Opsive 3rd-person controller. My character is using Update instead of Fixed Update on the Ultimate Character Locomotion. Game is locked to 60 FPS.

I first respawn my character. Then to teleport my character, I reset the rotation and position. Not sure if fully required, but I thought it was needed to reset the values when starting over the scenario again. Then I'm setting the position and rotation according to the Opsive docs.

Here is the code I'm using:

C#:
_charRespawner.Respawn();
_ultimateCharacterLocomotion.ResetRotationPosition();
_ultimateCharacterLocomotion.SetPositionAndRotation(Position, Rotation, _snapAnimator, _stopAllAbilities);

The problem I'm getting is that every so often when teleporting my character, my character will appear somewhere slightly random after teleporting. It seems like the character doesn't quite make it to the original start position (which is cached at the start of the script). Sometimes I've seen the character get stuck inside other 3D objects, outside level bounds, etc. Generally, the character is pretty close to the start position. Somewhere within about 10 world units, I would say. It appears like the character isn't teleporting, but rather moving very fast to the original start position. If this is the case, is it possible the character is sometimes colliding with other objects in the scene preventing it from moving as expected?

Because teleporting isn't consistently teleporting to the start position every time it is breaking the game when it occurs. It is very hard to replicate the issue consistently, but it seems like it might occur more often when there are big changes in FPS in the game.

I was curious if there was something I was doing wrong. Or if there was something else I should try doing to ensure this issue does not occur.

Thanks!

-Kirt
 
_ultimateCharacterLocomotion.ResetRotationPosition(); is not required, in the same frame it will be trying to set position and rotation to character transform current position and rotation. That could be causing issues. Have you tried without that line?
 
The CharacterRespawner inherits from Respawner which does the teleport. So there is no need to manually teleport the character. You only need to define the respawn location (either start position, a spawn point, or the current location).
You can also call CharacterRespawner.Respawn(position, rotation, true) to explicitly set a position and rotation.
 
Wow, thank you both for the responses! I tested out both of those responses, and I was still getting the same problem. I decided to test my character in an empty scene with a brand new Opsive character and found that it was not experiencing the same issues. After removing components from my player and trying to slowly match the new Opsive character I finally found the problem. It was because on the main rigidbody component Interpolate was set to Interpolate instead of None. I forgot that a long time ago on the main rigidbody I had set Interpolate since it was needed on the rigidbodies for the ragdoll to smooth out the ragdoll. At the time, I thought maybe I needed it on the main rigidbody as well...and since I didn't notice anything negative by turning it on...I figured it was fine. So if anyone comes across this issue in the future...make sure the rigidbody is set to None and not interpolate!

As a side note, both of those responses above did help me to clean up my code and use the respawn and the SetPositionAndRotation correctly. Thanks!
 
Top