Position Sync issue with OnTriggerStay and Animation Curve

Options
Hello,

I have been scratching my head and searching/ watching videos on the subject for a week now and cant figure this one out.

My character controller(not using a rigid body) works perfectly on and off the network, the problem comes when I enter my explosion object that is meant to send me flying..... it works perfectly(I'm very proud of it) except for when I'm on the network and Player A see's Player B go into the explosion trigger. On Player A's screen, Player B goes into the trigger explosion and then fly's straight into some random position(Usually in the direction that the character entered the trigger at) and then fly's quickly to the correct position. While on Player B's screen he smoothly adjust from inside the trigger and fly's smoothly to the correct position. and of course Player B see's Player A do the exact same thing.

I've tried a couple of things like: None of it has worked so far
Sync position with RPC calls
using OnPhotonSerializeView() to sync position
moving all the explosion code onto the player object(This makes it worse, instead of rubber-banding to the correct position the player just fly's off into neverland forever.

My jump works perfectly and it uses the same Animation Curve code that my trigger does with no problems so I don't think the Animation Curve itself is the issue.

Here is the Explosion Trigger code (This code is on the explosion object that my character goes into)
``
void OnTriggerStay(Collider other)
{
// Vector3 otherPos;

otherPos = other.transform.position; // Position of player

tossDir2 = otherPos - transform.position; // Direction of where to throw the player

_charTest = other.GetComponent<CharacterController>(); // The players CharacterController

StartCoroutine(JumpEventEx()); // Starts the exploding coroutine

}


private IEnumerator JumpEventEx()
{
float timeInAir = 0.0f; // Keeps track of the time in the air
do
{
float jumpForce = jumpFallOffEx.Evaluate(timeInAir); // jumpForce based on the animation curve at that time in the air
// THE GRAVITY OF FALLING IS BASED ON THE _controller.SimpleMove IN THE PlayerMovement FUNCTION //
_charTest.Move(tossDir2 * jumpForce * tossSpeed * Time.deltaTime); // Moves the character up based on the jumpMultiplier and the jumpForce animation curve
timeInAir += Time.deltaTime; // Adds a single second to our time in the air // Makes gravity look more realistic // Increments the timeInAir for the "float jumpForce = jumpFallOff.Evaluate(timeInAir);" line above
yield return null; // Gives errors without this

// While the character controller is not grounded and there is not a colider above the player (This prevents the player from sticking into the ceiling before the animation curve has finished)
} while (!_charTest.isGrounded && _charTest.collisionFlags != CollisionFlags.Above);

}
``
Is there some Photon code that I am missing for the position of the character to be correct while it is going through my Animation Curve?

Here is a visual of my issue
https://media.giphy.com/media/RNJZZhRoGvHYFm3G1Y/giphy.gif
giphy.gif

If my copy and paste code is hard to read here is a picture.
https://i.imgur.com/hRXI6xB.png

hRXI6xB.png

What isn't shown in the picture is just stuff i was testing with that is commented out

Thank you,

Comments

  • HotPockets
    Options
    I've learned that Player A only see's Player B synchronize when Player B hits another object on Player A's screen.
  • HotPockets
    Options
    I figured it out.

    It was because I had CharacterController.SimpleMove and CharacterController.Move at the same time without having a statement to check if it is my photonView on the CharacterController.Move

    I moved the code off of the object and put it on my Player Object instead so I could use the the photonVew.IsMine

    Here is my code in case anyone needs it in the future. I am going to see is there is away to run the photonView.IsMine from another object later on, Also I am going to find out if doing it this way will cause me problems later on. if i remember to I will report my findings here.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;

    public class Explosion : MonoBehaviourPun
    {
    private float tossSpeed = 0.5f;
    public AnimationCurve jumpFallOffEx2;

    public CharacterController testChar2;
    private Vector3 tossDir2;

    // Start is called before the first frame update
    void Start()
    {
    testChar2 = gameObject.GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {

    }

    void OnTriggerStay(Collider other)
    {
    Vector3 otherPos;

    if (photonView.IsMine == false && PhotonNetwork.IsConnected == true)
    {
    return;
    }
    otherPos = other.transform.position;

    tossDir2 = transform.position - otherPos;

    StartCoroutine(JumpEventEx()); // Starts the jumping coroutine


    }


    private IEnumerator JumpEventEx()
    {
    float timeInAir = 0.0f; // Keeps track of the time in the air
    do
    {

    float jumpForce = jumpFallOffEx2.Evaluate(timeInAir); // jumpForce based on the animation curve at that time in the air
    // THE GRAVITY OF FALLING IS BASED ON THE _controller.SimpleMove IN THE PlayerMovement FUNCTION //
    testChar2.Move(tossDir2 * jumpForce * tossSpeed * Time.deltaTime); // Moves the character up based on the jumpMultiplier and the jumpForce animation curve
    timeInAir += Time.deltaTime; // Adds a single second to our time in the air // Makes gravity look more realistic // Increments the timeInAir for the "float jumpForce = jumpFallOff.Evaluate(timeInAir);" line above
    yield return null; // Gives errors without this

    // While the character controller is not grounded and there is not a colider above the player (This prevents the player from sticking into the ceiling before the animation curve has finished)

    } while (!testChar2.isGrounded && testChar2.collisionFlags != CollisionFlags.Above);

    }

    }

    Thanks,