Skip to content

Commit

Permalink
Create collisions part of PlayerController script - tilemap Overworld
Browse files Browse the repository at this point in the history
Part 3
1 problem: can't add the SolidObjects layer in the inspector. @randomrok can you figure this out? We need to add the SolidObjects [regular] layer as a parameter/value for a variable in the script (through the inspector) to prevent the player from walking into things based on the Overworld Tilemap

#21
  • Loading branch information
Gizmotronn committed Dec 23, 2020
1 parent 0c653ee commit bd2649e
Show file tree
Hide file tree
Showing 10 changed files with 1,445 additions and 46 deletions.
954 changes: 944 additions & 10 deletions Pokemon RPG/Assets/Scenes/New Scene.unity

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion Pokemon RPG/Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public LayerMask solidObjectsLayer;

private bool isMoving;
private Vector2 input;
Expand Down Expand Up @@ -37,7 +38,8 @@ void Update()
targetPos.x += input.x;
targetPos.y += input.y;

StartCoroutine(Move(targetPos));
if (IsWalkable(targetPos))
StartCoroutine(Move(targetPos));
}else
{
animator.SetBool("isMoving", false);
Expand All @@ -54,4 +56,12 @@ IEnumerator Move(Vector3 targetPos) { // Do something over a period of time (IEn
else isMoving = false;
}

private bool IsWalkable(Vector3 targetPos) { // Check if the tile position is walkable
if (Physics2D.OverlapCircle(targetPos, 0.3f, SolidObjects, solidObjectsLayer) != null) // Tile is not walkable if the IF statement is not null, as there is something at that Vector3 position // Solid objects layer as third parameter
{
return false;
}

return true; // Call Move Coroutine if we return true
}
}
58 changes: 29 additions & 29 deletions Pokemon RPG/Library/CurrentLayout-default.dwlt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ MonoBehaviour:
y: 30
width: 1920
height: 987
m_MinSize: {x: 648, y: 494}
m_MinSize: {x: 683, y: 494}
m_MaxSize: {x: 14004, y: 14044}
vertical: 0
controlID: 131
controlID: 57
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -67,14 +67,14 @@ MonoBehaviour:
y: 0
width: 389
height: 987
m_MinSize: {x: 242, y: 222}
m_MaxSize: {x: 4002, y: 4022}
m_ActualView: {fileID: 12}
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 16}
m_Panes:
- {fileID: 16}
- {fileID: 12}
m_Selected: 1
m_LastSelected: 0
m_Selected: 0
m_LastSelected: 1
--- !u!114 &4
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -94,8 +94,8 @@ MonoBehaviour:
y: 0
width: 379
height: 597
m_MinSize: {x: 202, y: 222}
m_MaxSize: {x: 4002, y: 4022}
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 17}
m_Panes:
- {fileID: 17}
Expand Down Expand Up @@ -150,7 +150,7 @@ MonoBehaviour:
y: 0
width: 1920
height: 1037
m_MinSize: {x: 950, y: 544}
m_MinSize: {x: 950, y: 300}
m_MaxSize: {x: 10000, y: 10000}
--- !u!114 &7
MonoBehaviour:
Expand Down Expand Up @@ -219,7 +219,7 @@ MonoBehaviour:
m_MinSize: {x: 406, y: 494}
m_MaxSize: {x: 10002, y: 14044}
vertical: 1
controlID: 54
controlID: 58
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -244,7 +244,7 @@ MonoBehaviour:
m_MinSize: {x: 406, y: 222}
m_MaxSize: {x: 8006, y: 4022}
vertical: 0
controlID: 55
controlID: 59
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -266,14 +266,14 @@ MonoBehaviour:
height: 597
m_MinSize: {x: 204, y: 222}
m_MaxSize: {x: 4004, y: 4022}
m_ActualView: {fileID: 19}
m_ActualView: {fileID: 18}
m_Panes:
- {fileID: 18}
- {fileID: 19}
- {fileID: 14}
- {fileID: 13}
m_Selected: 1
m_LastSelected: 3
m_Selected: 0
m_LastSelected: 1
--- !u!114 &12
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -434,20 +434,20 @@ MonoBehaviour:
m_SkipHidden: 0
m_SearchArea: 1
m_Folders:
- Assets/Art/gfx
- Assets/Scripts
m_ViewMode: 1
m_StartGridSize: 64
m_LastFolders:
- Assets/Art/gfx
- Assets/Scripts
m_LastFoldersGridSize: -1
m_LastProjectPath: D:\Git\Unity-Intro\Pokemon RPG
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: b62f0000
m_LastClickedID: 12214
m_ExpandedIDs: 000000003e2d0000962e000000ca9a3b
m_SelectedIDs: 743f0000
m_LastClickedID: 16244
m_ExpandedIDs: 00000000402d00007e2f000000ca9a3b
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -475,7 +475,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 000000003e2d0000
m_ExpandedIDs: 00000000402d0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -598,9 +598,9 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 9e300000
m_LastClickedID: 0
m_ExpandedIDs: 72fbffffdc3c0000
m_SelectedIDs: 3a450000
m_LastClickedID: 17722
m_ExpandedIDs: 72fbffff4c450000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -660,9 +660,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 0, y: 0, z: 0}
m_Target: {x: 2.0856931, y: -0.4027805, z: -0.553041}
speed: 2
m_Value: {x: 0, y: 0, z: 0}
m_Value: {x: 2.0856931, y: -0.4027805, z: -0.553041}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
Expand Down Expand Up @@ -695,9 +695,9 @@ MonoBehaviour:
speed: 2
m_Value: {x: 0, y: 0, z: 0, w: 1}
m_Size:
m_Target: 10
m_Target: 15.529694
speed: 2
m_Value: 10
m_Value: 15.529694
m_Ortho:
m_Target: 1
speed: 2
Expand Down Expand Up @@ -772,7 +772,7 @@ MonoBehaviour:
m_HSlider: 0
m_VSlider: 0
m_IgnoreScrollWheelUntilClicked: 0
m_EnableMouseInput: 1
m_EnableMouseInput: 0
m_EnableSliderZoomHorizontal: 0
m_EnableSliderZoomVertical: 0
m_UniformScale: 1
Expand Down
Loading

0 comments on commit bd2649e

Please sign in to comment.