Identify Game Object For Intersection

In regular C#, you can use Intersect to identify something intersecting another, but Unity doesn’t seem to have that “Intersect” option.

If I want to script another object and have my Main Character intersect with it, then create any kind of event to happen, what do we do?

Do NOT respond with posts regarding Rigidbody, and do NOT respond with questions about “Why not”, this is strictly a question about bare coding.

I’m not sure what you mean “In regular C#,” C# doesn’t have an API for geometric intersections. So which C# method are you talking about?

I’m also not really sure what you’re asking, but it sounds like you need a trigger and a rigidbody.

This is the only kind of Intersect I can find in C# - finding elements that two lists have in common, which is not anywhere close to having your main character intersect with something. What are you talking about?

I just want to 1) detect my main character’s object with, say, a weapon they find on the ground, then 2) Write a script so they obtain that weapon

I tried this in a simple script attached to my weapon, where in the Update…

void Update () {
if (bounds1.Intersects(MainCharacterScript);
{
}

Only because I could not find a place to select my main character’s object itself.

So I decided to use a script attached to the object, other than that I cannot think of a way to get this done.

I am only basing this on posts I have read and the Unity Docs.

It’s possible to write your own intersection-detecting code, but you might end up basically reimplementing a large part of a physics engine… when you’ve got a perfectly good physics engine just sitting there available for your use (that’s more performant than anything you’d be able to write, btw).

Any intersection-detecting code we would give you might be subject to any of the same problems that you might run into by simply using the physics engine, unless you can tell us the reasons you’re so dead-set on avoiding it.

What you want are rididbodies and triggers.

If you don’t want them to be interactable like a physics object (like you don’t want the weapon on the ground to bounce around, fall over, etc), you just need to set the Kinematic property to true. But yeah, rigidbody is the answer you want.

I’ll just leave it to anyone else who is interested in replying, okay?

I helped someone to write code you’re describing almost exactly. They used Triggers. They were picking up items in the world with a key (to add to their inventory).

Did it require Rigidbody

Your original post amounts to: “I have two things over here and two things over there, how can I figure out how many things there are? Do NOT reply telling me to use addition.”

I’m 99% certain that you don’t want to use rigidbodies because you’re misunderstanding something about rigidbodies, because rigidbody+trigger is exactly 100% the answer to your question. The reason I asked why you don’t want to use them is to either help you fix this misunderstanding, or to learn something myself, because that would imply you have some bizarre edge case that actually rules out the usage of rigidbodies.

But if you’re going to ask for help on a forum and then reject help from that forum, enjoy not learning anything and not fixing your problem, I guess.

Yes. Collisions and triggers in Unity do not happen without a rigidbody.

I was kinda going to say what StarManta wrote, in my own way/words. I got the feeling that you were opposed to rigidbodies, but you weren’t sure why. And you thought people were “forcing” you to do something you didn’t want, and not realizing that they were trying to help and not just ignoring your request. For fun, just try the situation with a Trigger + rigidbody. (yes, the person I helped included a rigidbody; it had to ** had to: much simpler)

@TheRedGuy90 I’ll be the one guy to offer an alternative solution. Sorry to resurrect perhaps an old thread.

You described:

You already stated you do not want to use rigidbodies, thus I guess you are using a character script that does not utilise the rigidbody component.

So, rather than even requiring colliders on your items…

Create a script (call it whatever you want) and drop it onto every item that can be picked up in the game. In this script’s Update() method, or a coroutine, you can check for the item’s distance to the player using Vector3.Distance.

Two variables are required: the Transform component of the player, and a float for how close you can get to the item before it gets picked up.

…Incase you don’t quite understand my wording (or anybody else):

public Transform Player;
public float distanceToCollect; // call this whatever you want

void Update () {
if (Vector3.Distance(Player.position, transform.position) <= distanceToCollect) {
// Pickup method here
Destroy(gameObject); // For keeping the playing field clean for performance
}
}

That’s the basics of it. The rest is up to you.