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 Critcher · Nov 22, 2012 at 10:08 AM · cameramouseposition

Issues with mouse moving camera

Hi all,

I'd like to start by saying that this script works fine, I just need some guidance on how to do three things (pointers are great don't need anyone to write my game for me !)

  1. The mouse feels jittery, is there a way to smooth the movement?

  2. I can't seem to think of how to stop scrolling right and left at certain points for example where the camera starts is point 0 the camera can only scroll left to say 100 and it can't exceed 100 left or go less than the initial position 0 right.

  3. I'm (obviously) just getting started around here but I feel that constantly spamming the screen width a hundred times a second or whatever the rate is seems clunky, is there a smarter way to accomplish this?

I've tried moving the variable around places (function start, awake etc. but funny things start to happen with the borders. I used LateUpdate because I read that camera controls should be in there and not in update???

Anyways, Here's the little script

 var CameraToMove:Camera;
 var CameraSpeed = 10;
 var Border : int = 50;
 
 function LateUpdate () 
 
 {
     var WideScreen = Screen.width;
 
         if (Input.mousePosition.x > WideScreen - Border)
         {
             CameraToMove.transform.Translate(CameraSpeed*Time.deltaTime,0,0);
         }
         if (Input.mousePosition.x < 0 + Border)
         {
             CameraToMove.transform.Translate (-CameraSpeed*Time.deltaTime,0,0);
         }
 }

So thanks for reading this giant block o' text, any hints or tips would be much appreciated!

Comment
Add comment · Show 2
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 AeonIxion · Nov 22, 2012 at 10:37 AM 0
Share

Take a look at http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html

and

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.Clamp.html

avatar image Critcher · Nov 22, 2012 at 07:24 PM 0
Share

Thanks for the leads Aeonlxion, I read about clamp and I thought I got it... I did not! So here is what I'm looking at, maybe if you could point where I'm wrong?

CameraTo$$anonymous$$ove.transform.position = Vector3($$anonymous$$athf.Clamp(CameraSpeed*Time.deltaTime, 1.0, 100.0) //this part I thought was the x position with a $$anonymous$$ x of 0 and max x of 100, but that doesn't seem right, it does stop the camera from moving left any further and when I move right it seems to move less than 1 to the x going back left brings it back to 0 , 80, -10); this I'm assu$$anonymous$$g is a flat y,z and it seems to be holding.

Thanks very much

0 Replies

· Add your reply
  • Sort: 

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

Camera.main.ScreenToWorldPoint works within Unity editor, but not in builds 0 Answers

Make object follow mouse, while actually moving camera, instead of object 2 Answers

MousePosition input problem after rotating object. 0 Answers

ScreenToWorldPoint exclude objects or layers? 1 Answer

[Solved] Constraining a position within a radius (2D crosshair) 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