#collision issue big sad :( :(
1 messages · Page 1 of 1 (latest)
// currentCube = gameObject.name;
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.name == currentCube && hasRun == false) {
if (collision.gameObject.GetInstanceID() < GameObject.Find(currentCube).GetInstanceID()) {
i'm not sure if there's a problem here
can you explain a little more whats wrong
watch the video
do you not want the cubes to combine
there's 3 cubes and they all get "collided" even when they don't touch
only two shpould combine at a time
even if that cube was on the other side of the map it would still combine
looks like it runs as soon as player touches it
you'd have to show more of the code
it runs when two cubes touch
use the links in !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
rest of the code is related just for creating a cube (PrimitiveObject)
find out how to make it so if the cube is in that enlarged state then it no longer takes in other cubes
i got that working, its only an issue when the objects are in their merging phase
this script has no direct parent, it gets replicated to each cube when they are created/merged
so i can't use a serialised var
there are better ways, esp whatever spawns those
check the colliders of the cubes
how so?
Would cloning a script keep its serialised links?
because that could be more reliable
what are you trying to link what to what, I don't know your setup
Although currentcube will always change upon combine so yeah not much j can do about that
find is my best method so far
it might be finding other objects of the same name potentially
is the goal here just to combine cubes?
yeah
why do you need to find the cube in the whole scene instead of through the collision?
i mean transform.parent exists
any script with monobehaviour has a transform & gameobject property
but again doesn't seem you need any other cube references aside from the ones that collide with eachother
you just need to run the function of combining onto one of them by using that ID check method
script.parent as in the object the script is in
Would that just be transform
I feel like that would solve it because find is probably finding other cubes of the same name
And then merging them all
why not just do this
void OnCollisionEnter(Collision collision) {
if (collision.collider.TryGetComponent(out CubeScript cube))
{
if(gameObject.GetInstanceID() < cube.gameObject.GetInstanceId() )
{
//Combine();
//Create new Cube
}
}```