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 kevinspawner · Feb 02, 2015 at 03:51 AM · movementtouchclamp

Clamping Issue

I have limited the y movement by clamping the values. But still the object moves beyond the clamped values. Not quiet sure what is the reason behind the problem.

Any help would be appreciated.

Edit: If I replace this rigidbody2D.velocity = movement*Speed;

with this player.transform.Translate(movement*Speed*Time.deltaTime);

it works fine.. It is clamping as intended. But the movement is not smooth as rigidbody2D.velocity. I need to translate the object by rigidbody2D.velocity. I need to know what is the issue! It is really frustrating for weeks now!

Thanks.

 switch(phase)
                         {
                             
                             case TouchPhase.Began:
 
                             touchStartPos = Camera.main.ScreenToWorldPoint(touch.position);                  
 
                             break;
 
                             case TouchPhase.Moved:
 
                             touchEndPos = Camera.main.ScreenToWorldPoint(touch.position);
 
                             differencePos = touchEndPos.y - touchStartPos.y;
 
                             movement = new Vector2(0,differencePos);
                             
                             rigidbody2D.velocity = movement*Speed;
                            
                             Vector3 Pos  =  transform.position;                            
                             Pos.y =  Mathf.Clamp(Pos.y,maxY,minY);
 
                             clampPos.y =  Pos.y - transform.position.y;
                             transform.Translate(clampPos);  
                              
                               
 
                               break;
 
                          }






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 kevinspawner · Feb 02, 2015 at 06:11 AM 0
Share

Any Help?.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Feb 02, 2015 at 06:56 AM

The only thing you're clamping is Pos.y. Did you mean to clamp clampPos.y, which is the y component of the vector you're actually translating by?

Comment
Add comment · Show 13 · 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 kevinspawner · Feb 02, 2015 at 07:23 AM 0
Share

Thanks for your quick reply. Am translating by the rigidbody2D.velocity. I need to clamp the translation y value.

avatar image kevinspawner · Feb 02, 2015 at 07:27 AM 0
Share

I have tried clamping both pos.y and clampPos.y, Both is not clamping the movement.. The object keep moving in y axis... It need to be clamped maxY,$$anonymous$$Y.

avatar image kevinspawner · Feb 03, 2015 at 08:09 AM 0
Share

Any help please?

avatar image Scribe · Feb 03, 2015 at 08:25 AM 0
Share

Translate moves your transform in a direction with some amount of speed, clamping the values as you have done simply stops the object moving more than a certain speed not moving more than a certain position.

 rigidbody2D.velocity = movement*Speed;
 
 Vector3 Pos  =  transform.position;                            
 Pos.y =  $$anonymous$$athf.Clamp(Pos.y,maxY,$$anonymous$$Y);
 transform.position = Pos;
avatar image Bonfire-Boy · Feb 03, 2015 at 09:23 AM 0
Share

Haven't you just got your $$anonymous$$ and max the wrong way round in the clamp call?

Show more comments

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

19 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

Related Questions

How to Touch Drag 3D Objects 2 Answers

Mobile game Player follow finger input problem (C#) 2 Answers

Swipe to move object: object sometimes flying off screen even though value is clamped 1 Answer

working on an endless runner. Need help with clamping. 1 Answer

How can i drag objects smoothly with touch? Please help me with this code! 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