initial commit
This commit is contained in:
318
Assets/FPController/Character.prefab
Normal file
318
Assets/FPController/Character.prefab
Normal file
@@ -0,0 +1,318 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &3783089677589408436
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3783089677589408394}
|
||||
- component: {fileID: 3783089677589408437}
|
||||
- component: {fileID: -8838009715090066251}
|
||||
- component: {fileID: 4453667725109520444}
|
||||
m_Layer: 6
|
||||
m_Name: Character
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &3783089677589408394
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089677589408436}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 3783089678612372415}
|
||||
- {fileID: 3783089678093014820}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!143 &3783089677589408437
|
||||
CharacterController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089677589408436}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Height: 2
|
||||
m_Radius: 0.5
|
||||
m_SlopeLimit: 45
|
||||
m_StepOffset: 0.5
|
||||
m_SkinWidth: 0.08
|
||||
m_MinMoveDistance: 0.001
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &-8838009715090066251
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089677589408436}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Actions: {fileID: -944628639613478452, guid: 9ea33b5d80f455b3c9f29309f70337ad, type: 3}
|
||||
m_NotificationBehavior: 0
|
||||
m_UIInputModule: {fileID: 0}
|
||||
m_DeviceLostEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_DeviceRegainedEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ControlsChangedEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionEvents:
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 03c3bd24-f439-463f-9321-9ad5d4c8ec44
|
||||
m_ActionName: Player/Move[/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: f9227e6e-32bd-48e8-94ba-e05ef74876e1
|
||||
m_ActionName: Player/Look[/Mouse/delta]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: c46027b0-30db-4c25-a210-43ca1ec97621
|
||||
m_ActionName: Player/Fire[/Mouse/leftButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: ee7c62cc-c1b1-412f-b9d1-a66d38b8122e
|
||||
m_ActionName: UI/Navigate[/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 468cb2bb-3bdc-4155-8040-0101b8746fb2
|
||||
m_ActionName: UI/Submit[/Keyboard/enter]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: be74892c-2310-4c5a-9933-a3d900177233
|
||||
m_ActionName: UI/Cancel[/Keyboard/escape]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 1d29b622-2f03-4d81-9c2b-c1d7c17ba1e9
|
||||
m_ActionName: UI/Point[/Mouse/position]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 9a37c626-5ce1-4d0b-99e7-d3e2c1387598
|
||||
m_ActionName: UI/Click[/Mouse/leftButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: e318f11f-1538-40e6-8259-5c26f83eee2b
|
||||
m_ActionName: UI/ScrollWheel[/Mouse/scroll]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 7727ae59-584a-40db-b4f9-3697864c60d2
|
||||
m_ActionName: UI/MiddleClick[/Mouse/middleButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 7d259ed3-88b7-4cb2-b580-e8ed86d613c1
|
||||
m_ActionName: UI/RightClick[/Mouse/rightButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 415b92b6-0ded-4c75-9b1c-f084fe07ddfc
|
||||
m_ActionName: UI/TrackedDevicePosition
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 2ece3b9b-2a00-4def-882d-5e859d54e00e
|
||||
m_ActionName: UI/TrackedDeviceOrientation
|
||||
m_NeverAutoSwitchControlSchemes: 0
|
||||
m_DefaultControlScheme:
|
||||
m_DefaultActionMap: Player
|
||||
m_SplitScreenIndex: -1
|
||||
m_Camera: {fileID: 0}
|
||||
--- !u!114 &4453667725109520444
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089677589408436}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 89440bbf6aff41a3caf76bc75a4f22e2, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
playerSpeed: 6
|
||||
cameraSensitivityMouse: 0.1
|
||||
cameraSensitivityGamepad: 2
|
||||
upperAngleClamp: 60
|
||||
lowerAngleClamp: -60
|
||||
--- !u!1 &3783089678093014823
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3783089678093014820}
|
||||
- component: {fileID: 3783089678093014842}
|
||||
- component: {fileID: 3783089678093014821}
|
||||
m_Layer: 6
|
||||
m_Name: Camera
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &3783089678093014820
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089678093014823}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3783089677589408394}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!20 &3783089678093014842
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089678093014823}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!81 &3783089678093014821
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089678093014823}
|
||||
m_Enabled: 1
|
||||
--- !u!1 &3783089678612372414
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3783089678612372415}
|
||||
- component: {fileID: 3783089678612372402}
|
||||
- component: {fileID: 3783089678612372413}
|
||||
m_Layer: 6
|
||||
m_Name: Capsule
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &3783089678612372415
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089678612372414}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3783089677589408394}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &3783089678612372402
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089678612372414}
|
||||
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &3783089678612372413
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3783089678612372414}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
7
Assets/FPController/Character.prefab.meta
Normal file
7
Assets/FPController/Character.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3500e61f03ba021efad4f18c2307233a
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
240
Assets/FPController/Controls.cs
Normal file
240
Assets/FPController/Controls.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Controls : MonoBehaviour
|
||||
{
|
||||
public float playerSpeed = 0.2f;
|
||||
public float cameraSensitivityMouse = 0.01f;
|
||||
public float cameraSensitivityGamepad = 2f;
|
||||
public float upperAngleClamp = 60;
|
||||
public float lowerAngleClamp = -60;
|
||||
|
||||
private Vector2 currentMotion = Vector2.zero;
|
||||
private GameObject playerCameraObject;
|
||||
private CharacterController controller;
|
||||
private PlayerInput playerInput;
|
||||
private Vector2 currentLook = Vector2.zero;
|
||||
private bool useGamepad = false;
|
||||
private bool doJump = false;
|
||||
private bool canDoubleJump = true;
|
||||
private float timeJump = -1f;
|
||||
|
||||
private bool doDash = false;
|
||||
private float timeDash = -1f;
|
||||
|
||||
private Vector3 hookPos;
|
||||
private bool isHooked = false;
|
||||
|
||||
private float timeJumpPad = -1f;
|
||||
|
||||
public int hp = 100;
|
||||
public Text hpText;
|
||||
|
||||
public GameObject projectile;
|
||||
|
||||
void Start()
|
||||
{
|
||||
controller = this.GetComponent<CharacterController>();
|
||||
playerInput = this.GetComponent<PlayerInput>();
|
||||
playerCameraObject = this.transform.Find("Camera").gameObject;
|
||||
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
//Movement
|
||||
Vector3 forward = this.transform.TransformDirection(Vector3.forward);
|
||||
Vector3 strafe = this.transform.TransformDirection(Vector3.right);
|
||||
float vertical = 0f;
|
||||
if (!this.controller.isGrounded && !this.isHooked){
|
||||
vertical += Physics.gravity.y * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
if (this.doJump){
|
||||
this.doJump = false;
|
||||
this.canDoubleJump = false;
|
||||
this.timeJump = 0f;
|
||||
this.isHooked = false;
|
||||
}
|
||||
|
||||
if (this.controller.isGrounded){
|
||||
this.canDoubleJump = true;
|
||||
}
|
||||
|
||||
if (this.timeJump >= 0f){
|
||||
if (this.timeJump >= 0.5f) {
|
||||
this.timeJump = -1f;
|
||||
}else{
|
||||
var jumpProgress = this.timeJump / 0.5f;
|
||||
vertical += (sinApply(jumpProgress) * 1.4f);
|
||||
this.timeJump += Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.timeJumpPad >= 0f){
|
||||
|
||||
if (this.timeJumpPad >= 0.8f){
|
||||
this.timeJumpPad = -1f;
|
||||
}else{
|
||||
var progress = this.timeJumpPad / 0.8f;
|
||||
vertical += sinApply(progress) * 4f;
|
||||
this.timeJumpPad += Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
var movement = (((strafe * this.currentMotion.x) + (forward * this.currentMotion.y)) * this.playerSpeed) + (Vector3.up * vertical);
|
||||
|
||||
if (this.doDash){
|
||||
this.isHooked = false;
|
||||
this.doDash = false;
|
||||
this.timeDash = 0f;
|
||||
}
|
||||
|
||||
if (this.timeDash >= 0f){
|
||||
if (this.timeDash >= 0.3f){
|
||||
this.timeDash = -1f;
|
||||
}else{
|
||||
var progress = this.timeDash / 0.3f;
|
||||
movement += (forward * progress);
|
||||
this.timeDash += Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isHooked){
|
||||
// Apply force in the direction of the hook pos
|
||||
var dirVec = this.hookPos - this.transform.position;
|
||||
if (dirVec.magnitude >= 1.5f){
|
||||
movement += Vector3.Normalize(dirVec)* 1.1f;
|
||||
}else{
|
||||
this.isHooked = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.controller.Move(movement);
|
||||
|
||||
// Look if gamepad
|
||||
if (this.useGamepad){
|
||||
ApplyLookVector(this.currentLook,cameraSensitivityGamepad);
|
||||
}
|
||||
}
|
||||
|
||||
private void hook(){
|
||||
Ray ray = new Ray(this.playerCameraObject.transform.position, playerCameraObject.transform.TransformDirection(Vector3.forward));
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 100f)){
|
||||
hookPos = hit.point;
|
||||
isHooked = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnHook(InputValue value){
|
||||
hook();
|
||||
}
|
||||
|
||||
public void Damaged(){
|
||||
this.hpText.text = this.hp.ToString();
|
||||
if (this.hp <= 0){
|
||||
// Player died
|
||||
// TODO: death message
|
||||
Debug.Log("dead");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retuns a value from 0 to 1 of how much of the force should be applyed at the current progress of the action
|
||||
/// </summary>
|
||||
/// <param name="progress"></param>
|
||||
/// <returns></returns>
|
||||
private float sinApply(float progress){
|
||||
return (float)(Math.Sin(progress * Math.PI) / Math.PI);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by PlayerInput when Move value change.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public void OnMove(InputValue value)
|
||||
{
|
||||
this.currentMotion = value.Get<Vector2>();
|
||||
}
|
||||
|
||||
public void OnAttack(InputValue value){
|
||||
var instantiatedProjectile = Instantiate(projectile, this.playerCameraObject.transform.position, Quaternion.identity);
|
||||
var rig = instantiatedProjectile.GetComponent<Rigidbody>();
|
||||
rig.velocity = this.playerCameraObject.transform.forward * 35f;
|
||||
Physics.IgnoreCollision(instantiatedProjectile.GetComponent<SphereCollider>(), this.GetComponent<Collider>());
|
||||
}
|
||||
|
||||
public void OnJump(InputValue value)
|
||||
{
|
||||
if (this.controller.isGrounded){
|
||||
this.doJump = true;
|
||||
this.canDoubleJump = true;
|
||||
}else if (this.canDoubleJump){
|
||||
this.doJump = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by PlayerInput when Look value change.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public void OnLook(InputValue value)
|
||||
{
|
||||
var camMovement = value.Get<Vector2>();
|
||||
|
||||
if (this.useGamepad){
|
||||
this.currentLook = camMovement;
|
||||
}else{
|
||||
ApplyLookVector(camMovement,cameraSensitivityMouse);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDash(InputValue value){
|
||||
this.doDash = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by PlayerInput when the user starts using mouse or gamepad.
|
||||
/// </summary>
|
||||
public void OnControlsChanged(){
|
||||
this.useGamepad = playerInput.currentControlScheme == "Gamepad";
|
||||
}
|
||||
|
||||
public void JumpPad(){
|
||||
this.timeJumpPad = 0f;
|
||||
}
|
||||
|
||||
void ApplyLookVector(Vector2 vector,float sensitivity){
|
||||
// Left right looking
|
||||
this.transform.Rotate(Vector3.up * vector.x * sensitivity);
|
||||
|
||||
// Up down looking
|
||||
Vector3 rot = playerCameraObject.transform.rotation.eulerAngles + new Vector3(-vector.y * sensitivity, 0f, 0f);
|
||||
rot.x = ClampAngle(rot.x, this.lowerAngleClamp, this.upperAngleClamp);
|
||||
playerCameraObject.transform.eulerAngles = rot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps an angle.
|
||||
/// </summary>
|
||||
/// <param name="angle"></param>
|
||||
/// <param name="from">e.g. -45</param>
|
||||
/// <param name="to">e.g. 45</param>
|
||||
/// <returns>Clamped angle from 0 to 360</returns>
|
||||
float ClampAngle(float angle, float from, float to)
|
||||
{
|
||||
if (angle < 0f) angle = 360 + angle;
|
||||
if (angle > 180f) return Mathf.Max(angle, 360 + from);
|
||||
return Mathf.Min(angle, to);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
11
Assets/FPController/Controls.cs.meta
Normal file
11
Assets/FPController/Controls.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89440bbf6aff41a3caf76bc75a4f22e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
310
Assets/FPController/FPInput.inputactions
Normal file
310
Assets/FPController/FPInput.inputactions
Normal file
@@ -0,0 +1,310 @@
|
||||
{
|
||||
"name": "FPInput",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Player",
|
||||
"id": "a71b3ee4-1a8b-4b38-b0f3-4274b7517dfb",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Move",
|
||||
"type": "Value",
|
||||
"id": "03c3bd24-f439-463f-9321-9ad5d4c8ec44",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": ""
|
||||
},
|
||||
{
|
||||
"name": "Look",
|
||||
"type": "Value",
|
||||
"id": "f9227e6e-32bd-48e8-94ba-e05ef74876e1",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": ""
|
||||
},
|
||||
{
|
||||
"name": "Jump",
|
||||
"type": "Button",
|
||||
"id": "206ab4c9-2bba-49a3-ae21-4847e569aa7a",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": ""
|
||||
},
|
||||
{
|
||||
"name": "Dash",
|
||||
"type": "Button",
|
||||
"id": "6e93120e-d624-4a32-93a1-1607626ebe80",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": ""
|
||||
},
|
||||
{
|
||||
"name": "Hook",
|
||||
"type": "Button",
|
||||
"id": "49075234-a6cb-4645-83a3-35803b49c629",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": ""
|
||||
},
|
||||
{
|
||||
"name": "Attack",
|
||||
"type": "Button",
|
||||
"id": "94067ce8-eedc-4aeb-a82d-81f7b944bc5b",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": ""
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "",
|
||||
"id": "978bfe49-cc26-4a3d-ab7b-7d7a29327403",
|
||||
"path": "<Gamepad>/leftStick",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Gamepad",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "WASD",
|
||||
"id": "00ca640b-d935-4593-8157-c05846ea39b3",
|
||||
"path": "Dpad",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "e2062cb9-1b15-46a2-838c-2f8d72a0bdd9",
|
||||
"path": "<Keyboard>/w",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "8180e8bd-4097-4f4e-ab88-4523101a6ce9",
|
||||
"path": "<Keyboard>/upArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "320bffee-a40b-4347-ac70-c210eb8bc73a",
|
||||
"path": "<Keyboard>/s",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "1c5327b5-f71c-4f60-99c7-4e737386f1d1",
|
||||
"path": "<Keyboard>/downArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "d2581a9b-1d11-4566-b27d-b92aff5fabbc",
|
||||
"path": "<Keyboard>/a",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "2e46982e-44cc-431b-9f0b-c11910bf467a",
|
||||
"path": "<Keyboard>/leftArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "fcfe95b8-67b9-4526-84b5-5d0bc98d6400",
|
||||
"path": "<Keyboard>/d",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "77bff152-3580-4b21-b6de-dcd0c7e41164",
|
||||
"path": "<Keyboard>/rightArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "c1f7a91b-d0fd-4a62-997e-7fb9b69bf235",
|
||||
"path": "<Gamepad>/rightStick",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Gamepad",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "8c8e490b-c610-4785-884f-f04217b23ca4",
|
||||
"path": "<Mouse>/delta",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse;Touch",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "ba2df36e-8966-4cc4-b97a-236dd5d37702",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Jump",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "f50a54fb-bb76-4677-b455-65968df9c7a2",
|
||||
"path": "<XInputController>/buttonSouth",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Jump",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "0269f1c5-6cae-425b-b215-f5c8c3de7003",
|
||||
"path": "<Keyboard>/shift",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Dash",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "e38735ff-622f-4d8f-887e-721283315576",
|
||||
"path": "<Keyboard>/e",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Hook",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "0fc0794e-f312-44a5-bca8-837df5578ab1",
|
||||
"path": "<Mouse>/leftButton",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": [
|
||||
{
|
||||
"name": "Keyboard&Mouse",
|
||||
"bindingGroup": "Keyboard&Mouse",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<Keyboard>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
},
|
||||
{
|
||||
"devicePath": "<Mouse>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Gamepad",
|
||||
"bindingGroup": "Gamepad",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<Gamepad>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Touch",
|
||||
"bindingGroup": "Touch",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<Touchscreen>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Joystick",
|
||||
"bindingGroup": "Joystick",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<Joystick>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "XR",
|
||||
"bindingGroup": "XR",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<XRController>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
14
Assets/FPController/FPInput.inputactions.meta
Normal file
14
Assets/FPController/FPInput.inputactions.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ea33b5d80f455b3c9f29309f70337ad
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
18
Assets/FPController/JumpPad.cs
Normal file
18
Assets/FPController/JumpPad.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class JumpPad : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other){
|
||||
var characterController = other.GetComponent<Controls>();
|
||||
if (characterController != null){
|
||||
characterController.JumpPad();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/FPController/JumpPad.cs.meta
Normal file
11
Assets/FPController/JumpPad.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68f5362da3fcc1bca9e5320041a95492
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
111
Assets/FPController/JumpPad.prefab
Normal file
111
Assets/FPController/JumpPad.prefab
Normal file
@@ -0,0 +1,111 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &8314568732944286798
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 4589120558693393262}
|
||||
- component: {fileID: 1555833352617876600}
|
||||
- component: {fileID: 2969619133205361989}
|
||||
- component: {fileID: 2170941204670691750}
|
||||
- component: {fileID: 4660876031926875556}
|
||||
m_Layer: 0
|
||||
m_Name: JumpPad
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &4589120558693393262
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8314568732944286798}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 26.41, y: 0.11, z: -1.06}
|
||||
m_LocalScale: {x: 2, y: 0.1, z: 2}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &1555833352617876600
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8314568732944286798}
|
||||
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &2969619133205361989
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8314568732944286798}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!136 &2170941204670691750
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8314568732944286798}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_Enabled: 1
|
||||
m_Radius: 0.5000001
|
||||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
|
||||
--- !u!114 &4660876031926875556
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8314568732944286798}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 68f5362da3fcc1bca9e5320041a95492, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
7
Assets/FPController/JumpPad.prefab.meta
Normal file
7
Assets/FPController/JumpPad.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cc9dec85776f842fb3d7560482e765a
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user