• 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 U92 · Aug 20, 2020 at 09:26 AM · gameobjecttransform.rotationtransform.rotate

Setting a blocks rotation to predetermined values.

angles 120, and 270 seem to break any solution i throw at it any ideas.

 ![using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Specialized;
 using System.Diagnostics;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using UnityEngine;
 
 public class meinStruggle : MonoBehaviour
 {
 
     int blocksOn = 1;
     int blockSpawned = 0;
     int currentPosition = 4;
     GameObject activeBlock;
     int blockMovementSpeed = 100;
     private float decay;
     public float blockRotationSpeed = 100f;
     float smooth = 5.0f;
 
 
 
     Vector3[] blockPosition = new[] {
         new Vector3(10f, 10f, 0f),
         new Vector3(8.6602f, 10f, -5f),
         new Vector3(4.999999f, 10f, -8.660254f),
         new Vector3(-9.536743f, 10f, -10f),
         new Vector3(-5.000001f, 10f, -8.660254f),
         new Vector3(-8.660256f, 10f, -5f),
         new Vector3(-10f, 10f, 0f),
         new Vector3(-8.660258f, 10f, 5.000001f),
         new Vector3(-5.000005f, 10f, 8.660255f),
         new Vector3(-4.768372f, 10f, 10f),
         new Vector3(4.999996f, 10f, 8.660257f),
         new Vector3(8.660252f, 10f, 5.000003f),
     };
 
 
     Vector3[] blockRotation = new[] {
         new Vector3(90, 0,  0),
         new Vector3(90,  30, 0),
         new Vector3(90,  60, 0),
         new Vector3(90,  90, 0),
         new Vector3(90,  120, 0),
         new Vector3(90,  150, 0),
         new Vector3(90,  180, 0),
         new Vector3(90,  210, 0),
         new Vector3(90,  240, 0),
         new Vector3(90,  270, 0),
         new Vector3(90,  300, 0),
         new Vector3(90,  330, 0)
 
 
     };
 
     public GameObject block;
 
 
     // Start is called before the first frame update
     void Start()
     {
 
 
 
 
 
 
 
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         Reset();
 
         if (blocksOn == 1 && blockSpawned == 0)
         {
 
 
 
             activeBlock = (GameObject)Instantiate(block, new Vector3(blockPosition[currentPosition][0], 30, blockPosition[currentPosition][2]), Quaternion.Euler(blockRotation[currentPosition][0], blockRotation[currentPosition][1], blockRotation[currentPosition][2]));
 
             print(" BP is : " + blockPosition[currentPosition][0]);
 
             blockSpawned = 1;
 
             
 
 
 
             
 
 
         }
 
 
 
         // keyboard input 
         float horizontalValue = Input.GetAxis("Horizontal");
         float verticalValue = Input.GetAxis("Vertical");
 
         if (horizontalValue < 0 && decay == 0)
         {
             currentPosition = currentPosition - 1;
             //if current position is negative out of range going left, loop back to 11
             if (currentPosition == -1)
             {
                 currentPosition = 11;
             }
             // if current position is positive out of range going right, loop back to 0
             if (currentPosition > 11)
             {
                 currentPosition = 0;
             }
             decay = 0.25f;
             print("Left");
             //  StartCoroutine(RotateMe(Vector3.right * -30, decay));
             // activeBlock.transform.Rotate(blockRotation[currentPosition],Space.World);
 
             //activeBlock.transform.rotation = Quaternion.Euler(90, 0, -1 * (currentPosition*30));
 
 
             activeBlock.transform.Rotate(0,0,  30 , Space.Self);
 
         }
 
         if (horizontalValue > 0 && decay == 0)
         {
             currentPosition = currentPosition + 1;
             //if current position is negative out of range going left, loop back to 11
             if (currentPosition == -1)
             {
                 currentPosition = 11;
             }
             // if current position is positive out of range going right, loop back to 0
             if (currentPosition > 11)
             {
                 currentPosition = 0;
             }
             decay = 0.25f;
             print("Right");
             //  StartCoroutine(RotateMe(Vector3.right * 30, decay));
            // activeBlock.transform.Rotate(blockRotation[currentPosition],Space.World);
 
         }
 
         if (verticalValue < 0)
         {
             //DROP THE BLOCK
             print("Down");
         }
 
         if (verticalValue > 0)
         {
             print("Up");
         }
 
 
 
 
 
         // calc move
         Vector3 newPos = Vector3.MoveTowards(activeBlock.transform.position, new Vector3(blockPosition[currentPosition][0], blockPosition[currentPosition][1], blockPosition[currentPosition][2]), blockMovementSpeed * Time.deltaTime);
         //move
         activeBlock.transform.position = newPos;
 
 
 
 
 
 
 
         //calc tween rotation
 
 
         //activeBlock.transform.rotation = Quaternion.LookRotation(blockRotation[currentPosition]);
 
         // activeBlock.transform.rotation = new Vector3(blockPosition[currentPosition][0], blockPosition[currentPosition][1], blockPosition[currentPosition][2]);
 
         
 
 
 
 
 
 
 
         print("CP : " + currentPosition);
 
 
 
 
     }
 
 
 
 
 
 
     private void Reset()
     {
         if (decay > 0)
         {
             decay -= Time.deltaTime;
         }
         if (decay < 0)
         {
             decay = 0;
 
         }
 
 
     }
 
 
 
 
 
 
     IEnumerator RotateMe(Vector3 byAngles, float inTime)
     {
         var fromAngle = activeBlock.transform.rotation;
         var toAngle = Quaternion.Euler(activeBlock.transform.eulerAngles + byAngles);
         for (var t = 0f; t < 1; t += Time.deltaTime / inTime)
         {
             activeBlock.transform.rotation = Quaternion.Lerp(fromAngle, toAngle, t);
             yield return null;
         }
     }
 
 
 
 
 }][1]


[1]: /storage/temp/165896-50b03b6b91a1c3bf2457b9aea4ba19a6.png

50b03b6b91a1c3bf2457b9aea4ba19a6.png (109.4 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by U92 · Aug 21, 2020 at 03:17 AM

screw it, after 20 hours and no resources for help you get dirty as code like this.

             if (currentPosition == 9)
             {
                 activeBlock.transform.rotation = block9.transform.rotation;
                 activeBlock.transform.position = block9.transform.position;
 
             }
             else if ( currentPosition == 3 )
             {
                 activeBlock.transform.rotation = block3.transform.rotation;
                 activeBlock.transform.position = block3.transform.position;
             }
             else
             {
 
 
                 // calc move
                 Vector3 newPos = Vector3.MoveTowards(activeBlock.transform.position, new Vector3(blockPosition[currentPosition][0], blockPosition[currentPosition][1], blockPosition[currentPosition][2]), blockMovementSpeed * Time.deltaTime);
                 //move
                 activeBlock.transform.position = blockPosition[currentPosition];
 
 
 
                 activeBlock.transform.rotation = Quaternion.Euler(90,  (currentPosition * 30),0);
             }

now to try and animate this jank

never would have thought rotating an object 30 degrees would take 20+ hours to end up with a jank solution.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

206 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

Related Questions

Transform.Rotate() is rotating less than given rotation. What's going on? 4 Answers

Stopping transform.Rotate on an exact rotation value 1 Answer

Rotating an Object in Update Function 1 Answer

weird framrate behaviour in day/night cycle 0 Answers

Rotate Issue 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges