```
feat(EnemyBaseMove): 添加重力系统和物理材质优化 - 添加重力加速度变量和垂直速度控制 - 实现applyGravity()和getVerticalVelocity()方法处理垂直运动 - 在Attack状态和静止时应用重力效果 - 为CharacterController添加新的物理材质引用 - 调整CharacterController中心位置从(0,0,0)到(0,1,0) - 在场景中禁用根动作应用以配合自定义移动系统 ```
This commit is contained in:
1 parent
cdae901b96
commit
b80d31101c
2 files changed
+50
-16
No files matched your search
@@ -124,18 +124,6 @@ NavMeshSettings:
|
|||||||
debug:
|
debug:
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
m_NavMeshData: {fileID: 0}
|
m_NavMeshData: {fileID: 0}
|
||||||
--- !u!134 &14211372
|
|
||||||
PhysicMaterial:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_Name:
|
|
||||||
dynamicFriction: 0.6
|
|
||||||
staticFriction: 0.6
|
|
||||||
bounciness: 0
|
|
||||||
frictionCombine: 0
|
|
||||||
bounceCombine: 0
|
|
||||||
--- !u!1 &46311543
|
--- !u!1 &46311543
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1429,6 +1417,11 @@ PrefabInstance:
|
|||||||
value:
|
value:
|
||||||
objectReference: {fileID: 22100000, guid: c205ebfae56f644af94a7948cc0609be,
|
objectReference: {fileID: 22100000, guid: c205ebfae56f644af94a7948cc0609be,
|
||||||
type: 2}
|
type: 2}
|
||||||
|
- target: {fileID: 5866666021909216657, guid: aedf6e849dd924e229c57640f99ff50a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_ApplyRootMotion
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
@@ -1455,7 +1448,7 @@ CharacterController:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 989436104}
|
m_GameObject: {fileID: 989436104}
|
||||||
m_Material: {fileID: 14211372}
|
m_Material: {fileID: 1431018394}
|
||||||
m_IncludeLayers:
|
m_IncludeLayers:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 0
|
m_Bits: 0
|
||||||
@@ -1473,7 +1466,7 @@ CharacterController:
|
|||||||
m_StepOffset: 0.3
|
m_StepOffset: 0.3
|
||||||
m_SkinWidth: 0.08
|
m_SkinWidth: 0.08
|
||||||
m_MinMoveDistance: 0.001
|
m_MinMoveDistance: 0.001
|
||||||
m_Center: {x: 0, y: 0, z: 0}
|
m_Center: {x: 0, y: 1, z: 0}
|
||||||
--- !u!114 &989436106
|
--- !u!114 &989436106
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1764,6 +1757,18 @@ MeshFilter:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1369034729}
|
m_GameObject: {fileID: 1369034729}
|
||||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!134 &1431018394
|
||||||
|
PhysicMaterial:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: ' (Instance)'
|
||||||
|
dynamicFriction: 0.6
|
||||||
|
staticFriction: 0.6
|
||||||
|
bounciness: 0
|
||||||
|
frictionCombine: 0
|
||||||
|
bounceCombine: 0
|
||||||
--- !u!1 &1489219289
|
--- !u!1 &1489219289
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ public class NewBehaviourScript : MonoBehaviour
|
|||||||
//移动速度
|
//移动速度
|
||||||
public float speed = 5f;
|
public float speed = 5f;
|
||||||
|
|
||||||
|
//重力加速度
|
||||||
|
public float gravity = -20f;
|
||||||
|
|
||||||
//活动范围
|
//活动范围
|
||||||
public float range = 500f;
|
public float range = 500f;
|
||||||
|
|
||||||
@@ -35,6 +38,9 @@ public class NewBehaviourScript : MonoBehaviour
|
|||||||
// 角色控制器
|
// 角色控制器
|
||||||
private CharacterController controller;
|
private CharacterController controller;
|
||||||
|
|
||||||
|
//垂直速度
|
||||||
|
private float verticalVelocity;
|
||||||
|
|
||||||
//状态枚举
|
//状态枚举
|
||||||
public enum State
|
public enum State
|
||||||
{
|
{
|
||||||
@@ -73,6 +79,7 @@ public class NewBehaviourScript : MonoBehaviour
|
|||||||
if (state == State.Attack)
|
if (state == State.Attack)
|
||||||
{
|
{
|
||||||
animator.SetInteger("speed", 0);
|
animator.SetInteger("speed", 0);
|
||||||
|
applyGravity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,19 +171,41 @@ public class NewBehaviourScript : MonoBehaviour
|
|||||||
if (movement == Vector3.zero)
|
if (movement == Vector3.zero)
|
||||||
{
|
{
|
||||||
animator.SetInteger("speed", 0);
|
animator.SetInteger("speed", 0);
|
||||||
|
applyGravity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//改变动画控制器的参数
|
//改变动画控制器的参数
|
||||||
animator.SetInteger("speed", 1);
|
animator.SetInteger("speed", 1);
|
||||||
//向目标点移动
|
//向目标点移动,同时应用垂直重力
|
||||||
controller.Move(movement.normalized * Time.deltaTime * speed);
|
Vector3 velocity = movement.normalized * speed;
|
||||||
|
velocity.y = getVerticalVelocity();
|
||||||
|
controller.Move(velocity * Time.deltaTime);
|
||||||
//改变角色朝向目标点,只改变y轴
|
//改变角色朝向目标点,只改变y轴
|
||||||
transform.rotation = Quaternion.LookRotation(movement, Vector3.up);
|
transform.rotation = Quaternion.LookRotation(movement, Vector3.up);
|
||||||
transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0);
|
transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private float getVerticalVelocity()
|
||||||
|
{
|
||||||
|
if (controller.isGrounded && verticalVelocity < 0)
|
||||||
|
{
|
||||||
|
verticalVelocity = -2f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
verticalVelocity += gravity * Time.deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return verticalVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyGravity()
|
||||||
|
{
|
||||||
|
controller.Move(Vector3.up * getVerticalVelocity() * Time.deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
//随机目标点
|
//随机目标点
|
||||||
private void randomTargetPos()
|
private void randomTargetPos()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user