- Home /
Locating proper gameObject to which player has to jump
I am developing a game, in which the player has to jump to a position and look at next position... I have made the positions into gameObjects, and thus now I need to find a way by which the player can locate the right gameObject to which it has to jump and locate the gameObject it has to look at. I thought of using collider or overlap spheres but can't think of applying it in this situation. Here I have attached a Image to understand what I want to do more precisely. In this example player has to jump from it's current position to next position and look at the next to next position. Hope you shall help me Thank-you!
Answer by bhavinbhai2707 · Jul 10, 2018 at 08:01 AM
Just create an array or List of GameObjects. As soon as you jump to your first GameObject
use Distance(Vector3 a, Vector3 b);
to calculate distance between player and first gameobject in array/list.
if it is near the player(eg : 0.5f near) then just make player to lookat next Gameobject in array/List.
Yes thankyou for your answer, I indeed had thought of using array/list in my project but you see, this game is going to be made into a sandbox type, so I thought it would be better for the player to detect the positional gameObjects through code itself. Thus Asking if there is a way to detect these gameObject in runtime
@Vedang202 Array/list is the most efficient way i can think of. Using Overlap sphere is way way expensive.
N i don't understand what you mean by detecting through code itself! IF you use array/list, they are part of code as well!
I meant to say by saying "code itself" was, the users will be instantiating these new gameObject to which player has to jump to. Now user can instantiate the gameObject anyhow. For this example first they may instantiate the first position gameObject then they may instantiate 3rd and then 2nd. I need a method to make player decide on which position gameObject it had to jump and which it has to look at. As user is going to instantiate the positions array is not a right way. Ofcourse Array has to be used. But the way of filling the array is what I am looking for. I hope I made my question clear
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Resetting a position after reaching a certain point 2 Answers
C# Transform modification. 1 Answer
Change the value of string in other class by triggering collision (c#) 1 Answer