Browse Source

terrain

master
Gharke 2 months ago
parent
commit
a0d645d659
  1. 157
      Assets/Scenes/SampleScene.unity
  2. 17
      Assets/Scripts/BattleController.cs
  3. 2
      Assets/Scripts/BattleController.cs.meta
  4. 44
      Assets/Scripts/PlayerController.cs
  5. BIN
      Assets/Terrain/Terrain Data/Grass_Texture.png
  6. 117
      Assets/Terrain/Terrain Data/Grass_Texture.png.meta
  7. BIN
      Assets/Terrain/Terrain Data/Overworld.asset
  8. 28
      ProjectSettings/TagManager.asset

157
Assets/Scenes/SampleScene.unity

@ -572,6 +572,59 @@ MonoBehaviour:
m_LightCookieSize: {x: 1, y: 1}
m_LightCookieOffset: {x: 0, y: 0}
m_SoftShadowQuality: 1
--- !u!1 &574594174
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 574594175}
- component: {fileID: 574594176}
m_Layer: 6
m_Name: GrassTrigger (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &574594175
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574594174}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 16.73, y: 21.65, z: -0.53}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1335103631}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &574594176
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574594174}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 22.315044, y: 1, z: 13.483817}
m_Center: {x: -1.9125233, y: 0, z: 4.1119084}
--- !u!1 &723551637
GameObject:
m_ObjectHideFlags: 0
@ -584,6 +637,7 @@ GameObject:
- component: {fileID: 723551641}
- component: {fileID: 723551640}
- component: {fileID: 723551638}
- component: {fileID: 723551642}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@ -606,6 +660,10 @@ MonoBehaviour:
speed: 3
anim: {fileID: 981551053}
playerSprite: {fileID: 981551052}
grassLayer:
serializedVersion: 2
m_Bits: 64
stepsInGrass: 0
--- !u!4 &723551639
Transform:
m_ObjectHideFlags: 0
@ -672,6 +730,18 @@ CapsuleCollider:
m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &723551642
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 723551637}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e0424d1087575734d8438d755c8cfc7a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &778721156
GameObject:
m_ObjectHideFlags: 0
@ -1011,6 +1081,39 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1335103630
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1335103631}
m_Layer: 0
m_Name: GrassTriggers
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1335103631
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1335103630}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -20.258644, y: -20.891117, z: 23.306154}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1813274606}
- {fileID: 574594175}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1515600890
GameObject:
m_ObjectHideFlags: 0
@ -1073,6 +1176,59 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1813274605
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1813274606}
- component: {fileID: 1813274607}
m_Layer: 6
m_Name: GrassTrigger
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1813274606
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1813274605}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 16.73, y: 21.65, z: -10.76}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1335103631}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1813274607
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1813274605}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 12.69, y: 1, z: 10.46}
m_Center: {x: 2.9, y: 0, z: 2.6}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
@ -1085,3 +1241,4 @@ SceneRoots:
- {fileID: 410087041}
- {fileID: 832575519}
- {fileID: 1204603268}
- {fileID: 1335103631}

17
Assets/Scripts/BattleController.cs

@ -0,0 +1,17 @@
using UnityEngine;
public class BattleController : MonoBehaviour
{
private void FixedUpdate()
{
}
}

2
Assets/Scripts/BattleController.cs.meta

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e0424d1087575734d8438d755c8cfc7a

44
Assets/Scripts/PlayerController.cs

@ -2,17 +2,31 @@ using UnityEngine;
public class PlayerController : MonoBehaviour
{
/**************************************************************************
* MOVEMENT VARIABLES
*************************************************************************/
[SerializeField] private int speed;
[SerializeField] private Animator anim;
[SerializeField] private SpriteRenderer playerSprite;
private PlayerControls playerControls;
private Rigidbody rb;
private Vector3 movement;
private const string IS_WALK_PARAM = "IsWalk";
// Start is called once before the first execution of Update after the MonoBehaviour is created
/**************************************************************************
* BATTLE DETECTION VARIABLES
*************************************************************************/
[SerializeField] private LayerMask grassLayer;
[SerializeField] private int stepsInGrass;
private bool movingInGrass;
private float stepTimer;
private const float timePerStep = 0.5f;
private void Awake()
{
playerControls = new PlayerControls();
@ -51,7 +65,31 @@ public class PlayerController : MonoBehaviour
{
if (movement != null)
{
rb.MovePosition(transform.position + movement * speed * Time.fixedDeltaTime);
rb.MovePosition
(
transform.position + movement * speed * Time.fixedDeltaTime
);
}
/***** BATTLE DETECTION *****/
// Battle occurs after a random number of steps in a grass collider
// https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html
Collider[] colliders = Physics.OverlapSphere(transform.position, 1, grassLayer);
movingInGrass = colliders.Length != 0 && movement != Vector3.zero;
if (movingInGrass == true)
{
stepTimer += Time.fixedDeltaTime;
if (stepTimer > timePerStep)
{
stepsInGrass++;
stepTimer = 0;
// check to see if we have reached an encounter
// ->change the scene
}
}
}
}

BIN
Assets/Terrain/Terrain Data/Grass_Texture.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

117
Assets/Terrain/Terrain Data/Grass_Texture.png.meta

@ -0,0 +1,117 @@
fileFormatVersion: 2
guid: 0ed670d0c365ba049a5038f3fcf5db6b
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Terrain/Terrain Data/Overworld.asset

Binary file not shown.

28
ProjectSettings/TagManager.asset

@ -2,7 +2,7 @@
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
serializedVersion: 3
tags: []
layers:
- Default
@ -11,7 +11,7 @@ TagManager:
-
- Water
- UI
-
- GrassLayer
-
-
-
@ -50,27 +50,3 @@ TagManager:
- Light Layer 5
- Light Layer 6
- Light Layer 7
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

Loading…
Cancel
Save