[Solved] Positioning? Unity3d

Options
om3n
om3n
edited January 2011 in DotNet
I was wondering if there was an example on how the backend uses coordinates.

I threw in a bit of ugly code to see if i couldn't get it using coordinates rather then topleft or topright corner but it has me somewhat stumped.

var Center = new Vector { X = 663, Y = 297 };

this.npc5 = new Npc(Center.ToCoordinate(), properties, "npc", (byte)ItemType.Avatar, this, viewDistanceEnter, viewDistanceExit);

The code compiles fine but I recieve an error in unity which im sure has to do with the new addition since its the only change. Seems to kill the connection on CreateWorld sue to the new npc. Sorry if this looks pretty weak, still trying to get a feel for the engine and im not the strongest programmer.

Dunno if its just beyond me or what but this just seems confusing -

var bottomLeftCorner = new Vector { X = topLeftCorner.X, Y = bottomRightCorner.Y };

Any input would be greatly appreciated.

Comments

  • What error are you getting from Unity?

    Also, are you using the Mmo demo sample as a base for your code?
  • om3n
    Options
    Yes im using the mmo demo for a base. At least for the time being. Although i dont think the unity error will be much help but then im sure there's a possibility i could be wrong with that statement.

    Unity: unexpected operation error Fatal from operation CreateWorld in state Connected

    UnityEngine.Debug:Log(Object)
    MmoEngine:LogError(Game, String) (at Assets/Photon/MmoEngine.cs:186)
    Photon.MmoDemo.Client.Game:OnUnexpectedOperationError(OperationCode, ErrorCode, String, Hashtable)
    Photon.MmoDemo.Client.GameStateStrategies.Connected:OnOperationReturn(Game, OperationCode, ReturnCode, Hashtable)
    Photon.MmoDemo.Client.Game:OperationResult(Byte, Int32, Hashtable, Int16)
    ExitGames.Client.Photon.NConnect:deserializeNeutron(Byte[])
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.EnetPeer:Service()
    ExitGames.Client.Photon.PhotonPeer:Service()
    Photon.MmoDemo.Client.GameStateStrategies.Connected:OnUpdate(Game)
    Photon.MmoDemo.Client.Game:Update()
    MmoEngine:Update() (at Assets/Photon/MmoEngine.cs:145)


    Which is:

    public void LogError(Game game, string message)
    {
    Debug.Log(message);
    }

    So if im not mistaken its a message sent by the backend?
  • Boris
    Options
    please check the mmo.server.log
  • om3n
    Options
    2011-01-17 09:32:04,092 [22] ERROR Photon.MmoDemo.Server.PhotonApplication - System.InvalidOperationException: Operation is not valid due to the current state of the object.
    at Photon.MmoDemo.Server.Npc..ctor(ICoordinate position, Hashtable properties, String itemId, Byte itemType, IWorld world, Vector viewDistanceEnter, Vector viewDistanceExit)
    at Photon.MmoDemo.Server.MmoWorld..ctor(String name, Vector topLeftCorner, Vector bottomRightCorner, Vector tileDimensions)
    at Photon.MmoDemo.Server.MmoWorldCache.TryCreate(String name, Vector topLeftCorner, Vector bottomRightCorner, Vector tileDimensions, MmoWorld& world)
    at Photon.MmoDemo.Server.MmoPeer.OperationCreateWorld(Peer peer, OperationRequest request)
    at Photon.MmoDemo.Server.MmoPeer.OnOperationRequest(Peer peer, OperationRequest operationRequest)
    at Photon.SocketServer.Rpc.OperationQueue.ExecuteOperation(Func`1 action, Peer peer, OperationRequest operationRequest) in c:\Dev\photon-socketserver-sdk\src\Photon.SocketServer\Rpc\OperationQueue.cs:line 167


    Heres the error.

    Edit: I'm pretty sure it stems from what i added as it was in a working state previous to the change.
  • dreamora
    Options
    the error implies that you try to create the world in the wrong global state. perhaps you are not connected yet or you are already in a world.
  • om3n
    Options
    Thank you for the input Dreamora, I see you giving a lot of useful advice. This error only occurred with this new bit of code in the first post. Well aside from the private readonly declaration of the actual npc5. The error i started getting after the change to the backend. before dropping in the new files and rebooting i was connecting fine as were the bots. I was thinking there was an issue in how i did this:


    var Center = new Vector { X = 663, Y = 297 };

    this.npc5 = new Npc(Center.ToCoordinate(), properties, "npc", (byte)ItemType.Avatar, this, viewDistanceEnter, viewDistanceExit);

    I had thought it was an issue with Center. I tried to variate it by adding a Z = as well but im still fairly inexperienced with the code on top of some weaker(newer) programming skills. I was trying to figure out how to spawn an npc without using topLeftCorner or such and more of a readable format (readable to me at least) Thank you again for the input.
  • Boris
    Options
    I assume you have not deployed the pdb file together with the dll because I don't see any file line numbers in the stack trace?
    Anyway, I think the source of the exception is INSIDE the Npc constructor.
    Looking at the source
    if (!world.ItemCache.AddItem(this.representation))
                {
                    throw new InvalidOperationException();
                }
    
    this means another item with the same type and id has already been added.
    Is this the case?
  • om3n
    Options
    Wow... Boris it always seems you come to my rescue, especially when im being an idiot.. I've moved just the dll and xml files over i never thought on the pdb... i always assumed it was not necessary.. I'll report back but it sounds like that could be an issue.

    The only npc/item i have added has been just the one, so i cant see it being that.
  • om3n
    Options
    Well Boris, thank you for helping me get a grasp on reality again... lol. Although if you or anyone else could give me insight as why

    var Center = new Vector { X = 663, Y = 297 };

    Is equal to "top right npc"? It's not seeming to take the coords at all. Is just stacking.
    Thanks again for the input.
  • Boris
    Options
    The vector values are 100 times bigger than the input floats.
    In your case this is what happens:
    this.npc5 = new Npc(Center.ToCoordinate(), ...
    
    Center.ToCoordinate() creates a float[] 100 times smaller than the input vector, which means this is a coordinate similar to 6.63, 2.97 which would be the top left if the demo client did not invert the x axes (which is inherited from the unity3d island demo).

    Solution:
    var center = new Vector { X = 66300, Y = 29700 };
    
  • om3n
    Options
    Things are clearer now, thank you Boris. Although its still a little odd i can deal with a little compensation.

    var Center = new Vector { X = 724000, Z = 3200, Y = 1062000 };
    // x 724 z 32 (inverted yz) y 1062 is a float x 100 although z is odd and displaying as 29.5
  • Boris
    Options
    Are you saying that 3200 arrives at 29.5 on the client?
    Float is not very exact, but that seems a bit too far off.

    By the way, you can also initialize your NPC with float arrays (new Coordinate { Value = new float[] { 724, 1062, 32 } }). Then there is no dividing by 100.
  • om3n
    Options
    Yea thats what 3200 shows up as in client(29.5). Thanks for the tip on the float, will make things much easier in the long run.
  • Boris
    Options
    did you log the floats that arrive or is this a property of a game object (could have been altered by unity with gravity for instance)?
  • om3n
    Options
    My assumption is that it is in unity, i grabbed the position from inside the editor after i noticed the npc partially under the terrain. Thats how i came to see 29.5. I wasnt overly concerned with this. I can take more of a look into it if you like to understand whats happening. The only changes ive made on the backend have been adding a npc to grasp whats going on.

    Off the topic question, not sure if its worth creating a new thread for. but are there other needed calls i should be using if/when i change a scene? ie: into a building and back into a larger scene

    Thanks again for your helpfulness!
  • Boris
    Options
    om3n wrote:
    Off the topic question, not sure if its worth creating a new thread for. but are there other needed calls i should be using if/when i change a scene? ie: into a building and back into a larger scene
    you could think about using a different world instance (or lite room) for different scenes if players in the different scenes don't need to see each other.
  • om3n
    Options
    I was hoping to have many scenes which i could use for internal areas of buildings, bunkers etc. Extending some use from the lite lobby could help accomplish this? I would prefer that players be able to see each other in these new scenes, if they were to follow or be in the same area.
  • Boris
    Options
    if your scenes use the same coordinate system you could just leave them in the same world. if not (e.g position 10,10 is relative to building and not to outside world) you'd either have to map scene coordinates to world coordinates or either enter a lite room or enter a new mmo world for each different scene. The first approach would give you the benefit that players the look out of a window can see other players outside (different scene) approaching.
  • om3n
    Options
    For alot of the meshes im using there is an interior as well as an exterior, I've got some open ones. My concern would be in an urban setting and having perhaps hundreds of entrances. I'm still having issues on how to accomplish it. At first i thought about placing interiors underneath the terrain and using some form of teleport system. Little worried about hacks that way though since it would rely on client sending the updates. My thinking is using scenes might be better to use, still kinda unsure which would be best. Any thoughts are appreciated.