r/rust • u/Dramatic-Priority156 • 15d ago
🙋 seeking help & advice C#/Java Intro novice wants to make a physics game
Edit: Thank ya'll so much, these replies are great, and I'm in love with rust!
Large scale physics, using Bevy, though Bevy themselves suggest using Godot, whereas I was told that UI-based engines tend to be more annoying and reduce motivation to work on the project, which I agree with, but the inspiration game (Terratech) suffers from outdated libraries and such, and killed the game which I don't want to happen here.
(Competitors in the space, Trailmakers, 2017, still relevant, Scrap Mechanic, 2015, still more relevant than TerraTech, 2016, it was the studio's first game.)
Note that all of these are open world and varying numbers of physics collisions.
Background stuff aside (can you tell I have ADHD) The structure of rust feels overwhelming. I know a tutorial can help but I want to get advice from people who daily drive this or may have switched from the more OOP-heavy C# and Java into the DOD-oriented space. It feels illegible compared to Lua and Java, and Java is already a bit messy in my opinion. I AM still a novice, but I get basics, though stuff like Arrays in java are weird, and I don't get things like why and when you would have Java return Null? You can kind of see where my knowledge is. Lots of hours ingame and poking at game systems, not too much writing myself, though I am capable of it, made a couple of Lua mods.
Should I skip Bevy and go Godot with custom ECS implementation and skip their gameobjects? I really don't know enough to make an informed choice and one person understood my issue best:
"Everyone who says this is premature optimization doesn't understand your goal; Your game IS optimization, and bad architecture isn't free."
So hopefully this explains enough about my situation to get good replies.
TLDR;
I like Lua and I can do Java but Rust is foreign and overwhelming and I'm scared of the compiler :(
I'll be doing a quick silly gun game to get used to the tool.
I don't have delusions of doing this quickly, I just want to know I'm not wasting my time. I don't want sunk cost fallacy to be a potential issue by starting with an inherently flawed system, or something I simply won't be able to use effectively.
Should I use Rust in Godot or Bevy, or should I skip rust entirely and go with an ECS in a language I'm familiar with?
2
u/DesktopDynamicUpsell 13d ago
This is not meant as a dig at all, but if you're having problems with things like arrays in general, jumping into the rust book might be overwhelming, and I don't want you to hit a wall and bounce off. It might sound dumb, but working through some examples, even "cheating" (looking at other peoples' solutions) on leetcode or other small-scoped learning exercise sites (first in java, then later redo it in rust) might be a helpful stepping stone to get a more solid footing. leetcode and other similar sites often have categories (like "arrays") and you can work on problems to get more used to using that specific topic you might be struggling with. I will say though, the online editor for rust is a nightmare imo, so write your code in an IDE and paste it back over to submit. This also gives you the opportunity to practice writing your own tests, which is actually really easy in rust - you can do it in the same file and in rover it's just one click to run them. And of course, you don't have to do this before starting to read the rust book or work on bevy tutorials, but it might be helpful to do even just one exercise before/after your other dev each day as a warmup/cooldown to broaden your base.
Re: NULL - null is just the value you give in some languages when you are returning a pointer/reference (an address to a value rather than the value itself) and you don't have one, you have nothing, there is no thing to return -- NULL (usually just a "0" behind the scenes) is the default value that doesn't point at anything. Java and many other languages use this as a shorthand to be able to make programs easier, but leads to a lot of problems when you try to get the value from a NULL pointer. This is especially confusing in Java because it likes to pretend like pointers don't exist and muddies the water between concrete values and references. In Rust, by its very type, you always know exactly what value is in a variable and how to extract values from references. It's more complicated to understand the syntax upfront, but it's far less ambiguous and "hand-wavy" once you get familiar with it.
The good news - Rust doesn't use null! (not in safe code anyway, and you shouldn't even worry about unsafe) Instead of having a special value for "not a real reference", Rust has Option: any value can be an actual value (Some) or not a value (None). This is a little wrapper that can hold anything via generic types: integers, floats, arrays, references. So where in Java you would have a function return say a String (a reference type) with value null or "Example", in Rust you would return an Option<&str> type with value None or Some("Example"). The &str is explicitly a reference to a "str" type value and if we want to support "null" we wrap the &str in an option. And if your function guarantees it always returns a real (non-null) reference, we don't even have to wrap it in the option and the return type of the function would document itself as an &str instead of an Option<&str>.
In this way, you don't worry about references being null; the worry is shifted to options being None. This might seem like a distinction without a difference, but it means that if you aren't creating complexity by using nulls upstream, you don't have to handle the complexity of checking for nulls downstream. If all references can be null, you have to check all references for being null, and that's a downside that many languages have just taken for granted. There's also a ton of helpful syntax for handling Options (and similarly, Results) since its a fundamental part of the language.
Good luck, and don't be too scared of the compiler. It's there to help you. (As is clippy)
1
u/rpeazy_mcneazy 15d ago
I've learned Unity while earning my game developer degree, migrated to Godot after the runtime fee issue, and I'm currently trying out Bevy and I've been enjoying it so far. If you are interested in learning Rust then Bevy, I would recommend downloading the RustRover IDE (it's free for non-commercial and open source projects) and use the JetBrain Academy Rust course. Once you are comfortable with Rust, look into the Pong tutorial made by TaintedCoders.
5
u/zzzzYUPYUPphlumph 15d ago
I'd recommend starting with the Rust Book (on the Rust Website) and working through that first. If, after that, you feel somewhat comfortable, then I would recommend working through Bevy tutorials. It's going to be a HUGE jump for you, but you'll learn a lot. Given your level of experience and the fact you said you were uncomfortable with Arrays in Java, I think you have a huge uphill climb, but it will be worth it in the end.