Add jump
This commit is contained in:
parent
63e2927e83
commit
761861e135
50
Assets/Prefab/PPV.prefab
Normal file
50
Assets/Prefab/PPV.prefab
Normal file
@ -0,0 +1,50 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &7152489397314124950
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7152489397314124952}
|
||||
- component: {fileID: 7152489397314124953}
|
||||
m_Layer: 8
|
||||
m_Name: PPV
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7152489397314124952
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7152489397314124950}
|
||||
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: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &7152489397314124953
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7152489397314124950}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
sharedProfile: {fileID: 11400000, guid: 45c620574ff0f6043888e8f692caf52b, type: 2}
|
||||
isGlobal: 1
|
||||
blendDistance: 0
|
||||
weight: 1
|
||||
priority: 0
|
@ -176,6 +176,7 @@ GameObject:
|
||||
- component: {fileID: 8667386836911801601}
|
||||
- component: {fileID: 8667386836911801600}
|
||||
- component: {fileID: 8667386836911801603}
|
||||
- component: {fileID: 4768974422273388731}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Player
|
||||
@ -246,6 +247,22 @@ MonoBehaviour:
|
||||
runSpeed: 20
|
||||
rotateSpeed: 5
|
||||
mouseSensitive: 100
|
||||
jump: 5
|
||||
onGround: 0
|
||||
--- !u!136 &4768974422273388731
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8667386836911801605}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_Enabled: 1
|
||||
m_Radius: 0.35
|
||||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 0.9, z: 0}
|
||||
--- !u!1 &8667386838808186343
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -135,7 +135,7 @@ GameObject:
|
||||
- component: {fileID: 763829263}
|
||||
m_Layer: 0
|
||||
m_Name: Cube
|
||||
m_TagString: Untagged
|
||||
m_TagString: Ground
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@ -368,6 +368,11 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8667386836911801603, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: jump
|
||||
value: 5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8667386836911801605, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
@ -375,51 +380,72 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 4f1a4eb0e633f7740b9c4928cf54ce35, type: 3}
|
||||
--- !u!1 &1623431975
|
||||
GameObject:
|
||||
--- !u!1001 &7152489398920308657
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1623431977}
|
||||
- component: {fileID: 1623431976}
|
||||
m_Layer: 8
|
||||
m_Name: PPV
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1623431976
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1623431975}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
sharedProfile: {fileID: 11400000, guid: 45c620574ff0f6043888e8f692caf52b, type: 2}
|
||||
isGlobal: 1
|
||||
blendDistance: 0
|
||||
weight: 1
|
||||
priority: 0
|
||||
--- !u!4 &1623431977
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1623431975}
|
||||
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: 0}
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 7152489397314124950, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
value: PPV
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_RootOrder
|
||||
value: 3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: b3358042f02e73e408eb7939bcbda893, type: 3}
|
||||
|
@ -9,6 +9,9 @@ public class PlayerManager : MonoBehaviour
|
||||
public float runSpeed = 20;
|
||||
public float rotateSpeed = 5;
|
||||
public float mouseSensitive = 100;
|
||||
public float jump = 5;
|
||||
private Vector3 jumpPower = new Vector3();
|
||||
public bool onGround = false;
|
||||
private bool run = false;
|
||||
private Camera playerCamera;
|
||||
private Rigidbody rigidBody;
|
||||
@ -27,7 +30,7 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
|
||||
Jump();
|
||||
Move();
|
||||
RunSwitch();
|
||||
}
|
||||
@ -54,10 +57,22 @@ public class PlayerManager : MonoBehaviour
|
||||
rigidBody.MovePosition(
|
||||
transform.position +
|
||||
(transform.forward * (run ? runSpeed : speed) * Input.GetAxis("Vertical") * Time.deltaTime) +
|
||||
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime)
|
||||
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime) +
|
||||
jumpPower
|
||||
);
|
||||
}
|
||||
|
||||
void Jump()
|
||||
{
|
||||
Debug.Log(rigidBody.velocity.y);
|
||||
if (Input.GetAxisRaw("Jump") > 0) {
|
||||
if (rigidBody.velocity.y <= 2 && onGround)
|
||||
{
|
||||
jumpPower = transform.up * jump * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rotate()
|
||||
{
|
||||
rigidBody.freezeRotation = false;
|
||||
@ -95,4 +110,21 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
rigidBody.freezeRotation = true;
|
||||
}
|
||||
|
||||
public void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.tag == "Ground")
|
||||
{
|
||||
jumpPower = Vector3.zero;
|
||||
onGround = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.tag == "Ground")
|
||||
{
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
--- !u!78 &1
|
||||
TagManager:
|
||||
serializedVersion: 2
|
||||
tags: []
|
||||
tags:
|
||||
- Ground
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
Loading…
Reference in New Issue
Block a user