Added basic character controller via importing Starter Assets from Unity.

This commit is contained in:
2025-11-08 11:59:44 +09:00
parent 3e92e5684a
commit e7e0733258
347 changed files with 46833 additions and 8 deletions

View File

@@ -0,0 +1,35 @@
using UnityEngine;
public class BasicRigidBodyPush : MonoBehaviour
{
public LayerMask pushLayers;
public bool canPush;
[Range(0.5f, 5f)] public float strength = 1.1f;
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (canPush) PushRigidBodies(hit);
}
private void PushRigidBodies(ControllerColliderHit hit)
{
// https://docs.unity3d.com/ScriptReference/CharacterController.OnControllerColliderHit.html
// make sure we hit a non kinematic rigidbody
Rigidbody body = hit.collider.attachedRigidbody;
if (body == null || body.isKinematic) return;
// make sure we only push desired layer(s)
var bodyLayerMask = 1 << body.gameObject.layer;
if ((bodyLayerMask & pushLayers.value) == 0) return;
// We dont want to push objects below us
if (hit.moveDirection.y < -0.3f) return;
// Calculate push direction from move direction, horizontal motion only
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0.0f, hit.moveDirection.z);
// Apply the push and take strength into account
body.AddForce(pushDir * strength, ForceMode.Impulse);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 909d917d73a63f940ac158d02e936645
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267961
packageName: 'Starter Assets: Character Controllers | URP'
packageVersion: 2.0.2
assetPath: Assets/Starter Assets/Runtime/Common/BasicRigidBodyPush.cs
uploadId: 721456