12.4 C
New York
Sunday, November 16, 2025

Tetris block kinematic inflexible our bodies traverse one another with Remodel.Translate


I am making an attempt to create a 3D Tetris recreation in Unity, however I can not get the completely different blocks to work together (to detect one another, to take a seat on prime of one another as an alternative of passing via one another). I’ve set the bottom with a field collider and the swan blocks include inflexible our bodies and set off colliders.

This works to get them to take a seat properly on the bottom, however when I attempt to place one block on prime of one other, they each have kinematic inflexible our bodies and the collision detection would not work they usually find yourself overlapping. The issue is that if I take away the inflexible physique from the already seated block, it’s going to undergo the bottom.

Any concepts the best way to make 2 generated objects detect one another?

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UIElements;

public class moveBlock : MonoBehaviour
{    
    public static float pace = 2;
    public GameObject() blocks;
    public static Record<GameObject> blocksSpawned = new Record<GameObject>();
    public static Record<Rigidbody> blocksRBSpawned = new Record<Rigidbody>();
    public static bool triggerPlatform = true;
    Rigidbody rb;

    void Replace()
    {
        Vector3 enter = new Vector3(Enter.GetAxisRaw("Horizontal"), 0, Enter.GetAxisRaw("Vertical"));
        Vector3 route = enter.normalized;
        Vector3 velocity = route * pace;
        Vector3 moveAmount = velocity * Time.deltaTime;

        if (triggerPlatform)
        {
            blocksSpawned.Add((GameObject)Instantiate(blocks(Random.Vary(0, 7)), new Vector3(0, 6, 0), Quaternion.Euler(Vector3.proper)));
            rb = blocksSpawned(blocksSpawned.Rely - 1).GetComponent<Rigidbody>();
            blocksRBSpawned.Add(rb);
            triggerPlatform = false;
        }
        /*if (!triggerPlatform)
        {
            Destroy(blocksRBSpawned(blocksRBSpawned.Rely - 1));
        }*/
        if (blocksSpawned(blocksSpawned.Rely - 1) != null)
        {
            blocksSpawned(blocksSpawned.Rely - 1).rework.Translate(Vector3.down * Time.deltaTime*pace, Area.World);
            blocksSpawned(blocksSpawned.Rely - 1).rework.Translate(moveAmount);
        }
    }
}

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class set off : MonoBehaviour
{    
    non-public void OnTriggerEnter(Collider different)
    {
        moveBlock.triggerPlatform = true;
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles