Skip to content

Commit abb543b

Browse files
authored
feat: add basic camera setup (#10)
1 parent aa4f099 commit abb543b

File tree

7 files changed

+385
-10
lines changed

7 files changed

+385
-10
lines changed

Assets/Player/ChainLink.prefab

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Player/ChainManager.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
using System;
2+
using System.Collections;
23
using UnityEngine;
34

45
namespace Player {
56
public class ChainManager : MonoBehaviour {
67
[SerializeField] private GameObject _link;
78
[SerializeField] private int _length;
8-
[SerializeField] private Vector3 _offset;
99
[SerializeField] private float _linkLength = 1;
1010

1111
[SerializeField] private Rigidbody _from;
1212
[SerializeField] private Rigidbody _to;
13+
[SerializeField] private Vector3[] _positions;
14+
[SerializeField] private Quaternion[] _rotations;
1315

1416
private Rigidbody[] _links;
1517

1618
private void Awake() {
19+
#if UNITY_EDITOR
20+
if (_positions.Length < _length) {
21+
_positions = new Vector3[_length];
22+
}
23+
24+
if (_rotations.Length < _length) {
25+
_rotations = new Quaternion[_length];
26+
}
27+
#endif
28+
1729
_links = new Rigidbody[_length];
1830
var prev = Instantiate(_link);
19-
prev.transform.position = _from.position;
31+
prev.transform.position = _positions[0];
32+
prev.transform.rotation = _rotations[0];
2033
_links[0] = prev.GetComponent<Rigidbody>();
2134

2235
var joint = _to.GetComponent<Joint>();
@@ -30,7 +43,8 @@ private void Awake() {
3043

3144
for (var i = 1; i < _length; i++) {
3245
var link = Instantiate(_link);
33-
link.transform.position = _from.position + _offset * i;
46+
link.transform.position = _positions[i];
47+
link.transform.rotation = _rotations[i];
3448
joint = prev.GetComponent<Joint>();
3549
_links[i] = link.GetComponent<Rigidbody>();
3650
joint.connectedBody = _links[i];
@@ -55,5 +69,18 @@ private void Awake() {
5569
anchor.y = _linkLength;
5670
joint.connectedAnchor = anchor;
5771
}
72+
73+
#if UNITY_EDITOR
74+
[ContextMenu("Store Chain Transform")]
75+
private void StoreChainTransform() {
76+
_positions = new Vector3[_length];
77+
_rotations = new Quaternion[_length];
78+
for (var i = 0; i < _length; i++) {
79+
var link = _links[i].transform;
80+
_positions[i] = link.position;
81+
_rotations[i] = link.rotation;
82+
}
83+
}
84+
#endif
5885
}
5986
}

Assets/Player/PlayerController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ private void HandleCommand(InputAction.CallbackContext context) {
206206
if (Raycast(out var hit)) {
207207
if (hit.transform.gameObject.layer == _config.GroundLayer) {
208208
Navigate();
209+
if (NavMesh.SamplePosition(
210+
hit.point,
211+
out var point,
212+
100,
213+
NavMesh.AllAreas
214+
)) {
215+
_target.transform.position = point.position;
216+
}
209217
} else if (hit.transform.TryGetComponent<Interactable>(
210218
out var interactable
211219
)) {

0 commit comments

Comments
 (0)