Im making a game, and stuck with this mechanic, i know that this system can be done with rigidbody joints or something idk. I need it exactly like hl2, so the props doesnt rotates, dont goes through walls, cant boost player in sky. Help please!
With a requirement like this:
You will not be able to succeed until you can decompose that into the parts of whatever it is that makes it “exactly like hl2.”
Get started on some tutorials for pickups. Your best bet will be to get any kind of random pickup system fully working, then when you have identified how it differs from hl2, change the parts until it matches.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Imphenzia: How Did I Learn To Make Games:
Well, “exactly” is already an issue depending on what physics engine you plan to use. When you use “normal” gameobjects and rigidbodies, you will be using Nvidia’s PhysX engine while HL2 / Source uses a modifed Havok engine.
Unity actually has collaborated with Havok to create their DOTS physics engine. I can’t say how similar it will be to the exact implementation the source engine may use, but it may have a better similarity.
Now it gets very specific and some of the things you mention just aren’t true ^^. Prop-flying is specifically a source thing, especially known from Gary’s Mod but various kind of prop launching / boosting is still a thing. Some source games tried to “solve” some of the glitches by simply disabling the collision between the carried item and the player and / or if a collision is detected it simply stops carrying. Those changes have made prop-climbing quite difficult lately, but it still works in most source games.
As for “not rotating” this is not really true. Picking up a prop with “E” will automaticaly snap / rotate the object to the closest orientation so the closest cardinal direction points up. That means grabbing for example a barrel that is slighly tilted would align itself when grabbing it. Of course all those adjustments are done through applying correction forces over a small time span. Note that the “gravity gun” actually works quite different. It actually freezes the rotation the moment you grab the object and the object rotates with the player while objects grabbed with “E” do not rotate with the player.
Carrying with “E” does not really “attach” or parent the object to the player. Instead you have a reference position in front of the player and the prop is simply moved towards this position every frame with forces. So the object would naturally get stuck at a wall when you move your reference point into / behind the wall.
The exact behaviour has many many tiny details to it that you most likely have to account for yourself. So you may want to jump into the game again and doing some experiments and observations in order to first determine the exact behaviour that you want. Of course Valve put a lot of efford into preventing certain bugs and glitches, especially when they are game breaking. They weren’t that keen to make it perfectly realistic or prevent any glitches at all. It just has to be good enough so it does not accidentally get in the way of the intended gameplay. At the same time it still leaves options for speedrunners ![]()
We can’t tell you every detail they may have considered since we have never seen the source code. So you can only do black box analysis.