[[ NEW ]] FPS Demo!

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 30 Sep 2011, 07:04

Hey, im fairly new to SF and have a question relating to the demo. I set up the server just fine, and enabled the local ip of the server machine, if i boot the FPS demo on the server machine I can connect to my local 192.168.2.xx however if I attempt to run the client on my laptop and connect to 192.168.2.xx I get "No connection could be made because the target machine actively refused it".

I know the obvious answer would be a firewall, but I only have the basic windows firewall installed, its been shut down, and ive enabled port 9933 UDP and TCP both outgoing and incoming and enabled the server software to bypass the firewall. Ive also opened TCP and UDP ports 9933 on my router and assigned them to my server machine. So my question is, why am I not able to connect to the local ip from my laptop but my server desktop works fine?

Also in order to allow other people from the internet to access my server, I simply need to add my public IP to the server.xml file or is there more to it? Sorry ive been struggling to find anything substantial on how to allow internet access to my SF server. Thanks for the help in advance.
anabelle345
Posts: 1
Joined: 30 Sep 2011, 08:29
Contact:

Postby anabelle345 » 30 Sep 2011, 08:35

Can I find anywhere some tutorial? The case is generic ----- that I have some instalation problems
Last edited by anabelle345 on 06 Dec 2011, 06:18, edited 1 time in total.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 30 Sep 2011, 09:35

what kind of problems ? There is no real tutorial, you need to learn from the demo.
Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 02 Oct 2011, 04:49

Im not sure if this was the right place to post but i tried to make a kind of aim bot for this fps demo with the code being

Code: Select all

if(Input.GetKeyDown("t")) {
            GameObject go = GameObject.FindGameObjectWithTag("Enemy");
            target = go.transform;
            
            transform.LookAt(target);
            //transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), rotationSpeed * Time.deltaTime);
         }   


I attached this to the update part of the mouse look script and no compiler errors occurred however clicking T does nothing. I can see that the target of the player clone does infact become an enemy clone(I added the enemy tag of course) however there is no alteration to the camera. Im fairly new to incorporating networking into games so im unsure if the fact that the transform im trying to get is that of another player is rendering the code useless or if im simple over seeing another issue.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 02 Oct 2011, 07:26

You might wan't to post this on the Unity forum since it's not SFS related but my guess would be that the 'transform.LookAt(target)' only gets executed once when you click "t":

Code: Select all

if(Input.GetKeyDown("t")) {
            GameObject go = GameObject.FindGameObjectWithTag("Enemy");
            target = go.transform;
             
            transform.LookAt(target);
            //transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), rotationSpeed * Time.deltaTime);
         }


I would do something like this :

Code: Select all

if(Input.GetKeyDown("t")) {
            GameObject go = GameObject.FindGameObjectWithTag("Enemy");
            target = go.transform;
}

if (target)             
transform.LookAt(target);
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), rotationSpeed * Time.deltaTime);


this way the LookAt() gets executed even when you don't press the button "t".
Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 02 Oct 2011, 13:42

Well I wanted to know if the transform of an enemy is accessible to another player considering this is now being run over a network and not your standard unity project where every information is accessible to the client. Although unfortunately your code doesnt work either, the target of my player in the inspector does indeed become enemy clone, but the camera is simple not rotated at all, neither with my or your approach. Thanks for the help though.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 02 Oct 2011, 15:01

You can still access the transform as if it was a non networked game. You can access all thats present in the scene.
Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 02 Oct 2011, 16:00

So no ideas as to what the problem might be?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 02 Oct 2011, 17:05

Hard to tell but it surely isn't an SFS issue, i would strongly suggest you post your problem in the scripting section on the Unity forum.
Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 31 Oct 2011, 04:40

Hey, sorry to disturb again :)

I've sat on and off during the past month analyzing the source code for the project and for the most part i've come to grips with it. However now I want to create teams for the game and some issues come up.

To start with, im going to just have a check box at login when checked puts you on the blue team if not then on the red team. The problem is that I'm struggling with figuring out how to approach this. As far as I understand, on a player spawn SpawnMe request is sent to the server which is then managed by SpawnMeHandler, which gets components from CombatPlayer and is managed into an array in the World class. After everything is processed HandlePlayerInstantiate is called back in NetworkManager which then tells PlayerManager to instantiate an enemy prefab based on everything sent to it. As it stands this feels like a maze and im struggling to get the macro picture of how things work.

Basically I dont understand where a "player" per say is defined. I am actually unable to even find a place where the name of a player is allocated to it. I need some way to have the client send an int which is 0 or 1 based on the team, and that int has to be an integral part of what defines the "player" as it must become stored on the server and then relayed to all players clients, so at the moment I dont exactly understand where I can in the server extension modify the player definition to include this bit of information. I also dont really understand how I can send the int to the server because the only way I see the client communicate with the server is through:
ExtensionRequest request = new ExtensionRequest("spawnMe", new SFSObject(), room);
and I dont see how I can modify that request to include the desired integer for a team.

I'm sorry if im missing something obvious, however its been slightly hard getting my head around everything.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 31 Oct 2011, 09:47

Hi

You can solve it in at least 2 different ways I would say

Solution 1
Instead of sending an empty SFSObject in the spawnMe request

new ExtensionRequest("spawnMe", new SFSObject(), room);

you can make a SFSObject and add an int to that and use that object as parameter 2 instead of the empty one. On the server you then read that int out of the object sent to add the player to a team.

Solution 2
Set a UserVariable to the player that is then distributed to all other clients automagically to be read.

Hope that helps you along!

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Oct 2011, 11:43

That's indeed the path a connection follows at start, the new player object is requested in the world class :

Code: Select all

    public boolean addOrRespawnPlayer(User user) {
        CombatPlayer player = getPlayer(user);
        if (player == null) {
            player = new CombatPlayer(user); ---> HERE
            players.add(player);
            extension.clientInstantiatePlayer(player);
            return true;
        }
        else {
            player.resurrect();
            extension.clientInstantiatePlayer(player);
            return false;
        }
    }


in the combat player class it will hit on this :

Code: Select all

    public CombatPlayer(User sfsUser) {
        this.sfsUser = sfsUser;
        this.transform = Transform.random();
        this.collider = new Collider(0, 1, 0, 0.5, 2);
    }


There is your new player.
The player name isn't handled by the extension but by sfs internaly.
Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 31 Oct 2011, 13:41

ThomasLund wrote:Hi

You can solve it in at least 2 different ways I would say

Solution 1
Instead of sending an empty SFSObject in the spawnMe request

new ExtensionRequest("spawnMe", new SFSObject(), room);

you can make a SFSObject and add an int to that and use that object as parameter 2 instead of the empty one. On the server you then read that int out of the object sent to add the player to a team.
/Thomas


Right yea im trying to go with this approach, and I set up the code on the Network Manager easily. However, when that request is sent where exactly does that sent object go, in fpsExtension I dont see any use of the empty SFSObject sent, nor in spawnMeHandler. Im sure this is also trivial but I just cant see the link there.

Is the empty SFSObject used here:
public void handleClientRequest(User u, ISFSObject data) {
In the spawn me handler? I ask this because in the spawnMeHandler the ISFSObject data is never used again, so I dont really see the point, unless its just standardized that a Request Handler must receive an Object?

Also to add the team aspect, in the code:
public CombatPlayer(User sfsUser) {
this.sfsUser = sfsUser;
this.weapon = new Weapon();
this.transform = Transform.random();
this.collider = new Collider(0, 1, 0, 0.5, 2);
}

Can I simply do this.team = data.getInt("team"); once i send the data object to the CombatPlayer or do I somewhere have to specify that team is an aspect of CombatPlayer because im unable to find where its specified where weapon is an aspect of CombatPlayer. (My java is a bit rusty)

Finally, I know the code
private void OnExtensionResponse(BaseEvent evt) {
try {
string cmd = (string)evt.Params["cmd"];
ISFSObject dt = (SFSObject)evt.Params["params"];

containts the data of the player for the client in which
if (cmd == "spawnPlayer") {
HandleInstantiatePlayer(dt);
}

is used, but I dont know which part of the extension sends BaseEvent evt, because I need to have that returned BaseEvent include the team data such that ISFSObject dt will have the information about which team the player is on and I just dont know where I can modify that returned evt.

Sorry this was long and again thanks for the help.
Jackiepro
Posts: 12
Joined: 30 Sep 2011, 06:54

Postby Jackiepro » 31 Oct 2011, 15:58

Ok so I made the following changes to the code:
public void SendSpawnRequest() {
int team = 0;
if (OptionsManager.InvertMouseY) {
team = 1;
}


Room room = smartFox.LastJoinedRoom;
ISFSObject data = new SFSObject();
data.PutInt("team", team);
ExtensionRequest request = new ExtensionRequest("spawnMe", data, room);
smartFox.Send(request);
}




public void handleClientRequest(User u, ISFSObject data) {
int team = data.getInt("team");
World world = RoomHelper.getWorld(this);
boolean newPlayer = world.addOrRespawnPlayer(u, team);



public boolean addOrRespawnPlayer(User user, int team) {
CombatPlayer player = getPlayer(user);

if (player == null) {
player = new CombatPlayer(user, team);



public CombatPlayer(User sfsUser, int team) {
this.sfsUser = sfsUser;
this.team = team;
this.weapon = new Weapon();
this.transform = Transform.random();
this.collider = new Collider(0, 1, 0, 0.5, 2);
}

public void toSFSObject(ISFSObject data) {
ISFSObject playerData = new SFSObject();

playerData.putInt("id", sfsUser.getId());
playerData.putInt("score", this.score);
playerData.putInt("team", this.team);


transform.toSFSObject(playerData);
data.putSFSObject("player", playerData);
}

public int getTeam() {
return team;
}



private void HandleInstantiatePlayer(ISFSObject dt) {
ISFSObject playerData = dt.GetSFSObject("player");
int userId = playerData.GetInt("id");
int score = playerData.GetInt("score");
int team = playerData.GetInt("team");
NetworkTransform ntransform = NetworkTransform.FromSFSObject(playerData);

User user = smartFox.UserManager.GetUserById(userId);
string name = user.Name;

if (userId == smartFox.MySelf.Id) {
PlayerManager.Instance.SpawnPlayer(ntransform, name, score);
}
else {
PlayerManager.Instance.SpawnEnemy(userId, ntransform, name, score, team);
}
}



public void SpawnEnemy(int id, NetworkTransform ntransform, string name, int score, int team) {
int myTeam = 0;
GameObject playerObj;
if (OptionsManager.InvertMouseY) {
myTeam = 1;
}

if (myTeam == team) {
playerObj = GameObject.Instantiate(allyPrefab) as GameObject;
} else {
playerObj = GameObject.Instantiate(enemyPrefab) as GameObject;
}


Hopefully I posted all that in a logical order. Im assuming this works? Im unable to compile the new jar yet so im not able to test it but are there any repercussions to the code changes I made here. Also the only thing still puzzling me is the definition of a "player". In combat player I simply added this.team = team however I dont know if team is a part of the combat player object or there is other code I must add to define the team of a combat player. Thanks for the help in advance. [/quote]
epi3rc3
Posts: 1
Joined: 01 Nov 2011, 04:19

Postby epi3rc3 » 01 Nov 2011, 04:28

I'm having trouble with this example. I basically figured everything out and put it all into my own game but only the player moves around and the enemy just stays still. I know theres the NetworkTransformSender and Receiver but i don't understand how the sender knows to which receiver to send too? is there anything else i need to do besides add a NetworkTransformSender to the Player and NetworkTransformReciever + NetworkTransformInterpolation to the Enemy?

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 26 guests