Help making a npc ask for an object

Godot Version

4.0 something something

Question

I am very new here, and have probably bitten off more than I can chew, but free will.

I am making a junkyard game (Voices of the Void inspired, and I want to learn how I can make an NPC who asks for a random part from a car (each car is in a separate scene, and has individual rigid body parts) that I have to bring back to him. And have a few different npc that I can eventually give voice lines and models. Also they will be in a truck probably (haven’t decided wether to make them come in the front shot or wait in their truck)

Please help, I am super new and want to learn.

Already have car some car models, and a player that can walk, run, jump, and pick up objects.

TLDR; use an area3d’s area entered signal that prompts the “exchange”, then maybe a variables in the npc’s area3d’s script that say what item they need is, to which you can compare the item the player has and the npc needs using the parameters the area entered signal calls (if area.item_npc_needs == item_holding:)

I think what you’re missing here is signals. So given they can pick up objects, i assume you have the object stored in some sort of variable in your player script or something.

There’s more efficient ways to do this but I’ll keep it simple. I think the way to go around this would be to attach an Area3D to your NPC and set its collision layer via the inspector docker to some random number. Then in your player script, create another Area3D with its collision MASK set to that same value you chose, which will allow either area nodes to detect when they have collided by connecting the area entered signal via inspector

Then the specifics from there are really up to you. The key is connecting the area entered signal. You might also need to make a custom signal too, there’s a lot of good tutorials for that. I personally like making a “SignalManager” autoload, and just dumping all my signals ordered by the sequence they’re likely to pop up with notes.

once you understand signals and maybe even classes, the sky really is the limit. hopefully that all made sense i need to sleep.

Please do not do this. If you’re asking for help, at least put enough effort into it that you look up the exact version of the engine you are using.

You can click on the version number at the bottom right of the editor and it’ll be copied to your clipboard.

Theres more than one solution but without knowing more about your project, what I think I would do is make a custom CarPart class that extends RigidBody3D, and give them a car_part_type property, if your player can bring any generic part of that type. The property can hold a simple String, or maybe a custom resource if you need to store more information about it. Make the NPC store the type of CarPart it needs. If instead the player needs to bring back THAT specific part from THAT car, then make the NPC store a reference to that specific CarPart. When your player picks up the part and interacts with the NPC with the car part in their hands, make the NPC compare either the CarPart.car_part_type properties to see if the types match, or the reference to the specific object you needed, depending on what you want.

I suggest using a state machine for your NPC, and giving them a “Waiting to ask player for part” state, a “Waiting for player to bring the car part” state, and a “Car part succesfully brought back” state.

You will also need to store the reference to the CarPart your player is currently holding somewhere in the player’s script, for the NPC to compare to what he asked for.

Look up tutorials on how to make custom classes, custom resources, state machines, and signals. You will have most of the logic needed to think of the best way to do it yourself.

I am on my phone, I couldn’t check the exact version

Thanks for the replies, I will try this put tonight. Will be back to ask more.

Would it help if I uploaded some videos here to show the current state of the project?

I can’t write your project for you but if you need help with something specific you could send your code and scene tree, and explain the intended behavior and what’s going wrong