• 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
Question by stas0 · Nov 13, 2016 at 01:24 PM · physics2d gamespriterigidbody2d2d-physics

2D game - Sprite deformation when add frce

Hi.

I created an image and added to it Collider, Rigidbody2D. Also I create script with function which called when pressing the space key and AddForce to this image. After when I start project and press Space key I saw that object start deformed. Whel it collision with other object Player very deformaed. It is deformed and stretched in width upwards. But when I set equal force for X and Y axis Player didn't deformed. For example

 transform.AddForce(500f, 3000f); // Deformed
 
 transform.AddForce(3000f, 3000f);//  Not deformed

alt text

Ball components alt text

Ball script with AddForce

 void Update () {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             Debug.Log("Add force");
             GetComponent<Rigidbody2D>().AddForce(new Vector2(xForce, yForce));
         }
 }

What do to fix this problem?

1.png (48.5 kB)
1.png (22.4 kB)
Comment

People who like this

0 Show 9
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 MelvMay · Nov 13, 2016 at 03:19 PM 0
Share

I see, that sprite start deformation.

No idea what this means and your images don't help either.

What do to fix this problem?

No idea what the prblem is beyond just guessing. You should spend more time trying to explain the problem in detail rather than sum it up with things like 'sprite deformation' if you want other people to spend time trying to help you.
avatar image stas0 MelvMay · Nov 13, 2016 at 03:30 PM 0
Share

Ok. I updated question with more descriptions of problem.

avatar image amimox · Nov 13, 2016 at 04:28 PM 1
Share

Also transform.AddForce(float x, float y) is not an existing transform function. RigidBody2D has a function AddForce(Vector2 force). That code is very weird.

avatar image tanoshimi amimox · Nov 13, 2016 at 04:33 PM 1
Share

Exactly what I was going to say! @stas0 - please post the actual code you're using, because what you've written will just generate a compiler error. Also please post a screenshot of what this "deformation" looks like.

avatar image amimox tanoshimi · Nov 13, 2016 at 04:39 PM 0
Share

In fact he posted it :

  void Update () {
          if (Input.GetKeyDown(KeyCode.Space))
          {
              Debug.Log("Add force");
              GetComponent<Rigidbody2D>().AddForce(new Vector2(xForce, yForce));
          }
  }

but thats really bad code with the get of RigidBody each time instead of caching it in Start!

Show more comments
avatar image amimox · Nov 13, 2016 at 04:31 PM 0
Share

Your ball also seems to have a different scale in XY thats maybe why you are getting different scale -_- cause like @MelvMay saidm it's impossible for a rigidbody to scale a transform. Try cleaning your code and have lower RigidBody values and put Gravity Scale to 1.

avatar image amimox · Nov 13, 2016 at 05:02 PM 0
Share

I see you changed the code but use a Gravity scale of 1, which represents 9.8 m/^s like on Earth. Also be sure nothing else affect the scale.

Can you try to reduce also the force applied, like only 100 ?

If that doesn't work, there is something wrong that affect the size of your object...

avatar image stas0 amimox · Nov 13, 2016 at 05:09 PM 0
Share

I test with 100 value and it is didn't help. Also I test with other object the smae code and all work fine. I will search a problem

2 Replies

  • Sort: 
avatar image

Answer by MelvMay · Nov 13, 2016 at 03:38 PM

Can you please explain what you mean by 'deformed'? Do you mean the scale changes? Adding a force or colliders contacting do not change the Transform scale so you must have some other script/animation doing that.

Adding a force only changes the velocity of a Rigidbody2D and nothing else.

Comment

People who like this

0 Show 4 · 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 stas0 · Nov 13, 2016 at 03:41 PM 0
Share

Sorry for my bad english, 'deformed' I mean the deformation. I don't have any script that do deformation with ball, only ball script that call AddFroce when press Space key. After this ball start change scale.

avatar image MelvMay stas0 · Nov 13, 2016 at 03:44 PM 0
Share

I honestly have no idea. There's no way a Rigidbody2D can set the scale of the Transform. The only other option is to submit a bug case for Unity QA to look at it.

avatar image stas0 MelvMay · Nov 13, 2016 at 03:45 PM 0
Share

Ok. What version of Unity you use?

Show more comments
avatar image

Answer by amimox · Nov 13, 2016 at 04:22 PM

Hi ! First of all you shouldn't use GetComponent method each frame just to get the same rigidbody. This is very bad for performance.

 private RigidBody2D rb;
 void Start(){
      rb = GetComponent<RigidBody2D>();
 }
 
  void Update () {
          if (Input.GetKeyDown(KeyCode.Space))
          {
              Debug.Log("Add force");
              rb.AddForce(new Vector2(xForce, yForce));
          }
  }

Also don't use a Gravity scale of 110. That is very bad and can cause severe problem. This show a problem in your current hierarchy. Try to tweak the size of your game object instead of computing crazy Physics parameters.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

I have a problem with 2D terrain, help mee! 0 Answers

Help with a 2d game and trajectory projection 0 Answers

2D Character won't jump diagonally 1 Answer

Unity 2D gravity 1 Answer

How to make a 2D Player move a box properly ? 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