Advertisement

Finally starting

Started by July 08, 2015 06:22 PM
13 comments, last by dtkaos 9 years, 3 months ago

Feel free to PM with any questions, and hopefully I will be able to help.

I'll PM you for future reference. Thanks.

Thus far, I've underestimated the knowledge requirements for everything that I've tried. I was able to actually do what was laid out, but I couldn't make sense of what was going on and wasn't learning anything. I decided to start even smaller and eventually found this:

http://www.thegamecontriver.com/p/unity-2d-car-physics.html

I've successfully created the first version and am on to the second. Maybe my thinking is off, but I do believe that this is a good route to chase as it involves the lower levels of in-game physics.

Visual studio is proving to be easier to use. I think I'll stick with it.

I've successfully created the second version and I'm now trying to attach suspension to it. I've got the shocks divided into 2 parts: body and shaft and have them inserted as sprites. I can attach the shock body to the car and the shock shaft to either the shock body or car and they move with the car when playing, but I don't know where to start with getting the shock shaft to actuate with the wheel travel. For a better picture, I'm trying to get the shock shaft to move along the same axis as the shape of the shock body sprite.

I think binding it to only move along the Y-axis would be a simpler route, but I would eventually like to have them move as a real-world shock would (compress/decompress with motion) and unbound by an axis.

I've tried to apply a spring joint and wheel joint with the shock shaft and neither seem to work. I've set box colliers around the shock body on either side and have another on the shock shaft that allows a small amount of clearence on each side, but that seems to be all but useless at keeping the shock in check.

What approaches shoud I consider when doing this? What C# coding would be required for this to work?

Advertisement

Also, is there any way to dictate the speed at which spring joint or wheel joint compresses and decompresses? I've tinkered with the settings, but neither seem to do much to affect anything other than overall stiffness. If this is impossible, I'll be looking at alternatives to Unity as the ability for users to adjust this is one of my main goals.

For a clearer picture on what I'm trying to replicate, I'll try and briefly describe the adjustable functions that I'm shooting for.

1. Multiple rate springs - softer in initial compression, stiffer as the shock approaches 100% compression.

2. Preload adjustment - stiffness of the actual springs.
3. Compression adjustment - additional resistance that suppliments the spring resistance when the shock compresses

4. Rebound adjustment - the resistance force that slows the spring on decompression/extension.

This may provide somewhat of an idea: http://www.houser-racing.com/upload/images/Shocks/Elka_Stage_4_Front.jpg

These are very important, especially the last 3.

you may want to, at this point, defer for a more thorough review of physics, spend a few weeks browing or such. or maybe go through works with the game engine you picked.

my implementations are bastardised, uncorroborated, and just code, no game engines. don't know anything about them.

mass-springs undoubtedly have many references in physics simulation, i'm acquainted with them through audio modeling and originally from programming many decades ago as a child.. like if you are a kid and decide to make a bouncy ball algo, you soon realise you need to record the previous state, or velocity, and develop some form of harmonic oscillator............

i have a bit on harmonic oscillators here - http://www.xoxos.net/sem/dsp2public.pdf

basically, if you have two numbers, a location and another thingy, updating each other, you can control the rate of oscillation with angular velocity.. w = 2pi * f / fs :) depending on how your #s are arranged, either w will set the rate of oscillation/springyness or k, which is effectually -w * w - knowing that you can wheedle stuff to find rate (unstable higher than samplerate / 4)

there's a few rolls of the mass-springs in my pdf, and you're sure to find better stuff for games elsewhere using those terms, but they'll work.

piston thingy at an angle (i know zero about cars) use the mass-spring to modulate the magnitude of the piston as a 2d vector (scale both axes similarly).

neither a follower nor a leader behttp://www.xoxos.net

I don't know anything about Joint2D or really anything about the Unity. It has been sometime since I have worked Unity with when my skills were much more amateur.

But from looking at this: http://docs.unity3d.com/ScriptReference/Joint2D.html

It's maybe that the features you are looking for are not within this API, which means you would have to code these yourself unless you are able to work with what you are provided to get it to work. I believe the first part of the tutorial is great for a new programmer or getting aquinted with the Unity software, but I believe you may need to step down a bit, and understand classes and objects a little more so you can added theses specific features yourself.

I know is not what you probably want to hear, but I am just being honest.

This topic is closed to new replies.

Advertisement