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 DarKTower · Jul 19, 2014 at 05:08 AM · networkingmultiplayeriphonespawninglevel

Image-based Level Generator having problems

Alright so I've built a custom level generator that generates a level based off of a randomly chosen Texture2D in the game files. These textures are 140x80 and are highly colorful. The level generator reads the files, then spawns objects based on the color in the image and spawns them in the world. Note that my game is an entirely top-down 2D game, with an Orthographic camera that does not move.

Now this works fine and dandy for the primary device I am developing for (iPhone 5, 1136x640 resolution), but I get problems when I play on other devices: The way I am spawning the objects is based on the Camera, by using the position of the pixel in the image as the position to spawn the object in the World.

In a singleplayer game this would be fine, because you would be the only one seeing everything and all NPCs and things would respect the definitions you've set because everything revolves around you. But my game is a Multiplayer game.

So a quick example of the problem... A player joins a server on an iPhone 5 (1136x640), the arena is spawned based on parameters sent by the Server on connection, and begins moving around. Another player joins using an iPad 3 (2048x1536), spawns the arena based on parameters sent by the Server, and then starts moving around. So the iPhone5 user sees the arena based on their aspect ratio (16:9), while the iPad3 user sees the arena based on their aspect ratio (4:3). On one screen (iPhone5), the player could be moving left+down through a hallway, but on the other screen (iPad3), that player seems to be walking into the wall just below/above the hallway as though stuck, because the map has been spawned slightly differently because of the width/height of the screen.

If anybody could help, that would be great. The entire resolution/aspect ratio/device thing is incredibly confusing to me, and I would dearly like to finish up this level generator and move onto more gameplay-oriented code.

The background of the arena is 1136x852, which perfectly fits all aspect ratios I am trying to support (16:9, 4:3, 3:2) when I zoom out the camera slightly to fit in the proper width. The main problem is with the height, which auto-adjusts based on the resolution.

ArenaGenerator.js

 #pragma strict
 
 var environmentColors: Color[]; //THE COLORS TO BE READ
 var environmentObjects: GameObject[]; //OBJECTS TO BE SPAWNED FOR THE COLORS
 var environmentImages: Texture2D[]; //THE ARENA TEXTURES THEMSELVES
 
 function SpawnTheArena() {
     var setScreenWidth: float = 1136;
     var setScreenHeight: float = 640;
     var diffScreenWidth: float = Camera.main.pixelWidth/1136;
     var diffScreenHeight: float = Camera.main.pixelHeight/640;
 
     var chosenArenaID: int = 0; //SET BY THE SERVER THROUGH RPC CALLS NOT INCLUDED IN THIS SNIPPET
 
     for (var w:float=0;w<environmentImages[chosenArenaID].width;w++) {
         for (var h:float=0;h<environmentImages[chosenArenaID].height;h++) {
             var thisPixel = environmentImages[chosenArenaID].GetPixel(w, h);
 
             var xPos: float = (w/environmentImages[chosenArenaID].width)*setScreenWidth*diffScreenWidth;
             var yPos: float = (h/environmentImages[chosenArenaID].height)*setScreenHeight*diffScreenHeight;
             var thisPixelSpot: Vector3 = Camera.main.ScreenToWorldPoint(Vector3(xPos,yPos,0));
 
             //MY COLOR READING AND SPAWNING CODE GOES HERE BASED ON THE VECTOR3 ABOVE.
             }
         };
     };
 }

Any help would be very much appreciated. Thank you!

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

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

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

Unity networking tutorial? 6 Answers

HLAPI: How to spawn players from preGameScene 1 Answer

Players Not Showing 0 Answers

Networking Question: Spawning selectively / on only one client. 1 Answer

How to make UNITY multiplayer with two HTC VIVE in the same real room? 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