Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Instantiation problem

Discussion in 'Physics' started by qaddah, Jul 17, 2019.

  1. qaddah

    qaddah

    Joined:
    Jul 17, 2019
    Posts:
    2
    Hello, i need to instantiate an object i designed as an endless runner tile..but its inclined (rotated 35 degrees on the Y-axis so that it will serve as an infinite straight hill) i couldn't find a way to spawn it properly without it being messed up because i don't know how to instantiate on the local axis. please help me instantiate it on its local axis not matter what rotation it has. im still new to instantiate function handling :(
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Rather than worrying about Instantiating on the local axis, you should rework your problem so it is easier to understand. Picture that each "hill piece" has an origin point, and assume that point is at the base of the hill. I'm assuming you modeled the piece or rotated it or something, right? You should know the distance the hill covers from the base until the end. At this point you have 2 options:

    1. Now you can do some math to find the distance from start to end on the x and y plane:



    You have the angle of 35 degrees, and you know that the X/Y angle is 90. That means the last angle is 180 - 90 - 35. In this example I put your known side as 5m. You now have all 3 angles and 1 side, which is enough to find the other two sides. You don't have to do the equation yourself either, you can plug it into a site or just do some distance guess/check in google graphs or something.

    2. Alternatively, you could stick a reference point at the end of each hill piece you spawn. It's a prefab, right? So you can add as many children to it as you like and each spawned object will contain them as well. You can manually line up the child object at the end of the hill piece, and each time you need to spawn a new one, just retrieve the position of your last spawned reference object and put it there. You'll need to store that as a variable of course, but it should be easy enough.

    Hopefully this has opened your mind a bit to problem solving and to how you can turn a complex problem into a series of smaller steps. Don't overthink it, you won't always need complicated equations or transformation of positions, if you're willing to take new approaches you can always tackle problems in gamedev by simply breaking it down into "what needs to happen?", "what steps should the program take to get it to happen?", and "what information does the program need for it to happen?"