- Home /
Local player always at same position
I am trying out UNET and I am building a space invaders like game but with two players at each side of the screen shooting at each other.
I want the local player to always be at the bottom of the screen and see the enemy at the top.
I tried checking isLocalPlayer and isServer and only if both are false -> this means it's the enemy player and change his transform and rotation to be facing downwards and be at the top. But this brings unexpected behavior like spawning the bullets on the original position.
Answer by Dibbie · Nov 06, 2015 at 05:27 PM
Stuff like bullet spawning, you want to Instantiate them as prefabs, from the position of the player firing it, and the rotation of the player firing it as well, and not inherit its (the bullet prefab) own rotation and position, or else youll get stuff like that happening - you wanna make sure everything that a player is responsible for, even moving left and right, take place from the players current perspective and not the perspective of the world. Even better, try using local everything when changing stuff, like localRotation, localPosition, localScale, etc, for more accuracy.
A better option, id suggest for you, is before your script spawns the players, dont do it individually, put them in a "Waiting room" feel, and just wait for both to be connected, then once a match is supposed to start (maybe do a count down from 3 seconds after both players are connected/the room has 2 players in it), then check if the first player in the room is the local player, and spawn that local player at the bottom, then by default, the other person has to be another computer, so spawn it at the top.
Regardless, your going to get some weird stuff happening, maybe even with movement, and it will be very clear if you tried adding a forward/backward option as well, maybe even with left and right, at the bottom, right might go left, and at the top, vice versa...
And that would be because of HOW you have it set up for movement. You want to make sure everything is based off the PLAYER and not the WORLD. So even for moving left, make sure its the players left. A easy way to do this is to create a empty gameobject, and have the player move closer to that game object, but attach that game object to the players left side, that way their always forced to move on their own left (because its a child of the player itself), or when moving left, take the players location X and move to its own location X - 1.
Answer by $$anonymous$$ · Dec 04, 2015 at 04:04 PM
What you are describing sounds more like a Player vs Player setup rather than Space Invaders.
In any case the movement and Spawn location script is really all you need to be concerned with.
You already know about how far left or right forward or back you are moving so you might want to create some sort of physical barrier to stop movement beyond a certain point and just make them invisible, especially since some of the coding for limiting how far left or right by code doesn't work correctly like it did in 4.6 with math clamping being limited to certain area in x_min/x_max, etc.
But when it comes to the enemy if its a live player verses player deal, the point of their spawn needs to be a negative rotation of the direction you are facing. So if you are 0 on the Z axis, they need to be 180 or -180 on the Z axis so they face your direction.
Your answer
Follow this Question
Related Questions
my multiplayer game second player not active 0 Answers
Player sets up server UNet. 0 Answers
Error in the script 0 Answers
Problem with Unity Multiplayer.. I control my friend character ? 0 Answers