- Home /
Move everything within Collider around an specific angle
I have a rubiks cube like constructionand now i want to move it like a rubiks cube. ive got a collider for every move that is possible within a rubiks cube, so speaking about a 5x5 rubix cube there are 15 colliders, but i have no clue how i can get every object within the collider and mover it around a specific angle for 90°.
im looking into the trigger section right now but it seems im looking for the wrong section or im just to stupid to get it, not sure right now.
can you give my some hints maybe?
would be grateful....
achhandrian
EDIT: Got some hints from a friend but im still a bit clueless.... and got some
NullReferenceException WuerfelRotation.Update () (at Assets/Scripts/WuerfelRotation.cs:25)
with this script.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public class Wuerfelinha : MonoBehaviour
{
public System.Collections.Generic.List <GameObject> inhalt = new System.Collections.Generic.List<GameObject>();
public void FixedUpdate()
{
for (int i = 0; i < inhalt.Count; i++)
{
if (inhalt[i] == null || ! inhalt[i].active )
{
inhalt.RemoveAt(i);
i = 0;
}
}
}
public void OnTriggerEnter(Collider Kollision)
{
if (! inhalt.Contains(Kollision.gameObject))
{
inhalt .Add(Kollision.gameObject);
}
}
public void OnTriggerExit(Collider Kollision)
{
if (inhalt.Contains(Kollision.gameObject))
{
inhalt.Remove(Kollision.gameObject);
}
}
}
using UnityEngine;
using System.Collections;
public class WuerfelRotation : MonoBehaviour {
public GameObject other;
public string ColliderName;
void Update(){
switch(Random.Range(1, 4)){
case 1:
ColliderName = ("ColliderA" + Random.Range(1, CreateDiceV1.Anzahl+1));
other = GameObject.Find(("ColliderA" + Random.Range(1, CreateDiceV1.Anzahl+1)));
other.collider.isTrigger = true;
break;
case 2:
ColliderName = ("ColliderB" + Random.Range(1, CreateDiceV1.Anzahl+1));
other = GameObject.Find(("ColliderB" + Random.Range(1, CreateDiceV1.Anzahl+1)));
other.collider.isTrigger = true;
break;
case 3:
ColliderName = ("ColliderC" + Random.Range(1, CreateDiceV1.Anzahl+1));
other = GameObject.Find(("ColliderC" + Random.Range(1, CreateDiceV1.Anzahl+1)));
other.collider.isTrigger = true;
break;
default:
//Debug.Log("ERROR");
break;
}
if (other.GetComponent<Wuerfelinha>())
{
Wuerfelinha bla = other.GetComponent<Wuerfelinha>();
for ( int i = 0; i < bla.inhalt.Count; i++)
{
//bla.inhalt[i].;
}
other.collider.isTrigger = false;
}
}
}
Answer by Xtro · Aug 13, 2013 at 01:57 PM
I didn't read your code but I think you should parent all the objects under a central object (the center of the rotation) and you should rotate this central object. After the rotation, you can break the parenting links back to normal.
i would still need to get everything insides this collider to do that because its constantly changing......
you can use the trigger(enter and exit) events to collect the objects inside the collider(trigger) actively.
did you test even if the trigger events are firing ?? try to see if you have a problem in your scene setup by adding some debug code in the trigger events.
tested it today and no seems the trigger events are not working.... :(
tested a bit the trigger is getting fired with a character controller but i need it fired with another gameobject.....
ok adding a rigid body work, last thing i need to to do make the collidors into a trigger and back so iu need to get the specific collider by the name.....