Move function poorly named?

Isn’t that a relatively bad name for the second move function seeing as we are setting the movement to vector3.zero… which really is more like… stay?

Not really. We are not making a new function, we are just creating a new instance of our main “Move” function. If you look at any Unity Method, most of them have multiple versions of themselves with different arguments.

In the screenshot Vector3.SmoothDamp() has 3 versions of the same method - each with different parameters. If you do not fill one, Unity will use a default value - the same thing we do with our Move function.

Unity Doesn’t show you 2 Move functions, it displays multiple options for it.

You can read more about this here Methods In C# | Part 2 - Multiple, Required And Optional Parameters + Named Arguments | Unity Game Development Tutorial - Bite Sized Tech

Hell Mihaivlad,

I think your post doesn’t really address the point I was making.

Namely, we hardcode a movement of zero into the function, and because of this , the name “move” for the function is quite misleading as the movement is to no where. Instead, if would be more sensible to create the function and name it, “Stop” or “Stay”, that way, there is no ambiguity as to what the function does when it is called from the outside.

Hope that helps.
Kindly,
A

This isn’t truly a Stop() method as part of the reason we are rolling a Move() method in the base state in the first place is so that we can add the ForceReciever’s output to the output of the Move(). Stop() would be misleading because unless there is no force applied from the force receiver, the character won’t always stop.

That being said, you can always name the method Stop() if you wish.

Hey, @Aionlasting, Yes, you’re right. From a semantic point of view, you can rename the function however you see fit. However, as Brian points out, we still “move” via outside forces. From a learning/teaching point of view, I still think this was an excellent opportunity to showcase what I mentioned in my previous post.

1 Like

If we are going to be technical and argue about it, one could say that stay, stop, also implies force, as when you stay in a position, gravity doesn’t suddenly go out the equation. Similarly with this move function. I have decided therefor to name it “Stay” as that is what we are doing. Thanks for the discussion!

Let’s hope we can all see this is more of a spirited debate than an argument. The most important part of any method or variable name is one’s ability to discern what is going on with a simple reading. I like to call this the six month test. If you look back on old code and you can’t figure out the purpose of a variable or method, then it’s probably named incorrectly. In a team environment, this becomes even more important.
By that token, Move with no destination, Stop, or Stay are all actually fine, as long as that’s the thing that you’ll remember six months from now when you look back over your code. It’s your project, and there’s absolutely nothing wrong with customizing the code to suit your needs. I do it all the time.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms