Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Feb 10, 2016 at 10:06 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by meat5000 · Aug 25, 2013 at 08:32 PM · physicscollidertimebehaviour

Physics behaves more strangely with Time? Bouncing and Sliding Objects

Is there any plausible reason why Physics would act more and more strangely over time?

I have gameobjects that spawn and destroy over time.

As time progresses the way these objects react to Colliders becomes more and more strange. There is no Time factor in my collision scripts.

Things that are affected most are Bounce (increasing) and Friction (decreasing).

The number of gameobjects doesn't seem to be an issue IN THIS CASE as having few or many gameObjects early on will not behave this way but having few or many later on will.

Is my FixedUpdate() dropping steps? I'm getting a stable 80 fps!

EDIT: Ive added a HIGH FRICTION Physic Material and it has NO EFFECT on this issue!

alt text

highf.jpg (34.3 kB)
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 25, 2013 at 08:37 PM 1
Share

Any chance there's something in one of your game scripts that's changing gravity slightly?

avatar image meat5000 ♦ · Aug 25, 2013 at 09:01 PM 0
Share

I actually don't use set world gravity but I've scripted Physics.Gravity to change with accelerometer ins$$anonymous$$d. So it's not a slight change but a full 360 degree changability around the z axis when the phone is turned around (android).

avatar image meat5000 ♦ · Aug 25, 2013 at 09:09 PM 0
Share
 var gravityVal : float = 20.0;
     var Grav : Vector3;
     var dir : Vector3 = Vector3.zero;
 
     function Start()
     {
         Grav = Vector3(-gravityVal,gravityVal,0);
     }
     
     
     function Update ()
     {
         dir.x = -Input.acceleration.x;
         dir.y = Input.acceleration.y;
         
         if (dir.sqr$$anonymous$$agnitude > 1)
             dir.Normalize();
         
         Physics.gravity = Vector3(dir.x*Grav.x, dir.y*Grav.y, 0);
     }
avatar image getyour411 · Aug 25, 2013 at 09:41 PM 1
Share

I don't grasp the concepts of these things yet, but from reading the Normalize bit about a vector3 that's (really) small getting set to zero makes me wonder if that, over time, is the culprit. Edit: hmm that would make the whole equation come to 0,0,0 if that happened, which does not sound like it would results in a slight bounce/friction change - not sure.

avatar image meat5000 ♦ · Aug 25, 2013 at 09:47 PM 0
Share

Noted. I'll look into it.

Basically, I normalize to find the Unit Vector, which is just the direction component of the Vector. Then I multiply that by the Gravity value. I do it this way so I can play around with the components at different stages in the game.

The x,y,z of the accelerometer each vary between -1 and 1.

 dir.x = -Input.acceleration.x;
 dir.y = Input.acceleration.y;

are the calls for retrieving x and y values of the accelerometer.

I think this was one of the first scripts I wrote for my game; maybe I was being hasty, but the gravity actually seems to behave very well on my gameObjects.

Show more comments

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by meat5000 · Sep 04, 2013 at 12:33 AM

I actually hacked it.

Solved with my other Q/A

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by aldonaletto · Aug 25, 2013 at 11:31 PM

If you want to just rotate the gravity about the device Z axis (perpendicular to the screen), zero the Z axis and normalize the accelerometer value, then multiply it by gravityVal :

 function Update ()
 {
    dir = Input.acceleration;
    dir.x = -dir.x; // mirror X as you were already doing
    dir.z = 0; // ignore Z axis
    dir.Normalize();
    Physics.gravity = gravityVal * dir.normalized;
 }

If the accelerometer is too jerky, filter it with a "Lerp filter":

 ...
 public smoothSpeed: float = 5;

 function Update ()
 {
    var temp: Vector3 = Input.acceleration;
    temp.x = -temp.x; // mirror X as you were already doing
    temp.z = 0; // ignore Z axis
    temp.Normalize(); // normalize it
    dir = Vector3.Lerp(dir, temp, smoothSpeed * Time.deltaTime);
    Physics.gravity = gravityVal * dir;
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Aug 25, 2013 at 11:43 PM 0
Share

Thanks for the reply dude. Writing a gravity script wasn't really the problem. I kinda breezed that :P The problem is the strange physics defects that occur after a Time.

I've now tried dir.z = 0; I actually prefer it without as the gravity responds differently when the phone is flat. I don't $$anonymous$$d the unit vector pointing in z as all objects are z-locked and the response encourages the user to hold the phone up a particular way.

I use

 Physics.gravity = Vector3(dir.x*Grav.x, dir.y*Grav.y, 0);

to zero the z ins$$anonymous$$d.

I keep the components separate so my Governor can play with the gravity, but I havent updated it for separate gravityVal's yet.

And I was very surprised by how smoothly the Accelerometer handles. Technically Unity automatically accesses Gyro data when its referring to accel. Which is a lot smoother anyway.

The strange Physics defects seem only to happen after a certain amount of time rather than any other factor.

One thing I will mention is, the common offending object has a $$anonymous$$esh Collider AND has Generate Colliders checked. It is a screen bordering object that encapsulates ALL other gameObjects, so primitives just wont do.

Frankly though, all these problems would be solved if I could find a solution to my other, see$$anonymous$$gly simply problem:

http://answers.unity3d.com/questions/500349/how-to-fix-rigidbody-dir-vector-despite-force-dir.html

avatar image meat5000 ♦ · Aug 26, 2013 at 12:17 AM 0
Share

By the way Aldo

Electronic engineer, specialized in audio, analog and digital electronics, microcontrollers, and addicted to program$$anonymous$$g.

Snap :) I'm the same!

avatar image aldonaletto · Aug 27, 2013 at 03:06 PM 1
Share

@meat5000: so, you're a colleague engineer! That's nice - I was feeling kind of solitaire among all programmers in UA! About the question: I supposed that your problem could be caused by gravity beco$$anonymous$$g too low: the main difference between our scripts is that in yours gravity falls near to zero when the device approaches a horizontal position, while in $$anonymous$$e it's constant - only its direction changes. But from your comments I deduce that gravity is working as you expect, and only collisions with the outer mesh collider behave strangely. If so, my suggestion is to replace the mesh collider by box colliders that surround the same volume. $$anonymous$$esh colliders are somewhat slow and problematic: collision detection starts at the collider bounds, than iteration through the mesh triangles takes place in order to find the hit point, if any. This is time consu$$anonymous$$g, specially when compared to primitive colliders like box, capsule and sphere: in these cases the collision detection is solely based in their basic properties (center, radius, height, size etc.), which's more reliable and a lot faster.

PS: I saw your previous question and tried some solutions, but no one worked as expected. I tried to project rigidbody.velocity on the desired direction and assign it back, but the RB gradually slipped out of the original trajectory. I also tried to clamp the rigidbody position to the desired trajectory in FixedUpdate, but weirdly this didn't work either - again, the rigidbody drifted from the ideal trajectory while moving.

avatar image meat5000 ♦ · Sep 01, 2013 at 05:09 PM 0
Share

Thanks for trying dude! I'm getting stressed out by this see$$anonymous$$gly simple problem.

avatar image meat5000 ♦ · Jan 23, 2015 at 07:01 PM 0
Share

I've gone back to read your comment again. I think I didn't understand it back then. $$anonymous$$akes much more sense to me now :)

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Only take into account colliders' bounds on single gameobject in hierarchy 1 Answer

Ignore sub-colliders for center of mass in Rigidbody2d? 1 Answer

Tossing an object with the correct force at any distance from another so that it collides with the other 1 Answer

Colliders not working 1 Answer

Target Wheel Rotation/Physics 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges