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 GregoryNeal · Jun 19, 2015 at 10:59 PM · rigidbody2dvelocity

Freezing a RigidBody2D causes it to "accelerate"

Hi, I'm freezing a GameObject that has a RigidBody2D manaully (I'm not using RigidBodyConstraints2D). It stops moving alright, but while I was debugging other things I noticed that if I read it's velocity (while it's frozen in space), it's actually accelerating! Any ideas on what could be causing this?

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 zach-r-d · Jun 20, 2015 at 12:36 AM 0
Share

What do you mean by freezing it manually? Are forces still being applied to the object while it is frozen?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Jun 20, 2015 at 12:12 AM

You said you're "freezing it manually". Do you mean you "teleported" it back to it's last position by setting it's position manually?

When you do something like that when a collision happens the rigidbody get a collision force applied (the collision response). If you force the object to the same position the force is applied as long as you're colliding. The force is ment to seperate the two colliding objects. Since you don't allow this the force builds up speed over time.

If you manually clamp the position in one or two axes you should also zero the velocity in the same axes.

Comment
Add comment · Show 3 · 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 GregoryNeal · Jun 20, 2015 at 12:48 AM 0
Share

I freeze it by recording the point of collision using Collision2D.contacts[0].point, then in update I manually set the position each frame. I can post my script if you'd rather see that.

Edit 1: I should mention that the x velocity stays constant (not 0) but the y velocity accelerates.

Edit 2: Here it is just in case you did want to see it.

 using UnityEngine;
 using System.Collections;
 
 public class StickWhenHit : $$anonymous$$onoBehaviour {
 
     private Vector3 stickPosition;
     private bool stick = false;
     private Transform tp;
 
     void Start()
     {
 
     }
 
     void Update()
     {
         if(stick && tp != null)
         {
             tp.position = stickPosition;
         }
 
         else if(tp == null)
         {
             stick = false;
         }
 
     }
 
     void OnCollisionEnter2D(Collision2D coll)
     {
         if(coll.gameObject.name == "teleporter(Clone)" && stick == false)
         {
             tp = coll.gameObject.transform;
 
             //tp.GetComponent<Rigidbody2D>().fixedAngle = true;
             float hitXPos = coll.contacts[0].point.x;
             float xPos = 0;
             if(hitXPos > transform.position.x)
             {
                 xPos = transform.position.x + GetComponent<BoxCollider2D>().bounds.extents.x + coll.gameObject.GetComponent<BoxCollider2D>().bounds.extents.x;
             }
             else if(hitXPos < transform.position.x)
             {
                 xPos = transform.position.x - GetComponent<BoxCollider2D>().bounds.extents.x - coll.gameObject.GetComponent<BoxCollider2D>().bounds.extents.x;
             }
             stickPosition = new Vector3(xPos,coll.contacts[0].point.y,tp.position.z);
             stick = true;
         }
     }
 }
avatar image Bunny83 · Jun 20, 2015 at 02:12 AM 0
Share

Well, regardless of possible collisions you probably have gravity still enabled. So you have a constant acceleration of 9.81 on the negative y axis. Usually this speed get resetted once you hit the floor.

Do you actually want any forces to affect your rigidbody? if not, why don't you simply set is$$anonymous$$inematic to true?

avatar image GregoryNeal · Jun 20, 2015 at 07:05 PM 0
Share

Yea that way is so much simpler and that's what I had ended up doing, I was just perplexed on what the specific issue was. If I understand it correctly, I was manually freezing it by setting it's position each frame, but the body was still subject to forces, like gravity. So it's velocity was increasing but it was unable to move because I was setting it's position.

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

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

Related Questions

Stuttering/jerky movement of kinematic rigidbody 2d moving by velocity in 2D game on iOS 0 Answers

Displaying the y value score,Displaying the score of the Y value 1 Answer

Make object stay inside circle 1 Answer

Jumping with Rigidbody.AddForce not working? 1 Answer

RigidBody velocity ends with weird floating value, when axis key is released. 3 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