Rat behaviour in a scene: Best approach ?

Hi all :slight_smile:

I want to integrate rats in my scene and i was wondering what would be the best approach for making them evolve from a point A to a point B.

As ideas, i have:

  • Popping a rat at A and make it move to B through AI pathfinding ( with somewhat erratic moves ? ) ?
  • Popping a rat at A and make it follow a spline ?
  • Popping a rat at A and make it move with complex C# script with randomness ?
  • Popping a Rat at A and learn how to move it with DOTs ? ( i dont need billion rats, only 5 or 6 )
  • forget about the rat, it’s just useless :stuck_out_tongue:

Note that the rat has no rig except maybe for the tail. so its a lowpoly mesh that can be considered a a point

I already hear from thos who will telle me << try every solution and choose the best >> wich is indeed the royal way but am not a studio with tons of dollars and i was wondering for advices from those of you who already ask this question :wink:

Thanks for you help and happy unitying ! :smile:

Tons and tons of tutorials for all of these different concepts.

Nobody is gonna retype a whole tutorial and technical approach tree for you here in this box.

Whatever you do, you will do it one step at a time, like this guy:

Imphenzia: How Did I Learn To Make Games:

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Finally, when you have errors, don’t post here… just go fix your errors! Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Anyone for a relevant answer ? :slight_smile:

1 Like

And what approaches HAVE you tried?

Have you tried even one approach?

I’m not sure what kind of answer you’re expecting other than the one you should already have if you want to do virtually anything with game development.

  • create a navmesh
  • create a navmesh agent for the rats
  • pick a random point for spawning (or create spawn points and choose one randomly), test if it’s not inside an object or things like that
  • pick another reasonable random point on the surface, test them for not being inside objects, etc
  • set it as the target for the agent, calculate path, execute

All these steps have tutorials online both videos and written.

Good luck! If you have any more narrow question and you stuck somewhere, feel free to ask again.

2 Likes

What I’ve done is to choose a point randomly in a circle around the destination (B) and move there for a few seconds before repeating(*). Put the destination far enough past where you really need them so that there’s no issue with wandering inside the circle. That causes everyone to weave mostly towards the target.

And, or course, add a tiny state machine – give them a 15% chance to stand around for 1 or 2 seconds, or to wander a short distance in a small circle around them; and have a 10% chance for them to move at double speed. Or to be fancy, have types of rats that prefer to go fast, or to wander or wait (I can’t recall if I did that).

As I recall, the end result looked pretty decent.

(*) I actually chose a point along that line a few units away, so that extra-fast movement doesn’t go extra far; but I suppose one could divide the movement time by 2 to also accomplish that.

2 Likes

@Lurking-Ninja Thanks a lot for your answer :smile:
As i mentioned in my 1st question i thought about navmesh but what i was wondering is if it is not overpowered for only making rats move. The good part is that it is more optimized than a C# script.
If this is the way you’d choose, i’ll give it a try :slight_smile:
Thanks again ! :smile:

@Owen-Reynolds Thanks you too for you answer :smile:
I did this several years ago ( for chickens ). It worked like a charm and was pretty convenient to have the hand on every parameter. The bad part was the CPU greed and i was wondering wether a DOTs solution wouldn’t be the right way ?
Thanks for this answer.

My question purpose is to have advice from some people who already treated those topics, just to avoid spending time at trying all possible solutions.

Thanks a lot for your answers and happy unitying !!! :smile:

I don’t understand the mention of DOTs or a nav-mesh at all. Neither seem to apply to this at all. But I could be missing something:

o DOTs is just a way of rearranging data – for speed with massive amounts of parallel data – right? “Using DOTs to move rats” doesn’t seem to make sense. It’s like saying “I could assemble this birdhouse using nails or glue, or do it over the weekend”. Yes, using DOTs or doing it over the weekend might be nice, but neither says how.

o And – last I looked was years ago – but the end-product of a nav-mesh is a path, a set of waypoints, right? A nav-mesh is great if we walk between lots of spots on a big map. But the rats just go from A to B. And if that’s not a straight line we can just hand-make a set of waypoints (or a spline).