Real Player Controls

This commit is contained in:
brausjonas
2022-05-13 12:02:02 +02:00
parent 8b2ac28a16
commit fee664a936
2 changed files with 54 additions and 20 deletions
+38 -5
View File
@@ -369,7 +369,7 @@ Camera:
y: 0
width: 1
height: 1
near clip plane: 0.3
near clip plane: 0.01
far clip plane: 1000
field of view: 60
orthographic: 0
@@ -397,7 +397,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1356629356}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0, y: 0.709, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1789911867}
@@ -431,7 +431,7 @@ Light:
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 0.9339623, g: 0.5683072, b: 0.5683072, a: 1}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 0.8
m_Range: 10
m_SpotAngle: 30
@@ -474,7 +474,7 @@ Light:
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_BounceIntensity: 0.5
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
@@ -682,6 +682,8 @@ GameObject:
m_Component:
- component: {fileID: 1789911867}
- component: {fileID: 1789911868}
- component: {fileID: 1789911869}
- component: {fileID: 1789911870}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@@ -717,5 +719,36 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
mouseSpeed: 3
moveSpeed: 10
moveSpeed: 5
jumpForce: 5
world: {fileID: 948138834}
--- !u!136 &1789911869
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1789911866}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 0.4
m_Height: 1.9
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!54 &1789911870
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1789911866}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 112
m_CollisionDetection: 0
+16 -15
View File
@@ -8,42 +8,44 @@ public class Player : MonoBehaviour
//game
[SerializeField] private float mouseSpeed;
[SerializeField] private float moveSpeed;
[SerializeField] private float jumpForce;
[SerializeField] private World world;
private Camera camera = null;
private Rigidbody rigidbody;
//network
private Client client = null;
private void Start()
{
rigidbody = GetComponent<Rigidbody>();
client = world.GetClient();
Cursor.lockState = CursorLockMode.Locked;
camera = GetComponentInChildren<Camera>();
}
private void FixedUpdate()
{
transform.Translate(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.fixedDeltaTime, 0,
Input.GetAxisRaw("Vertical") * moveSpeed * Time.fixedDeltaTime);
}
private void Update()
{
transform.Rotate(0, Input.GetAxis("Mouse X") * mouseSpeed, 0);
camera.transform.Rotate(-Input.GetAxis("Mouse Y") * mouseSpeed, 0, 0);
float up = 0;
if (Input.GetKey(KeyCode.Space))
if (Input.GetKeyDown(KeyCode.Space))
{
up = 1;
}
if (Input.GetKey(KeyCode.LeftShift))
{
up = -1;
if (Physics.Raycast(transform.position, Vector3.down, 0.96f))
{
rigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
transform.Translate(Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime, up * moveSpeed * Time.deltaTime,
Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit))
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
{
hit.point += camera.transform.forward / 10;
client.EditBlock(hit.point, 0);
@@ -52,8 +54,7 @@ public class Player : MonoBehaviour
if (Input.GetMouseButtonDown(1))
{
RaycastHit hit;
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit))
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
{
hit.point -= camera.transform.forward / 10;
client.EditBlock(hit.point, 4);