#Switching camera positions
1 messages · Page 1 of 1 (latest)
!
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
What is it
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?
I wrote it on my script and it compiles fine
I'm not sure what you mean by this
To see if it's visible...
Also another question:
Your using wd right?
Hmm
Doesn't matter when using unity
This might be more challenging than I thought
Especially if you are in the early learning stages
Is there a reason it's not showing up in inspector?
I don't think Dictioaries can 😕
And I can't seem to type correctly right now 🤣
Ohhh
Are your rooms numbered?
Or named?
Uhhh they're not really anything right now. So far I've only got 1 room
They're all just built with a tilemap
Okay well if you number them we can sort them that way
What would I number though? The tilemap or something?
Becuase we can tell the camera to go to room 0 or 1 or 2...
No just name them 0, 1, 2
I don't understand what I'm naming though, there isn't a "room" GameObject
Or create an empty chuld in each one with that name
it's just a tilemap
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
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
Okay
I'll keep typing
-
Make each room a tilemap
-
Name each room counting up (starting from 0)
-
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. -
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.
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
Np. It happens. I was starting to wonder if you just left me. 😅
I did write this big guide to how you could do it, yesterday. Just incase you didn't see @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
Oh no
Add it to 1 gameobject
Not multiple
?
Yes you will want this
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
Sure
Let me think abour this though
I dont know about this though
I know how to do this
Sorry im talking too much
you don't think it could work?
maybe add a BoxCollider component to the camera?
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]
Yea but you would also need to compare the positions
Do I?
I imagine the camera position change would only trigger if any of the x/y components exceed a certain number
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
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
Wait is the camera covering the whole room?
So that wouldn't work
Because you would need t go outside of the camera
So outside of the room
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
here
I have an idea
Put a collider at every doorway
But on its own gameobject
Sound good?
Wym on its own gameobject
Adding a collider to every doorway was one of my first ideas
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
Yeah I just wanted an alternative with less colliders
I'm going to try out this idea
Sure
But
How are you going to switch cameras?
You need to think about that
@bronze brook
Change the camera's position
All 4 directions
Yup