- Home /
How do I move the camera dependent on the players position
I'm using iTween to move the camera but it's alright if you use the inbuilt commands. At the moment, I have a grid of 10x10x10 "sections" of my map and I need to detect when the player is in one of them and then move the camera to the center of that section. How can I do this? It also needs to only work when the player is COMPLETELY inside that section so there is no weird overlap.
Why don't you just keep track of the player's grid position? You can store all camera positions in an array and get the desired one from the position of the player within the grid.
What if I want the array to keep generating new 10x10x10 sections when I go to a new part of the map? Also what's the code for getting the players "grid" position?
you chould just do a late update check on the players position if its between the x,y at 0,0 and 0 , 10 for example move the camera to slot 1 of the grid and so on
Answer by Andres-Fernandez · Aug 19, 2014 at 07:27 AM
Well, it depends on how you implement your navigation system (how your player moves within the grid). You can use a "center position" system in which you store the position of each grid section center and use it to check the distance with the player to see where the player is located. That may require to have an array of "possible sections" to avoid checking the distance with all sections, since you only want to check the sections the player is allowed to be in (sections that are next to the current section of the player).
Your answer
Follow this Question
Related Questions
Make a camera loosely follow an object 1 Answer
How to create a camera follow setup. 1 Answer
Change angle of camera: eulerAngle issue 1 Answer