Skip to content
GitLab
Menu
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
4d4a686b
Commit
4d4a686b
authored
Mar 28, 2019
by
Unknown
Browse files
Einbeziehen von Movement Verhalten in unterschiedlichen Spieler Statie
parent
4252cd21
Changes
5
Hide whitespace changes
Inline
Side-by-side
Assets/_Game/Prefabs/Player/Player.prefab
View file @
4d4a686b
...
...
@@ -13,7 +13,12 @@ GameObject:
-
component
:
{
fileID
:
2055293003418080559
}
-
component
:
{
fileID
:
52145075018362291
}
-
component
:
{
fileID
:
52145075018362284
}
-
component
:
{
fileID
:
52145075018362287
}
-
component
:
{
fileID
:
779623631694574805
}
-
component
:
{
fileID
:
352228602
}
-
component
:
{
fileID
:
352228603
}
-
component
:
{
fileID
:
352228604
}
-
component
:
{
fileID
:
352228605
}
-
component
:
{
fileID
:
352228606
}
m_Layer
:
10
m_Name
:
Player
m_TagString
:
Player
...
...
@@ -30,7 +35,7 @@ Transform:
m_GameObject
:
{
fileID
:
52145075018362288
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
2
,
z
:
1
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
0
...
...
@@ -72,7 +77,7 @@ SpriteRenderer:
m_SortingLayerID
:
0
m_SortingLayer
:
0
m_SortingOrder
:
0
m_Sprite
:
{
fileID
:
21300000
,
guid
:
d0cee4e8b659c5646ac1e205b88a3256
,
type
:
3
}
m_Sprite
:
{
fileID
:
21300000
,
guid
:
c8a742c1f2ebb43b9afe34a47304c051
,
type
:
3
}
m_Color
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
m_FlipX
:
0
m_FlipY
:
0
...
...
@@ -109,25 +114,35 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_Speed
:
30
m_JumpForce
:
10
m_fallMultiplier
:
2.5
m_lowJumpMultiplier
:
2
m_MovementSmoothing
:
0.05
m_AirControl
:
1
m_CanSwim
:
1
m_WhatIsGround
:
serializedVersion
:
2
m_Bits
:
512
m_GroundCheck
:
{
fileID
:
52145075018362285
}
m_GroundCheckDistance
:
1
m_GroundCheckDistance
:
0.6
m_GroundedRadius
:
0.25
m_GroundedOffset
:
{
x
:
0
,
y
:
0
}
m_GroundMaxSlopeAngle
:
45
m_GroundedOffset
:
{
x
:
-0.09
,
y
:
-0.5
}
m_SecondsWaitToJump
:
0.5
m_MaxJumpCount
:
1
m_fallMultiplier
:
2.5
m_lowJumpMultiplier
:
2
OnLandEvent
:
m_PersistentCalls
:
m_Calls
:
[]
m_TypeName
:
UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnSwimEvent
:
m_PersistentCalls
:
m_Calls
:
[]
m_TypeName
:
UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnJumpEvent
:
m_PersistentCalls
:
m_Calls
:
[]
m_TypeName
:
UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
---
!u!50
&52145075018362284
Rigidbody2D
:
serializedVersion
:
4
...
...
@@ -149,8 +164,8 @@ Rigidbody2D:
m_SleepingMode
:
1
m_CollisionDetection
:
1
m_Constraints
:
4
---
!u!
61
&52145075018362287
Box
Collider2D
:
---
!u!
70
&779623631694574805
Capsule
Collider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
...
...
@@ -162,16 +177,86 @@ BoxCollider2D:
m_IsTrigger
:
0
m_UsedByEffector
:
0
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
:
0.16
,
y
:
0.16
}
adaptiveTilingThreshold
:
0.5
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
serializedVersion
:
2
m_Size
:
{
x
:
1
,
y
:
1
}
m_EdgeRadius
:
0
m_Offset
:
{
x
:
-0.03
,
y
:
-0.36
}
m_Size
:
{
x
:
1.05
,
y
:
1.39
}
m_Direction
:
0
---
!u!114
&352228602
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
52145075018362288
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
2f8415a7fda2c084e87b3caa1b43ffbf
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
state
:
{
fileID
:
11400000
,
guid
:
c5777bcc7b64ce24c9bd65d2c4b7c639
,
type
:
2
}
onElementInfused
:
{
fileID
:
11400000
,
guid
:
7e5b80a8353af1846a878c3a997bdb4a
,
type
:
2
}
---
!u!114
&352228603
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
52145075018362288
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
adc21094da13d8649a490855a137565f
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
cooldown
:
0
volleySize
:
0
launchPower
:
0
attackSpeed
:
0
shotSpawn
:
{
fileID
:
0
}
elementalAttack
:
{
fileID
:
0
}
---
!u!114
&352228604
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
52145075018362288
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
ad90db0185377664288543ce4696c6b8
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
---
!u!114
&352228605
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
52145075018362288
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
83eb4399ff535ee4cbc76de3b8a32e46
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
Cooldown
:
0
volleySize
:
0
launchPower
:
0
attackSpeed
:
0
shotSpawn
:
{
fileID
:
0
}
fireBall
:
{
fileID
:
0
}
---
!u!114
&352228606
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
52145075018362288
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
5a8392b2d467dfc428ede6cd785337f2
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
weight
:
0
isPerformingAction
:
0
windAttack
:
{
fileID
:
0
}
Cooldown
:
0
attackRange
:
0
firePower
:
0
Assets/_Game/Scripts/CameraController.cs
View file @
4d4a686b
...
...
@@ -4,22 +4,36 @@ using UnityEngine;
public
class
CameraController
:
MonoBehaviour
{
public
GameObject
player
;
//Public variable to store a reference to the player game object
public
Transform
target
;
//Public variable to store a reference to the player game object
public
float
smoothSpeed
=
0.5f
;
public
bool
lookAt
=
false
;
public
float
maxDistance
=
5f
;
private
Vector3
offset
;
//Private variable to store the offset distance between the player and camera
// Use this for initialization
void
Start
()
{
target
=
GameObject
.
FindGameObjectWithTag
(
"Player"
).
transform
;
//Calculate and store the offset value by getting the distance between the player's position and camera's position.
offset
=
transform
.
position
-
player
.
transform
.
position
;
offset
=
transform
.
position
-
target
.
transform
.
position
;
if
(
offset
.
sqrMagnitude
>
maxDistance
*
maxDistance
)
{
offset
.
x
=
0f
;
offset
.
y
=
0f
;
}
}
// LateUpdate is called after Update each frame
void
Late
Update
()
void
Fixed
Update
()
{
// Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
transform
.
position
=
player
.
transform
.
position
+
offset
;
//transform.position = player.transform.position + offset;
Vector3
desiredPosition
=
target
.
position
+
offset
;
Vector3
smoothedPosition
=
Vector3
.
Lerp
(
transform
.
position
,
desiredPosition
,
smoothSpeed
);
transform
.
position
=
smoothedPosition
;
if
(
lookAt
)
transform
.
LookAt
(
target
);
}
}
Assets/_Game/Scripts/Player/MovementController.cs
View file @
4d4a686b
...
...
@@ -2,20 +2,22 @@ using System.Collections;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.Events
;
using
_Game.Scripts.Scriptable_Object
;
[
RequireComponent
(
typeof
(
Rigidbody2D
),
typeof
(
Box
Collider2D
))]
[
RequireComponent
(
typeof
(
Rigidbody2D
),
typeof
(
Capsule
Collider2D
))]
public
class
MovementController
:
MonoBehaviour
{
[
Header
(
"Movement"
)]
[
SerializeField
]
private
float
m_Speed
=
10f
;
[
Header
(
"Movement"
)]
[
SerializeField
]
private
float
m_Speed
=
10f
;
[
SerializeField
]
private
float
m_JumpForce
=
400f
;
// Amount of force added when the player jumps.
[
SerializeField
]
private
float
m_fallMultiplier
=
2.5f
;
[
SerializeField
]
private
float
m_lowJumpMultiplier
=
2.0f
;
[
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
bool
m_CanSwim
=
true
;
[
Header
(
"Ground Check Control"
)]
[
SerializeField
]
private
LayerMask
m_WhatIsGround
;
// A mask determining what is ground to the character
[
Header
(
"Ground Check Control"
)]
[
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
;
...
...
@@ -23,7 +25,6 @@ public class MovementController : MonoBehaviour
[
SerializeField
]
private
float
m_SecondsWaitToJump
=
0.3f
;
[
SerializeField
]
private
int
m_MaxJumpCount
=
1
;
private
bool
m_Grounded
=
false
;
// Whether or not the player is grounded.
private
bool
m_Swimming
=
false
;
private
bool
m_Airborn
=
true
;
...
...
@@ -41,12 +42,21 @@ public class MovementController : MonoBehaviour
//Wird Aktiviert wenn Spieler Landet
public
UnityEvent
OnLandEvent
;
public
UnityEvent
OnSwimEvent
;
public
UnityEvent
OnJumpEvent
;
public
float
GravityModifier
public
void
SetMovementParameters
(
MovementState
state
)
{
set
=>
m_Rigidbody2D
.
gravityScale
=
value
;
m_JumpForce
=
state
.
jumpForce
;
//m_MovementSmoothing = state.smoothing;
m_AirControl
=
state
.
airControl
;
m_CanSwim
=
state
.
canSwim
;
m_Speed
=
state
.
moveSpeed
;
m_MaxJumpCount
=
state
.
maxJumpCount
;
m_Rigidbody2D
.
mass
=
state
.
mass
;
m_Rigidbody2D
.
gravityScale
=
state
.
gravity
;
}
public
void
SetSwimming
(
bool
value
)
...
...
@@ -59,6 +69,16 @@ public class MovementController : MonoBehaviour
}
}
public
bool
Swimming
{
get
=>
m_Swimming
;
}
public
bool
Grounded
{
get
=>
m_Grounded
;
}
private
void
Awake
()
{
m_Rigidbody2D
=
GetComponent
<
Rigidbody2D
>();
...
...
@@ -105,9 +125,9 @@ public class MovementController : MonoBehaviour
public
void
Move
(
Vector2
move
,
bool
jump
)
{
Debug
.
Log
(
m_Swim
ming
);
Debug
.
Log
(
m_
Can
Swim
);
//only control the player if grounded or airControl is turned on
if
(
m_Grounded
||
m_AirControl
||
m_Swimming
)
if
(
m_Grounded
||
m_AirControl
||
(
m_Swimming
&&
m_CanSwim
)
)
{
// Move the character by finding the target velocity
Vector2
targetVelocity
=
new
Vector2
((
move
.
x
*
m_Speed
*
Time
.
deltaTime
)
*
10f
,
m_Rigidbody2D
.
velocity
.
y
);
...
...
@@ -133,7 +153,7 @@ public class MovementController : MonoBehaviour
// If the player should jump...
if
(
jump
)
{
if
(((
m_Grounded
)
||
(
m_TempJumpCount
>
1
)
||
m_Swimming
)
&&
!
m_Jumped
)
if
(((
m_Grounded
)
||
(
m_TempJumpCount
>
1
)
||
(
m_Swimming
&&
m_CanSwim
)
)
&&
!
m_Jumped
)
{
// Add a vertical force to the player.
OnJumpEvent
.
Invoke
();
...
...
@@ -148,7 +168,8 @@ public class MovementController : MonoBehaviour
if
(
m_Rigidbody2D
.
velocity
.
y
<
0
&&
!
m_Swimming
)
{
m_Rigidbody2D
.
velocity
+=
Vector2
.
up
*
Physics2D
.
gravity
.
y
*
(
m_fallMultiplier
-
1
)
*
Time
.
deltaTime
;
}
else
if
(
m_Rigidbody2D
.
velocity
.
y
>
0
&&
!
Input
.
GetButton
(
"Jump"
))
}
else
if
(
m_Rigidbody2D
.
velocity
.
y
>
0
&&
!
Input
.
GetButton
(
"Jump"
))
{
m_Rigidbody2D
.
velocity
+=
Vector2
.
up
*
Physics2D
.
gravity
.
y
*
(
m_lowJumpMultiplier
-
1
)
*
Time
.
deltaTime
;
}
...
...
@@ -182,4 +203,3 @@ public class MovementController : MonoBehaviour
Gizmos
.
DrawWireSphere
(
pos
+
Vector3
.
down
*
m_GroundCheckDistance
,
m_GroundedRadius
);
}
}
Assets/_Game/Scripts/Player/PlayerInteract.cs
View file @
4d4a686b
...
...
@@ -8,6 +8,9 @@ using _Game.Scripts.Scriptable_Object;
namespace
_Game.Scripts.Player
{
[
RequireComponent
(
typeof
(
PlayerAirAttack
),
typeof
(
Player_FireAttack
))]
[
RequireComponent
(
typeof
(
PlayerEarthAttack
),
typeof
(
PlayerWaterAttack
))]
public
class
PlayerInteract
:
MonoBehaviour
{
...
...
@@ -23,12 +26,16 @@ namespace _Game.Scripts.Player
private
Player_FireAttack
_fireAttack
;
private
PlayerWaterAttack
_waterAttack
;
private
MovementController
_controller
;
private
void
Start
()
{
_airAttack
=
this
.
gameObject
.
GetComponent
<
PlayerAirAttack
>();
_earthAttack
=
this
.
gameObject
.
GetComponent
<
PlayerEarthAttack
>();
_fireAttack
=
this
.
gameObject
.
GetComponent
<
Player_FireAttack
>();
_waterAttack
=
this
.
gameObject
.
GetComponent
<
PlayerWaterAttack
>();
_controller
=
this
.
gameObject
.
GetComponent
<
MovementController
>();
}
private
void
Update
()
...
...
@@ -78,6 +85,7 @@ namespace _Game.Scripts.Player
_waterAttack
.
enabled
=
false
;
break
;
}
_controller
.
SetMovementParameters
(
state
.
GetCurrentMovementState
());
_targetScript
.
InfuseElement
();
}
...
...
Assets/_Game/Scripts/Scriptable Object/MovementStates.cs
View file @
4d4a686b
...
...
@@ -40,16 +40,19 @@ namespace _Game.Scripts.Scriptable_Object
public
float
jumpForce
;
public
float
smoothing
;
public
bool
airControl
;
public
bool
canSwim
;
public
float
moveSpeed
;
public
int
maxJumpCount
;
public
float
mass
;
public
float
gravity
;
public
MovementState
(
float
jumpForce
,
float
smoothing
,
bool
airControl
,
float
moveSpeed
,
int
maxJumpCount
,
float
gravity
,
float
mass
)
:
this
()
public
MovementState
(
float
jumpForce
,
float
smoothing
,
bool
airControl
,
bool
canSwim
,
float
moveSpeed
,
int
maxJumpCount
,
float
gravity
,
float
mass
)
:
this
()
{
this
.
jumpForce
=
jumpForce
;
this
.
smoothing
=
smoothing
;
this
.
airControl
=
airControl
;
this
.
canSwim
=
canSwim
;
this
.
moveSpeed
=
moveSpeed
;
this
.
maxJumpCount
=
maxJumpCount
;
this
.
gravity
=
gravity
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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