-1
\$\begingroup\$

I'm not good at Coding or C# and I've been looking around the internet but couldn't find the answer that I was looking for.

I'm using Unity and I want to make an AI somewhat like The Sims, That just walks around aimlessly and maybe interacts with other objects and interacts with the player if the player interacts with the AI. (like the player just talks to the AI)

This is my first time posting and I'm not confident in C# so thanks for the help.

\$\endgroup\$
4
\$\begingroup\$

I would suggest as a starting point, that you get some sheets of clean paper and structure what you want to happen. Your phrasing on the question is vague, at best, so you need to clarify things in your plan down to boolean (true/false) values for a computer to understand.

You want your AI to "wander around". Does that mean they wander in random directions? What would be a minimal length of a directon (It can look meaningless of the scale of your random walk is gameworld millimetres rather than metres, for example).

Then you want your AI to "interact" with objects. Which objects, what is the criteria for interactions - proximity? time of day? mood?

You need to set a clear process tree and for each subroutine, such as "pick up desk lamp and wave it around for 5 seconds", you need to set what criteria needs to be forfilled by your AI before this event is begun, such as

  • "is AI within 5m of a desk lamp?",
  • "is AI script state marked as "bored" " ,
  • "is AI marked as Awake" (rather than sleepwalking!)

If these criteria are all true, then you can start the "play with desk lamp" subroutine,

Etc. etc.

Overall I would suggest you need to really clarify the behaviours and routines you want to create, and what would cause them and enable them. Then once all these "factors" are set out clearly in your mind and in your plan, you can work on coding each one, one by one, until you have a full behaviour setup.

Good luck.

\$\endgroup\$
  • 3
    \$\begingroup\$ The way to interact with an object, in games like The Sims, is integrated within the object data, and it tells the Sim how to use it. Your answer is good to get the ball rolling, though :) \$\endgroup\$ – Alexandre Vaillancourt Dec 9 '16 at 13:09
  • 2
    \$\begingroup\$ gameai.com/wiki/index.php?title=The_Sims provides some more info on @AlexandreVaillancourt 's comment \$\endgroup\$ – Niels Dec 9 '16 at 13:57
2
\$\begingroup\$

This is how I would do what you call an "AI like Sims" in a simplistic way:

bool canRoam = true;
void Update()
{
if(canRoam&&!isNearInteractable)
    {
    RoamAround();
    }
if(isNearInteractable)
    {
    InteractWithObject(ObjectID);
    }
}
void onPlayerInteraction()
{
    canRoam = false;
}
void onPlayerInteractionEnd()
{
    canRoam = true;
}

Of course, those functions have to be custom made and yes you will need to get better at C# if you want to code AI. There's no way around it other than using Unity assets from the store (which would still mean getting better at C#). Try something easier first, make an object move around randomly.

Two "objects" interacting with each other means you have to learn how to send and receive messages or how to raycast. There is no easy way of doing this. (Other than getting ready to use assets in the store of course and that would mean learning to use said assets, which is still not easy.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.