#Collision

1 messages ยท Page 1 of 1 (latest)

teal beacon
#

@errant leaf alright.

errant leaf
#

Please post all relevant context in this thread

#

(Full inspectors of both objects, and relevant code)

teal beacon
#

NPC Inspector

#

Player Inspector
(It's identical, except there is no collision detection script on it.)

#

Script

errant leaf
#

So please make a screenshot of that

teal beacon
#

Which one?

#

Oh, right.

errant leaf
#

Your CollisionDetection one

errant leaf
#

It's in the pins

teal beacon
errant leaf
#

col.gameObject.CompareTag("tag")

errant leaf
#

Are they all applied to the original prefab?

teal beacon
#

Yes.

errant leaf
#

Otherwise there'd not be blue lines

teal beacon
#

It hadn't been applied yet, you're right.

errant leaf
#

If you apply it, do the tickboxes reappear?

teal beacon
#

I applied it and changed to CompareTag.

#

No, they still don't appear on some scripts.

errant leaf
#

Strange

#

It's intended apparently

teal beacon
#

Oh, didn't know that! ๐Ÿ™‚

errant leaf
#

Regardless that'd pbb not be the culprit of the problem anyway, it just caught me off-guard

teal beacon
#

NPC has the collision detection script.
Player doesn't.

Player has "IsTrigger", NPC hasn't.

Both have rigidbodies 2D.
Both are kinematic.

errant leaf
#

Can you show your current code?

#

Both are kinematic.
There's your problem

teal beacon
#

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

public class CollisionDetection : MonoBehaviour
{
public bool collided;
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.CompareTag("Player"))
{
collided = true;
Debug.Log("yey!");

    }
}

void OnTriggerExit2D(Collider2D col)
{
    if (col.gameObject.CompareTag("Player"))
    {
        collided = false;
        Debug.Log("yey!");
    }
}

}

errant leaf
#

I'd read through the docs

teal beacon
#

Hm, tried making both dynamic, still no luck.
I will read them. But I tried it in every possible configuration for the last 2 hours. Dynamic, kinematic, ...

errant leaf
#

That's 3D though so I'm currently looking at the 2D of it

teal beacon
#

IsTrigger on either one, OnCollisonEnter2D, on TriggerEnter2D...

errant leaf
#

Hmm there seems to be quite the difference with 2D and 3D regarding kinematic

#

I'd just use a dynamic rigidbody for now though

errant leaf
#

For 2D it seems to be a hidden property, only accesed through code which is odd

teal beacon
#

I made this work easily before. Collision. I don't know what the freaking problem is this time. xD

#

But no matter what I try, it doesn't work.

errant leaf
#

place a debug.log outside of the if

#

See if that does anything

#

Wait how do the entities collide?

#

How are you moving object A to object B

teal beacon
#

1.) The debug outside doesn't show in console, when both objects meet.

2.) The collision happens by moving via WASD. It uses a script that gets RawAxis from Edit > Project Settings > Input Manager

errant leaf
#

Mind showing?

teal beacon
errant leaf
#

void gets called in Update I assume?

teal beacon
#

Yep.

errant leaf
#

Could you show the scene with both objects colliding with the bounding boxes visibly shown?

teal beacon
errant leaf
#

Or a video

#

btw after this is solved, look into enums and use those instead of strings

errant leaf
#

The thing that's moving is the "Mage" right

teal beacon
#

Yep.

#

It gets renamed by script, but is derived from prefab.

#

All attached scripts and configurations are identical.

errant leaf
#

Did you put the RB's on dynamic?

teal beacon
#

Both of them (NPC and Player) look like this now.

#

For a search with CompareTag - do both of the Game Objects need to be on the same layer maybe?

errant leaf
#

No.

#

What's your collision matrix?

#

I'd put them both on the default layer

#

Unless you tinkered with the matrix of the default layer

teal beacon
#

Hold on, I'll get the matrix.

#

Oh...

#

My...

#

Fucking...

errant leaf
#

Was it that?

teal beacon
#

God...

#

It was the matrix.

errant leaf
#

Welcome to programming XD

teal beacon
#

Bro...

errant leaf
#

Don't move them out of the default layer if you don't have to kek

teal beacon
#

Literally one fucking click on a checkbox cost 5 hours. xD

errant leaf
#

Should've pbb asked about it earlier, whoops

#

In code beginner a lot of people don't know what the collision matrix is so I don't ask it as the first thing kek

errant leaf
#

I've been fixing a bug this entire workday, so y'know

teal beacon
#

Wumpie. I'm somewhat good with pixel art, UI design, quest design and lore stuff. If you ever need advice, an opinion, an idea - Please ask. ๐Ÿ™‚

teal beacon
errant leaf
#

I need advice on how to not go insane after trying to fix a bug for 8 hours XD

#

XD

teal beacon
#

Well, leave and come back to it. That usually works for me. It randomly pops up in my head during the day, but I'm sure you know this. ^^

errant leaf
#

Then I can read my code even less next monday XD

#

I'm working on a buff system but it's getting really complex

teal beacon
#

What are you working on? ๐Ÿ™‚

#

I guess the most practical advice is "never give up". It's generic, I know.

errant leaf
#

If I give up I'll fail my internship, so even if I wanted to, I don't have a choice XD

errant leaf
teal beacon
#

Sure, why not! ๐Ÿ™‚

#

I might answer slow, tho. I can't remember when I ate something for the last time and probably fix up smthg.

errant leaf
#

Have fun XD

errant leaf
#

Only god and I know how the code works XD

#

I did fix the bug

#

But another bug took it's place

#

And now I'm even more confused kek

#

I probably actually found another bug I never knew was there

#

So that's an oof

errant leaf
#

You're probably right

#

I'll just go work in the weekend on it Ig

#

This bug is a lot bigger than I initially though

#

I suppose it's mainly due to poor code architecture choices, oof

#

Anyway ima go now then, I've a train to catch