#collision issue big sad :( :(

1 messages · Page 1 of 1 (latest)

sullen mirage
#
// 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

vocal flower
#

can you explain a little more whats wrong

sullen mirage
#

watch the video

vocal flower
#

do you not want the cubes to combine

sullen mirage
#

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

grizzled moat
#

looks like it runs as soon as player touches it

#

you'd have to show more of the code

sullen mirage
#

it runs when two cubes touch

grizzled moat
#

use the links in !code

regal wigeonBOT
sullen mirage
#

rest of the code is related just for creating a cube (PrimitiveObject)

vocal flower
#

find out how to make it so if the cube is in that enlarged state then it no longer takes in other cubes

sullen mirage
grizzled moat
#

also why are you doing this GameObject.Find(currentCube)

#

don't use Find functions

sullen mirage
#

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

grizzled moat
#

there are better ways, esp whatever spawns those

vocal flower
#

check the colliders of the cubes

sullen mirage
#

Would cloning a script keep its serialised links?

#

because that could be more reliable

grizzled moat
sullen mirage
#

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

grizzled moat
#

is the goal here just to combine cubes?

sullen mirage
#

yeah

grizzled moat
#

why do you need to find the cube in the whole scene instead of through the collision?

sullen mirage
#

Script.parent is there something like that

#

That would be better than find

grizzled moat
#

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

sullen mirage
#

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

grizzled moat
#

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
        }
    }```