Starting wall jump and moving plateform implementation

This commit is contained in:
Anonymous Raccoon
2018-03-05 14:59:23 +01:00
parent 808e7084f7
commit 8d4f4c27e6
5 changed files with 175 additions and 16 deletions

View File

@@ -10,4 +10,4 @@ PhysicMaterial:
staticFriction: 0
bounciness: 0
frictionCombine: 1
bounceCombine: 0
bounceCombine: 3

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovingElement : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 49ea6d0c92f14454aa950f9902c7e3ed
timeCreated: 1520258245
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,13 +8,17 @@ public class PlayerMovement : MonoBehaviour
[SerializeField] private int jumpForce = 8;
[SerializeField] private int smallJump = 4;
[SerializeField] private float gravity = 8.5f;
[SerializeField] private int wallJump = 200;
[SerializeField] private int wallJumpPush = 250;
[Space]
[SerializeField] private LayerMask groundMask;
[SerializeField] private LayerMask wallMask;
private bool isGrounded = true;
private bool canCancel = false;
private bool canWallJump = false;
private int wallDirection;
private float jumpDirection;
private bool airControl = false;
@@ -29,14 +33,26 @@ public class PlayerMovement : MonoBehaviour
private void FixedUpdate()
{
if (Physics.OverlapSphere(rb.position, 1.5f, groundMask).Length > 0)
{
isGrounded = true;
canCancel = false;
}
else
isGrounded = false;
if (Physics.OverlapSphere(rb.position, 1, wallMask).Length > 0)
Collider[] walls = Physics.OverlapSphere(rb.position, 1, wallMask);
if (walls.Length > 0)
{
canWallJump = true;
if(walls[0].transform.position.x > rb.position.x)
wallDirection = -1;
else
wallDirection = 1;
}
else
{
canWallJump = false;
}
if (!isGrounded)
@@ -57,7 +73,7 @@ public class PlayerMovement : MonoBehaviour
}
}
rb.MovePosition(rb.position + new Vector3(Input.GetAxis("Horizontal"), 0, 0) * (airControl ? airSpeed : speed) * Time.fixedDeltaTime);
rb.MovePosition(rb.position + new Vector3(Input.GetAxis("Horizontal") * (airControl ? airSpeed : speed) * Time.fixedDeltaTime - rb.velocity.x, 0, 0));
airControl = false;
@@ -65,17 +81,29 @@ public class PlayerMovement : MonoBehaviour
{
jumpDirection = Input.GetAxis("Horizontal");
isGrounded = false;
rb.velocity = new Vector3(0, jumpForce, 0);
rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
canCancel = true;
}
if(Input.GetButtonUp("Jump") && !isGrounded && rb.velocity.y > smallJump)
if (Input.GetButtonUp("Jump") && !isGrounded && rb.velocity.y > smallJump && canCancel)
{
rb.velocity = new Vector3(0, smallJump, 0);
canCancel = false;
rb.velocity = new Vector3(rb.velocity.x, smallJump, rb.velocity.z);
}
if (rb.velocity.y < 1)
{
rb.velocity = new Vector3(0, rb.velocity.y - gravity * Time.fixedDeltaTime, 0);
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y - gravity * Time.fixedDeltaTime, rb.velocity.z);
}
if (canWallJump && !isGrounded && Input.GetButtonDown("Jump"))
{
print("Wall Jumping");
canCancel = false;
jumpDirection = wallDirection;
rb.velocity = new Vector3(wallJumpPush * -wallDirection, wallJump, rb.velocity.z);
//rb.AddForce(new Vector3(wallJumpPush * -wallDirection, wallJump, 0), ForceMode.Acceleration);
}
}
}

View File

@@ -188,7 +188,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 5749160}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalPosition: {x: 0, y: 1, z: -12.6}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@@ -206,7 +206,7 @@ GameObject:
- component: {fileID: 33115648}
- component: {fileID: 33115647}
m_Layer: 9
m_Name: Cube (1)
m_Name: Wall
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -291,7 +291,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4620220062861480, guid: 1e59ce4d0aab18f44a51b286de5259c4, type: 2}
propertyPath: m_LocalPosition.y
value: 3.137
value: 3.46
objectReference: {fileID: 0}
- target: {fileID: 4620220062861480, guid: 1e59ce4d0aab18f44a51b286de5259c4, type: 2}
propertyPath: m_LocalPosition.z
@@ -333,7 +333,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4061937932440146, guid: b21e2e91c2466fa4ba8c38be7831894c, type: 2}
propertyPath: m_LocalPosition.y
value: 2.701
value: 3.024
objectReference: {fileID: 0}
- target: {fileID: 4061937932440146, guid: b21e2e91c2466fa4ba8c38be7831894c, type: 2}
propertyPath: m_LocalPosition.z
@@ -375,7 +375,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4928226377463138, guid: bebad6dbaee6f9440afb6cfabba013d3, type: 2}
propertyPath: m_LocalPosition.y
value: 2.909
value: 3.2319999
objectReference: {fileID: 0}
- target: {fileID: 4928226377463138, guid: bebad6dbaee6f9440afb6cfabba013d3, type: 2}
propertyPath: m_LocalPosition.z
@@ -499,11 +499,11 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1180913636}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -4.69, y: 4.34, z: 0}
m_LocalPosition: {x: -4.24, y: 4.34, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1180913642
MonoBehaviour:
@@ -521,12 +521,114 @@ MonoBehaviour:
jumpForce: 8
smallJump: 4
gravity: 8
wallJump: 4
wallJumpPush: 2
groundMask:
serializedVersion: 2
m_Bits: 256
wallMask:
serializedVersion: 2
m_Bits: 0
m_Bits: 512
--- !u!1 &1200947730
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1200947735}
- component: {fileID: 1200947734}
- component: {fileID: 1200947733}
- component: {fileID: 1200947732}
- component: {fileID: 1200947731}
m_Layer: 9
m_Name: Moving Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!54 &1200947731
Rigidbody:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1200947730}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!23 &1200947732
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1200947730}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
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_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
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
--- !u!65 &1200947733
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1200947730}
m_Material: {fileID: 13400000, guid: 3f67cbc34e2adef4e808c3445e69a63d, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &1200947734
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1200947730}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1200947735
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1200947730}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -10.42, y: 3.4, z: 0}
m_LocalScale: {x: 3, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1699708122
GameObject:
m_ObjectHideFlags: 0
@@ -604,7 +706,7 @@ GameObject:
- component: {fileID: 1936456413}
- component: {fileID: 1936456412}
m_Layer: 8
m_Name: Cube
m_Name: Ground
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0