Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xKyungsoo · May 14, 2019 at 09:12 PM · unity 5transformposition

Problem how to access Y-position value

I am making a voice-controlled variant of Flappy Bird. To make the bird move across the Y-axis, I have a function that converts pitch note (frequency) to the corresponding Y-position. Just like the original game, the pipes have a randomly generated opening through which the bird has to pass. Every time the bird successfully passes through a pipe opening, I need to save it in my database in following data format:

-seqNum: (int) keeps track of the pipe order

-maxFreq: the opening's upper threshold value, converted from Y position to frequency

-minFreq: the opening's lower threshold value, converted from Y position to frequency

-hitFreq: the frequency that the user actually hit (= the bird's position)

My problem is not "converting from Y to frequency". As I already have a function that converts from frequency to Y, doing it the opposite way is easy to achieve. My problem is getting the actual Y positions. My pipes are generated in a Prefab as a parent GameObject with 3 children:

1) the upper pipe sprite

2) a boxcollider in the middle as the "opening"

3) the lower pipe sprite

Here's a screenshot of the positions that I need to save in my database: https://prnt.sc/nolosx

hitFreq (1) would be easy to access as I can just use the player's transform.position.y

But I have no idea how I'm supposed to access maxFreq (2) and minFreq (3). I can get the position of the parent Prefab object, but I don't know how I can calculate the positions of the upper edge and lower edge of the opening. I'd appreciate if someone could help me find a solution!

Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · May 14, 2019 at 09:51 PM 0
Share

Your issue then is knowing number 2 and 3 position? You could add childs objects at the upper and lower edge and calculate the current when you trigger the box collider, or when you trigger the collider use 2 raycast upwards and botton and compare collision position

avatar image xKyungsoo xxmariofer · May 14, 2019 at 10:05 PM 0
Share

This is my first application using Unity, so I don't really know how to apply your solutions :( I followed a tutorial for the code that I have now... I understand the code that I have, but my knowledge is limited to that

avatar image xKyungsoo xxmariofer · May 15, 2019 at 07:18 PM 0
Share

Hi @xxmariofer, I'm sorry for insisting, but this is an app for my bachelor thesis so it's very important... I have looked at what Raycasts are and it seems like it could be a solution, but I need help on how to actually use them

avatar image xxmariofer xKyungsoo · May 15, 2019 at 08:54 PM 0
Share

without knowing your code is hard to say but something like this could help

         RaycastHit2D hit1 = Physics2D.Raycast(transform.position, Vector2.up);
 
         // If it hits something...
         if (hit.collider != null)
         {
             float position= $$anonymous$$athf.Abs(hit.point.y);
         }

this should be done inside the ontrigger and using the vector2.up/down for getting both points

Show more comments
Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

237 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Copy position from one object to another on one axis 0 Answers

Help! I want to make a following camera but in with Y position is constant ? 2 Answers

Global transform position and scale for gameObject 0 Answers

How do i move a GameObject to the same height as another GameObject? 0 Answers

Accurate placed object's transform messes up on game start 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges