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 sriramkb · Feb 04, 2014 at 04:31 PM · androidedge detection

Detecting the Edge of the Screen - Object is Flickering

Hi am developing a simple Space Shooter styled 2D game and I am stuck at the point where the Object should restrict itself moving beyond the left and right edges of the screen.

I implemented @Waz solution in one of the answers and it works great if the object is not a rigidbody. However if it is applied to a rigidbody, the object starts to flicker. Below is the code that I used from @Waz

         float speed = 0.1f;
         Vector3 viewPos = Camera.main.WorldToViewportPoint(transform.position);
         viewPos.x = Mathf.Clamp01(viewPos.x);
         viewPos.y = Mathf.Clamp01(viewPos.y);
         transform.position = Camera.main.ViewportToWorldPoint(viewPos);


I am not sure how to modify the above code so that the object I touch and move does not flicker and even though the speed is 0.1f the object moves very fast when I touch and drag it, I am not sure if this issue is related to the above one but any help would be great.

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
Best Answer

Answer by LeonineStudios · Feb 04, 2014 at 04:49 PM

I had a similar problem early today. To fix it, I moved my clamp to FixedUpdate() as opposed to Update().

See if that works.

Comment
Add comment · Show 3 · 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 sriramkb · Feb 05, 2014 at 01:35 AM 0
Share

Thanks @LeonineStudios. The flickering disappeared but the other issue continues. The object is moving very fast even I give the speed as 0.01f. Any idea on this? $$anonymous$$y entire code is:

 public float speed = 0.01f;
 void FixedUpdate () {

 if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved)
     {
         //The below four lines of code will make sure that the object does not move out of the screen.
         Vector3 viewPos = Camera.main.WorldToViewportPoint(transform.position);
         viewPos.x = $$anonymous$$athf.Clamp01(viewPos.x);
         viewPos.y = $$anonymous$$athf.Clamp01(viewPos.y);
         transform.position = Camera.main.ViewportToWorldPoint(viewPos);

         Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
         transform.Translate(touchDeltaPosition.x * speed, 0, 0);

     }
 }
avatar image robertbu · Feb 05, 2014 at 02:07 AM 0
Share

@sriramkb - the code we see here is not using 'speed'.

avatar image sriramkb · Feb 05, 2014 at 03:28 AM 0
Share

@robertbu - I can see it in line 13. Do you think there is something wrong in that line of code to use the speed?

     transform.Translate(touchDeltaPosition.x * speed, 0, 0);

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 place objects at edge of screen for mobile devices 0 Answers

Edge Detection Camera Script Not Working (Android) 1 Answer

Is there any way to use Screen.SetResolution on Android without occasional screen flicker with Samsung Galaxy S4 Notification Panel? 1 Answer

Scrolling Parallax flickers on some Android devices (2D) 1 Answer

Edge detection lagging on mobile devices 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