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 /
avatar image
0
Question by killradio · May 10, 2014 at 06:05 PM · collisionphysicsbehaviourstrange

Floor and Sphere collision, strange physic behavior

Hi everyone !

I am having a strange behavior with what I believed was a simple game... I searched on the web for questions and answers but couldn't find anything useful so far.

Let me explain my problem :

I have a Sphere (the simple one, made in Unity) that is my character. It has a rigidbody as well as a sphere collider. The rigidbody uses gravity and is also modified with a script of mine to make the ball go left or right like this :

 void Update()
 {
     movement = Input.GetAxis("Horizontal");
 }
 
 void FixedUpdate()
 {
     Vector3 velocity = rigidbody.velocity;
         
     velocity.x = movement * speed;
     velocity.z = Mathf.Clamp(velocity.z, 0, maximumSpeed);
         
     rigidbody.velocity = velocity;
 }

Basically, the script handles the X movement as well as a Z limited speed. The Z is handled with a Constant Force component pushing the sphere on Z. (and only on Z)

With that, I have a floor that is a simple cube, scaled, just below my sphere so it can roll over it. The floor is managed with another script that handles the generation of an infinite floor (more of a corridor really).

 public void Update()
 {
     float currentPosition = player.transform.position.z;
 
     if (currentPosition + playerOffsetBeforeNextSpawn >= currentOffset + offsetBeforeNextSegment)
         {
             currentOffset += offsetBeforeNextSegment;
 
             GameObject segment = PickSegment();
             segment.transform.position = new Vector3(0, 0, currentOffset);
         }
 
         RecycleOldSegments();
 }

The segments are nicely side by side (no space between them). The script uses a pool of segments (the one behind the camera are recycled). So the segments are just moving in Z to continue the corridor.

What goes wrong is this : From time to time, my sphere (capped at 100 z velocity) will jump off, with a random amplitude. There is no script that affects its Y velocity and I know the cause, I just can't get it working correctly !

I think the problem is due to the segments being segments and not a unique mesh. The sphere would collide with the "new" ground and go crazy over it !

I can't see a solution for making it not jumping so randomly... :(

  • have the following constraints :*

    • My sphere need to be able to jump so I can't used the rigidbody constraints.

    • I need to create the corridor segment by segment and can't simply use a unique mesh.

With all that said, I am posting here to know if anyone of you already faced this problem? Is there a better way to achieve what I am trying to do? How? Maybe the constant force is not appropriate here, how can I achieve an automatic acceleration without it and no input ?

Thank you for your time and many thanks in advance ! =D

PS : This behavior happens even without doing anything (movement = 0) and the sphere rolling straight ahead!

Comment
Add comment · Show 1
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 Atomic Nipple · Nov 22, 2014 at 07:51 PM 0
Share

I have the same problem. To be honest I didn't read everything you wrote but my ball moves horizontally along planes and one in a while it jumps just like you said. Seems like it's collides with the edges or gaps of the planes. There's another thread like this one here but without an answer. I'm still waiting :/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by killradio · May 11, 2014 at 08:48 AM

Hi again,

I'm keeping track of everything I tested so far to resolve this problem, without any luck though...

Here are the few things I tested with no changes :

  • Set the offset of my "segment factory" so the segment of the ground are not side by side but overlap a little on the Z axis.

  • Removed the constant force and applied a simple, fixed, Z velocity to my sphere.

  • Wrapped the ground in a "Ground" Layer, and set it not to collide with itself (and repeat first test).

  • Changed my factory to work and create segments in the "FixedUpdate".

Those modifications did not change the jump effect.

I also modified the offset of my segment factory to make the segment side by side with a small gap in between. That way we can clearly see the sphere jumping when changing segment (normal behavior).

In the inspector, all my created segment have the same X and Y. Only Z changes. So their box collider are nicely side by side (even linked when the offset is lower than the size of the segment).

To be sure that I am targeting right where the problem is, I made my sphere fly over the ground (0.5 Y above) and froze the Y position in its rigidbody. The bug disappear.

Unfortunately, I can't keep it that way as my sphere has to be able to go higher or lower. But at least, I'm sure that this is the problem : my sphere collides with the new segment (from time to time), even if its on the same height as the previous one.

Anyone having this issue? I'm still new to Unity so maybe I'm skipping something important here... :(

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image avatar image avatar image

Related Questions

Collision impact force 1 Answer

I want my Player to have collision physics 1 Answer

How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer

OnCollisionStay stops firing after a second or two? 2 Answers

Keep rotation when changing parent in Unity 3D 1 Answer


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