Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
This question was closed May 26, 2019 at 08:25 AM by McBowie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by McBowie · May 23, 2019 at 06:12 AM · resolutionscalingpositioning

GameObjects not spawning at specified position when the resolution is changed

I have a problem when instantiating a game object into the game via script. I checked manually where the object has to be in order to sit perfectly in bottom-right corner of the screen. I wrote the script that instantiates that object at the same location. As long as I starting the scene in the same resolution i had while checking the values, everything is great, but whenever I try something with different aspect ratio, the object spawns in a different place due to the change of camera viewing size. I've tried making a reference to the camera and checking pixelWidth and pixelHeight, then making an aspect ratio out of them and spawning the object at the same point, but multiplied by the ratio, but it didn't resolve the problem, although it made it less apparent. Thanks for the help in advance. Edit: the code that was supposed to instantiate the GameObjects

 public class CharacterPlacements : MonoBehaviour
 {
 
     Vector3 right;
     Vector3 left;
     Vector3 middle;
 
     void Start()
     {
         right.Set( 7.5f, -4.5f, 0); // These coordinates are working fine at 16:10
         left.Set(-7.5f, -4.5f, 0);
         middle.Set(0, 0, 0);
     }
 
     public void Create(string characterName, string where)
     {
         GameObject character = Instantiate(Resources.Load(characterName, typeof(GameObject))) as GameObject;
         character.name = characterName;
         if(where == "r")
             character.transform.position = right; 
         if (where == "m")
             character.transform.position = middle;
         if (where == "l")
             character.transform.position = left;
     }
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 tormentoarmagedoom · May 23, 2019 at 07:37 AM 0
Share

Hello $$anonymous$$cBowie.

If you have problems with some script, you must paste it here (Use code sampler or Crtl+$$anonymous$$). If not is impossible to know what are you doing...

When Instantiate, you must give a position in worldspace, so camera resolution is not a variable at all, unless you are finding the worldposition in reference with some mouse/canvas property...

Please post your code.

Bye.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by tormentoarmagedoom · May 23, 2019 at 10:34 AM

Hello again.

Are this vector 3 variables the coord in world space? I think the prolem is that when you change resloution, you see the world different, but the characters are instantiated at same world point...

Can you show some images?

As i see in this script is, you have 3 points in the world scene:

Then you just instantiate and move the charcater to oine of this positions.

Resolution of the camera does not change anythig, only change what you see... so if you say they are moving, i say no, they are not moving.. you are changent the prespective, the field of vision, the zoom.... but the object are still in same palce in the world scene.

IF what you want is to instantiate always in the corners of the screen in all aspect ratios, you need to change the position in relation to your screen, not the wolrd coords.

So you need to use thie function ScreenToWorld so you take some position of screen as reference, and from there, you can calculate the world position where to move the character.

Good luck!

Comment
Add comment · Show 2 · 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 McBowie · May 23, 2019 at 12:18 PM 0
Share

Thank you so much! This pushed me into the right direction.
The way I solved it was: I read the camera's width, then I use it as a X coordinate for in a variable, which i feed to the ScreenToWorldPoint function and then add the offset deter$$anonymous$$ed by my character's width, and now it works like a dream!
Thanks a milion!

avatar image daniobey46 · Sep 25, 2021 at 12:31 AM 0
Share

Can u share the code please , I need them.

Follow this Question

Answers Answers and Comments

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

Related Questions

Understanding relationship between scale and position 0 Answers

Is there a reason a sprite might be positioned differently depending on resolution? 1 Answer

Scaling Sprites based on 800x1280 resolution 0 Answers

Unity build resolution works on PCs but not mac? 0 Answers

Screen scaling isn't scaling properly. 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