#"March in place dynamic"

1 messages · Page 1 of 1 (latest)

wicked bridge
#

I posted some source code and a video code walkthrough for a "march in place" locomotion provider to my github. This is me being excited about learning and hoping to start a discussion around source code. In open-sourcing the code, in terms of remuneration, this is basically anti-self-promotion but if anyone objects to this message just delete it or ask me to delete it. https://github.com/shalperin/YouDontNeedA_Treadmill

[edit] I realized that all of the boilerplate in this project is obscuring the fact that it is only meaningfully 3 scripts. The path to that is Assets/_UDNAT/scripts

GitHub

March-In-Place-Dynamic | Unity, Quest. Contribute to shalperin/YouDontNeedA_Treadmill development by creating an account on GitHub.

stuck mauve
# wicked bridge I posted some source code and a video code walkthrough for a "march in place" lo...

I don't have any specific opinion here on if this is self promotion or around open source code.
Just that these coding channels are used more for specific questions. You likely aren't gonna find anyone willing to download a project and watch this video just to discuss your setup here. If you're asking for a code review, since that tag was used, then directly as for one and point to relevant code files you want.

wicked bridge
stuck mauve
#

im not sure if you understood what I wrote, in that this thread likely wont get the discussion you're looking for. I was referring to you specifically when I mentioned the code review, because you used the code review tag.

#

These are meant for specific questions, not just general discussion about what people make. Mostly because there isn't actually anything to discuss if you don't have a specific question

alpine hollow
wicked bridge
#

Also I admit I probably should have pointed to a specific commit rather than the whole repo. Again it's 3 scripts but that's obscured by the chaos of the Assets folders. So apologies on that front!

stuck mauve
wicked bridge
#

So I'm a little hung up on this critique of process. Backing up a second, many of us are working in isolation post-covid and after the meltdown and layoffs in the tech industry. My experience, which I assert is the normative experience around code review, is that one submits a link to a specific commit looking for comments on architecture, approach, glaring concerns which the author hadn't thought about...etc

In that code review is different from "fix this for me" or "tech support" requests.

I think I was aspirationally posting to this channel in the hope that if anyone took time to respond they would be interested in acting as a teammate -- if only momentarily for the duration of the code review.

wooden plinth
#

i don't think anyone is actively objecting to this post, just confused on what your intent is

#

code review isn't an uncommon thing here

wicked bridge
#

Just marking this (my) thread as the place I stopped responding and asked (in a separate message) for feedback from moderators.

copper holly
#

I generally agree with bawsi - you typically won't get a while project or even system review here, simply because of how much effort and time it takes. Normally I'm getting a salary for code reviews, and as you might have guessed, no one in this discord is getting paid for code reviews.
It doesn't help that I need to open github and navigate to the actual scripts manually.
Sharing just the relevant scripts(especially since it's just 3) according to the code sharing rules, and providing a short overview of the code and it's purpose(it's not obvious what the heck "march in place dynamic" is) would make people more likely to help you. Mentioning open source and whatnot doesn't help either. You have code like that and a lot better all over the github. There's no need to imply that you're making some kind of huge contribution to the community at your expense. Being a bit humble can get you a long way.

However, since it's only 3 scripts and I was bored enough in the transport, I had a quick look. Should note that I can't comment at all on the VR side of things. For that you'll probably need to ask in the vr channel.
Other than that, the code is simple enough, to a degree that there are only code style and conventions issues I can spot:

  • Usage of public fields in a class. In a serious scenario(a gamedev company) that would be the first thing to rewrite. Use private serialized fields instead and properties if you need them exposed.
  • Abuse of vars. While it's not bad in itself, using them too much can make the code less readable and you might even make actual mistakes due to misunderstanding what types you're actually working with(float vs int confusion for example).
  • There are a few broken indentations.
wicked bridge
# copper holly I generally agree with bawsi - you typically won't get a while project or even s...

Appreciate you taking the time, especially the comment about public fields. Thanks!

100% agree that the expectation someone is going to sift through an Assets folder to find 3 scripts is a broken one.

This was unnecessary though, I get that Discord has a certain tone, but geeze:

"Mentioning open source and whatnot doesn't help either. You have code like that and a lot better all over the github. There's no need to imply that you're making some kind of huge contribution to the community at your expense. Being a bit humble can get you a long way. "

You prefaced your comment that VR was not a context you are familiar with. However, the significance of a working march-in-place or walk-in-place dynamic is that eventually omni-treadmills will be a reality. Any project written with 'udnat' could be ported to that hardware in about 3 seconds.

Just as a footer (interpret the tone of this paragraph as appropriately tongue-in-cheek 🙂 ) - one of the things I struggle with on Discord is that people don't put many meaningful links in their bios. I might not have included the bit about the gratuitous comment on humility if I could easily surf to your github or linkedin or whatever and see how worried I should be about wasting your time.

#

Just writing up the previous comment about public fields versus private serialized fields. TIL...!

1st - both are editable in the inspector.

However, the difference between the two flavors below is that no one can programmatically munge "speed" from a script when the private serialized field is used.

public float speed;

[SerializedField] private float speed;

In the second case, this code will fail:

var comp = go.GetComponent<PlayerMovement>();
comp.speed = -100f;

Additionally you could provide a public API for setting speed as in :

public float Speed
{
    get => speed;
    set => speed = Math.Max(0, value);
/// forbid negative speed
}   
stuck mauve
stuck mauve
# wicked bridge Appreciate you taking the time, especially the comment about public fields. Tha...

About that part which you said was unnecessary: I'm sorry but anyone who's worth listening to would say the same statement. I even thought the same when reading this is open source, I just didnt say it.
The "open source everything" ideology just doesnt make sense in this context. Some may make games as a hobby but there's always some possibility of making money. Open sourcing everything you do will take away from that.

#

Being blunt as possible here, because I couldn't find another way to word this.
If you're going to open source something with the intent other people will use it, you should already know everything dlich told you above. Even if its free, people are going to expect quality if they're taking a gamble using your system in their game. Time is money, people wont be happy if they implement a system you made and find it fails to meet expectations 2 months down the line. You wouldnt want something poorly made associated with your name.
Incase anyone doesnt agree with me on this harsh reality check. There are youtubers, like brackeys, who we actively tell people not to use as a resource because of the amount of bad content he has put out. He could publish the best movement tutorial tomorrow and id guarantee most of us would still keep the same rhetoric to not use his videos.

tribal sinew
#

Really just dumbs down to "the fastest someone can help you the more likely someone will help you"

copper holly
wicked bridge
#

Is this a pattern or anti-pattern?

        [SerializeField]
        [Header("Runtime state exposed publicly as IsWalking")]
        private bool _isWalking = true;

        public bool IsWalking
        {
            get => _isWalking;
            private set => _isWalking = value;
        }
#

sorry about the indent

copper holly
#

It is the the correct way to expose access to fields to outside the class. It's neither a pattern, nor an anti pattern.

wicked bridge
#

sheesh. I'm never going to get used to Discord tone.

copper holly
#

Just correcting the terminology to avoid misunderstandings.
A singleton is a pattern(or antipattern depending on who you ask), a factory is a pattern.

Properties are part of the language syntax and a common convention.

Just to make it clear, asking if a property is a pattern or antipattern is like asking if a brick is a good building/structure or not.

wooden plinth
#

you could also use autoprops to make it more concise

#
        [field: SerializeField]
        public bool isWalking { get; private set; }
#

though,

[Header("Runtime state exposed publicly as IsWalking")]
you shouldn't serialize states

#

if you want to view them in the inspector, you can use the debug inspector to do so

wicked bridge
#

OK awesome. I did not know about [field: SerializeField].. I'm assuming it serializes the auto-generated backing prop? I'll have to try it.

My argument for serializing the state (although I defer to you that it is wrong) is that it self-documents the component's API.

wooden plinth
#

I'm assuming it serializes the auto-generated backing prop?
that's correct, yeah see dlich's answer below

#

it self-documents the component's API
i don't see how serializing it plays into that at all

wicked bridge
#

I get that. For me it's just... 6 months from now when I look at the WalkingEngagedProvider GameObject, and see that the component has this note "runtime state, this field is publically accessible via IsWalking" I'll know immediately what it does without spelunking into the code. It's just a stylistic thing that might or might not be forbidden by local convention in a commercial context I guess.

tribal sinew
#

the name conveys the same amount of information

copper holly
#

*backing field. Not backing prop. Terminology is important.

wooden plinth
#

i would argue the "exposed" is also part of public rather than SerializeField

#

SerializeField doesn't expose anything, it just makes it serialized

wooden plinth
tribal sinew
#

I agree vibe wise but in this case the act of serializing a runtime field and not using hideininspector is an intentional act to expose it to the editor, which the header is the context we're talking in, no?

#

(i should have put an arrow on both :P)

wooden plinth
#

uhh, 🤷 to that i guess. i'm focusing on the fact it shouldn't be serialized

wicked bridge
#

The other reason for serializing it is I can twiddle IsWalking manually in the inspector. Although I admit ignorance about the debug inspector( which I have to read up on)

wooden plinth
#

serializing it removes control over the default state

tribal sinew
wooden plinth
#

the = true; becomes the default value when creating the component, rather than the initial value at runtime

wicked bridge
#

good point. I think that's another argument for serializing it... I haven't decided if I want the game to start with walking on or off and it might be dependent on which scene the component is included in.

wooden plinth
#

then it wouldn't be just a state, which would probably make it harder to work with - that would turn into an issue of architecture

wicked bridge
#

learning a lot here 🙏

wooden plinth
#

being a state means the runtime controls it, and initial config isn't super important

making it not just a state isn't "wrong", it just changes the scope of the field, and that can introduce complexity

wicked bridge
#

I think 'scope' is the right word there. I don't want someone to call GetComponent<WalkingEngagedProvider> and set the boolean. But I do want to be able to set it myself when directly looking at the GO in the inspector.

#

I'm onboard though. I get what y'all are saying.

wooden plinth
wicked bridge
#

totally. I have to experiment with that

wicked bridge
# stuck mauve Your messages feels completely AI written, while also not at the same time. Fro...

While I do use AI, usually at the function/method level to generate and evaluate code, I basically never use it to write english for me. At the risk of again being accused of self promotion, you might find this interesting: https://youtu.be/lqCDy9y8oM8?si=9wC9nyRSrR1zC4Ad

If you find this really bizarre, consider how anachronistic your perspective is quickly becoming.

▶ Play video
tribal sinew
#

was ai used to generate the code your asking for feedback on

wicked bridge
#

How do you want me to answer that? I definitely use AI to remember syntax, formal parameters, and APIs.

#

I don't think that's a major admission in 2025. Maybe watch the video I just posted? The TLDR is "use AI at the method/function level, not at the project level."

copper holly
#

While using AI in itself to help with coding is not an issue, I'd definitely avoid relying on it as a beginner. Especially for syntax and basic api.
Syaing that as someone relatively pro AI on this server. Before you get rocks thrown at you.😏

wicked bridge
#

I agree, beginners should not use AI to generate code.

#

At this point I've forgotten more syntax than I currently hold in my head.

copper holly
#

Yes, and it's clear as day that you are a beginner. This whole thread wouldn't exist otherwise.

wicked bridge
#

that was really unneccesary.

#

also factually incorrect

#

I guess I'll repeat what I said before which is it would be amazing if people had useful info in their discord profiles. I don't know any of you, allthough I hope to get to know some of you.

wooden plinth
#

i don't want to get to know people here much tbh

#

or in most of the online spaces im in

copper holly
#

You don't "forget" syntax. It's like the rising a bycicle. Muscle memory. I can understand forgetting api, but forgetting syntax just means that you're not used to use it (possibly because you're relying on Ai to write your code)

wooden plinth
# wicked bridge also factually incorrect

well, you did mention you weren't aware of the debug inspector or serializing autoproperties
i'd say that's still somewhat on the edge of beginner territory for unity

wicked bridge
#

Spoken like a youngin who has only ever used a handful of frameworks to write code in.

#

(that was a response to the comment about forgetting syntax)

wooden plinth
#

ive used several languages with different syntaxes, i agree with dlich, you don't really forget it when using it

#

ive forgotten java's foreach, but that's because i haven't used java's foreach in a heck of a long time

#

(and also every goddamn language does it differently lmao)

wicked bridge
#

that makes me smile

#

there is more life to live

wooden plinth
#

also, writing code by hand just gives more practice lol

#

i can get codegen simple idioms, like "generate getters and setters" for some field in java (where that's the norm)

#

but generating logic? no thanks lol, i'd rather know what's going on myself

copper holly
wicked bridge
#

Frameworks are related to syntax if the frameworks use different languages

wooden plinth
#

no, that's just not it

#

frameworks can be related to language.
language can be related to syntax
frameworks aren't related to syntax - that's just not a consideration

copper holly
wicked bridge
#

Sure.

I've been on both sides of the AI debate. I think I could work effectively on a vibe-code cleanup crew (I love Alberta Tech's channel on YT). In 2025 though I think I wouldn't hire you if you insisted on writing everything by hand, including boilerplate, including logic that's easy to specify in an NLP prompt but arduous to hand code..

wooden plinth
#

cool, wouldn't want to work in an ecosystem like that either

#

oh, yeah i didn't take it personally, i assumed it was an abstract "you"

wicked bridge
#

ok awseome

#

sorry

wooden plinth
#

that's a discord feature, s/x/y replaces x to y in your previous message as an edit

#

basically sed syntax, it's an easter egg

wicked bridge
#

fun stuff

#

[references deleted message about sed easter egg]

wicked bridge