This commit is contained in:
2025-06-16 15:14:23 +02:00
committed by devbeni
parent 60fe4620ff
commit 4ff561284f
3174 changed files with 428263 additions and 0 deletions

View File

@ -0,0 +1,46 @@
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;
protected override void OnValidate()
{
base.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);
}
}
}
}