Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 BelokurenkoPavel · Sep 10, 2018 at 07:22 AM · vector3vectorvector2dragging

Why the object being moved is faster than the rest?

Behaviour i have now - http://skrinshoter.ru/v/090918/lZLCoJYj?a

I move one object, for other I translate by how much and in what direction this object was moved. However, the object that I move initially - moves faster than others .. I can not understand why.

 //This object moved by player
 void OnFixedUpdate()
 {
         if (IsDragged)
         {
             var lastPosition = transform.position;
             direction = cursorPosition - (Vector2)transform.position;
             transform.Translate(direction * Time.fixedDeltaTime * dragSpeed);
             if (OnDragEvent != null)
                 OnDragEvent(this, transform.position - lastPosition);
         }
 }

 //This method repeat the movement on another objects. Method called when OnDragEvent executed
 void TranslateDrag(IDragable obj, Vector2 v)
 {
      for (int i = 0; i < groupObjects.Count; i++)
       {
            if (groupObjects[i] != obj)
                (groupObjects[i] as SelectableComponent).transform.position += (Vector3)v;
       }
 }










Comment
Add comment · Show 3
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 tormentoarmagedoom · Sep 10, 2018 at 07:24 AM 0
Share

I'm not sure, but...

HAve the objects the same scale? Depending on how you are moving them, is possiblee that scale affects the realworld distance to move.

Check it. Bye!ª

avatar image BelokurenkoPavel tormentoarmagedoom · Sep 10, 2018 at 07:26 AM 0
Share

Sure, objects are the same

avatar image Bunny83 BelokurenkoPavel · Sep 10, 2018 at 12:44 PM 0
Share

Are they the same or are they 1,1,1? Do you have a parent object for those objects? Your code assumes a scale of 1,1,1 for the parent since you move your dragged object in local space while you move the "other" objects in worldspace.


Translate without a Space parameter defaults to localspace. Setting ".position" of an object moves it in worldspace. So you should either use .position in both cases, or use Translate in both cases. $$anonymous$$ixing them is not a good idea.

1 Reply

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

Answer by Eno-Khaon · Sep 10, 2018 at 09:13 AM

I don't see any sanity checks in place by your example to prevent the TranslateDrag() event from affecting the object you're actively moving as well.

I would venture a guess that when you drag one object around, you move it, then you tell all of the objects, including the one you just moved, to move by the same amount.

As a result, the object you drag is moving exactly twice as fast as all of the others linked to it.

What you may want to do, then, is not move the object during your isDragged check in OnFixedUpdate(). Instead, simply record the value for the movement without moving the object and let the OnDragEvent handle the movement of the selected object, too.

Comment
Add comment · Show 1 · 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 Bunny83 · Sep 10, 2018 at 12:39 PM 0
Share

Right. We don't even know what GroupObjects actually are. Are they parent objects for all those nodes? If that are the actual objects, what is the exact element type of the groupObjects list? Since "this" is passed as obj parameter it would be important that the same component is actually inside that list.


I also would strongly recommend to change the as cast into a normal cast. An as cast without null check is never a good idea.


Finally we can only speculate where the code is actually called from. It seems it's called inside FixedUpdate. Though i don't see any reason why you want to do this. Any sort of input is processed per visual frame. The process of dragging an object is a visual thing which is directly linked to the input. So you should do this in Update. Also you can always use Time.deltaTime. When deltaTime is read from inside a FixedUpdate callback it will return the value of fixedDeltaTime. So you don't have to care about from where a certain piece of code is called when you use Time.deltaTime.

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

114 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 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

[HELP] Translating vector 2 co-ordinates to real space 1 Answer

Iterating over Vector's axes 1 Answer

Fixed error but error still shows in the console 2 Answers

Vector based on the rotation of the main camera 1 Answer

Rotate vector around vector? 2 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