Search Unity

Less flighty objects

Discussion in 'Editor & General Support' started by BlitheD, Aug 28, 2006.

  1. BlitheD

    BlitheD

    Joined:
    Aug 28, 2006
    Posts:
    36
    Any advice on how to make objects less "flighty" (I am not sure how else to put it)?
    When I run an object into a stationary object the tendency is for the moving object to fly right over the stationary one even at low speeds. I would like it to work like a car hitting a curb in real life - at low speeds it is deflected by the curb and at sufficiently high speeds it "jumps" over the curb.
    I have tried adjusting the moving object's mass, drag and center of mass (with the script in the race game tutorial) but have not been able to solve the problem (though I may not be getting the settings right).
    Any ideas?
    Thanks
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What are you using for a collider? Maybe the shape you're using isn't ideal for what you want.

    --Eric
     
  3. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Maybe increase friction in the PhysicMaterial(s) you're using?

    (You can make you own PhysicMaterials very easily: just duplicate one of the built-in ones and tweak it.)
     
  4. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    tough to really say but i'd bet the answer is keep tweaking drag, angular drag etc. (angular drag is how fast you slow down in the air iirc). did you try changing the object's scale? i had a heck of a time getting a good motorcycle set up. still isn't quite right but i'm getting close. scale and drag were the biggest factors.
     
  5. BlitheD

    BlitheD

    Joined:
    Aug 28, 2006
    Posts:
    36
    Thanks for your advice, but unfortunately nothing seems to be helping. I played with size and with materials and friction more but no matter what I do the moving object still flies up over the stationary one at lower speeds than what I want (anything faster than a crawl really). As to the colliders, I am simply using two boxes: the moving one at a size ratio of 1,1,2 (so it's a rectangular box) and the stationary one at one fifth the height and depth of the moving object and set at a 45 degree angle to the moving object. So it's a pretty simple setup. It seems there should be some way to make the moving object stay grounded better, like putting a weight on a radio control car or loading the family car up with tons of luggage. As it is the moving object just loves to "taste air". But I still could be using the friction wrong...
    Thanks again for responding. If anything else comes to mind please let me know.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Maybe if you uploaded a webplayer showing the problem, it would be easier to understand what exactly you get and how you want it to work.
     
  7. BlitheD

    BlitheD

    Joined:
    Aug 28, 2006
    Posts:
    36
    OK. Thank you. What's the best way to do that (I'm really new at this)? What files should I include and can I add them as an attachment here or do they need to be zipped?
     
  8. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    file menu -> build settings -> webplayer. this will generate an html page and the build. if you have your own web space post a link to the html page. if not, zip them and post the zip here. also under render or project settings (or one of the others :? ) you can adjust the resolution. the default is pretty small.
     
  9. BlitheD

    BlitheD

    Joined:
    Aug 28, 2006
    Posts:
    36
    OK. Should the ".unityweb" files work with Geocities? It won't let me upload them...
     
  10. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    probably not. i guess? both files need to be online and in the same directory by default i believe. the html doc tells your browser to load the file .unityweb and where it is. the .unityweb file is the actual game that will load when browsing to the html page. like flash. how big are they zipped? small i'd guess. zip em and post them here as an attachment. we can play them locally after dl. or email it to me and i'll post it on my site it for a bit. petem aT ocluardgi [dot] com
     
  11. BlitheD

    BlitheD

    Joined:
    Aug 28, 2006
    Posts:
    36
    Here are two examples in a .sit file. One has the variable speed set to five and the other has it set to seven. I was surprised though to see that the webplayer objects behaved differently than testing within Unity. Also, a Mac standalone that I tested had still different behavior. In Unity, with the speed set to seven the "player" flies over the "wall" almost every time. In the webplayer it sometimes stops and sometimes jumps up. Is this normal for there to be such a difference even with "simple" collisions like this? Does this mean that the objects in games will behave very differently on different machines as well?

    Anyways, back to the main problem... What I am trying to do here is consistently adjust the behaviour of the "player" (the moving object) so that it stays grounded at higher speeds (or flies off at lower speeds depending on the kind of game I'm making). For example, a brick slid across a floor would deflect off on an obstacle while staying grounded unless it was slid at a fairly high speed, right? But a block of Styrofoam on the other hand would fly up upon meeting the object at a much lower speed. It is that kind of behaviour I want to simulate. Mainly I want things to stay grounded at higher speeds than they seem to as a default in Unity.
    In my testing in Unity, the "player" is deflected while staying grounded at speed five and flies up over the obstacle at speed seven. I'd like to see it stay grounded until about speed 10.
    Use the up arrow key to move the "player".
    Any ideas?
     

    Attached Files:

  12. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    If you are using physics to move the block (i.e. AddForce), then try applying a downward force. You can make this force change with speed. The car.js script in the RaceDemo has an example of using a variable downward force. Taken from that script:
    Code (csharp):
    1.  
    2. if( isGrounded )
    3.     {      
    4.         var downPressure = Vector3(0,0,0);
    5.         downPressure.y = -Mathf.Pow(rigidbody.velocity.magnitude, 1.2) * downPressureFactor;
    6.         downPressure.y = Mathf.Max( downPressure.y, -70 );
    7.         rigidbody.AddForce( downPressure, ForceMode.Acceleration );
    8.     }
    9.  
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you're seeing differences in behavior in different situations, then you're probably not using Time.deltaTime. Which you should be using, or else different framerates make things go faster/slower. If you're using a non-kinematic rigidbody controller, then you have to be careful about not fighting the physics system or else you get weird behavior.

    --Eric
     
  14. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    boy that's really tough to tell what you're hoping for. looks pretty correct to me. i didn't mess with it very long. it's a bit hard to get the block to hit at the same angle enough to test. if it hits squarely at the 5 speed and doesn't go flying and then catches a corner at the 7 speed and goes flying, well that isn't very comparable. hitting squarely at 7 doesn't go flying either and i'd expect catching a corner at 5 would go flying. if that makes sense. are you sure it's not different collisions doing different things rather than the webplayer or different machines. i only tried the webplayer on one machine. if it's really something like that see what eric said about time.

    i also think it still might be an issue of mass, scale, drag and angular drag which you need to adjust for different objects. as well as finding the right speed. to use the brick styrofoam concept...

    brick = high mass, high drag, high angular drag.
    styrofoam = low mass, low drag, really low angular drag.

    slide a brick across the floor square at a board. slow it will bump and stop. faster it will bump, wobble and stop. really fast and it will roll over and tumble away. do the same thing but aim it at an angle and you'll get different results. that's what i got when looking at the webplayer.

    styrofoam on the other hand would lift off the ground with very little speed even before contacting the board if fast enough. to simulate that try a near zero angular drag and a low mass. tweak drag so it doesn't speed off too fast but i'd expect it a pretty low number too.

    for both, scale will impact your results. so you need to play with that too. and as ifrog mentioned you need to apply a downforce at higher speeds to keep it from fyling away. high on the brick. low on the styrofoam. the physics enigne creates "lift" on objects at high speeds. well sort of i think...

    anyway, blah blah blah. long post!
     
  15. BlitheD

    BlitheD

    Joined:
    Aug 28, 2006
    Posts:
    36
    Thank you all for taking the time to offer so much help - that is very encouraging. I am still not able to do just what I want but there is lots of good info here and I will keep studying it and playing around with things. So, thanks again and I hope that someday I can return the favor to someone new who is starting to use Unity!
     
  16. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    So did you try attaching a physic material to the curb, that has the dynamic and static friction set to 1 and combine friction mode set to maximum value.