#CameraStuff
1 messages · Page 1 of 1 (latest)
okay! please give some time, I need to rethink all that stuff
no problem
basic idea is
1. Main camera is enabled by default.
2. You start hosting a server.
3. Player gets instantiated, player spawns in their own camera if IsLocalPlayer is true.
4. Main camera gets disabled (whole gameObject).
5. Player gets the camera script off of that new instantiated camera gameobject, sets the followTarget to themselves.
Wait, but if I disable the menu main camera on one client, it will 1. not enable it later 2. it will destroy other peoples' menus?
No, so, I have not used mlapi but, generally speaking, things that a client does locally are not synced on the server automatically
only things you specifically tell the server to do are synced across the network
The same rule applies to whatever UI you use to host and join a game
You have to think about it as though you are both playing singleplayer games, but then you can tell the server to sync specific values between each other
such as player position, rotation, etc
Almost nothing is synced by default
but again, I have not used MLAPI, I am just assuming
yeah, I am looking at MLAPI right now and it looks just like every other networking solution I have seen
so I believe everything I am saying should still apply
ok so I a little don't understand
- Instantiate(cameraPrefab); - how do I tell to specifically choose and target the prefab, not the main camera? It gives a warning when I try to switch the name
- gameObject.SetActive(false); - but how do I target something with it? for example Main Camera
// inside the player script
private void Start()
{
if (IsLocalPlayer)
{
// disables the main camera
Camera.main.gameObject.SetActive(false);
// spawns in the player camera
GameObject playerCamObj = Instantiate(cameraPrefab);
// updates the followTarget of the camera script, I don't know what your script is called so I am saying "PlayerCamera"
playerCamObj.GetComponent<PlayerCamera>().followTarget = transform;
}
}
this is assuming your main camera has the MainCamera tag, and that your cameraPrefab camera does not have the MainCamera tag
wait... what are tags
and yes, this code gives two errors - cameraPrefab and PlayerCamera
yes, you have to actually make a cameraPrefab variable
and I mentioned in my comment why PlayerCamera would error
I don't know what your camera script is called
yes, the thing that has followTarget in it
do you know about how you would make a variable for your cameraPrefab, and how you would assign it to the prefab in your assets folder?
No...
I won't say "dont do it" but, it might be good to start with something not-multiplayer. But I will help anyway since I am this far in already
have you made variables before?
in Pascal yes
[SerializeField]
private float speed;
if this is a variable then I think I understand how
so if you make a variable of type GameObject, then make it public (or [SerializeField] private)
it will show up in the inspector
yes, and the [SerializeField] means it will appear in the inspector for you to change
without needing to go into the code
so you need to do the same thing for the cameraPrefab
you make a variable of the correct type, and it will appear in the inspector for you to set to whatever you want
is it ok that since the main camera I just dragged the cube for menu main camera is blue now? May I destroy it and create a new camera or blue cubes are ok in server projects?
you mean like, it is rendering blue onto the screen?
oh
how do I explain... Can you right click that camera and press "Unpack completely"?
you don't want the main camera to be the prefab, I would make a new camera and make that the prefab
leave the main camera how it is
ok, so my code looks like that now, but later some random line gives me an error (nullrefexcept)
this is the code:
private void Start()
{
if (IsLocalPlayer)
{
// disables the main camera
Camera.main.gameObject.SetActive(false);
// spawns in the player camera
GameObject playerCamObj = Instantiate(cameraPrefab);
// updates the followTarget of the camera script, I don't know what your script is called so I am saying "PlayerCamera"
playerCamObj.GetComponent<Tracker>().followTransform = transform;
}
}
and this is the line
animator.SetBool("moving", false);
what is the line?
oh
then "animator" is null
and it must be set to something
try making "animator" appear in the inspector using [SerializeField] and drag something in
could it be that the problem is that you have transform in your code and I use it too in one of the functions? If so, what do I need to change your or my transform to?
if the line with "animator" is erroring, that does not have anything to do with the transform
you sure? that's the code
where are you setting "animator"
how would it know what animator you are talking about?
it's just, animator I added yesterday and everything was working right
But still, try and find where it you tell it which animator you are that variable to be set to
is it set in the inspector? or are you using GetComponent? or what
send a screenshot of the top of that code
the parts I cant see
I do not know how it was working yesterday based on this
you never actually assign "animator" to be anything
but I assign it here
No, so
the word "animator" means nothing until you put something in it
there is no animator in it because you never actually set the variable equal to something
this would be assigning it
animator = GetComponent<Animator>();
not that you should write that, but it is an example
perhaps you should put [SerializeField] over the animator variable declaration at the top
then you can drag whatever animator you want from the scene into that slot in the inspector
You are missing some foundational knowledge
unless you actually pressed Add Component and put a new animator on, you still have 1 animator
you are just telling your PlayerMovement script which animator you are talking about
wait, so, should I remove Animator in movement or not?
nope
because that isn't an animator, it is a reference to an existing animator
which you need
You should go through some basic courses on Unity Learn
I have heard it is quite good
and it is free
stuff like this would take you minutes at most
ok, but if this is a problem, what should I do? Because now it gives me error on that line transform.position + change.normalized * speed * Time.deltaTime);
send the entire line
or I guess I can see it
nevermind, its in the top picture
what does it say?
null ref exception?
yes, on line 73
you probably aren't setting the rigidbody variable either
which is a comment
in Start(), write
myRigidbody = GetComponent<Rigidbody2D>();
or you could make it [SerializeField] like you did for the animator
and drag it in
OOOH I'm really sorry, I'm dumb, I deleted a part of code when replacing the start function
that's why it was working yesterday
I see..
well it was probably something like this
private void Start()
{
animator = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
}
if you do that, which is probably how it was, you can remove the [SerializeField] in front of the animator variable at the top
of course keep the other Start() code we just made in there
well I have to go, good luck with this
Okay! I hope to talk to you tomorrow, I haven't fixed the problem...