Make better move and platform detection
This commit is contained in:
parent
15491b7272
commit
361262cac8
@ -131,7 +131,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 2.7, y: 0.55, z: 5}
|
||||
m_Size: {x: 3, y: 0.55, z: 6}
|
||||
m_Center: {x: -0.35, y: 0.25, z: 0}
|
||||
--- !u!65 &5071310171994536778
|
||||
BoxCollider:
|
||||
@ -144,7 +144,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.5, y: 1.128, z: 5}
|
||||
m_Size: {x: 0.5, y: 1.128, z: 6}
|
||||
m_Center: {x: 0.75, y: 1.09, z: 0}
|
||||
--- !u!114 &8372693939530454457
|
||||
MonoBehaviour:
|
||||
|
@ -181,7 +181,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 3.3, y: 0.5, z: 5}
|
||||
m_Size: {x: 4, y: 0.5, z: 6}
|
||||
m_Center: {x: 0, y: 0.25, z: 0}
|
||||
--- !u!114 &-443919199017515566
|
||||
MonoBehaviour:
|
||||
|
@ -219,7 +219,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 3.3, y: 0.5, z: 5}
|
||||
m_Size: {x: 4, y: 0.5, z: 6}
|
||||
m_Center: {x: 0, y: 0.25, z: 0}
|
||||
--- !u!114 &1204402889283165505
|
||||
MonoBehaviour:
|
||||
|
@ -179,6 +179,7 @@ GameObject:
|
||||
- component: {fileID: 411423064055404482}
|
||||
- component: {fileID: 459485775853362848}
|
||||
- component: {fileID: 2187729912207573111}
|
||||
- component: {fileID: -6415571428727075267}
|
||||
m_Layer: 0
|
||||
m_Name: platform_start
|
||||
m_TagString: platform
|
||||
@ -214,7 +215,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 5, y: 0.5, z: 5}
|
||||
m_Size: {x: 6, y: 0.5, z: 6}
|
||||
m_Center: {x: 0, y: 0.25, z: 0}
|
||||
--- !u!33 &411423064055404482
|
||||
MeshFilter:
|
||||
@ -278,3 +279,19 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 61dae18984b7ff147ab1d77fb817687a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!114 &-6415571428727075267
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2628890434173161082}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fdc803964e5f2b042bece1765b69164f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
type: 0
|
||||
speed: 0
|
||||
audioSource: {fileID: 0}
|
||||
audioClips: []
|
||||
|
@ -1859,7 +1859,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: b108dca155b156640a1beb1eeaa1995d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
maxDistanceFromCenterLine: 30
|
||||
maxDistanceFromCenterLine: 40
|
||||
speed: 7.5
|
||||
maxSpeed: 15
|
||||
minSpeed: 5
|
||||
@ -1889,7 +1889,7 @@ MonoBehaviour:
|
||||
- {fileID: 8300000, guid: 5e15f53ccc08c4e4496e13306a9e4743, type: 3}
|
||||
- {fileID: 8300000, guid: 049628ae43735224990d9bcea2f744ad, type: 3}
|
||||
- {fileID: 8300000, guid: 227c760da48796046b26b76b3706319b, type: 3}
|
||||
collide: 0
|
||||
platformStatus: exit
|
||||
saveDirection: {x: 0, y: 0, z: 0}
|
||||
--- !u!82 &1943902172017936589
|
||||
AudioSource:
|
||||
@ -2355,7 +2355,7 @@ Camera:
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
|
@ -213,7 +213,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 5, y: 0.8, z: 7.4}
|
||||
m_Size: {x: 6, y: 0.8, z: 8}
|
||||
m_Center: {x: 0, y: 0.14, z: 1.25}
|
||||
--- !u!114 &4297191551228047469
|
||||
MonoBehaviour:
|
||||
|
@ -114,7 +114,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8768991388683709947}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0.25, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
@ -218,7 +218,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 5.03, y: 0.7, z: 5}
|
||||
m_Size: {x: 6, y: 0.7, z: 6}
|
||||
m_Center: {x: 0, y: 0.1, z: 0}
|
||||
--- !u!114 &-5509448037057392871
|
||||
MonoBehaviour:
|
||||
|
@ -129,7 +129,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8768991388683709947}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0.25, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
@ -215,7 +215,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 5.03, y: 0.7, z: 5}
|
||||
m_Size: {x: 6, y: 0.7, z: 6}
|
||||
m_Center: {x: 0, y: 0.1, z: 0}
|
||||
--- !u!114 &-7597049073915248875
|
||||
MonoBehaviour:
|
||||
|
@ -130,7 +130,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8768991388683709947}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0.25, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
@ -201,7 +201,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
type: 1
|
||||
speed: 5
|
||||
speed: 10
|
||||
audioSource: {fileID: 5862113707430629064}
|
||||
audioClips:
|
||||
- {fileID: 8300000, guid: e25b1f5c308fe154a8d7203703e2f298, type: 3}
|
||||
@ -218,7 +218,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 5.03, y: 0.7, z: 5}
|
||||
m_Size: {x: 6, y: 0.7, z: 6}
|
||||
m_Center: {x: 0, y: 0.1, z: 0}
|
||||
--- !u!114 &-142748814437030588
|
||||
MonoBehaviour:
|
||||
|
@ -215,7 +215,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 3.4, y: 0.5, z: 5}
|
||||
m_Size: {x: 4, y: 0.5, z: 6}
|
||||
m_Center: {x: 0, y: 0.25, z: 0}
|
||||
--- !u!114 &5433657018731068073
|
||||
MonoBehaviour:
|
||||
|
@ -219,7 +219,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 3.4, y: 0.5, z: 5}
|
||||
m_Size: {x: 4, y: 0.5, z: 6}
|
||||
m_Center: {x: 0, y: 0.25, z: 0}
|
||||
--- !u!114 &5433657018731068073
|
||||
MonoBehaviour:
|
||||
|
@ -47,7 +47,7 @@ BoxCollider:
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 5, y: 0.8, z: 7.6}
|
||||
m_Size: {x: 6, y: 0.8, z: 8}
|
||||
m_Center: {x: 0, y: 0.14, z: 1.3}
|
||||
--- !u!114 &2125975832863856952
|
||||
MonoBehaviour:
|
||||
|
@ -5273,6 +5273,10 @@ PrefabInstance:
|
||||
propertyPath: jumpSpeed
|
||||
value: 3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356566819001086, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: maxDistanceFromCenterLine
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3244356567246256142, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
|
||||
propertyPath: menuCamera
|
||||
value:
|
||||
|
@ -35,15 +35,23 @@ public class PlatformManager : MonoBehaviour
|
||||
case PlatformType.Basic:
|
||||
return;
|
||||
case PlatformType.Pull:
|
||||
if (status == "exit")
|
||||
if (status == "stay")
|
||||
{
|
||||
player.jumpModifier = speed * 10f;
|
||||
player.jumpModifier = -speed / 10f;
|
||||
}
|
||||
else if (status == "exit")
|
||||
{
|
||||
player.jumpModifier = 0f;
|
||||
}
|
||||
return;
|
||||
case PlatformType.Push:
|
||||
if (status == "exit")
|
||||
if (status == "stay")
|
||||
{
|
||||
player.jumpModifier = speed * 10f;
|
||||
player.jumpModifier = speed / 10f;
|
||||
}
|
||||
else if (status == "exit")
|
||||
{
|
||||
player.jumpModifier = 0f;
|
||||
}
|
||||
return;
|
||||
case PlatformType.RotateY:
|
||||
|
@ -11,7 +11,6 @@ public class PlayerController : MonoBehaviour
|
||||
public float minSpeed = 5.0f;
|
||||
[HideInInspector]
|
||||
public float currentSpeed = 0f;
|
||||
[HideInInspector]
|
||||
public float speedModifier = 0.0f;
|
||||
Vector3 moveDirection = Vector3.zero;
|
||||
bool canMove = false;
|
||||
@ -25,7 +24,6 @@ public class PlayerController : MonoBehaviour
|
||||
public bool isFalling = false;
|
||||
[Header("Jump")]
|
||||
public float jumpSpeed = 7.5f;
|
||||
[HideInInspector]
|
||||
public float jumpModifier = 0.0f;
|
||||
[HideInInspector]
|
||||
public bool inAir = false;
|
||||
@ -44,7 +42,10 @@ public class PlayerController : MonoBehaviour
|
||||
public List<AudioClip> jumpClips = new List<AudioClip>();
|
||||
public List<AudioClip> audioClips = new List<AudioClip>();
|
||||
PlatformManager collidePlatform;
|
||||
string platformStatus = "exit";
|
||||
GameObject colliderObject;
|
||||
public string platformStatus = "exit";
|
||||
float fallingTimer = 0.1f;
|
||||
float fallingTime = 0f;
|
||||
// Start is called before the first frame update
|
||||
|
||||
[HideInInspector]
|
||||
@ -142,13 +143,23 @@ public class PlayerController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
if (saveDirection != -transform.up)
|
||||
{
|
||||
Vector3 axis;
|
||||
float angle;
|
||||
axis = Vector3.Cross(-transform.up, saveDirection);
|
||||
|
||||
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, saveDirection));
|
||||
transform.RotateAround(axis, angle * Time.deltaTime * 8f);
|
||||
}
|
||||
|
||||
PlatformManager localP = null;
|
||||
if (collidePlatform != null)
|
||||
{
|
||||
collidePlatform.Step();
|
||||
collidePlatform.Action(this, platformStatus);
|
||||
localP = collidePlatform;
|
||||
if (platformStatus == "enter")
|
||||
if (platformStatus == "enter" || platformStatus == "stay")
|
||||
{
|
||||
platformStatus = "stay";
|
||||
collidePlatform = null;
|
||||
@ -159,6 +170,7 @@ public class PlayerController : MonoBehaviour
|
||||
if (platformStatus == "stay")
|
||||
{
|
||||
platformStatus = "exit";
|
||||
fallingTime = fallingTimer + Time.time;
|
||||
if (localP != null)
|
||||
{
|
||||
localP.Action(this, platformStatus);
|
||||
@ -167,24 +179,6 @@ public class PlayerController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
if (jumpTime <= Time.time)
|
||||
{
|
||||
jumpModifier = 0.0f;
|
||||
Vector3 locGrav = (Physics.gravity * Time.deltaTime);
|
||||
if (!isGrounded)
|
||||
{
|
||||
_velocity += Physics.gravity / 50 * Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_velocity = Physics.gravity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_velocity += transform.up * (jumpSpeed + jumpModifier) / 5 * Time.deltaTime;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
|
||||
{
|
||||
//inAir = true;
|
||||
@ -197,9 +191,33 @@ public class PlayerController : MonoBehaviour
|
||||
isGrounded = false;
|
||||
}
|
||||
|
||||
if (jumpTime <= Time.time)
|
||||
{
|
||||
if (!isGrounded)
|
||||
{
|
||||
_velocity += Physics.gravity / 50 * Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_velocity = Physics.gravity / 10 * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_velocity += transform.up * (jumpSpeed + jumpModifier) / 5 * Time.deltaTime;
|
||||
}
|
||||
|
||||
chc.Move(moveDirection + _velocity);
|
||||
|
||||
//rb.MovePosition(rb.position + moveDirection);
|
||||
|
||||
if (platformStatus == "exit")
|
||||
{
|
||||
if (fallingTime < Time.time)
|
||||
{
|
||||
isGrounded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
@ -235,16 +253,6 @@ public class PlayerController : MonoBehaviour
|
||||
this.isFalling = false;
|
||||
}
|
||||
|
||||
if (saveDirection != -transform.up)
|
||||
{
|
||||
Vector3 axis;
|
||||
float angle;
|
||||
axis = Vector3.Cross(-transform.up, saveDirection);
|
||||
|
||||
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, saveDirection));
|
||||
transform.RotateAround(axis, angle * Time.deltaTime * 8f);
|
||||
}
|
||||
|
||||
var distanceFromYAxis = new Vector2(transform.position.x, transform.position.y).magnitude;
|
||||
if (UiController.isInMenu == false && distanceFromYAxis > this.maxDistanceFromCenterLine)
|
||||
{
|
||||
@ -306,17 +314,25 @@ public class PlayerController : MonoBehaviour
|
||||
|
||||
void OnControllerColliderHit(ControllerColliderHit hit)
|
||||
{
|
||||
Vector3 contact = hit.normal;
|
||||
if (contact.normalized != -hit.gameObject.transform.right.normalized &&
|
||||
contact.normalized != hit.gameObject.transform.right.normalized &&
|
||||
contact.normalized != hit.gameObject.transform.forward.normalized &&
|
||||
contact.normalized != -hit.gameObject.transform.forward.normalized)
|
||||
{
|
||||
jumpModifier = 0.0f;
|
||||
isGrounded = true;
|
||||
if (platformStatus == "exit") {
|
||||
}
|
||||
if (platformStatus == "exit" || colliderObject != hit.gameObject) {
|
||||
platformStatus = "enter";
|
||||
}
|
||||
if (hit.gameObject.tag != "platform") return;
|
||||
|
||||
colliderObject = hit.gameObject;
|
||||
collidePlatform = hit.gameObject.GetComponent<PlatformManager>();
|
||||
|
||||
Vector3 contact = hit.normal;
|
||||
if (contact != -hit.gameObject.transform.up &&
|
||||
contact != hit.gameObject.transform.up)
|
||||
if (contact.normalized != -hit.gameObject.transform.up.normalized &&
|
||||
contact.normalized != hit.gameObject.transform.up.normalized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class ProceduralGeneration : MonoBehaviour
|
||||
|
||||
Bounds bounds = this.getPrefabBounds(lastObject);
|
||||
Bounds b = this.getPrefabBounds(objToSpawn);
|
||||
Vector3 nextBlockLocation = new Vector3(lastObject.transform.position.x, lastObject.transform.position.y, lastObject.transform.position.z + bounds.extents.z + b.extents.z);
|
||||
Vector3 nextBlockLocation = new Vector3(objToSpawn.transform.position.x, objToSpawn.transform.position.y, lastObject.transform.position.z + bounds.extents.z + b.extents.z);
|
||||
GameObject newObject = Instantiate(objToSpawn, nextBlockLocation, (Quaternion.identity));
|
||||
newObject.transform.parent = parentLevelObject.transform;
|
||||
return newObject;
|
||||
@ -141,7 +141,7 @@ public class ProceduralGeneration : MonoBehaviour
|
||||
for (var i = 0; i < this.spawnedLevelBlocks.Count; i++)
|
||||
{
|
||||
float distance = Vector3.Distance(this.spawnedLevelBlocks[i].transform.position, playerPosition);
|
||||
if (distance > this.maximumDistanceOfPlatformFromPlayer && this.spawnedLevelBlocks.Count >= this.maximumNumberOfPlatformsAtScene && playerPosition.z > this.spawnedLevelBlocks[i].transform.position.z + 2)
|
||||
if (distance > this.maximumDistanceOfPlatformFromPlayer && this.spawnedLevelBlocks.Count >= this.maximumNumberOfPlatformsAtScene && playerPosition.z > this.spawnedLevelBlocks[i].transform.position.z + 3f)
|
||||
{
|
||||
Destroy(this.spawnedLevelBlocks[i]);
|
||||
this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user