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 /
This question was closed Oct 26, 2017 at 06:33 PM by kire466 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by kire466 · Oct 26, 2017 at 04:29 PM · rotationtransformparentchild objecttetris

Problem retrieving transform.position after parent rotation

Hello, I am trying to make a Tetris clone to practice a bit but I stumbled upon a problem I can't resolve. I spawn a brick, for example the L shaped one,made from gameobjects representing each one piece of the brick. I make a piece the parent of all the other pieces in order to rotate the brick around this piece with a simple transform.roation. When I rotate it everything looks fine, but when I try to move it, so I go and check if the brick can move, transform.position for one of the child gets me the wrong value, giving me a free position as a position occupied by that piece. This only happens when trying to move on the field with the x value equal to 0. My tetris field where i can move the bricks is 10 positions in width and 20 positions in height. Its seems to me as if transform.position is returning me the local value insted of the gobal when i check for positions with the x = 0.

The code that follows is how i check and move the brick, with brick[0] the parent of the other pieces. I rotate the brick with a simple

brick [0].transform.Rotate (0f, 0f, 90f); ...

void MoveBrick(int xDirection){

     foreach (GameObject bri in brick) {
         int newPosX =(int) bri.transform.position.x + xDirection;
         int newPosY = (int)bri.transform.position.y;
         if (newPosX < 0 || newPosX >= columns)
             return;
         if (newPosY<rows&&placeTaken [newPosX-originX, newPosY-originY])
             return;
     }

     brick [0].transform.position = new Vector3 (brick [0].transform.position.x +xDirection, brick [0].transform.position.y);
 }
Comment
Add comment · Show 4
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 izaazyunus · Oct 26, 2017 at 04:34 PM 0
Share

Ins$$anonymous$$d of moving individual bricks, can't you move the parent object left and right ins$$anonymous$$d?

avatar image kire466 izaazyunus · Oct 26, 2017 at 04:44 PM 0
Share

I am moving the parent object only agter the foreach loop with

brick [0].transform.position = new Vector3 (brick [0].transform.position.x +xDirection, brick [0].transform.position.y);

In the foreach loop I check if the positions to the left or right of each part of the brick are free and in the playing field

avatar image izaazyunus · Oct 26, 2017 at 05:16 PM 0
Share

Answer by izaazyunus · 9 $$anonymous$$utes ago @kire466 Got it. In that case, you can get the individual bricks coordinate in the parents coordinates by just adding the parent's position and the local position of the brick. For example if the parent is at (100,100) and a brick is at (10,-10) then the coordinates in the parent space is just (110,90)

avatar image kire466 izaazyunus · Oct 26, 2017 at 05:18 PM 0
Share

I dont think we understood eachother. The problem i got is tat after the rotation, transform.position gives me a position that the brick does not occupy

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by kire466 · Oct 26, 2017 at 06:01 PM

I fixed it... the problem was in the conversion from float to int... putting

int newPosY = (int) Math.Round(bri.transform.position.y);

fixed my problem

Comment
Add comment · Share
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

Follow this Question

Answers Answers and Comments

112 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

Related Questions

moving child objects in hierarchy and keep stacks/sorting? Help needed 0 Answers

Moving objects together without parenting 5 Answers

Camera follow ball along cylinder 1 Answer

Moving child transform also moves parent rigidbody 0 Answers

Fixing pivot points with second gameObject workaround 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