• 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 Jakob Steinn · Nov 08, 2010 at 05:03 PM · localglobal

Classic Tetris like game - brick movement.

Hi community

I'm in the middle of a school project and i decided to make a Tetris game 'cause it's a game everyone can relate to, but...

I've got a problem when it comes to the movement, until now I've got a script that looks like this:

var target : Transform;

function Update () { if(Input.GetButtonDown("Fire1")) { // Vector3(x,y,z) transform.Translate(1,0,0); } else if(Input.GetButtonDown("Fire2")) transform.Translate(-1,0,0); else if(Input.GetButtonDown("Jump")) transform.RotateAround(target.position, Vector3.forward, 90);

 //transform.Rotate(Vector3.right, Time.deltaTime);

}

But the problem is that i want my brick to move in the Global axis and the rotation to be the local z axis, more specific i want it to rotate around the center pivot, how is that possible? I've been looking around at other questions and tried different scripts but this one is the closest i can get.

Comment
Add comment · Show 2
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 VS48 · Nov 08, 2010 at 05:10 PM 0
Share

transform.RotateAround(target.position, transform.forward, 90);

avatar image Jakob Steinn · Nov 09, 2010 at 08:20 AM 0
Share

thanks a lot! (:

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jakob Steinn · Nov 09, 2010 at 08:18 AM

Well i stayed up late last night so i could figure this out. I want to thank cmixco and VS48 for their fast answers. but here's what I've come up with:

'var target : Transform; var hasRotated : boolean = false; var angle1 : int = 90; var angle2 : int = -90;

function Update () {

if(Input.GetButtonDown("Jump") && hasRotated == true) {

 transform.RotateAround(target.position, Vector3.forward, angle1);
 //transform.localRotation = Quaternion.AngleAxis(90,Vector3.forward);
 //transform.RotateAround (Vector3.forward, Vector3.forward, 90);
 hasRotated = false;

} else if(Input.GetButtonDown("Jump") && hasRotated == false) {

 //transform.RotateAround (Vector3.forward, Vector3.forward, 270);
 transform.RotateAround(target.position, Vector3.forward, angle2);
 hasRotated = true;

}

if(Input.GetButtonDown("Fire1") && hasRotated == false) { // Vector3(x,y,z) transform.Translate(1,0,0); } else if(Input.GetButtonDown("Fire1") && hasRotated == true) { //Vector3(x,y,z) transform.Translate(0,1,0); }

if(Input.GetButtonDown("Fire2") && hasRotated == false) {

 transform.Translate(-1,0,0);

} else if(Input.GetButtonDown("Fire2") && hasRotated == true) {

 transform.Translate(0,-1,0);

}

//transform.Rotate(Vector3.right, Time.deltaTime);

}'

Please let me know if you see any way to optimize this script! Thanks again. - Jakob Steinn

Comment
Add comment · Show 1 · 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
avatar image Proclyon · Nov 16, 2010 at 12:26 PM 0
Share

looks just right the way it is, no new keywords hiding in calls which should be locals. No null references hiding around. Got more code you need checked? I'm sure the people at UnityAnswers can quickly spot some optimizations

avatar image
1

Answer by cmixco · Nov 09, 2010 at 03:19 AM

place the actual shape into an empty game object where the shape is centered perfectly. then update the rotation/movement of the empty and voila! thats what i did for my quasi-tetris game...

myTransform.Rotate(Vector3.right, 90); //x axis
myTransform.Rotate(Vector3.up, 90); //y axis
myTransform.Rotate(Vector3.forward, 90); //z axis

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Maya objects with different transforms. 1 Answer

Child coordinates misunderstanding. 0 Answers

tower defense turret turns right by 90degree 0 Answers

Rigidbody Constraints not work in local space(Unity 5) 0 Answers

How can I rotate one axis locally, and another globally? 0 Answers


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