#CameraStuff

1 messages · Page 1 of 1 (latest)

manic snow
#

we will type here instead

verbal escarp
#

okay! please give some time, I need to rethink all that stuff

manic snow
#

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.
verbal escarp
#

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?

manic snow
#

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

verbal escarp
#

ok so I a little don't understand

  1. 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
  2. gameObject.SetActive(false); - but how do I target something with it? for example Main Camera
manic snow
#
// 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

verbal escarp
#

wait... what are tags
and yes, this code gives two errors - cameraPrefab and PlayerCamera

manic snow
#

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

verbal escarp
#

Camera script? You mean tracker thin?

#

*thing

manic snow
#

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?

verbal escarp
#

No...

manic snow
#

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?

verbal escarp
#

in Pascal yes

manic snow
#

alright well

#

prefabs are of type GameObject

verbal escarp
#

[SerializeField]
private float speed;
if this is a variable then I think I understand how

manic snow
#

so if you make a variable of type GameObject, then make it public (or [SerializeField] private)

#

it will show up in the inspector

manic snow
#

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

verbal escarp
#

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?

manic snow
#

you mean like, it is rendering blue onto the screen?

verbal escarp
manic snow
#

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

verbal escarp
#

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);
manic snow
#

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

verbal escarp
#

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?

manic snow
#

if the line with "animator" is erroring, that does not have anything to do with the transform

verbal escarp
#

you sure? that's the code

manic snow
#

where are you setting "animator"

#

how would it know what animator you are talking about?

verbal escarp
#

it's just, animator I added yesterday and everything was working right

manic snow
#

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

verbal escarp
manic snow
#

I do not know how it was working yesterday based on this

#

you never actually assign "animator" to be anything

verbal escarp
#

but I assign it here

manic snow
#

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

verbal escarp
#

but I already have animator..?

#

now I have two animators

manic snow
#

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

verbal escarp
#

wait, so, should I remove Animator in movement or not?

manic snow
#

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

verbal escarp
manic snow
#

send the entire line

#

or I guess I can see it

#

nevermind, its in the top picture

#

what does it say?

#

null ref exception?

verbal escarp
#

yes, on line 73

manic snow
#

you probably aren't setting the rigidbody variable either

verbal escarp
#

which is a comment

manic snow
#

in Start(), write

myRigidbody = GetComponent<Rigidbody2D>();
#

or you could make it [SerializeField] like you did for the animator

#

and drag it in

verbal escarp
#

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

manic snow
#

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

verbal escarp
#

Okay! I hope to talk to you tomorrow, I haven't fixed the problem...