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 /
avatar image
0
Question by shotttt · Jun 23, 2017 at 01:29 AM · transformpositionmovetowardsoncollisionstay

reset an object's position doesn't work fine

I'm doing a fishing game where you grab fishes, there 2 Cases:

1-transform the hook to a random place, hit nothing and come to Hook_Source(type=transform). 2-collide with a fish and both objects (fish and hook) transform to Hook_Source.

In order to grab many times, the condition hook.transform.position=Hook_Source.position must be true.

In the first case the hooking (not really hooking) operation works fine and the hook position reset after I transform it. but in the second case the problem is the hook operation works fine, but the hook don't reset to Hook_Source, there's about -+0.1 difference in distance don't know why, which affects my second hook operation, here's a video explains the situation :

https://youtu.be/leLwIv6D5fo

my Collision script ( the script is attatched to the hook(sprite)):

 void OnCollisionStay2D(Collision2D coll){
         if(coll.gameObject.tag == "fish"){
             fish = coll.gameObject;
             fish.transform.position = this.transform.position;
             StartCoroutine(moveHookBack(Hook_Source, 10f));
             }
         if(Vector3.Distance(this.transform.position, Hook_Source.position) < 2){
                 Destroy(fish);
                 this.transform.position = Hook_Source.position;
                 }
     }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IMemeManI · Jun 23, 2017 at 09:04 AM

I had this problem, it kept morphing my item and it didn't go to the position I wanted.

My solution: Create an empty gameobject and attach it to the position you wish, make it a child of the hook and add a collider, make it a trigger, when the "Fish" colliders with it instead of making it's position relative to the hook, it'll make it relative to the empty object which will stop object morphing and will make it attach to the position you wish.

 GameObject Fish;
 
 void OnTriggerEnter(Collider coll)
 {
  (if coll.gameobject.tag == "Fish")
 
 Fish = coll.gameobject; //Now it can be used.
 Fish.transform.position = this.transform.position; /* makes it 0,0,0 on the empty*/
 }
Comment
Add comment · Show 2 · 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 shotttt · Jun 24, 2017 at 12:24 AM 0
Share

Thanks for the suggestion, but I think you either didn't understand well my problem or I didn't explain enough. I made a gameobject ( Hook_Source) using only its position to reset the Object Hook (sprite) to it after every hook. In the video at 12s you can notice the transform.position of the Hook-sprite morphing a bit before I click again and it affect my next hook (doesn't go where I click, in order to go where I click, I need Hook-sprite=Hook_Source).

I tried a bit to do you suggest but didn't get it well, I just want this piece of code this.transform.position = Hook_Source.position; works

avatar image shotttt · Jun 24, 2017 at 12:28 AM 0
Share

$$anonymous$$aybe my moveHook function code will help to get things clear:

     IEnumerator moveHookBack(Transform end, float S){
         while(transform.position != end.position ){
             this.transform.position = Vector2.$$anonymous$$oveTowards (this.transform.position, end.position, S * Time.deltaTime);
         yield return new WaitForEndOfFrame();
         }
     }

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

82 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

Related Questions

move toward but keep going 1 Answer

Setting target position in Vector3.MoveTowards 2 Answers

Reposition to minimum distance from target 2 Answers

Trying to set up some GUI using planes and textures. Need help with dynamic changes. 0 Answers

Two gameobjects with the same transform 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