Add basic breakout to scene
This commit is contained in:
8
Assets/Scripts/Breakout.meta
Normal file
8
Assets/Scripts/Breakout.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89d3a05ad04982945b581cb2b7146965
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/Breakout/EndForcefield.cs
Normal file
18
Assets/Scripts/Breakout/EndForcefield.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EndForcefield : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Breakout/EndForcefield.cs.meta
Normal file
11
Assets/Scripts/Breakout/EndForcefield.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9028d8e31a1966540aff16d72263c97d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Breakout/KinematicSpeedTransfer.cs
Normal file
35
Assets/Scripts/Breakout/KinematicSpeedTransfer.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class KinematicSpeedTransfer : MonoBehaviour
|
||||
{
|
||||
public float amplification = 1f;
|
||||
|
||||
private Vector3 _oldPosition;
|
||||
private Vector3 _velocity;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_oldPosition = transform.position;
|
||||
_velocity = Vector3.zero;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 newPosition = transform.position;
|
||||
Vector3 posDiff = newPosition - _oldPosition;
|
||||
_velocity = posDiff / Time.deltaTime;
|
||||
_oldPosition = newPosition;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
if (other.rigidbody.isKinematic) return;
|
||||
|
||||
other.rigidbody.AddRelativeForce(_velocity * amplification, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Breakout/KinematicSpeedTransfer.cs.meta
Normal file
11
Assets/Scripts/Breakout/KinematicSpeedTransfer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad1c1fb4f4c956040a341a0dbda221c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Scripts/Breakout/OffsetOnDirectHit.cs
Normal file
33
Assets/Scripts/Breakout/OffsetOnDirectHit.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class OffsetOnDirectHit : MonoBehaviour
|
||||
{
|
||||
public float minAngle = 0;
|
||||
public float maxAngle = 20;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_rigidbody = new Rigidbody();
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
Vector3 normal = other.contacts[0].normal;
|
||||
Vector3 velocity = _rigidbody.velocity;
|
||||
|
||||
// Get Angle
|
||||
float angle = Vector3.Angle(velocity, -normal);
|
||||
|
||||
if (angle > minAngle & angle < maxAngle)
|
||||
{
|
||||
// Add random torque to randomize direction
|
||||
_rigidbody.AddTorque(new Vector3(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Breakout/OffsetOnDirectHit.cs.meta
Normal file
11
Assets/Scripts/Breakout/OffsetOnDirectHit.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d37534609f68e284b8080930a495d1f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Breakout/RigidbodySpeedLimiter.cs
Normal file
35
Assets/Scripts/Breakout/RigidbodySpeedLimiter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RigidbodySpeedLimiter : MonoBehaviour
|
||||
{
|
||||
public float maxSpeed = 5f;
|
||||
public float minSpeed = 2f;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (_rigidbody.IsSleeping()) return;
|
||||
|
||||
float velocity = _rigidbody.velocity.magnitude;
|
||||
|
||||
Debug.Log(velocity);
|
||||
|
||||
if (velocity < minSpeed)
|
||||
{
|
||||
_rigidbody.velocity = _rigidbody.velocity.normalized * minSpeed;
|
||||
}
|
||||
else if (velocity > maxSpeed)
|
||||
{
|
||||
_rigidbody.velocity = Vector3.ClampMagnitude(_rigidbody.velocity, maxSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Breakout/RigidbodySpeedLimiter.cs.meta
Normal file
11
Assets/Scripts/Breakout/RigidbodySpeedLimiter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83f379a702a6eff48b7a38d9e14b79af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Scripts/UnityXR/XRGrabVelocityTracked.cs
Normal file
26
Assets/Scripts/UnityXR/XRGrabVelocityTracked.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class XRGrabVelocityTracked : XRGrabInteractable
|
||||
{
|
||||
protected override void OnSelectEntered(XRBaseInteractor interactor)
|
||||
{
|
||||
SetParentToXRRig();
|
||||
base.OnSelectEntered(interactor);
|
||||
}
|
||||
|
||||
protected override void OnSelectExited(XRBaseInteractor interactor)
|
||||
{
|
||||
SetParentToWorld();
|
||||
base.OnSelectExited(interactor);
|
||||
}
|
||||
|
||||
public void SetParentToXRRig()
|
||||
{
|
||||
transform.SetParent(selectingInteractor.transform);
|
||||
}
|
||||
|
||||
public void SetParentToWorld()
|
||||
{
|
||||
transform.SetParent(null);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UnityXR/XRGrabVelocityTracked.cs.meta
Normal file
11
Assets/Scripts/UnityXR/XRGrabVelocityTracked.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c96c5d5e9ecc35d4b8732d567d0c8458
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user