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 mindbubbles · Jun 06, 2016 at 03:06 PM · collisionnetworkingmultiplayer

Multiplayer collision glitches

I try to make a simple multiplayer example. It doesn't matter if i try it in 2d or in 3d the result is the same. I will describe it in 3D that's what I tried a least. I simple add two cylinders to a Scene and a ball. I set up a script for the Player Controller so each Player can controll his own Player. I add the Network transform, the network ID set it to local playre authority for the Player prefab and did everything describe in the several tutorials I red.

Thinks are working as expected. On the host I can collide with the Ball and the other Player, after adding a bouncing material the ball is bouncing away from the Player and also the other Player does, when I hit him hard enough. (I added a boost on the fire button) I did not program the collisions, I just let the physics engine do the work. The Problem is on the Client side, there the Ball behave some Kind of sticky. It doesn't bounces of the Player it is glitchy and behaves just not the right way.

I tried every combination with Collision Detection Descrete - Continuous - Continuous Dynmics with Interpolation or without or Extrapolation. Combination between Player and Ball and Player / Player.

I also tried different combination with the Network Settings, but nothing helps.

I add some screenshots, so you have a better understandig of what I try to do and my Settings.

The Questions is: Is the pyhics engine in combination with Network capable, to do what I want, or is the better way to: Programm the pyhics OR put the Player from the Client back to the Server and let him just remote control from the Client. I think of catch the Input from the Keyboard and sending it to the Server and do the movment there and sync back only the graphics. (I hope, that you get what I mean)

alt text

alt text

Player Script:

using UnityEngine; using UnityEngine.Networking; using System.Collections; using UnityStandardAssets.CrossPlatformInput;

public class PlayerController : NetworkBehaviour {

 public float movmentForce = 75;
 public float accelerationOnFire;
 public GameObject ball;
 public float fireRate = 0.5F;
 private float nextFire = 0.0F;

 private Rigidbody rbPlayer;

 // Use this for initialization
 void Start()
 {
     Vector3 pos;
     Quaternion q;
     pos.x = 0;
     pos.y = 1;
     pos.z = 10;

     transform.position = pos;

     rbPlayer = GetComponent<Rigidbody>();

     ball = GameObject.FindGameObjectWithTag("Ball");


 }

 // Update is called once per frame
 void Update()
 {
     if (!isLocalPlayer)
         return;

     float inputHorizontal = CrossPlatformInputManager.GetAxis("Horizontal");
     float inputVertical = CrossPlatformInputManager.GetAxis("Vertical");
     //        float inputHorizontal = Input.GetAxis("Horizontal");
     //        float inputVertical = Input.GetAxis("Vertical");


     if (inputHorizontal != 0)
     {
         rbPlayer.AddForce(Vector3.right * movmentForce * inputHorizontal, ForceMode.Force);
     }
     if (inputVertical != 0)
     {
         rbPlayer.AddForce(Vector3.forward * movmentForce * inputVertical, ForceMode.Force);
     }
     if (CrossPlatformInputManager.GetButton("Fire1") && Time.time > nextFire)
     //        if (Input.GetButton("Fire1") && Time.time > nextFire)
     {
         nextFire = Time.time + fireRate;
         rbPlayer.AddForce(transform.forward * -accelerationOnFire, ForceMode.Force);
     }

     //Center the camera over the player
     Vector3 pos = transform.position;

     pos.y += 10;
     Camera.main.transform.position = pos;
 }

 void FixedUpdate()
 {
     if (!isLocalPlayer)
         return;

     //Rotates the Player towards the ball, so the Player faces the ball
     if (ball)
     {
         Vector3 dir = ball.transform.position - rbPlayer.transform.position;
         float angle = Mathf.Atan2(dir.x, dir.z) * Mathf.Rad2Deg;
         rbPlayer.transform.rotation = Quaternion.AngleAxis(angle, Vector3.up);
         rbPlayer.transform.Rotate(0, 180, 0);
     }
     else
     {
         ball = GameObject.FindGameObjectWithTag("Ball");
     }

 }

}

Ball Spawner:

using UnityEngine; using UnityEngine.Networking; using System.Collections;

public class BallSpawn : NetworkBehaviour {

 public GameObject ballPrefab;


 // Use this for initialization
 public override void OnStartServer()
 {
     SpawnBall();
 }


 void SpawnBall()
 {
     GameObject myBall = Instantiate<GameObject>(ballPrefab);//, Vector2.zero, Quaternion.identity);        

     NetworkServer.Spawn(myBall);

     myBall.tag = "Ball";
 }

}

unbenannt.png (185.8 kB)
unbenannt2.png (50.2 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Layer Collision in Networks (Mulitplayer Game). 0 Answers

Using SmartFoxServer extension to detect collisions? 2 Answers

Make objects collide only with other objects of same type 2 Answers

Players can't move each other in multiplayer? 1 Answer


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