Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Dragonsong · Nov 06, 2015 at 04:39 PM · multiplayerplayermultiplayer-networkingplayer movementshooter

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.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · 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
0

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.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

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

How to sync transform of character's bone(spine)? 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