-1

I have the following code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

public class Tetris : MonoBehaviour
{
    
    void Update()
        {
            transform.Translate(new Vector3(0, -3 * Time.deltaTime, 0) );
            CheckUserInput();
        }
    
    void CheckUserInput(){
        if (Input.GetKeyDown(KeyCode.Space))
            {
                transform.Rotate(0, 0, 90);
                
            }
}

How to make the object fall normally every time it is rotated?

derHugo
  • 83,094
  • 9
  • 75
  • 115
Chau Ngoc
  • 11
  • 2
  • Please make sure to use the correct tags. Your code is in `c#` **not** in `unityscript` which is or better **was** a JavaScript flavor like language used in previous Unity versions and is long deprecated by now. You should rather use the tag `unity3d` – derHugo Nov 12 '20 at 12:45
  • I got it, thank you – Chau Ngoc Nov 13 '20 at 04:40

1 Answers1

0

Try using method Translate(Vector3, Space) with Space.world or by placing view object as a child to Tetris component. The Tetris component should have a reference to that component.

public class Tetris : MonoBehaviour
{

public GameObject view;
void Update()
{
    transform.Translate(new Vector3(0, -0.3f * Time.deltaTime, 0));
    CheckUserInput();
}

void CheckUserInput()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        view.transform.Rotate(0, 0, 90);

    }
}
}