Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Wintersemester 2018-2019
Unity
Suck It
Commits
7a560776
Commit
7a560776
authored
Mar 27, 2019
by
Unknown
Browse files
Water Logik
parent
5b34a7ba
Changes
8
Hide whitespace changes
Inline
Side-by-side
Assets/.DS_Store
0 → 100644
View file @
7a560776
File added
Assets/_Game/.DS_Store
0 → 100644
View file @
7a560776
File added
Assets/_Game/Prefabs/Level_Elements/Water.prefab
0 → 100644
View file @
7a560776
%YAML
1.1
%TAG
!u!
tag:unity3d.com,2011:
---
!u!1
&100393043881132458
GameObject
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
serializedVersion
:
6
m_Component
:
-
component
:
{
fileID
:
100393043881132463
}
-
component
:
{
fileID
:
100393043881132462
}
-
component
:
{
fileID
:
100393043881132461
}
-
component
:
{
fileID
:
100393043881132460
}
-
component
:
{
fileID
:
100393043881132459
}
m_Layer
:
4
m_Name
:
Water
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
m_NavMeshLayer
:
0
m_StaticEditorFlags
:
0
m_IsActive
:
1
---
!u!4
&100393043881132463
Transform
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
100393043881132458
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
20
,
y
:
10
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
0
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
---
!u!212
&100393043881132462
SpriteRenderer
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
100393043881132458
}
m_Enabled
:
1
m_CastShadows
:
0
m_ReceiveShadows
:
0
m_DynamicOccludee
:
1
m_MotionVectors
:
1
m_LightProbeUsage
:
1
m_ReflectionProbeUsage
:
1
m_RenderingLayerMask
:
1
m_RendererPriority
:
0
m_Materials
:
-
{
fileID
:
10754
,
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
:
0
m_IgnoreNormalsForChartDetection
:
0
m_ImportantGI
:
0
m_StitchLightmapSeams
:
0
m_SelectedEditorRenderState
:
0
m_MinimumChartSize
:
4
m_AutoUVMaxDistance
:
0.5
m_AutoUVMaxAngle
:
89
m_LightmapParameters
:
{
fileID
:
0
}
m_SortingLayerID
:
0
m_SortingLayer
:
0
m_SortingOrder
:
0
m_Sprite
:
{
fileID
:
21300000
,
guid
:
d0cee4e8b659c5646ac1e205b88a3256
,
type
:
3
}
m_Color
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
m_FlipX
:
0
m_FlipY
:
0
m_DrawMode
:
0
m_Size
:
{
x
:
1
,
y
:
1
}
m_AdaptiveModeThreshold
:
0.5
m_SpriteTileMode
:
0
m_WasSpriteAssigned
:
1
m_MaskInteraction
:
0
m_SpriteSortPoint
:
0
---
!u!61
&100393043881132461
BoxCollider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
100393043881132458
}
m_Enabled
:
1
m_Density
:
1
m_Material
:
{
fileID
:
0
}
m_IsTrigger
:
1
m_UsedByEffector
:
1
m_UsedByComposite
:
0
m_Offset
:
{
x
:
0
,
y
:
0
}
m_SpriteTilingProperty
:
border
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
0
}
pivot
:
{
x
:
0.5
,
y
:
0.5
}
oldSize
:
{
x
:
1
,
y
:
1
}
newSize
:
{
x
:
1
,
y
:
1
}
adaptiveTilingThreshold
:
0.5
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
serializedVersion
:
2
m_Size
:
{
x
:
1
,
y
:
1
}
m_EdgeRadius
:
0
---
!u!253
&100393043881132460
BuoyancyEffector2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
100393043881132458
}
m_Enabled
:
1
m_UseColliderMask
:
1
m_ColliderMask
:
serializedVersion
:
2
m_Bits
:
1024
m_SurfaceLevel
:
0.5
m_Density
:
2
m_LinearDrag
:
5
m_AngularDrag
:
5
m_FlowAngle
:
0
m_FlowMagnitude
:
0
m_FlowVariation
:
0
---
!u!114
&100393043881132459
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
100393043881132458
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
e31800f7f0977471d9d711952e21cec3
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
m_CharacterLayer
:
10
Assets/_Game/
Scripts/Interaction
.meta
→
Assets/_Game/
Prefabs/Level_Elements/Water.prefab
.meta
View file @
7a560776
fileFormatVersion: 2
guid: 5782222d4c9b9424ea96676650e643a8
folderAsset: yes
DefaultImporter:
guid: e9f234b3fda124fe29a2b937c13c099e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
...
...
Assets/_Game/Scripts/.DS_Store
0 → 100644
View file @
7a560776
File added
Assets/_Game/Scripts/Elements/WaterLogic.cs
0 → 100644
View file @
7a560776
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
[
RequireComponent
(
typeof
(
BuoyancyEffector2D
),
typeof
(
BoxCollider2D
))]
public
class
WaterLogic
:
MonoBehaviour
{
[
SerializeField
]
private
int
m_CharacterLayer
=
10
;
private
void
OnTriggerEnter2D
(
Collider2D
other
)
{
if
(
other
.
transform
.
gameObject
.
layer
==
m_CharacterLayer
)
{
Debug
.
Log
(
"Enter Water"
);
MovementController
controller
=
other
.
transform
.
GetComponent
<
MovementController
>();
if
(
controller
!=
null
)
{
controller
.
SetSwimming
(
true
);
}
}
}
private
void
OnTriggerExit2D
(
Collider2D
other
)
{
if
(
other
.
transform
.
gameObject
.
layer
==
m_CharacterLayer
)
{
Debug
.
Log
(
"Exit Water"
);
MovementController
controller
=
other
.
transform
.
GetComponent
<
MovementController
>();
if
(
controller
!=
null
)
{
controller
.
SetSwimming
(
false
);
}
}
}
}
Assets/_Game/Scripts/Elements/WaterLogic.cs.meta
0 → 100644
View file @
7a560776
fileFormatVersion: 2
guid: e31800f7f0977471d9d711952e21cec3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Game/Scripts/Player/MovementController.cs
View file @
7a560776
...
...
@@ -4,51 +4,72 @@ using UnityEngine;
using
UnityEngine.Events
;
[
RequireComponent
(
typeof
(
Rigidbody2D
),
typeof
(
BoxCollider2D
))]
public
class
MovementController
:
MonoBehaviour
{
public
class
MovementController
:
MonoBehaviour
{
[
SerializeField
]
private
float
m_Speed
=
10f
;
[
SerializeField
]
private
float
m_JumpForce
=
400f
;
// Amount of force added when the player jumps.
[
Range
(
0
,
.
3f
)][
SerializeField
]
private
float
m_MovementSmoothing
=
.
05f
;
// How much to smooth out the movement
[
Range
(
0
,
.
3f
)]
[
SerializeField
]
private
float
m_MovementSmoothing
=
.
05f
;
// How much to smooth out the movement
[
SerializeField
]
private
bool
m_AirControl
=
false
;
// Whether or not a player can steer while jumping;
[
SerializeField
]
private
LayerMask
m_WhatIsGround
;
// A mask determining what is ground to the character
[
SerializeField
]
private
Transform
m_GroundCheck
;
// A position marking where to check if the player is grounded.
[
SerializeField
]
private
float
m_GroundCheckDistance
=
1.5f
;
[
SerializeField
]
private
float
m_GroundedRadius
=
.
2f
;
[
SerializeField
]
private
Vector2
m_GroundedOffset
=
Vector2
.
zero
;
[
SerializeField
]
private
float
m_GroundMaxSlopeAngle
=
45f
;
[
SerializeField
]
private
float
m_SecondsWaitToJump
=
0.3f
;
[
SerializeField
]
private
int
m_MaxJumpCount
=
1
;
private
bool
m_Grounded
;
// Whether or not the player is grounded.
private
bool
m_Airborn
;
private
bool
m_Grounded
=
false
;
// Whether or not the player is grounded.
private
bool
m_Swimming
=
false
;
private
bool
m_Airborn
=
true
;
private
Rigidbody2D
m_Rigidbody2D
;
private
bool
m_FacingRight
=
true
;
// For determining which way the player is currently facing.
private
Vector3
m_Velocity
=
Vector3
.
zero
;
private
int
m_TempJumpCount
=
0
;
private
bool
m_Jumped
=
false
;
[
Header
(
"Events"
)]
[
Space
]
private
RaycastHit2D
[]
m_RaycastHits2D
=
new
RaycastHit2D
[
16
];
private
ContactFilter2D
m_ContactFilter2D
;
private
Vector3
m_CurrentGroundNormal
;
[
Header
(
"Events"
)]
[
Space
]
//Wird Aktiviert wenn Spieler Landet
public
UnityEvent
OnLandEvent
;
public
float
GravityModifier
{
set
=>
m_Rigidbody2D
.
gravityScale
=
value
;
}
public
float
GravityModifier
{
set
=>
m_Rigidbody2D
.
gravityScale
=
value
;
}
private
void
Awake
()
{
m_Rigidbody2D
=
GetComponent
<
Rigidbody2D
>
();
public
void
SetSwimming
(
bool
value
)
{
m_Swimming
=
value
;
m_TempJumpCount
=
m_MaxJumpCount
;
}
private
void
Awake
()
{
m_Rigidbody2D
=
GetComponent
<
Rigidbody2D
>();
m_ContactFilter2D
.
SetLayerMask
(
m_WhatIsGround
);
if
(
OnLandEvent
==
null
)
OnLandEvent
=
new
UnityEvent
();
OnLandEvent
=
new
UnityEvent
();
}
private
void
Update
()
{
}
private
void
Update
()
{
}
private
void
FixedUpdate
()
{
private
void
FixedUpdate
()
{
bool
wasGrounded
=
m_Grounded
;
m_Grounded
=
false
;
// The player is grounded if a circlecast to the groundcheck position hits anything designated as ground
// This can be done using layers instead but Sample Assets will not overwrite your project settings.
Vector3
pos
=
m_GroundCheck
.
position
+
new
Vector3
(
m_GroundedOffset
.
x
,
m_GroundedOffset
.
y
);
/*
Vector3 pos = m_GroundCheck.position + new Vector3(m_GroundedOffset.x, m_GroundedOffset.y);
Collider2D[] colliders = Physics2D.OverlapCircleAll (pos, m_GroundedRadius, m_WhatIsGround);
for (int i = 0; i < colliders.Length; i++) {
if (colliders[i].gameObject != gameObject) {
...
...
@@ -57,39 +78,60 @@ public class MovementController : MonoBehaviour {
if (!wasGrounded)
OnLandEvent.Invoke ();
}
}*/
Vector3
pos
=
m_GroundCheck
.
position
+
new
Vector3
(
m_GroundedOffset
.
x
,
m_GroundedOffset
.
y
,
0
);
var
c
=
Physics2D
.
CircleCast
(
pos
,
m_GroundedRadius
,
Vector2
.
down
,
m_ContactFilter2D
,
m_RaycastHits2D
,
m_GroundCheckDistance
);
for
(
var
i
=
0
;
i
<
c
;
i
++)
{
if
(
m_RaycastHits2D
[
i
].
transform
.
gameObject
==
gameObject
)
continue
;
m_Grounded
=
true
;
m_TempJumpCount
=
m_MaxJumpCount
;
m_CurrentGroundNormal
=
m_RaycastHits2D
[
i
].
normal
;
if
(!
wasGrounded
)
{
OnLandEvent
.
Invoke
();
}
}
}
public
void
Move
(
Vector2
move
,
bool
jump
)
{
public
void
Move
(
Vector2
move
,
bool
jump
)
{
Debug
.
Log
(
m_Swimming
);
//only control the player if grounded or airControl is turned on
if
(
m_Grounded
||
m_AirControl
)
{
if
(
m_Grounded
||
m_AirControl
||
m_Swimming
)
{
// Move the character by finding the target velocity
Vector2
targetVelocity
=
new
Vector2
((
move
.
x
*
m_Speed
*
Time
.
deltaTime
)
*
10f
,
m_Rigidbody2D
.
velocity
.
y
);
Vector2
targetVelocity
=
new
Vector2
((
move
.
x
*
m_Speed
*
Time
.
deltaTime
)
*
10f
,
m_Rigidbody2D
.
velocity
.
y
);
// And then smoothing it out and applying it to the character
m_Rigidbody2D
.
velocity
=
Vector3
.
SmoothDamp
(
m_Rigidbody2D
.
velocity
,
targetVelocity
,
ref
m_Velocity
,
m_MovementSmoothing
);
m_Rigidbody2D
.
velocity
=
Vector3
.
SmoothDamp
(
m_Rigidbody2D
.
velocity
,
targetVelocity
,
ref
m_Velocity
,
m_MovementSmoothing
);
// If the input is moving the player right and the player is facing left...
if
(
move
.
x
>
0
&&
!
m_FacingRight
)
{
if
(
move
.
x
>
0
&&
!
m_FacingRight
)
{
// ... flip the player.
Flip
();
Flip
();
}
// Otherwise if the input is moving the player left and the player is facing right...
else
if
(
move
.
x
<
0
&&
m_FacingRight
)
{
else
if
(
move
.
x
<
0
&&
m_FacingRight
)
{
// ... flip the player.
Flip
();
Flip
();
}
}
// If the player should jump...
if
(
jump
)
{
if
(((
m_Grounded
)
||
(
m_TempJumpCount
>
1
))
&&
!
m_Jumped
)
{
if
(
jump
)
{
if
(((
m_Grounded
)
||
(
m_TempJumpCount
>
1
)
||
m_Swimming
)
&&
!
m_Jumped
)
{
// Add a vertical force to the player.
m_Grounded
=
false
;
m_TempJumpCount
--;
m_Rigidbody2D
.
AddForce
(
new
Vector2
(
0f
,
m_JumpForce
));
m_Rigidbody2D
.
AddForce
(
new
Vector2
(
0f
,
m_JumpForce
));
StartCoroutine
(
Wait
(
m_SecondsWaitToJump
));
}
}
...
...
@@ -102,7 +144,8 @@ public class MovementController : MonoBehaviour {
m_Jumped
=
false
;
}
private
void
Flip
()
{
private
void
Flip
()
{
// Switch the way the player is labelled as facing.
m_FacingRight
=
!
m_FacingRight
;
...
...
@@ -112,9 +155,14 @@ public class MovementController : MonoBehaviour {
transform
.
localScale
=
theScale
;
}
void
OnDrawGizmos
()
{
void
OnDrawGizmos
()
{
Gizmos
.
color
=
Color
.
green
;
Gizmos
.
DrawWireSphere
(
m_GroundCheck
.
position
+
new
Vector3
(
m_GroundedOffset
.
x
,
m_GroundedOffset
.
y
,
0
),
m_GroundedRadius
);
Vector3
pos
=
m_GroundCheck
.
position
+
new
Vector3
(
m_GroundedOffset
.
x
,
m_GroundedOffset
.
y
,
0
);
//Gizmos.DrawWireSphere (m_GroundCheck.position + new Vector3(m_GroundedOffset.x, m_GroundedOffset.y, 0), m_GroundedRadius);
Gizmos
.
DrawRay
(
pos
,
Vector3
.
down
*
m_GroundCheckDistance
);
Gizmos
.
DrawWireSphere
(
pos
+
Vector3
.
down
*
m_GroundCheckDistance
,
m_GroundedRadius
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment