trying the sebastian lague technique

master
Jordan Orelli 5 years ago
parent 7115fbe107
commit 5fd14b8d9b

@ -9,11 +9,12 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 6383496741192187647}
- component: {fileID: 7623484707498698197}
- component: {fileID: 7050504111816705868}
m_Layer: 0
- component: {fileID: 8462409473881997938}
- component: {fileID: 6891912346901077427}
- component: {fileID: 5588890751565926871}
m_Layer: 10
m_Name: Player
m_TagString: Untagged
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@ -33,7 +34,20 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &7623484707498698197
--- !u!65 &8462409473881997938
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6383496741192187632}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.25, y: 1, z: 0.25}
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!114 &6891912346901077427
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -42,30 +56,23 @@ MonoBehaviour:
m_GameObject: {fileID: 6383496741192187632}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7e392b35ca7959444b61a3e29a242f2b, type: 3}
m_Script: {fileID: 11500000, guid: 721dfc7e43d81b644a34024174f78c4e, type: 3}
m_Name:
m_EditorClassIdentifier:
moveSpeed: 1
jumpForce: 10
cc: {fileID: 0}
--- !u!143 &7050504111816705868
CharacterController:
box: {fileID: 0}
--- !u!114 &5588890751565926871
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6383496741192187632}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Height: 1
m_Radius: 0.125
m_SlopeLimit: 45
m_StepOffset: 0.3
m_SkinWidth: 0.08
m_MinMoveDistance: 0.001
m_Center: {x: 0, y: 0.5, z: 0}
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7e392b35ca7959444b61a3e29a242f2b, type: 3}
m_Name:
m_EditorClassIdentifier:
moveController: {fileID: 0}
--- !u!1 &6383496741659177281
GameObject:
m_ObjectHideFlags: 0
@ -77,7 +84,7 @@ GameObject:
- component: {fileID: 6383496741659177293}
- component: {fileID: 6383496741659177294}
- component: {fileID: 6383496741659177295}
m_Layer: 0
m_Layer: 10
m_Name: Body
m_TagString: Untagged
m_Icon: {fileID: 0}

@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]
public class MoveController : MonoBehaviour
{
public const float skinWidth = 0.015f;
public int horizontalRayCount = 4;
public int verticalRayCount = 4;
new private BoxCollider collider;
private RaycastOrigins raycastOrigins;
private float horizontalRaySpacing;
private float verticalRaySpacing;
void Start() {
collider = GetComponent<BoxCollider>();
}
void Update() {
UpdateRaycastOrigins();
CalculateRaySpacing();
// bottom face
for (int i = 0; i < verticalRayCount; i++) {
for (int j = 0; j < verticalRayCount; j++) {
Debug.DrawRay(raycastOrigins.bottomFrontLeft + Vector3.right * verticalRaySpacing * i - Vector3.back * verticalRaySpacing * j, Vector3.down, Color.red);
}
}
}
void UpdateRaycastOrigins() {
Bounds bounds = collider.bounds;
bounds.Expand(skinWidth * -2);
raycastOrigins.bottomFrontLeft = new Vector3(bounds.min.x, bounds.min.y, bounds.min.z); // 0 0 0
raycastOrigins.bottomBackLeft = new Vector3(bounds.min.x, bounds.min.y, bounds.max.z); // 0 0 1
raycastOrigins.topFrontLeft = new Vector3(bounds.min.x, bounds.max.y, bounds.min.z); // 0 1 0
raycastOrigins.topBackLeft = new Vector3(bounds.min.x, bounds.max.y, bounds.max.z); // 0 1 1
raycastOrigins.bottomFrontRight = new Vector3(bounds.max.x, bounds.min.y, bounds.min.z); // 1 0 0
raycastOrigins.bottomBackRight = new Vector3(bounds.max.x, bounds.min.y, bounds.max.z); // 1 0 1
raycastOrigins.topFrontRight = new Vector3(bounds.max.x, bounds.max.y, bounds.min.z); // 1 1 0
raycastOrigins.topBackRight = new Vector3(bounds.max.x, bounds.max.y, bounds.max.z); // 1 1 1
}
void CalculateRaySpacing() {
Bounds bounds = collider.bounds;
bounds.Expand(skinWidth * -2);
if (horizontalRayCount < 2) { horizontalRayCount = 2; }
if (verticalRayCount < 2) { verticalRayCount = 2; }
horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);
}
struct RaycastOrigins {
public Vector3 topBackLeft;
public Vector3 topBackRight;
public Vector3 topFrontLeft;
public Vector3 topFrontRight;
public Vector3 bottomBackLeft;
public Vector3 bottomBackRight;
public Vector3 bottomFrontLeft;
public Vector3 bottomFrontRight;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 721dfc7e43d81b644a34024174f78c4e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -2,39 +2,17 @@
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MoveController))]
public class PlayerController : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
public CharacterController cc;
public float gravityScale;
private Vector3 moveDirection;
public MoveController moveController;
void Start() {
cc = GetComponent<CharacterController>();
moveController = GetComponent<MoveController>();
}
void Update() {
float dx = Input.GetAxis("Horizontal") * moveSpeed;
moveDirection = new Vector3(dx, moveDirection.y, 0f);
if (cc.isGrounded) {
if (Input.GetButtonDown("Jump")) {
moveDirection.y = jumpForce;
} else {
moveDirection.y = moveDirection.y + Physics.gravity.y*gravityScale*Time.deltaTime;
if (moveDirection.y < 0f) {
moveDirection.y = 0f;
}
}
} else {
moveDirection.y = moveDirection.y + Physics.gravity.y*gravityScale*Time.deltaTime;
}
Debug.Log(moveDirection);
cc.Move(moveDirection * Time.deltaTime);
}
void FixedUpdate() {
float motor = Input.GetAxis("Vertical");
float steering = Input.GetAxis("Horizontal");
}
}

@ -1,43 +1,43 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
layers:
- Default
- TransparentFX
- Ignore Raycast
-
- Water
- UI
-
-
- PostProcessing
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
m_SortingLayers:
- name: Default
uniqueID: 0
locked: 0
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
layers:
- Default
- TransparentFX
- Ignore Raycast
-
- Water
- UI
-
-
- PostProcessing
-
- Player
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
m_SortingLayers:
- name: Default
uniqueID: 0
locked: 0

Loading…
Cancel
Save