407 lines
16 KiB
C#
Raw Normal View History

任务:实现基本玩法 1.策划数学模型 2.搬迁工具类如单例模式模板 3.创建玩家类,用于接受和发出指令、记录玩家信息等 4.创建马类,用来接受信息、物理计算、控制马的碰撞等模拟等 5.实装数学模型,实现马脚的控制 6.探索物理实现方式,给控制点加上碰撞体和刚体,似乎可行 --NG,分离的刚体无法作为整体传递力,脚的反作用力传不到身体上 7.把操控分组,左摇杆控制后两条腿、右摇杆控制前两条腿 8.探索物理的实现方式,尝试仅在主物体上挂载仅一个刚体,探索碰撞体组的使用方式/ ((1.给马添加四个碰撞体代表马足 ((2.每帧刷新碰撞体的偏移,使其对准真实马蹄位置,所以需要找准offset和世界空间下位置的对应关系 ((3.如何让马前进?目前发现无法使用真实物理的反作用力,只能根据输入或其他信息算出这个反作用力 (((1.最终应该通过原速度 + 计算出输入速度,不能使用力,因为使用力涉及的参数极多,很难修改 (((2.应该通过马足真实位置计算输入速度,不能使用控制点位置 (((3.每只足应该记住自己上一帧的位置,并每帧更新 ((4.本帧位置减上帧位置 = 运动速度,一个二维向量 ((5.并非一直有效,当本帧马足位置低于圆心 + 调整值时,才有效,否则该足贡献的速度为0.同时,需要有输入才有效,若无输入,同样贡献速度为0 ((6.NG,主要在判断速度是否有效上出了问题,试试每帧给足和地面测距,小于阈值的才给过,然后才加速度 ((7.GoodJob!通过上述方法和其他细微调整,已经使得马可以行走,并且得到不错的效果。但是肯定还有问题,需要后期更进一步调整 目前马能够受到控制,并且可以走动。同样支持键盘游玩,但是体验极差
2022-07-24 21:15:22 +08:00
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.3.0
// from Assets/勍/输入映射/PlayerC.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public partial class @PlayerC : IInputActionCollection2, IDisposable
{
public InputActionAsset asset { get; }
public @PlayerC()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""PlayerC"",
""maps"": [
{
""name"": ""GamePlay"",
""id"": ""d066c560-5817-4703-aecc-a975f13f7093"",
""actions"": [
{
""name"": ""MoveBackFoot"",
""type"": ""Value"",
""id"": ""1e173331-d5ad-4f9b-a307-56bf2eda0151"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
},
{
""name"": ""MoveFrontFoot"",
""type"": ""Value"",
""id"": ""d198c764-78f7-416a-a6b6-611e7f6fe52e"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
}
],
""bindings"": [
{
""name"": ""Keyboard"",
""id"": ""2f29b289-9196-49f9-879f-6e48c0fd135e"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveBackFoot"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""070f9c54-d3c3-4f9a-909b-c86b36554086"",
""path"": ""<Keyboard>/w"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""044805b5-ecef-4476-9a64-00f88f141f3f"",
""path"": ""<Keyboard>/s"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""2a896e80-041c-4c01-968a-793d2a741a6c"",
""path"": ""<Keyboard>/a"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""177e26dd-3a72-47e3-951a-3f9b3a942d40"",
""path"": ""<Keyboard>/d"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""GamePad"",
""id"": ""8e7cc629-4a8a-46f1-914b-46d7fd8da422"",
""path"": ""2DVector(mode=2)"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveBackFoot"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""aee182e3-5f55-494e-9293-cd5810f4a2dd"",
""path"": ""<Gamepad>/leftStick/up"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""6d7d49a7-f87d-45cb-81bb-a8139654b64b"",
""path"": ""<Gamepad>/leftStick/down"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""dbbc6bdf-e7d3-4a8b-8156-44b49947fb21"",
""path"": ""<Gamepad>/leftStick/left"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""bd9d31fa-3750-42db-a37a-fd6b24b35e29"",
""path"": ""<Gamepad>/leftStick/right"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveBackFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""Keyboard"",
""id"": ""847b8737-4b1b-4699-aca1-9ac3de703a77"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveFrontFoot"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""8b9631ca-0fa6-4272-ab7d-5bee70d9d367"",
""path"": ""<Keyboard>/upArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""bff77e64-88d3-41a3-9600-b07b5940fe0d"",
""path"": ""<Keyboard>/downArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""3d72b984-a8e0-432a-84fa-2501e1f0bf90"",
""path"": ""<Keyboard>/leftArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""94fd6f98-3a9d-4ca6-9934-f9ffb5ac487f"",
""path"": ""<Keyboard>/rightArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""GamePad"",
""id"": ""6e216e7e-d474-4342-af09-0f1936433ad9"",
""path"": ""2DVector(mode=2)"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveFrontFoot"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""51d7e337-7cdf-4c2e-9c93-7da2ace9f1e5"",
""path"": ""<Gamepad>/rightStick/up"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""36eb00e0-f26f-4fd4-a154-364f09ec4244"",
""path"": ""<Gamepad>/rightStick/down"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""4163f149-fe0e-43ce-ab08-95fbb2854cf6"",
""path"": ""<Gamepad>/rightStick/left"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""2a85b7b4-027a-4d5b-abf6-977ed6338453"",
""path"": ""<Gamepad>/rightStick/right"",
""interactions"": """",
""processors"": """",
""groups"": ""GamePlay"",
""action"": ""MoveFrontFoot"",
""isComposite"": false,
""isPartOfComposite"": true
}
]
}
],
""controlSchemes"": [
{
""name"": ""GamePlay"",
""bindingGroup"": ""GamePlay"",
""devices"": [
{
""devicePath"": ""<Gamepad>"",
""isOptional"": true,
""isOR"": false
},
{
""devicePath"": ""<Keyboard>"",
""isOptional"": false,
""isOR"": false
}
]
}
]
}");
// GamePlay
m_GamePlay = asset.FindActionMap("GamePlay", throwIfNotFound: true);
m_GamePlay_MoveBackFoot = m_GamePlay.FindAction("MoveBackFoot", throwIfNotFound: true);
m_GamePlay_MoveFrontFoot = m_GamePlay.FindAction("MoveFrontFoot", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
public IEnumerable<InputBinding> bindings => asset.bindings;
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
{
return asset.FindAction(actionNameOrId, throwIfNotFound);
}
public int FindBinding(InputBinding bindingMask, out InputAction action)
{
return asset.FindBinding(bindingMask, out action);
}
// GamePlay
private readonly InputActionMap m_GamePlay;
private IGamePlayActions m_GamePlayActionsCallbackInterface;
private readonly InputAction m_GamePlay_MoveBackFoot;
private readonly InputAction m_GamePlay_MoveFrontFoot;
public struct GamePlayActions
{
private @PlayerC m_Wrapper;
public GamePlayActions(@PlayerC wrapper) { m_Wrapper = wrapper; }
public InputAction @MoveBackFoot => m_Wrapper.m_GamePlay_MoveBackFoot;
public InputAction @MoveFrontFoot => m_Wrapper.m_GamePlay_MoveFrontFoot;
public InputActionMap Get() { return m_Wrapper.m_GamePlay; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(GamePlayActions set) { return set.Get(); }
public void SetCallbacks(IGamePlayActions instance)
{
if (m_Wrapper.m_GamePlayActionsCallbackInterface != null)
{
@MoveBackFoot.started -= m_Wrapper.m_GamePlayActionsCallbackInterface.OnMoveBackFoot;
@MoveBackFoot.performed -= m_Wrapper.m_GamePlayActionsCallbackInterface.OnMoveBackFoot;
@MoveBackFoot.canceled -= m_Wrapper.m_GamePlayActionsCallbackInterface.OnMoveBackFoot;
@MoveFrontFoot.started -= m_Wrapper.m_GamePlayActionsCallbackInterface.OnMoveFrontFoot;
@MoveFrontFoot.performed -= m_Wrapper.m_GamePlayActionsCallbackInterface.OnMoveFrontFoot;
@MoveFrontFoot.canceled -= m_Wrapper.m_GamePlayActionsCallbackInterface.OnMoveFrontFoot;
}
m_Wrapper.m_GamePlayActionsCallbackInterface = instance;
if (instance != null)
{
@MoveBackFoot.started += instance.OnMoveBackFoot;
@MoveBackFoot.performed += instance.OnMoveBackFoot;
@MoveBackFoot.canceled += instance.OnMoveBackFoot;
@MoveFrontFoot.started += instance.OnMoveFrontFoot;
@MoveFrontFoot.performed += instance.OnMoveFrontFoot;
@MoveFrontFoot.canceled += instance.OnMoveFrontFoot;
}
}
}
public GamePlayActions @GamePlay => new GamePlayActions(this);
private int m_GamePlaySchemeIndex = -1;
public InputControlScheme GamePlayScheme
{
get
{
if (m_GamePlaySchemeIndex == -1) m_GamePlaySchemeIndex = asset.FindControlSchemeIndex("GamePlay");
return asset.controlSchemes[m_GamePlaySchemeIndex];
}
}
public interface IGamePlayActions
{
void OnMoveBackFoot(InputAction.CallbackContext context);
void OnMoveFrontFoot(InputAction.CallbackContext context);
}
}