#Setting up the Start Position results different each time

94 messages · Page 1 of 1 (latest)

coral wraith
#

you don't show the start positions in the scene, but if you have Network Manager set to Random, that would do random of those. Change it to Round Robin if you want them used in order

twilit horizon
#

It is set to Round Robin

#

It actually does the work, it sets the transform to start point but it immediatly changes to Vector3.zero again. Its like sets the position to StartPoint and 1 frame later sets back to Vector3.zero

#

But sometimes it skips that 1 frame and accepts the start position which i've set in the code

#

@coral wraith

coral wraith
twilit horizon
#

No i only override that function inside my customnetworkmanager and in lobby scene only

#

you can see it in the code up above pastie.io link

coral wraith
#

You need an else in OnServerAddPlayer:

if (SceneManager.GetActiveScene().name == "Lobby-Scene")
    ...
else
    base.OnServerAddPlayer(conn);

And delete lines 40 and 42

And move line 41 to ThirdPersonController::OnStartLocalPlayer on the player object shortened to:
PlayerState = PlayerState.MOVEMENT;

#

I'd say get rid of this too (line 13)
GamePlayerInstance.ConnectionID = conn.connectionId;

all Network Behaviours have connectionToClient built in, so you don't need the redundancy

twilit horizon
#

okey done that

#

now trying

#

Nope, still teleports me to the Vector3.zero position

#

do i need a network identity component on those ?

#

@coral wraith

coral wraith
twilit horizon
#

I realized that and removed that also

#

But still it didnt work

coral wraith
#

show inspector of player prefab with all components folded up closed so I can see what's on it

twilit horizon
#

here sir

coral wraith
# twilit horizon here sir

Disable these 3 in prefab and enable them in OnStartAuthority or OnStartLocalPlayer in your PlayerObjectController script. Also make sure RigidBody is kinematic in the prefab, and set that false in OnStartAuthority / OnStartPlayer only if you're using AddForce on it

twilit horizon
#

I did what you wrote but didnt work i think because PlayerObjectController is instantiated on lobby scene , not in game scene . So if i override OnStartLocalPlayer or OnStartAuthority those will be called in Lobby scene not when game starts.I think you want me to enable them when game starts if i correctly understood

coral wraith
twilit horizon
#

I did but OnStartAuthority and OnStartLocalPlayer not fired when scene is changed, they only fired in Lobby scene when i instantiate

#

I Have my auto create player ticked on, i've added a debug log statements for the both functions i didnt get any prompt

coral wraith
#

This is from our PlayerController:

    [RequireComponent(typeof(CapsuleCollider))]
    [RequireComponent(typeof(CharacterController))]
    [RequireComponent(typeof(NetworkTransformReliable))]
    [RequireComponent(typeof(Rigidbody))]
    public class PlayerController : NetworkBehaviour
    {
        protected override void OnValidate()
        {
            base.OnValidate();
            Reset();
        }

        void Reset()
        {
            if (characterController == null)
                characterController = GetComponent<CharacterController>();

            // Override CharacterController default values
            characterController.enabled = false;
            characterController.skinWidth = 0.02f;
            characterController.minMoveDistance = 0f;

            GetComponent<Rigidbody>().isKinematic = true;

            this.enabled = false;
        }

        public override void OnStartAuthority()
        {
            // Add Scene Check here if appropriate
            characterController.enabled = true;
            this.enabled = true;
        }

        public override void OnStopAuthority()
        {
            this.enabled = false;
            characterController.enabled = false;
        }
}
coral wraith
twilit horizon
#

yes its DDOL

coral wraith
#

does it need to be?

twilit horizon
#

It would turn my week to hell if i need to remove it from DDOL

#

Can i achieve my goal if its in DDOL ?

coral wraith
#

what are you changing in the player in the lobby that you need to carry it through?

twilit horizon
#

PlayerObjectController script, where i get steam datas like username etc.

coral wraith
#

Wouldn't all that still work if the player was respawned?

#

Steam Manager or whatever is in DDOL, so it's still available

twilit horizon
#

if script values gets saved in despawning and respawning then it will work

#

oh yea i am holding their values in GamePlayers list

coral wraith
#

centralization - the bane of networking

#

if that's a static list that doesn't get cleared

twilit horizon
#

its not a static list but a list in custom network manager

#

so i dont think it gets cleared

#

but how would i know which player's value is which if i dont have any value about a player upon respawning?

coral wraith
#

Typically you'd keep player data on the player or in the connection, instead of centralizing, but if you can't easily unwind that, then you having player in DDOL really should've come up sooner. Everything I told you didn't consider that.

#

So your original post about Start Positions not working was a red herring. Your real issue is snap-back when force moving players with NT after scene change.

twilit horizon
#

Yes i am sorry because of misleading you and couldnt address my issue properly

#

My issue is exactly it is

coral wraith
#

Ok so if it's in DDOL, you can try this first....

#

In OnServerReady, inside the "Level-1" scene check:

Transform startPos = GetStartPosition();
NetworkTransformReliable nt = conn.identity.GetComponent<NetworkTransformReliable>();
nt.RpcTeleport(startPos.position. startPos.rotation);
#

And in PlayerObjectController you'll have to enable your components in OnClientSceneChanged, wrapped in the same scene check, since OnStartAuthority / OnStartLocalPlayer only run when first spawned

#

@twilit horizon

twilit horizon
#

doing that rn

#

PlayerObjectController is derrived from NetworkBehaviour, did you mean OnClientSceneChanged in CustomNetworkManager?

#

there is no suitable override in PlayerObjectController for OnClientSceneChanged function

coral wraith
#

oh right...yes

#

NetworkClient.localPlayer.GetComponent<PlayerObjectController>().EnableComponents();
And in EnableComponents you can turn things on by reference you set up at design time

twilit horizon
#

implementing rn give me couple mins pls

coral wraith
#

I always have treated the lobby player as an empty prefab that just does UI stuff in the lobby scene and is disposable, and game player prefab is separate. Anything I'd need to carry forward is either in a database or a struct in conn.authenticationData

#

I need to leave for meetings...back later

twilit horizon
#

Yes it still keeps happening i couldnt resolve, i think i just need to do what you do usually, which is treat as a empty prefab and spawn a player on scene

twilit horizon
#

Hello again, i managed to solve issue like this but i am not sure if its the best practice, I know only instantiate a lobby object where i hold the steam data and when i switch the scenes i instantiate a player object and replace the connection

#

But know issue is that since client doesnt have any authority on created player, i cant move the player from server or from client side, How do i assing an authority i've tried AssingClientAuthority function from network identity but it still doesnt work

#

@coral wraith

coral wraith
twilit horizon
#

i use ReplacePlayerForConnection

coral wraith
#

That also grants authority

twilit horizon
#

But if i Debug.Log(authority) or Debug.Log(isLocalPlayer) both of them returns false on spawned object

coral wraith
#

When are you doing that? OnStartAuthority / OnStartLocalPlayer is what you want (they only fire when true)

twilit horizon
#

i basically do that inside Update() but i watch for 20-30 seconds if it turns true or still false

coral wraith
#

I assume you mean isOwned or isLocalPlayer

twilit horizon
#

Yes

coral wraith
#

Are OnStartAuthority / OnStartLocalPlayer overrides firing on client?

twilit horizon
#

Let me check

#

Its firing on server side but not on client side

coral wraith
#

on server you're seeing host client firing those...server doesn't fire those

coral wraith
twilit horizon
#

yes sir

#

I wrote that based on this documentation

coral wraith
# twilit horizon https://pastie.io/wtvkep.cs

lines 60-65 don't belong in OnServerReady. Probably OnClientSceneChanged with a scene name check, and you'll need a name from someplace (I think you can get display name from steam on client).

#

line 40, it's better to do GetStartPosition before instantiate and use it in Instantiate instead of moving it

twilit horizon
#

trying it out

twilit horizon
#

this is the current code i've send link with paste.io

#

Positions are correctly set but the thing is that server can move its own character but client cant

#

this is the boolean check for movement maybe its because of isLocalPlayer returns false?

#

Nevermind its completly unreleated problem with Mirror, Somehow unity's player input script was randomly changing controller schemes, for server it sets keyboard-mouse but it set for client x-box now i changed auto switch and set default scheme.Problem solved

#

Thank you so much for your help, i took too many from your precious time.But as always you are a super good helper.I hope one day i can pay back the help in any way

coral wraith
#

edited ^

twilit horizon
#

Its 4 in the morning where i live, first thing in the morning i am gonna check it and transfer it to my customnetworkmanager

#

Thank you so much for revisions ! i appreciate it so much