#Switching camera positions

1 messages · Page 1 of 1 (latest)

wide flint
#

@bronze brook

bronze brook
#

!

wide flint
#

Better to talk here

#

We might have a long ways to go

#

Okay

#

Forget my public Transform[] cameraPostion

#

I need you to test something

#

For me

#

To help you

bronze brook
#

What is it

wide flint
#

Dictionary<string, Vector2> cameraPostitions = new Dictionary<string, Vector2>();

#

Can you put something like that onto a script

#

We need to know if it's serializable for the inspector

#

Does it show up?

bronze brook
#

I wrote it on my script and it compiles fine

bronze brook
wide flint
#

Oh

#

Pit public in front

wide flint
bronze brook
#

OH I see what you mean

#

in Unity

wide flint
#

Yes

#

If it is can you send a screenshot please

bronze brook
#

nope

wide flint
#

Also another question:
Your using wd right?

bronze brook
#

windows?

#

I am

wide flint
#

Hmm

wide flint
#

This might be more challenging than I thought

#

Especially if you are in the early learning stages

bronze brook
#

Is there a reason it's not showing up in inspector?

wide flint
#

I don't think Dictioaries can 😕

#

And I can't seem to type correctly right now 🤣

#

Ohhh

#

Are your rooms numbered?

#

Or named?

bronze brook
#

Uhhh they're not really anything right now. So far I've only got 1 room

#

They're all just built with a tilemap

wide flint
#

Okay well if you number them we can sort them that way

bronze brook
#

What would I number though? The tilemap or something?

wide flint
#

Becuase we can tell the camera to go to room 0 or 1 or 2...

#

No just name them 0, 1, 2

bronze brook
#

I don't understand what I'm naming though, there isn't a "room" GameObject

wide flint
#

Or create an empty chuld in each one with that name

bronze brook
#

it's just a tilemap

wide flint
#

Is each room a separate tilemap?

#

Or everything 1 big one?

bronze brook
#

for reference, I have 2 tilemaps. One for platforms, and another for obstacles (anything that damages the player)

#

But these 2 tilemaps essentially make up everything

wide flint
#

Okay

#

Can you make each room a separate tilemap?

#

Or is that too much work?

bronze brook
#

I suppose that's fine

#

I still want to separate the obstacles and platforms though, so each room will be a "group" of 2 tilemaps I guess

#

Sorry, I gotta go for like 10 mins

wide flint
#

Okay

#

I'll keep typing

#
  1. Make each room a tilemap

  2. Name each room counting up (starting from 0)

  3. Create this code:
    public Transform[] camPosition;
    You will see when entering the inspector that the array will start at 0. The 0th Transform is room 0.

  4. Now all you need is code to navigate by enabling and disabling the right cameras.

#

Obviously you don't have to follow this. You can do it your own way, im just giving you a solution.

bronze brook
#

That took way longer than expected, it's gotten too late for me unfortunately so I'll keep it at tomorrow. Thank you for all your help, it's appreciated

wide flint
wide flint
bronze brook
#

Hey, so I created an empty GameObject and added both obstacle and platform tilemaps as children

#

And renamed it to "room 0"

#

then I created a BoxCollider trigger that the player walks through and added a script called "SwitchCam", with the code you posted

wide flint
#

Add it to 1 gameobject

#

Not multiple

bronze brook
#

?

wide flint
#

Add the scripot to a single gameobjet

#

Yoiu wont want to put it for every room

bronze brook
#

This invisible wall that triggers the camera switch contains the script

#

oh ok

bronze brook
#

So should the camera have the script?

#

when the player touches the edge of the camera, the camera changes position depending on which border the player touches

wide flint
wide flint
#

Sorry im talking too much

bronze brook
#

maybe add a BoxCollider component to the camera?

wide flint
#

Im not sure how to find waht side its on

#

I guess you could compare it to a vector

bronze brook
#

vector yea

#

(1,0) = right, (0,1) = up, and so on

#

Maybe something like if (position.y > [max length of camera]) = [camera moves upwards]

#

(position.x < [max length]) = [camera moves left]

wide flint
#

Yea but you would also need to compare the positions

bronze brook
#

Do I?

#

I imagine the camera position change would only trigger if any of the x/y components exceed a certain number

wide flint
#

Well

#

here think of it this way

#

You need to get the position, lets say for if its above the camera. Well you need to see if its position is above not if its higher than the height. Because you might have the camera at -100 at some point. If the camera hieght is 12 for example. Then if you check to see if the player position is above the height (12) that will be way off from the camera's position (-100)

#

Let me know if you need me to be more specific @bronze brook

bronze brook
#

So I would have to check if playerPosition is 12 units high or something?

#

so that it can apply to every single room

#

hmmm

#

I actually can't think of what I can do for this, because it's not like the player's position resets when they enter a new room

#

it's constantly changing

#

I think my alternate solution of attaching colliders to the borders of the camera might be more realistic

wide flint
#

Wait is the camera covering the whole room?

bronze brook
#

The camera covers the entirety of each room

#

Yes

wide flint
#

So that wouldn't work

#

Because you would need t go outside of the camera

#

So outside of the room

bronze brook
#

Well, the effect I want is for my character to leave the room and then it changes the camera to the next room

#

That sounds fine to me

wide flint
#

here

#

I have an idea

#

Put a collider at every doorway

#

But on its own gameobject

#

Sound good?

bronze brook
#

Wym on its own gameobject

#

Adding a collider to every doorway was one of my first ideas

wide flint
#

Door 1

#

Door 2

#

Yea and I agreed with it

#

It just sounded like you didnt want to for a sec because you brought up the camera

bronze brook
#

Yeah I just wanted an alternative with less colliders

bronze brook
wide flint
#

But

#

How are you going to switch cameras?

#

You need to think about that

#

@bronze brook

bronze brook
#

Change the camera's position

wide flint
#

Oh okay

#

I see waht your doing

#

Are you rooms right above and beside?

bronze brook
#

All 4 directions

wide flint
#

Okay

#

So you dont need to have the rooms numbered

bronze brook
#

Yup

wide flint
#

And that code I gave

#

Get rid of it

#

Don't forget camera size will change depending on device though

#

I thought your rooms where apart from each other

#

My bad

#

Not connected basically

#

But I see now they are

bronze brook
#

Ye!

#

I'll figure it out tonight

wide flint
#

So if your doing colliders you will want to just add or minus from the position to move it

#

I wont give you more code