Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics Materials members

Discussion in 'Scripting' started by Ajaxamander, Jul 19, 2005.

  1. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    I notice in some of the built-in demos, as well as aarku's demos, the frictive properties of colliders is being defined expressly in a script, which is then attached to the object. What is the advantage of this? (My next question may very well be the answer)

    So, in these scripts, they use the PhysicMaterial properties "dynamicFriction2," which doesn't really have any documentation... what does it do?

    Also, in the 8 legged robot, the comments say it uses anisotropic friction, and sets the parameter 'frictionDirection' which doesn't seem to be documented. Is this because the type he's working with is a "DynamicsMaterial" instead of a PhysicMaterial (I can't find this either :oops:)

    Any pointers about this would be much appreciated!
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    DynamicsMaterial is the deprecated name for PhysicMaterial. So DynamicsMaterial still works, but we should all be using the new name.

    The reason to set the PhysicMaterial through scripting is that currently it is the only way to use anisotropic friction. This means you can have an object slip more going forward than it would side to side, for example.

    There isn't documentation on this right now, so what I did was just based from RaycastCar. Hopefully the docs for this will be there in 1.1.

    Until then, just experimenting a lot with the constants (which you'd probably do anyways) seems the best way to get the right feel for physics properties.

    My guess is that staticFriction runs against frictionDirection and staticFriction2 runs with frictionDirection.. . or the reverse or something. :D (a test or two would show the answer)

    But yeah, I would second a request for some detailed documentation on PhysicMaterial... including the contactSpring spelled out with some examples.

    Cheers,
    -Jon
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It will both be documented and added as properties in the inspector with version 1.1.
     
  4. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    So I thought I'd try and be sneaky and pull and end-run around Unity's physics API...
    http://www.ageia.com/pdf/PhysicsSDK.pdf
    Unfortunately, the members in NxMaterial are named slightly different than they are in Unity's wrapper. (see page 59 of the linked PDF.)

    As far as Anisotropic friction, I believe you mean that you can have it *grip* in the forward direction and *slip* in the tangential direction. In racecars, for example, 'rubber on dry asphalt' has a very high coefficient of friction in the direction of travel, while it is lower side-to-side at high speeds. This is why cars can 'fishtail' around turns, because their fast moving wheels can slide sideways. Similar to your Robot, who's front and back wheels must slide sideways over the terrain while the car zero-radius turns. If the wheels slipped more 'forward' they would just spin in place when trying to drive forward! Perhaps the terminology is backwards in the RaycastCar script because it doesn't use actual wheels, it just uses the wheels like runners on a snowmobile, from my understanding. It uses the Vector3.fwd vector for the high friction, because the "wheels" slide perpendicularly to the X-axis.

    All that said, I would agree with you that dynamicFriction runs parallel with frictionDirection, and dynamicFriction2 runs orthogonal to it. And thanks for clearing up what those other members were for! Looking at this Novodex SDK... I don't even know where to begin :eek: (just reading through the table of contents, I'm glad you guys switched to this from ODE!) There's some pretty sweet stuff in there. Is there any way to know how much of this is going to be exposed through Unity's APIs?
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    frictionDirection runs along what you define in friction2.

    We are changing the naming because it is inconsistent.

    The reason it was not documented is because we didn't have the time to cleanup the interface completely before 1.0
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    We will over time expand to pretty much every feature novodex has to offer.
    It always takes a bit of time because we have to write a nice wrapper around it.
    With 1.1 we will add more joints.
     
  7. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Thanks for the link! It is going to be a good read through.

    The wheels on the RaycastCar don't actually turn, so how the friction is set up is different. The values in my robot demo probably stink - I just altered them a few times quickly as I did the whole thing in the middle of a night with a deadline... took 4 hours or so. I wouldn't analyze them too much.

    But, sounds like you've got it all worked out! :eek: Now I know who to come to to help me get my 2d vehicle physics I'm working on better. . . *grin*

    Cheers,
    -Jon
     
  8. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    Right, the "not turning" is what I meant when I compare them to the skis on a snowmobile. When I said I agreed with you about the frictionDirection being paired with the *Friction values (as opposed to *Friction2) I was misreading the scripts... the dynamicFrictions ARE in fact set up such that the low dynamicFriction2 makes sense with the direction. Mea culpa. Joe set me right :)

    (This next bit is all from memory, I haven't got Unity or your project in front of me here at work)
    In fact, you got them pretty much exactly right. For *static* frictions, you've got a very HIGH value perpendicular to the desired motion, so it won't, say, slide sideways down a hill while parked. The 'forward' *static* friction is a touch lower, a bit realistic, since it might be likely to slide forward down a hill. For the dynamicFrictions, You have a HIGH value parallel to the desired motion, so the wheels will grip when they turn, and a LOW-ish value perpendicular to the motion, so the wheels can slide while the vehicle is turning (similar to how, when a tank twists, it tears up the ground below it, since parts of the treads need to move sideways.) Fantastic guesswork, sir!

    Maybe :? but if they're going to change the *Friction2s for *Frictions, then that means all existing scripts will break. What if v1.1 makes new things, perhaps more similar to Novodex's frictionU and frictionV (but better names, of course, more descriptive of which is parallel with the 'friction direction' and which one is perpendicular?) That way old scripts could still work with the vague *Friction/2 values, and new scripts should use the new ones?

    But yes, I'd love to be able to put help and advice back into the Unity community finally! Since I've been getting such useful pointers and now actually own a Pro license :D