Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
WidowmakerSimulator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
15박보승
WidowmakerSimulator
Commits
cf048ec3
Commit
cf048ec3
authored
5 years ago
by
15박보승
Committed by
Merseong
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
와이어 액션 구현
parent
9552248a
No related merge requests found
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
857 additions
and
118 deletions
+857
-118
SampleScene.unity
Grapplers/Assets/Scenes/SampleScene.unity
+805
-103
CameraController.cs
Grapplers/Assets/Scripts/CameraController.cs
+4
-2
DistanceJoint3D.cs
Grapplers/Assets/Scripts/DistanceJoint3D.cs
+10
-4
HookBehaviour.cs
Grapplers/Assets/Scripts/HookBehaviour.cs
+2
-1
PlayerController.cs
Grapplers/Assets/Scripts/PlayerController.cs
+36
-8
No files found.
Grapplers/Assets/Scenes/SampleScene.unity
View file @
cf048ec3
This diff is collapsed.
Click to expand it.
Grapplers/Assets/Scripts/CameraController.cs
View file @
cf048ec3
...
...
@@ -6,6 +6,8 @@ public class CameraController : MonoBehaviour
{
public
Transform
target
;
public
Vector3
offset
;
[
SerializeField
]
private
float
distance
=
10.0f
;
private
float
currentX
=
0.0f
;
...
...
@@ -30,8 +32,8 @@ public class CameraController : MonoBehaviour
{
Vector3
dir
=
new
Vector3
(
0
,
0
,
-
distance
);
Quaternion
rotation
=
Quaternion
.
Euler
(
currentY
,
currentX
,
0
);
transform
.
position
=
target
.
position
+
rotation
*
dir
;
transform
.
position
=
offset
+
target
.
position
+
rotation
*
dir
;
target
.
rotation
=
Quaternion
.
Euler
(
0
,
currentX
,
0
);
transform
.
LookAt
(
target
.
position
);
transform
.
LookAt
(
target
.
position
+
offset
);
}
}
This diff is collapsed.
Click to expand it.
Grapplers/Assets/Scripts/DistanceJoint3D.cs
View file @
cf048ec3
...
...
@@ -20,18 +20,24 @@ public class DistanceJoint3D : MonoBehaviour
//distance = Vector3.Distance(rb.position, ConnectedRigidbody.position);
}
private
void
Update
()
{
if
(
distance
>
0
)
{
distance
=
Mathf
.
Max
(
0
,
distance
-
50
*
Time
.
deltaTime
);
}
}
private
void
FixedUpdate
()
{
var
connection
=
rb
.
position
-
ConnectedRigidbody
.
position
;
var
distanceDiscrepancy
=
distance
-
connection
.
magnitude
;
rb
.
position
+=
distanceDiscrepancy
*
connection
.
normalized
;
//
rb.position += distanceDiscrepancy * connection.normalized;
var
velocityTarget
=
connection
+
rb
.
velocity
;
var
projectOnConnect
=
Vector3
.
Project
(
velocityTarget
,
connection
);
rb
.
velocity
=
(
velocityTarget
-
projectOnConnect
)
/
(
1
+
damper
*
Time
.
fixedDeltaTime
);
//rb.velocity = connection.normalized * Physics.gravity.y + Physics.gravity;
rb
.
velocity
=
(
velocityTarget
-
projectOnConnect
+
distanceDiscrepancy
*
connection
.
normalized
)
/
(
1
+
damper
*
Time
.
fixedDeltaTime
);
}
}
This diff is collapsed.
Click to expand it.
Grapplers/Assets/Scripts/HookBehaviour.cs
View file @
cf048ec3
...
...
@@ -20,15 +20,16 @@ public class HookBehaviour : MonoBehaviour
private
void
Update
()
{
Debug
.
Log
(
rb
.
velocity
);
lr
.
SetPosition
(
0
,
transform
.
position
);
lr
.
SetPosition
(
1
,
player
.
position
);
}
private
void
OnCollisionEnter
(
Collision
collision
)
{
Debug
.
Log
(
collision
.
gameObject
);
rb
.
velocity
=
Vector3
.
zero
;
rb
.
isKinematic
=
true
;
player
.
GetComponent
<
PlayerController
>().
ActiveWire
();
}
public
void
EnableHook
(
Vector3
velocity
)
...
...
This diff is collapsed.
Click to expand it.
Grapplers/Assets/Scripts/PlayerController.cs
View file @
cf048ec3
...
...
@@ -6,13 +6,17 @@ using UnityEngine;
public
class
PlayerController
:
MonoBehaviour
{
public
float
distance
=
10.0f
;
private
CharacterController
cc
;
//
private CharacterController cc;
float
velocityY
=
0.0f
;
const
float
gravity
=
9.8f
;
public
HookBehaviour
hook
;
private
Rigidbody
rb
;
private
DistanceJoint3D
joint
;
private
bool
isWired
;
#if UNITY_EDITOR
private
void
OnDrawGizmos
()
{
...
...
@@ -22,8 +26,10 @@ public class PlayerController : MonoBehaviour
private
void
Start
()
{
cc
=
GetComponent
<
CharacterController
>();
//
cc = GetComponent<CharacterController>();
Cursor
.
lockState
=
CursorLockMode
.
Locked
;
joint
=
GetComponent
<
DistanceJoint3D
>();
rb
=
GetComponent
<
Rigidbody
>();
}
private
void
Update
()
{
...
...
@@ -40,12 +46,20 @@ public class PlayerController : MonoBehaviour
ReturnHook
();
}
if
(!
isWired
)
{
/*
if (Input.GetButtonDown("Jump") && cc.isGrounded)
velocityY = 5.0f;
if (!cc.isGrounded)
velocityY -= gravity * Time.deltaTime;
cc.Move(horizontal * transform.right + vertical * transform.forward + new Vector3(0, velocityY, 0) * Time.deltaTime);
*/
}
else
{
if
(
Input
.
GetButtonDown
(
"Jump"
)
&&
cc
.
isGrounded
)
velocityY
=
5.0f
;
if
(!
cc
.
isGrounded
)
velocityY
-=
gravity
*
Time
.
deltaTime
;
cc
.
Move
(
horizontal
*
transform
.
right
+
vertical
*
transform
.
forward
+
new
Vector3
(
0
,
velocityY
,
0
)
*
Time
.
deltaTime
);
}
}
private
void
LateUpdate
()
...
...
@@ -55,13 +69,27 @@ public class PlayerController : MonoBehaviour
private
void
FireHook
()
{
joint
.
enabled
=
false
;
hook
.
gameObject
.
SetActive
(
true
);
hook
.
transform
.
position
=
transform
.
position
;
hook
.
EnableHook
((
transform
.
position
-
Camera
.
main
.
transform
.
position
)
*
5
0
);
hook
.
EnableHook
((
transform
.
position
-
Camera
.
main
.
transform
.
position
)
.
normalized
*
20
0
);
}
private
void
ReturnHook
()
{
joint
.
enabled
=
false
;
hook
.
DisableHook
();
isWired
=
false
;
rb
.
useGravity
=
true
;
//cc.enabled = true;
}
public
void
ActiveWire
()
{
joint
.
enabled
=
true
;
joint
.
distance
=
Vector3
.
Distance
(
transform
.
position
,
hook
.
transform
.
position
);
isWired
=
true
;
rb
.
useGravity
=
false
;
//cc.enabled = false;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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