/// <summary> /// tries to figure out floor material based on ground collision tag /// </summary> /// <param name="tag"></param> void DetermineFloorMat(RaycastHit2D cast) { Tilemap tileMapHit = cast.collider.GetComponent <Tilemap>(); if (tileMapHit) { //once we know that it hit a tilemap, decide which tilemap to *actually* pull the sound from, based on sort order Vector2 tilePoint = cast.point + Vector2.down; TileBase tileHit = tileMapHit.GetTile(tileMapHit.WorldToCell(tilePoint)); //default it does theese //grass exception: for (int i = 0; i < parentMovement.allTileMapsInScene.Count; i++) { tileHit = parentMovement.allTileMapsInScene[i].GetTile(parentMovement.allTileMapsInScene[i].WorldToCell(tilePoint)); if (tileHit) { break; //break the loop on the top tile that you hit } } //end of grass exception if (tileHit) { if (parentMovement.groundMatSettings.dirtTiles.Contains(tileHit)) { currentGround = groundMaterial.dirt; } else if (parentMovement.groundMatSettings.woodTiles.Contains(tileHit)) { currentGround = groundMaterial.wood; } else if (parentMovement.groundMatSettings.snowTiles.Contains(tileHit)) { currentGround = groundMaterial.snow; } else if (parentMovement.groundMatSettings.grassTiles.Contains(tileHit)) { currentGround = groundMaterial.grass; } else if (parentMovement.groundMatSettings.rockTiles.Contains(tileHit)) { currentGround = groundMaterial.rock; } else if (parentMovement.groundMatSettings.leafTiles.Contains(tileHit)) { currentGround = groundMaterial.leaves; } else { //default to wood I guess currentGround = groundMaterial.wood; } } } }
/// <summary> /// checks if a cast is hitting something you can jump off of /// </summary> /// <param name="cast">cast to check</param> /// <returns>returns true if it is, false if it isnt</returns> public bool CheckCastForJumpables(RaycastHit2D cast) { if (cast) { if (cast.collider.GetComponentInParent <PlayerPiece>()) { Movement collidedPlayerMovement = cast.collider.GetComponentInParent <PlayerPiece>().parentMovement; if (collidedPlayerMovement != parentMovement) { if (collidedPlayerMovement.grounded || butterflyJump) { //Debug.DrawLine(transform.position, cast.point, Color.blue); //you are ontop of a grounded player (made of wood I guess) currentGround = groundMaterial.wood; return(true); } else { return(false); } } else { //Debug.DrawLine(transform.position, cast.point, Color.red); return(false); } } else //hitting ground { DetermineFloorMat(cast); //Debug.DrawLine(transform.position, cast.point, Color.green); return(true); } } else { return(false); } }