#Hey guys I ve got this issue where
1 messages · Page 1 of 1 (latest)
Yes, the title is a bit dumb, but it's fine lol
No worries, I fked the name of threads several times myself as well XD
so both these objects have two continuous circle collider
Those assets are cute
hahahahah
Did you make them yourself?
thanks thanks hahah I drew them myself
yep yep haha
what happens is, when player clicks left mouse button, it Adds a force to the knife
towards the target ofcoz
private void OnCollisionEnter2D(Collision2D collision)
{
if (!_startFreeze)
{
//Add knife moving towards Knife Landing Point
if (collision.transform.tag == "Animal")
{
Debug.Log("HIT ANIMAL");
//Give 0.2s then bounce back
_rb.velocity = Vector3.zero;
_rb.angularVelocity = 0f;
_rb.AddForce((_knifePoint.transform.position - transform.position) * 5f, ForceMode2D.Impulse);
StartCoroutine(EnterIdle(_attackIntoIdle));
}
/*
if (collision.transform.tag == "Ground" && _currentState != States.Follow || collision.transform.tag == "Wall" && _currentState != States.Follow)
{
StartCoroutine(EnterIdle(_borderIntoIdle));
}
*/
_startFreeze = true;
}
}
sorry to interrupt, don't know if this is a feature on 2d colliders but try setting collision detection to continuous
both are already continuous, but thanks! That is also why Im confused hahah
most of these code you can ignore, the main thing is it Debug.Log
Also please use the cs syntax highlighting
well then other than increasing how often fixed update happens idk if there is a way
it's broken sometimes at least for me
It doesn't work on phone
I am always on pc
private void OnCollisionEnter2D(Collision2D collision)
{
if (!_startFreeze)
{
//Add knife moving towards Knife Landing Point
if (collision.transform.tag == "Animal")
{
Debug.Log("HIT ANIMAL");
//Give 0.2s then bounce back
_rb.velocity = Vector3.zero;
_rb.angularVelocity = 0f;
_rb.AddForce((_knifePoint.transform.position - transform.position) * 5f, ForceMode2D.Impulse);
StartCoroutine(EnterIdle(_attackIntoIdle));
}
/*
if (collision.transform.tag == "Ground" && _currentState != States.Follow || collision.transform.tag == "Wall" && _currentState != States.Follow)
{
StartCoroutine(EnterIdle(_borderIntoIdle));
}
*/
_startFreeze = true;
}
}
oh wow this is good haha didn't know about that cs thing my bad my bad
It's in the readme :P
hehe
so basically whenever it hits an animal, it should Debug.Log("HIT ANIMAL").
Why are you taking the tag from the transform?
shouldn't you take the tag from the gameObject?
And also you should use CompareTag()
wouldn't this be the same as transform?
I don't know but I've never seen it before with transform
I'd just use gameObject because it makes more sense
The tag is from the gameObject after all, not the transform
Even if it does work, I just wouldn't do it
It's odd
Regardless, you've to use CompareTag
(It's in the pins of #💻┃code-beginner )
hmmm ok I've changed it, but the issue seems to still be there
it does all the collision stuff, as in they collide and knife bounce off the pig, but it seems to not detect the collision
it's noticeable that it properly detects when the pig is stationary, but when the pig is moving and knife hits, it doesn't detect
You sure none of them are tagged as triggers?
What if you just put a knife without velocity in it's collider
If that doesn't work - then you know it's not the velocity
I'm sure, since the colliders are behaving like normal, as in it bounces off each other as physics behave
yes it does
hm
if (!_startFreeze)
{
//Add knife moving towards Knife Landing Point
Debug.Log(collision.gameObject.name);
if (collision.gameObject.CompareTag("Animal"))
Can you show your updated code?
sorry one sec I may have found the issue
fuhhh Im dumb haha
the _startFreeze = true; at the end, even if the collision was not with an animal it would still switched it to true
thus messing up the collision
So it was the bool
you're right hahahaha
I knew how to use them back in the vb.net days
not sure how to use in unity haha
Oh in that case I can explain it
You can press the edge to set a breakpoint on a line
Then attach it to unity
And you're good to go
It's that simple :P
You also have a couple of buttons once the breakpoint gets hit
Such as step in, step out, continue etc.
You can look it up for more info