Fixed grabber sorting logic
Added grabber sounds Improved grabber marker placement
This commit is contained in:
@@ -9,6 +9,9 @@ public class Grapparoni : MonoBehaviour
|
|||||||
public GameObject grabSpot;
|
public GameObject grabSpot;
|
||||||
public GameObject grabbedObject;
|
public GameObject grabbedObject;
|
||||||
|
|
||||||
|
[Header("DEBUG")]
|
||||||
|
public GameObject debugClosest;
|
||||||
|
|
||||||
private LineRenderer lineRenderer;
|
private LineRenderer lineRenderer;
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
@@ -21,7 +24,7 @@ public class Grapparoni : MonoBehaviour
|
|||||||
{
|
{
|
||||||
Collider[] items = Physics.OverlapSphere(grabSpot.transform.position, radius);
|
Collider[] items = Physics.OverlapSphere(grabSpot.transform.position, radius);
|
||||||
if (items.Length < 1) { lineRenderer.enabled = false; return; }
|
if (items.Length < 1) { lineRenderer.enabled = false; return; }
|
||||||
GameObject closest = items[0].gameObject;
|
GameObject closest = null;
|
||||||
foreach (Collider item in items)
|
foreach (Collider item in items)
|
||||||
{
|
{
|
||||||
Rigidbody rb = item.gameObject.GetComponent<Rigidbody>();
|
Rigidbody rb = item.gameObject.GetComponent<Rigidbody>();
|
||||||
@@ -29,21 +32,20 @@ public class Grapparoni : MonoBehaviour
|
|||||||
if (rb)
|
if (rb)
|
||||||
{
|
{
|
||||||
float dist = Vector3.Distance(item.transform.position, transform.position);
|
float dist = Vector3.Distance(item.transform.position, transform.position);
|
||||||
if (dist < Vector3.Distance(closest.transform.position, transform.position))
|
if (closest == null || dist < Vector3.Distance(closest.transform.position, transform.position))
|
||||||
{
|
{
|
||||||
closest = item.gameObject;
|
closest = item.gameObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!closest) { lineRenderer.enabled = false; return; }
|
||||||
Rigidbody closestRb = closest.transform.GetComponent<Rigidbody>();
|
Rigidbody closestRb = closest.transform.GetComponent<Rigidbody>();
|
||||||
if (closestRb)
|
if (closestRb)
|
||||||
{
|
{
|
||||||
lineRenderer.enabled = true;
|
lineRenderer.enabled = true;
|
||||||
lineRenderer.SetPosition(0, grabSpot.transform.position);
|
lineRenderer.SetPosition(0, grabSpot.transform.position);
|
||||||
lineRenderer.SetPosition(1, closest.transform.position);
|
lineRenderer.SetPosition(1, closest.transform.position);
|
||||||
} else
|
|
||||||
{
|
|
||||||
lineRenderer.enabled = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ public class Grapparoni : MonoBehaviour
|
|||||||
|
|
||||||
Collider[] items = Physics.OverlapSphere(grabSpot.transform.position, radius);
|
Collider[] items = Physics.OverlapSphere(grabSpot.transform.position, radius);
|
||||||
if (items.Length < 1) { return; }
|
if (items.Length < 1) { return; }
|
||||||
GameObject closest = items[0].gameObject;
|
GameObject closest = null;
|
||||||
foreach (Collider item in items)
|
foreach (Collider item in items)
|
||||||
{
|
{
|
||||||
Rigidbody rb = item.gameObject.GetComponent<Rigidbody>();
|
Rigidbody rb = item.gameObject.GetComponent<Rigidbody>();
|
||||||
@@ -80,12 +82,14 @@ public class Grapparoni : MonoBehaviour
|
|||||||
if(rb)
|
if(rb)
|
||||||
{
|
{
|
||||||
float dist = Vector3.Distance(item.transform.position, transform.position);
|
float dist = Vector3.Distance(item.transform.position, transform.position);
|
||||||
if (dist < Vector3.Distance(closest.transform.position, transform.position)) {
|
if (closest == null || dist < Vector3.Distance(closest.transform.position, transform.position)) {
|
||||||
closest = item.gameObject;
|
closest = item.gameObject;
|
||||||
|
debugClosest = closest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!closest) { return; }
|
||||||
Rigidbody closestRb = closest.transform.GetComponent<Rigidbody>();
|
Rigidbody closestRb = closest.transform.GetComponent<Rigidbody>();
|
||||||
if (closestRb)
|
if (closestRb)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,15 @@ public class RobotArmController : MonoBehaviour
|
|||||||
public GameObject targetMarker;
|
public GameObject targetMarker;
|
||||||
|
|
||||||
|
|
||||||
|
//Audio
|
||||||
|
public AudioSource backgroundSource;
|
||||||
|
public AudioSource sfxSource;
|
||||||
|
public AudioSource interactSource;
|
||||||
|
|
||||||
|
public AudioClip idleSound;
|
||||||
|
public AudioClip interactSound;
|
||||||
|
public AudioClip moveClip;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@@ -28,7 +37,10 @@ public class RobotArmController : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
targetMarker.transform.position = new Vector3(target.transform.position.x, transform.position.y + .5f, target.transform.position.z);
|
RaycastHit hit;
|
||||||
|
Physics.Raycast(grabber.grabSpot.transform.position, Vector3.down, out hit, 10);
|
||||||
|
|
||||||
|
targetMarker.transform.position = new Vector3(grabber.grabSpot.transform.position.x, hit.point.y + 0.05f, grabber.grabSpot.transform.position.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InteractNode(Node pre)
|
public void InteractNode(Node pre)
|
||||||
@@ -43,6 +55,8 @@ public class RobotArmController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (!isInUse) { return; }
|
if (!isInUse) { return; }
|
||||||
|
|
||||||
|
bool isMoving = false;
|
||||||
|
|
||||||
//return to network view with x
|
//return to network view with x
|
||||||
if (Keyboard.current.xKey.wasPressedThisFrame)
|
if (Keyboard.current.xKey.wasPressedThisFrame)
|
||||||
{
|
{
|
||||||
@@ -53,20 +67,29 @@ public class RobotArmController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
//return to network view with x
|
//return to network view with x
|
||||||
if (Keyboard.current.spaceKey.wasPressedThisFrame)
|
if (Keyboard.current.spaceKey.wasPressedThisFrame && !sfxSource.isPlaying)
|
||||||
{
|
{
|
||||||
grabber.GrabClosest();
|
grabber.GrabClosest();
|
||||||
|
interactSource.clip = interactSound;
|
||||||
|
interactSource.Play();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hoch/Runter
|
//Hoch/Runter
|
||||||
if (Keyboard.current.ctrlKey.isPressed && target.transform.position.y > transform.position.y)
|
if (Keyboard.current.ctrlKey.isPressed && target.transform.position.y > transform.position.y)
|
||||||
{
|
{
|
||||||
|
if(Physics.Raycast(grabber.transform.position, Vector3.down, .9f))
|
||||||
|
{
|
||||||
|
target.transform.localPosition -= Vector3.down * Time.deltaTime * armSpeed;
|
||||||
|
}
|
||||||
target.transform.localPosition += Vector3.down * Time.deltaTime * armSpeed;
|
target.transform.localPosition += Vector3.down * Time.deltaTime * armSpeed;
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.current.shiftKey.isPressed && target.transform.localPosition.y < targetConstraints.y)
|
if (Keyboard.current.shiftKey.isPressed && target.transform.localPosition.y < targetConstraints.y)
|
||||||
{
|
{
|
||||||
target.transform.localPosition += Vector3.up * Time.deltaTime * armSpeed;
|
target.transform.localPosition += Vector3.up * Time.deltaTime * armSpeed;
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Debug.Log(-targetConstraints.z);
|
//Debug.Log(-targetConstraints.z);
|
||||||
@@ -74,33 +97,50 @@ public class RobotArmController : MonoBehaviour
|
|||||||
if (Keyboard.current.aKey.isPressed && target.transform.localPosition.z > -targetConstraints.z)
|
if (Keyboard.current.aKey.isPressed && target.transform.localPosition.z > -targetConstraints.z)
|
||||||
{
|
{
|
||||||
target.transform.localPosition += Vector3.back * Time.deltaTime * armSpeed;
|
target.transform.localPosition += Vector3.back * Time.deltaTime * armSpeed;
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.current.dKey.isPressed && target.transform.localPosition.z < targetConstraints.z)
|
if (Keyboard.current.dKey.isPressed && target.transform.localPosition.z < targetConstraints.z)
|
||||||
{
|
{
|
||||||
target.transform.localPosition += Vector3.forward * Time.deltaTime * armSpeed;
|
target.transform.localPosition += Vector3.forward * Time.deltaTime * armSpeed;
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Left/Right
|
//Left/Right
|
||||||
if (Keyboard.current.qKey.isPressed)
|
if (Keyboard.current.qKey.isPressed)
|
||||||
{
|
{
|
||||||
transform.Rotate(0.0f, armRotationSpeed * Time.deltaTime, 0.0f, Space.Self);
|
transform.Rotate(0.0f, armRotationSpeed * Time.deltaTime, 0.0f, Space.Self);
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.current.eKey.isPressed)
|
if (Keyboard.current.eKey.isPressed)
|
||||||
{
|
{
|
||||||
transform.Rotate(0.0f, -armRotationSpeed * Time.deltaTime, 0.0f, Space.Self);
|
transform.Rotate(0.0f, -armRotationSpeed * Time.deltaTime, 0.0f, Space.Self);
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Forwards/Backwards
|
//Forwards/Backwards
|
||||||
if (Keyboard.current.wKey.isPressed && target.transform.localPosition.x > -targetConstraints.x)
|
if (Keyboard.current.wKey.isPressed && target.transform.localPosition.x > -targetConstraints.x)
|
||||||
{
|
{
|
||||||
target.transform.localPosition += Vector3.left * Time.deltaTime * armSpeed;
|
target.transform.localPosition += Vector3.left * Time.deltaTime * armSpeed;
|
||||||
|
isMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.current.sKey.isPressed && target.transform.localPosition.x < -3.5f)
|
if (Keyboard.current.sKey.isPressed && target.transform.localPosition.x < -3.5f)
|
||||||
{
|
{
|
||||||
target.transform.localPosition += Vector3.right * Time.deltaTime * armSpeed;
|
target.transform.localPosition += Vector3.right * Time.deltaTime * armSpeed;
|
||||||
|
isMoving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sfxSource.isPlaying && isMoving)
|
||||||
|
{
|
||||||
|
sfxSource.clip = moveClip;
|
||||||
|
sfxSource.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isMoving)
|
||||||
|
{
|
||||||
|
sfxSource.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Assets/Sounds/387239__deleted-user-228014__beerhiss1.wav
(Stored with Git LFS)
Normal file
BIN
Assets/Sounds/387239__deleted-user-228014__beerhiss1.wav
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -0,0 +1,22 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 66f5a01951ce1964993ffc0dda57c1df
|
||||||
|
AudioImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 6
|
||||||
|
defaultSettings:
|
||||||
|
loadType: 0
|
||||||
|
sampleRateSetting: 0
|
||||||
|
sampleRateOverride: 44100
|
||||||
|
compressionFormat: 1
|
||||||
|
quality: 1
|
||||||
|
conversionMode: 0
|
||||||
|
platformSettingOverrides: {}
|
||||||
|
forceToMono: 0
|
||||||
|
normalize: 1
|
||||||
|
preloadAudioData: 1
|
||||||
|
loadInBackground: 0
|
||||||
|
ambisonic: 0
|
||||||
|
3D: 1
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user