Browse Source

base push working but extremely buggy

Josh_Dev_branch
JoshuaReason 4 years ago
parent
commit
c0ad428fa2
9 changed files with 104 additions and 62 deletions
  1. +1
    -1
      Assets/Models.meta
  2. +8
    -0
      Assets/Plugins/IngameDebugConsole/Android.meta
  3. +8
    -0
      Assets/Plugins/IngameDebugConsole/Prefabs.meta
  4. +8
    -0
      Assets/Plugins/IngameDebugConsole/Scripts.meta
  5. +8
    -0
      Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta
  6. +2
    -48
      Assets/Scripts/Character.cs
  7. +57
    -9
      Assets/Scripts/LevelBlocks/Block.cs
  8. +4
    -4
      Assets/Scripts/LevelBlocks/Water.cs
  9. +8
    -0
      Assets/Scripts/LogicBlocks.meta

Assets/Scripts/Components.meta → Assets/Models.meta View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8d7394d70ec233849a60a26da5f23b75
guid: 296bd90e667df1f4697823a0aa45acf0
folderAsset: yes
DefaultImporter:
externalObjects: {}

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Android.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d7d7a61a5341904eb3c65af025b1d86
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Prefabs.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7dbc36665bc0d684db9a4447e27a7a4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Scripts.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 860c08388401a6d4e858fe4910ea9337
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f6caae32d463529478f2186f47c2e3fe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 48
Assets/Scripts/Character.cs View File

@ -103,7 +103,7 @@ public class Character : MonoBehaviour
public IEnumerator MoveToBlock(Block target, Animation animation, float time)
{
Block oldBlock = _currentBlock;
Vector3 moveDirection = Vector3.ProjectOnPlane(target.position - _currentBlock.position, Vector3.up).normalized;
_currentBlock.OnLeftByPlayer(this);
@ -116,10 +116,7 @@ public class Character : MonoBehaviour
yield return StartCoroutine(LerpToBlock(target.VisualPosition, time, yFunction));
_currentBlock= target;
_currentBlock.OnWalkedOnByPlayer(this);
yield return StartCoroutine(DoPush(oldBlock,_currentBlock, time));
yield return StartCoroutine (_currentBlock.OnWalkedOnByPlayer(this,moveDirection));
StopAnimation(animation);
}
@ -197,49 +194,6 @@ public class Character : MonoBehaviour
transform.position = _startPos + Vector3.up * heightOffset(1);
}
public IEnumerator DoPush(Block lastBlock, Block currentBlock, float animationTime)
{
//Direction player moved in ignoring Y value
Vector3 pushDirection = Vector3.ProjectOnPlane(currentBlock.position - lastBlock.position, Vector3.up).normalized;
foreach(Character character in _currentBlock.GetPushablePlayers())
{
if (character == this)
continue;
yield return StartCoroutine(character.GetPushed(pushDirection));
}
}
public IEnumerator GetPushed(Vector3 direction)
{
yield return null;
}
private Block getPushLocation(Vector3 pushDirection)
{
//setting up variables
Vector3 position = _currentBlock.position + pushDirection; // position wanted
Block hit; //output of block detection
//if move is obstucted no where to move
if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore))
return _currentBlock;
//If block at Position is walkable set it to moveTo
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
{
return hit;
}
//else if block down one is walkable
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
{
return hit;
}
return _currentBlock;
}
public void StartAnimation(Animation animation,float speed = 1)
{
characterAnimator.SetFloat("AnimationSpeed", (1 / speed));

+ 57
- 9
Assets/Scripts/LevelBlocks/Block.cs View File

@ -37,7 +37,7 @@ public class Block : MonoBehaviour
/// <summary>
/// List of current players on this block
/// </summary>
protected List<Character> currentPlayers = new List<Character>();
protected Character currentPlayer;
#endregion Private Functions
#region ReadOnly Properties
@ -71,9 +71,10 @@ public class Block : MonoBehaviour
/// Should be implemented by a derived class
/// </summary>
/// <param name="player">Player which moved on to block</param>
public virtual void OnWalkedOnByPlayer(Character player)
///<param name="moveDirection">The direction the player moved to get to this block</param>
public virtual IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection)
{
currentPlayers.Add(player);
yield return StartCoroutine(DoPush(player, moveDirection));
}
/// <summary>
@ -84,22 +85,69 @@ public class Block : MonoBehaviour
/// <param name="player">Player which moved on to block</param>
public virtual void OnLeftByPlayer(Character player)
{
currentPlayers.Remove(player);
currentPlayer = null;
}
/// <summary>
/// Returns an array of players who can be pushed off this block
/// Called to deal with players colliding on this block
/// </summary>
/// <returns>array of players who can be pushed off this block</returns>
public virtual Character[] GetPushablePlayers()
/// <param name="newPlayer">Player which is moving into this block</param>
/// <param name="moveDirection">The direction the player moved to get to this block</param>
public virtual IEnumerator DoPush(Character newPlayer, Vector3 moveDirection)
{
return currentPlayers.ToArray();
}
if (currentPlayer == null)
{
currentPlayer = newPlayer;
yield break;
}
Block pushBlock = GetPushLocation(moveDirection, ~currentPlayer.Ignore);
if (pushBlock != this)
{
Character oldPlayer = currentPlayer;
currentPlayer = newPlayer;
yield return StartCoroutine(oldPlayer.MoveToBlock(pushBlock, Character.Animation.Hit, 1));
}
else
{
Block returnBlock = GetPushLocation(-moveDirection, ~newPlayer.Ignore);
if (returnBlock != this)
yield return StartCoroutine(newPlayer.MoveToBlock(returnBlock, Character.Animation.Hit, 1));
}
}
#endregion Public Functions
#region Protected Functions
protected Block GetPushLocation(Vector3 pushDirection, LayerMask ignoreMask)
{
//setting up variables
Vector3 newPosition = position + pushDirection; // position wanted
Block hit; //output of block detection
//if move is obstucted no where to move
if (Block.isBlockAtPosition(newPosition + Vector3.up, 1, ignoreMask))
return this;
//If block at Position is walkable set it to moveTo
if (Block.isBlockAtPosition(newPosition, 1, ignoreMask, out hit) && hit.isWalkable(ignoreMask))
{
return hit;
}
//else if block down one is walkable
else if (Block.isBlockAtPosition(newPosition + Vector3.down, 1, ignoreMask, out hit) && hit.isWalkable(ignoreMask))
{
return hit;
}
return this;
}
#endregion Protected Functions
#region Editor Functions
private void OnDrawGizmos()
{

+ 4
- 4
Assets/Scripts/LevelBlocks/Water.cs View File

@ -16,17 +16,17 @@ public class Water : ActiveBlock
private Character trappedCharacter;
public override void OnWalkedOnByPlayer(PlayerData player)
public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection)
{
base.OnWalkedOnByPlayer(player);
base.OnWalkedOnByPlayer(player, moveDirection);
if (trappedCharacter == null)
{
player.character = trappedCharacter;
player = trappedCharacter;
trappedCharacter.stuck = true;
trappedCharacter.StartAnimation(Character.Animation.Hit);
StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition + Vector3.down * FallDistance, 1));
yield return StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition + Vector3.down * FallDistance, 1));
}
}

+ 8
- 0
Assets/Scripts/LogicBlocks.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8936b441d7647f74884c94f97bfb8931
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save