Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411281 Posts in 69324 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 11:35:08 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityDevLogsGearBlocks - Build working physics based machines and mechanisms [EARLY ACCESS]
Pages: 1 [2] 3 4 ... 12
Print
Author Topic: GearBlocks - Build working physics based machines and mechanisms [EARLY ACCESS]  (Read 51517 times)
Conker534
Guest
« Reply #20 on: February 20, 2014, 07:39:18 AM »

This, looks, awesome.

Bringing back memories of creating shitty vehicles in Little Big Planet, but only now the vehicles will make sense.

Seriously can't wait for something playable.
OH there is! Well I know what I'm doing then.
Logged
dangersam
Level 2
**



View Profile WWW
« Reply #21 on: February 21, 2014, 10:24:06 PM »

Attachment indicators

I’ve added new indicators that show the attachment points between parts, these indicators appear when a construction is frozen.  There are two types of indicator, one for rigid attachments, and one for rotating attachments.  I had to add extra data to the constructions for this, which unfortunately meant a change to the save game format, so old save games likely won’t load properly.

Rigid vs. rotating attachments

For a while now it’s been possible to attach blocks to axles either rigidly or free to rotate (pressing E to cycle between these two modes when a construction is selected).  However, gears and wheels could only be attached rigidly to axles.

Well, now gears and wheels can also be attached free to rotate, just like blocks.  This opens up more possibilities when building, but it does mean you have to be careful to select the correct attachment mode for what you’re trying to do.
« Last Edit: February 22, 2014, 01:08:07 PM by dangersam » Logged

dangersam
Level 2
**



View Profile WWW
« Reply #22 on: February 28, 2014, 07:18:08 PM »

Physics rigidbody mass properties

Unity’s physics automatically calculates the centre of mass and inertia tensor for a rigidbody based on the colliders attached to it.  The PhysX API allows you to specify a mass or density per collider, but unfortunately Unity doesn’t expose this, it just assumes a uniform density.

Given that the parts you build from can have very different densities based on their material (e.g. wood vs. metal), I wanted the centre of mass and inertia tensor of a construction to properly reflect its constituent parts.  So, after writing a whole load of code that essentially duplicates some PhysX functionality, per-part densities are now taken into account when calculating the total mass properties.

This is more physically correct, but what’s the practical benefit to the player?  Well, when building you can now decide to use heavier parts to affect the stability of your constructions (e.g. use metal parts for the chassis of a car, and lighter materials for the body, to give it a lower centre of gravity).  This will have more benefit once there are more part assets made from a greater variety of materials.

TL;DR The materials that parts are made from now affects physics game-play, not just the visuals.
Logged

FairlyIncognito
Level 0
*


Maker of things.


View Profile
« Reply #23 on: March 01, 2014, 04:18:44 PM »

Tried for a while to make the electric motor rotate a gear on an axle, but never got it to work. Am I missing something obvious? Tried for quite a while in every imaginable way (I feel).

Other than the issue, it's very promising. Could I get it to work, I'd enjoy it a ton I'm sure.
Logged
dangersam
Level 2
**



View Profile WWW
« Reply #24 on: March 01, 2014, 04:39:33 PM »

Tried for a while to make the electric motor rotate a gear on an axle, but never got it to work. Am I missing something obvious? Tried for quite a while in every imaginable way (I feel).

Other than the issue, it's very promising. Could I get it to work, I'd enjoy it a ton I'm sure.

Hmm, I really need to figure out a way to make the UI more obvious. Smiley

Once a motor is switched on (by hovering over it and pressing E), you hold Shift + A/D or W/S to control it.  To configure whether the horizontal or vertical directional controls (i.e. A/D vs. W/S) drive the motor, you have to hold Shift + E while hovering over it, which brings up its configuration dialog.  Hope this helps!
Logged

FairlyIncognito
Level 0
*


Maker of things.


View Profile
« Reply #25 on: March 02, 2014, 07:31:07 AM »

Ah, that worked Smiley Thank you.

And remembering to unfreeze ones construction is also VERY helpful Shrug
Logged
dangersam
Level 2
**



View Profile WWW
« Reply #26 on: March 06, 2014, 09:14:01 PM »

Just updated the playable build with a bunch of miscellaneous small changes and bug fixes, the main ones being:-

  • After detaching a part from a construction, it now becomes selected rather than just dropping onto the floor.
  • Added a “no control” mode to the motor part behaviour, in this mode the motor runs continuously when switched on rather than being controlled by player directional inputs.
  • I (re)disabled free spinning attachments between gears and axles as it doesn’t play well with physics when the axle spins quickly (too unstable - gears wobble all over the place).
  • Fixed a bug where part attachment intermittently doesn’t work during low frame rates.
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #27 on: March 17, 2014, 10:32:15 AM »



New part added: Servo motor

Frustratingly my video card died last week which slowed progress quite a lot (I’m resorting to my notebook PC at the moment).  However, I have added a new part, a servo motor.  Unlike the regular motor, it doesn’t spin continuously but, based on directional input, it’ll rotate between +/- some maximum angle (that you can specify).  This is intended for controlling vehicle steering (as shown in the image above), or any other situation where you need precise control.
« Last Edit: April 07, 2016, 08:21:45 PM by dangersam » Logged

dangersam
Level 2
**



View Profile WWW
« Reply #28 on: April 24, 2014, 01:50:30 PM »

Another long gap between updates I'm afraid!  I thought I'd gotten through the last of the really tricky physics issues once I'd sorted the gears, but oh no...  Over the past month I've been battling through a bunch of problems with wheel physics, but I finally have a solution that I think is satisfactory (albeit at some performance cost unfortunately, as I'll explain later).

There are two things to deal with when two physical objects contact each other (in this particular case, a wheel, and the ground), these being collision and friction.  In Unity, you'd normally just attach colliders to your objects, and leave it to PhysX to take care of it all, but this is not particularly well suited for wheels.  First of all, there are no colliders available that properly match the shape of a wheel (i.e. a cylinder), and that also roll smoothly across the terrain, really the only options are a sphere or capsule collider.  Secondly, you don't have enough control over friction, which is particularly important for wheels / tires.  Unity's built in wheel collider is a specialised solution that includes a spring / damper model, and must be attached to a vehicle chassis, not directly to the wheel itself, so it is not suitable for my purposes.


Various attempts

I tried several approaches to deal with the wheel to ground collision and friction response, which I'll briefly go through now.

Built in collider

Until now the wheels had been set up to use a capsule collider, but this doesn't conform to the wheel shape, the capsule ends stick out of the wheel itself which means the wheel can't tilt over properly while contacting the ground.  I even tried using a mesh collider to approximate the cylindrical shape of the wheel, but because it is faceted it doesn't roll smoothly across the ground.

Raycast to find ground contact

Given that using a built in collider wasn't going to work, the first thing I had to do was find the wheel's contact point with the ground for myself.  To do this, the wheel fires raycasts towards the ground (perpendicular to its rotational axis) to find a contact point and normal.

Custom constraint solver

I implemented a constraint solver that resolves the collision by calculating an impulse along the contact normal to push the wheel away from the ground so that it doesn't penetrate.  It also finds an impulse (tangential to the ground contact) to resolve friction, using a simple Coulomb friction model.  Essentially, exactly what PhysX does internally to resolve contacts, except now I'm able to use my own contact points.  This took a while to code up as I had to brush up on my physics knowledge a fair bit, it's very easy to screw things up and introduce energy into the system if you're not careful!  Once I got it sorted though, it worked great, the wheel rolled smoothly across the ground, was able to tilt over properly, etc.

However, there was a problem, with heavy constructions the wheel would sink into the ground and spring back out.  This is actually a similar issue to the laggy springiness my gear constraint solver suffers from.  I think it's because my solver update runs independently of the PhysX internal solver updates, and so doesn't get a chance to properly "compete" with the built in constraints (joints etc.)

Configurable joint

So, rather than use my own constraint solver, I tried to recreate it using a configurable joint (as available within Unity), connected to the wheel's rigidbody.  Every update the joint gets repositioned above the ground contact point, and has a linear limit set up to prevent the wheel going below the ground, thus providing the collision response.

For friction, the configurable joint's velocity drive is set up to force the ground relative velocity (tangential to the ground contact) to zero.  This alone would result in essentially infinite static friction, so a maximum impulse is set on the drive.  As per Coulomb, this impulse clamping needs to be based on the contact normal impulse.  However, there's no way to find out what impulse PhysX is applying to constrain the wheel to the linear limit, so what to do?  In the end I had to estimate it by using the approximate mass over the wheel and the force against gravity along the contact normal.  Kludgy, but it'll have to do.

This solution worked nearly as well as the custom constraint solver, and without wheels sinking into the terrain, so was the one I settled on.  The only downside of this method is that when you have a lot of wheels, the configurable joints seem to incur quite a noticeable performance cost.


Hopping wheels and sagging joints

The wheel collision and friction were not the only issues to deal with.  A problem I found a while ago after adding the servo part and using it in the game to build cars with steering, was that during cornering, the lateral forces would cause the wheel (or rather the hinge joints connecting it) to flop over.  It would then lose contact with the ground, snap back, gain contact again, and so on, causing the wheel to skitter and hop across the terrain.  Also, if the construction was heavy, the joints attaching the wheels would sag under the weight.

I tried to think of ways of forcing the wheel to remain vertical to the rest of the construction, but because the player is free to build in whatever way they want, I have no way to know which direction a wheel should be constrained in.  To be honest, the physics engine isn't really designed for what I'm trying to do, normally you wouldn't model vehicle physics with joints and rigidbodies for all the moving parts, instead you'd build a specialised vehicle physics engine.  For my game I can't do this though, as players construct the vehicles themselves in game.  In the end the only fix I was able to come up with was to increase the physics solver iteration count, which has the effect of tightening up the hinge joints and lessening their sloppiness.  This comes at the cost of a significant performance hit though unfortunately.


The build is now updated with the new wheel physics so you can try it out!  I've also added a wheel skid sound effect, and fixed a bunch of bugs, including a pretty major screw up with the rigidbody mass properties update that I've now sorted.
« Last Edit: April 24, 2014, 01:56:41 PM by dangersam » Logged

dangersam
Level 2
**



View Profile WWW
« Reply #29 on: April 29, 2014, 04:09:26 PM »

Just updated the build, it has a bunch of bug fixes and minor tweaks, but the main change is that part behaviour settings are now stored when you save a game.  For example, a motor’s directional controls and “is reversed” settings will be saved, so they won’t get lost whenever you save and then reload a game.  Unfortunately, as this required a change to the save game format, old save games won’t work.
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #30 on: May 02, 2014, 06:16:40 PM »





Just took a break from working on the game, and had some fun playing it instead!  Here’s a pickup I built, it features dual motors in the back, working steering and lots of lights. Smiley  Top speed is around 160 km/h.  Being narrow and fairly top heavy, it takes some finesse on the steering not to flip it over!
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #31 on: May 09, 2014, 05:50:00 PM »

Release build only, game breaking bug, oh joy

Gah, bloody typical.  It’s Friday evening and I’ve just discovered a game breaking bug.  In both the standalone and web-player builds, it seems Unity sometimes decides not to call my “on collision stay” callback, which breaks the whole construction mechanic - it means you can’t attach parts together!  I’m not sure how long it’s been like this, I usually test the game in the editor, which naturally enough doesn’t have this issue.  Lesson learned: I really should properly test the standalone builds more often!  Hrm, it could be a while before I figure this one out… Sad
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #32 on: June 03, 2014, 01:36:31 PM »

Non-collision bug update

I’ve been away on vacation for a couple of weeks, but after getting back I’ve been looking further into that non-collision bug. After some further investigation, it turned out that not only was my “on collision stay” callback not being called, but collisions between the parts were not happening altogether. I also managed to reproduce the issue in the editor as well as standalone / web-player builds.

I haven’t found a work around yet (not sure if I even can), but I put together a special cut down version of my game project and sent it off to Unity to help them reproduce the bug. In the meantime, the game is still broken unfortunately, the only way to get around the issue is by removing and re-adding parts to your construction until Unity physics corrects itself. I hope the Unity devs can fix this issue soon, but I guess we’ll just have to wait and see!
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #33 on: June 12, 2014, 03:11:58 PM »








New time-of-day / sky system in game

I felt like I needed a change after being bogged down with the construction mechanic and physics issues for so long, so I decided to do some rendering stuff over the last week or so.  As of the latest build, I have integrated Mod Monkeys' fantastic Time of Day system (available on the Unity asset store: http://u3d.as/4fg) into the game.  It implements atmospheric scattering, dynamic time-of-day, clouds, weather etc. and is really nicely done, a quality asset.  It wasn’t quite a straight drop in for me, as I had to apply the scattering to my terrain shaders and make a couple of minor mods, but overall it was very easy to integrate.  So far I have the time of day changing as you play, but the weather doesn’t do anything yet, I’ll have to look at hooking that up later.

Next up for me is back to the construction mechanic.  Still no word on that Unity collision bug…
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #34 on: June 12, 2014, 03:22:32 PM »








Time-of-Day timelapse

Having too much fun playing with this at the moment… Smiley
« Last Edit: June 12, 2014, 04:50:32 PM by dangersam » Logged

travisofarabia
Level 0
***



View Profile
« Reply #35 on: June 12, 2014, 04:45:42 PM »

Hey, This looks like tons of fun. I'm using Chrome and the game loads to a black screen? After I select play from the map seed menu it loads and I can open the inventory and options and everything, I can even hear the sound but visually nothing. The speed and altitude update as I use the controls as well, I attempted lowering the graphics thinking it may be that but to no resolve. Any suggestions?
Logged
dangersam
Level 2
**



View Profile WWW
« Reply #36 on: June 12, 2014, 04:47:53 PM »

Hey, This looks like tons of fun. I'm using Chrome and the game loads to a black screen? After I select play from the map seed menu it loads and I can open the inventory and options and everything, I can even hear the sound but visually nothing. The speed and altitude update as I use the controls as well, I attempted lowering the graphics thinking it may be that but to no resolve. Any suggestions?

Hrm, that's odd.  Did you try turning off HDR in the graphics settings?  Sometimes the HDR auto exposure can go a bit screwy.
« Last Edit: April 07, 2016, 08:34:32 PM by dangersam » Logged

dangersam
Level 2
**



View Profile WWW
« Reply #37 on: June 20, 2014, 10:46:46 PM »

Deleting attachments

Over the last week I’ve made a couple of changes to the way parts can be detached from one another.  Firstly, when you right-click a part, all attachments connecting that part are now deleted (not just hinges only or rigid only).  Secondly, and perhaps more interestingly, attachments can now be deleted individually.  This is done by hovering your cursor over the attachment to highlight it, and then right-clicking it.  For example this allows you to detach and re-position an entire sub-section of your construction by deleting only those attachments that are connecting it.  Remember though, stuff will stay attached together until all attachments connecting them have been severed.

Hopefully these changes will make it easier to modify your constructions, re-position things, and so on.  The plan is, in addition to deleting, you’ll soon be able to make modifications to highlighted attachments.  Hopefully I’ll have this done in the next week or so!
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #38 on: June 26, 2014, 04:25:49 PM »

Couple of updates in the build...

Attachments

Previously, when attaching parts together with a hinge, the game would attempt to remove any rigid attachments that would prevent these parts from rotating with respect to one another.  Now that you can go in and delete individual attachments after the fact, I’ve removed this behaviour as it was somewhat arbitrary.  At this point I think it’s better to leave it up to the player to decide which attachments to delete.

In conjunction with this, any hinges whose connected parts can’t rotate (due to being also rigidly attached in some way) are now highlighted red.  This will hopefully help you debug stuff in your constructions that isn’t rotating as you want it to.

Physics collisions

Up ‘til now, subsections of constructions that were directly attached together with a hinge would not collide with each other.  As of Unity 4.5, the PhysX flag that enables these collisions has been exposed, so I’ve now enabled it in game.  No more parts passing through each other, woop!
Logged

dangersam
Level 2
**



View Profile WWW
« Reply #39 on: July 07, 2014, 01:10:43 PM »



Alignment indicators

When aligning a selected part to another (frozen) part, prior to attachment, the game now shows where the available attachment points are.  These indicators reflect the type of attachment, either “surface” (e.g. as in block to block) or “interior” (e.g. as in block to axle).  The idea is that this should make it easier to accurately position parts where you want them.

Other stuff

In order to implement the alignment indicators I had to refactor a bunch of code, one side effect of which was that I was able to slightly reduce the per-rigidbody network data by calculating more stuff on the client side.  I also fixed a bug in explore mode, that was causing parts to not spawn.
« Last Edit: July 07, 2014, 01:17:14 PM by dangersam » Logged

Pages: 1 [2] 3 4 ... 12
Print
Jump to:  

Theme orange-lt created by panic