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 Shnayzr · Feb 08, 2015 at 11:20 AM · c#uimovementresolutionmove

transform.Translate doesnt travel the same distance for multi-reso

Hello

this transform.Translate code make my game object move to the negative y axis

  void Start()
  {
     ms = -700f;
  }
  
  void Update ()
  {
  transform.Translate (0, ms*Time.deltaTime, 0);
  }

but the problem is when i change the resolution of the game the object moves slower, so i decided to make the movement speed depends on the height of the screen, so for example if we have a screen with height 500px ms will be 250px/s and if the height is 1000px ms will be 500px/s

also i changed the Canvas Scaler to Scale with screen size 800*600 so a screen with 2:3 aspect ratio will have 800*1200 screen size. so and i made this code

 HoverW = ((float)Screen.height / (float)Screen.width);
 newHeight=800*HoverW; // 800 is the resolution refrence from canvas
 ms=newHeight;

so i thought from the above code the object will travel the screen height in 1 time unit and doesnt depend on the resolution, but unfortunately in some resoultions the object travels it in less or more than 1 time, i mean the object doesnt travel the whole height in on the same time for multi-reso

Comment
Add comment · Show 4
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 Shnayzr · Feb 08, 2015 at 04:34 PM 0
Share

i have tried to just do Screen.height as ms and didnt work also :(

any help please

avatar image meat5000 ♦ · Feb 08, 2015 at 04:39 PM 0
Share

I imagine it is going the same speed regardless of resolution. You will find that Unity likes to adjust the viewport which changes the amount of actual game-world 'real-estate' that can fit into your screen, in order to preserve image quality.

avatar image Shnayzr · Feb 08, 2015 at 04:50 PM 0
Share

then how can i balance the object speed from device to another?

cause i tested the game on my ipad and the object was very very slow while in the editor its speed was very fast maybe 5x or 6x the ipad speed

avatar image daneislazy · Feb 08, 2015 at 05:26 PM 0
Share

hmmm with that much of a difference I wonder if it's maybe a performance issue? Are there a lot of things going on besides the moving game object?

$$anonymous$$aybe try using FixedUpdate ins$$anonymous$$d of Update and Time.fixedDeltaTime ins$$anonymous$$d of Time.deltaTime ?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by daneislazy · Feb 08, 2015 at 04:53 PM

Translate should not be affected by the screen resolution or aspect ratio. I would guess, as meat5000 mentioned, that the amount of game world being shown is changing when the screen resizes so it just looks like it is moving at different speeds.

You can do some visual testing by putting a big Plane object behind the object you are moving so that you have a reference point, maybe with a repeating texture as well.

You can also make a second similar game object with a rigidbody attached to it. Turn off Gravity and set the drag to 0. Then, add rigidbody.velocity = Vector3.down * speed; into the Awake() method in a new script for it. And set speed to whatever you need it to go. (probably 700 based off of your initial example, also Vector3.down is already negative) Then you can compare the two speeds to see if something is wrong.

Edit: with regards to the question maker's comment on different platforms

You shouldn't need to worry too much about it because the screen resolution/ viewport size doesn't affect the positions of objects in the game world.

But if it's something to do with the how much can be seen or something...

If you are using an Orthographic camera the Size is in units from the center of the camera to the top/bottom of the screen so yes, changing the aspect ratio will change the amount that can be seen on the sides.

You could possibly add some in game "black bars" to the sides of the camera so that if it is too wide you just see black. But some people don't like that.

If you are using a perspective camera it's similar but uses a default of 60 degrees angle, again from the bottom of the screen so only the sides change.

Either way you shouldn't really need to change the game mechanics based on the resolution or aspect ratio unless there is some huge flaw in the camera system that I am overlooking.

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
avatar image
0

Answer by xdarned · Jan 17, 2021 at 01:29 AM

Hi, I will post this here since there is no other place where a similar question exists. This is not a solution! I have a canvas set to scale with screen size, and have a rectTransform inside the canvas. Anchors are set to center as well as pivot. Inside that rectTransform there is a child wich is an image. This child (rectTransform as well) has pivot and anchors set to center. I have a script:

 float speed; //Set from inspector
 
 void Update{
      transform.Translate(Vector3.down * speed);
 }

Now, this is the thing: If I run the game at full screen, the image moves slow. BUT if I run it windowed (small) the image moves realy fast.

This looks like the problem of OP to wich the provided solution didn't work.

So it looks like the problem is inside the transform.Translate itslef. I have tried to set speed directly dependant on screen size but no results. I will try another method for movement and share results if succed...

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

22 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Gameobjects move towards a moving object c# 1 Answer

Best way to move elements around screen [uGUI] 0 Answers

LeanTween.moveLocal sometimes snaps to position rather than moving over time 0 Answers

Unity 4.6 - How to Move a UI inside of the canvas 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