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
1
Question by Zoraph · Dec 11, 2012 at 10:44 AM · screenclampmathf.clampviewporttoworldpoint

my MainChara shakes when the Mathf.Clamp stops it from going off screen

I want to clamp the player from getting out of the screen in any resolution. It is working but when it stops it, my ship (side scroller) starts shaking as if it was actually push back. The last time I used the clamp it didn't shake... this is the code I used:

function Start () {

}

function Update () { var dist = (transform.position.z - Camera.main.transform.position.z); var leftLimitation = Camera.main.ViewportToWorldPoint(Vector3(1,0,dist)).x; var rightLimitation = Camera.main.ViewportToWorldPoint(Vector3(0,1,dist)).x; var upLimitation = Camera.main.ViewportToWorldPoint(Vector3(0,1,dist)).y; var downLimitation = Camera.main.ViewportToWorldPoint(Vector3(1,0,dist)).y;

transform.position.x = Mathf.Clamp(transform.position.x, rightLimitation + 2, leftLimitation - 2); transform.position.y = Mathf.Clamp(transform.position.y, downLimitation +1, upLimitation - 1);
}

Is there someone here who know how to fix this?

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 FlowStateGames · Dec 11, 2012 at 11:55 AM 0
Share

Is there a reason that you don't set your limitations on movement when the class is constructed? I'm wondering if this constant redefinition of 'var dist' and the limitations isn't causing this jitter.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zoraph · Dec 11, 2012 at 06:16 PM

I am not sure what you mean by that, I am not that good with classes yet, but either way, the problem has been solved and I don't know why since I didn't do anything.... I woke up this morning and it was working fine and I didn't even close Unity.

but just in case, is there something wrong with the way I did it or could it causes problems if it is called in a function Update because I tried putting the var outside first and it gave me an error message and it didn't work. It works when it is in the update but it was jittering a lot.... but not anymore for some reason lol ;)

Comment
Add comment · 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

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

10 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

Related Questions

Two Clamps on the Same axis 1 Answer

How to clamp player to viewport constraints when rotating 1 Answer

Limiting player movement (Partially done) 1 Answer

Strange vibrating when moving camera view 0 Answers

Make my player who uses Character Controller to stop moving in one certain direction once it reaches the borders. 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