Gonna move to server authority

This commit is contained in:
2022-01-31 17:27:38 +05:30
parent f3d21f4ec6
commit 7368968176
1354 changed files with 107808 additions and 80043 deletions

View File

@@ -1,44 +1,44 @@
using UnityEngine;
namespace Mirror.Examples.MultipleAdditiveScenes
{
[RequireComponent(typeof(Rigidbody))]
public class PhysicsCollision : NetworkBehaviour
{
[Tooltip("how forcefully to push this object")]
public float force = 12;
public Rigidbody rigidbody3D;
void OnValidate()
{
if (rigidbody3D == null)
rigidbody3D = GetComponent<Rigidbody>();
}
void Start()
{
rigidbody3D.isKinematic = !isServer;
}
[ServerCallback]
void OnCollisionStay(Collision other)
{
if (other.gameObject.CompareTag("Player"))
{
// get direction from which player is contacting object
Vector3 direction = other.contacts[0].normal;
// zero the y and normalize so we don't shove this through the floor or launch this over the wall
direction.y = 0;
direction = direction.normalized;
// push this away from player...a bit less force for host player
if (other.gameObject.GetComponent<NetworkIdentity>().connectionToClient.connectionId == NetworkConnection.LocalConnectionId)
rigidbody3D.AddForce(direction * force * .5f);
else
rigidbody3D.AddForce(direction * force);
}
}
}
}
using UnityEngine;
namespace Mirror.Examples.MultipleAdditiveScenes
{
[RequireComponent(typeof(Rigidbody))]
public class PhysicsCollision : NetworkBehaviour
{
[Tooltip("how forcefully to push this object")]
public float force = 12;
public Rigidbody rigidbody3D;
void OnValidate()
{
if (rigidbody3D == null)
rigidbody3D = GetComponent<Rigidbody>();
}
void Start()
{
rigidbody3D.isKinematic = !isServer;
}
[ServerCallback]
void OnCollisionStay(Collision other)
{
if (other.gameObject.CompareTag("Player"))
{
// get direction from which player is contacting object
Vector3 direction = other.contacts[0].normal;
// zero the y and normalize so we don't shove this through the floor or launch this over the wall
direction.y = 0;
direction = direction.normalized;
// push this away from player...a bit less force for host player
if (other.gameObject.GetComponent<NetworkIdentity>().connectionToClient.connectionId == NetworkConnection.LocalConnectionId)
rigidbody3D.AddForce(direction * force * .5f);
else
rigidbody3D.AddForce(direction * force);
}
}
}
}