Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by AthosBenther · Oct 19, 2016 at 06:28 PM · unity 2d

RigidBody2d not respecting parameters

i have this code:

     void FixedUpdate()
     {
         if (_respawn)
         {
             isMaxSize = false;
             Size = 0;
             growSpeed = 0.001f;
             maxSize = Random.Range(1, 5);
             float rndX = (int)Random.Range(-60, 60) * 100;
             float rndY = (int)Random.Range(-30, 30) * 100;
             Debug.Log("Trying to Respawn with the Max Size of " + maxSize.ToString() + " at positions X = " + rndX.ToString() + " and Y = " + rndY.ToString());
             rb.MovePosition(new Vector2(rndX, rndY));
             Debug.Log("Real respawn position: X = " + rb.position.x + " Y = " + rb.position.y);
             _respawn = false;
         }
     }
 

which outputs:

 Trying to Respawn with the Max Size of 4 at positions X = 1400 and Y = -800
 UnityEngine.Debug:Log(Object)
 food:FixedUpdate() (at Assets/Prefabs/food.cs:53)

and

 Real respawn position: X = -79.90599 Y = -63.46048
 UnityEngine.Debug:Log(Object)
 food:FixedUpdate() (at Assets/Prefabs/food.cs:55)

Even if i use float instead of int the results are the same. RigidBody2d is set to Kinematic, zero g and drag.

Am i missing something?

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 AthosBenther · Oct 19, 2016 at 06:34 PM 0
Share

Additionally, my inicial respawn code was something like

 void Respawn()
      {
              Size = Random.Range(1, 5);
              rb.$$anonymous$$ovePosition(new Vector2((int)Random.Range(-60, 60) *100,  (int)Random.Range(-30, 30) * 100));
      }

which was giving incorrect coordinates and a visual glitch where the food would appear in the old position with the new size before being moved. When I moved the Size statement under the $$anonymous$$ove statement the Food would not move upon respawn

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

[NOT SOLVED]2D Side Scroller, the Character suddenly starts to float mid air(Like climbing up some invisible stairs) and then falls back to the ground after couple of seconds 0 Answers

Black screen instead of playing video 0 Answers

loop and instantiate 1 Answer

OntriggerEnter2d not changing Boolean C# 0 Answers

Why can't I export my game to windows? 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