Skip to content

Commit bbf0627

Browse files
committed
More physics testing
1 parent 64a528c commit bbf0627

File tree

13 files changed

+362
-207
lines changed

13 files changed

+362
-207
lines changed

Assets/_Project/Prefabs/Player.prefab

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Transform:
124124
m_PrefabInstance: {fileID: 0}
125125
m_PrefabAsset: {fileID: 0}
126126
m_GameObject: {fileID: 880972579810857675}
127-
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
127+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
128128
m_LocalPosition: {x: 0, y: 0, z: 0}
129129
m_LocalScale: {x: 5, y: 5, z: 5}
130130
m_Children:
@@ -236,24 +236,36 @@ MonoBehaviour:
236236
m_Script: {fileID: 11500000, guid: cf888513164944c5a9dd9de0ecd0bbd0, type: 3}
237237
m_Name:
238238
m_EditorClassIdentifier:
239+
thrust: 3
239240
applyNewForce: 0
240241
newForceTime: 0
242+
applyNewDirection: 0
243+
newDirectionTime: 0
241244
force: {x: 0, y: 0, z: 0}
242245
forceInfluence: {x: 0, y: 0, z: 0}
243246
maxSpeed: 30
244-
testSpeed: {x: 0, y: 0, z: 0}
245247
facingDirection: {x: 0, y: 0, z: 0}
248+
testVector: {x: 0, y: 0, z: 0}
249+
testRotationSpeed: 30
246250
--- !u!1001 &3290878427680992746
247251
PrefabInstance:
248252
m_ObjectHideFlags: 0
249253
serializedVersion: 2
250254
m_Modification:
251255
m_TransformParent: {fileID: 2887565040518092645}
252256
m_Modifications:
257+
- target: {fileID: 1006420926045547698, guid: 1edc95efb8d7a4866b149a313687cc5e, type: 3}
258+
propertyPath: m_LocalPosition.z
259+
value: 0
260+
objectReference: {fileID: 0}
253261
- target: {fileID: 4010505626693846101, guid: 1edc95efb8d7a4866b149a313687cc5e, type: 3}
254262
propertyPath: m_Name
255263
value: Monster
256264
objectReference: {fileID: 0}
265+
- target: {fileID: 4976905702228071122, guid: 1edc95efb8d7a4866b149a313687cc5e, type: 3}
266+
propertyPath: m_Intensity
267+
value: 2
268+
objectReference: {fileID: 0}
257269
- target: {fileID: 6445481496505008102, guid: 1edc95efb8d7a4866b149a313687cc5e, type: 3}
258270
propertyPath: m_LocalPosition.x
259271
value: 5

Assets/_Project/Scenes/VizTest1.unity

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,24 +1551,6 @@ Transform:
15511551
m_Father: {fileID: 1366458513}
15521552
m_RootOrder: 5
15531553
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
1554-
--- !u!1 &739802974 stripped
1555-
GameObject:
1556-
m_CorrespondingSourceObject: {fileID: 880972579810857675, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
1557-
m_PrefabInstance: {fileID: 5893921238204685658}
1558-
m_PrefabAsset: {fileID: 0}
1559-
--- !u!114 &739802975
1560-
MonoBehaviour:
1561-
m_ObjectHideFlags: 0
1562-
m_CorrespondingSourceObject: {fileID: 0}
1563-
m_PrefabInstance: {fileID: 0}
1564-
m_PrefabAsset: {fileID: 0}
1565-
m_GameObject: {fileID: 739802974}
1566-
m_Enabled: 1
1567-
m_EditorHideFlags: 0
1568-
m_Script: {fileID: 11500000, guid: 6a5074ee399f24b0aa75aebac09ead06, type: 3}
1569-
m_Name:
1570-
m_EditorClassIdentifier:
1571-
username:
15721554
--- !u!1 &843737049
15731555
GameObject:
15741556
m_ObjectHideFlags: 0
@@ -3787,8 +3769,7 @@ Transform:
37873769
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
37883770
m_LocalPosition: {x: 0, y: 0, z: 0}
37893771
m_LocalScale: {x: 1, y: 1, z: 1}
3790-
m_Children:
3791-
- {fileID: 5893921238204685659}
3772+
m_Children: []
37923773
m_Father: {fileID: 0}
37933774
m_RootOrder: 3
37943775
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -4096,73 +4077,3 @@ CanvasRenderer:
40964077
m_PrefabAsset: {fileID: 0}
40974078
m_GameObject: {fileID: 2124984738}
40984079
m_CullTransparentMesh: 0
4099-
--- !u!1001 &5893921238204685658
4100-
PrefabInstance:
4101-
m_ObjectHideFlags: 0
4102-
serializedVersion: 2
4103-
m_Modification:
4104-
m_TransformParent: {fileID: 1948480987}
4105-
m_Modifications:
4106-
- target: {fileID: 880972579810857675, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4107-
propertyPath: m_Name
4108-
value: Player
4109-
objectReference: {fileID: 0}
4110-
- target: {fileID: 2331749708623315288, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4111-
propertyPath: m_LocalPosition.z
4112-
value: 0
4113-
objectReference: {fileID: 0}
4114-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4115-
propertyPath: m_LocalPosition.x
4116-
value: 0
4117-
objectReference: {fileID: 0}
4118-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4119-
propertyPath: m_LocalPosition.y
4120-
value: 0
4121-
objectReference: {fileID: 0}
4122-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4123-
propertyPath: m_LocalPosition.z
4124-
value: 0
4125-
objectReference: {fileID: 0}
4126-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4127-
propertyPath: m_LocalRotation.x
4128-
value: -0
4129-
objectReference: {fileID: 0}
4130-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4131-
propertyPath: m_LocalRotation.y
4132-
value: -0
4133-
objectReference: {fileID: 0}
4134-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4135-
propertyPath: m_LocalRotation.z
4136-
value: -0
4137-
objectReference: {fileID: 0}
4138-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4139-
propertyPath: m_LocalRotation.w
4140-
value: 1
4141-
objectReference: {fileID: 0}
4142-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4143-
propertyPath: m_RootOrder
4144-
value: 0
4145-
objectReference: {fileID: 0}
4146-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4147-
propertyPath: m_LocalEulerAnglesHint.x
4148-
value: 0
4149-
objectReference: {fileID: 0}
4150-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4151-
propertyPath: m_LocalEulerAnglesHint.y
4152-
value: 0
4153-
objectReference: {fileID: 0}
4154-
- target: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4155-
propertyPath: m_LocalEulerAnglesHint.z
4156-
value: 0
4157-
objectReference: {fileID: 0}
4158-
- target: {fileID: 7546354161021910840, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4159-
propertyPath: m_Intensity
4160-
value: 2
4161-
objectReference: {fileID: 0}
4162-
m_RemovedComponents: []
4163-
m_SourcePrefab: {fileID: 100100000, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4164-
--- !u!4 &5893921238204685659 stripped
4165-
Transform:
4166-
m_CorrespondingSourceObject: {fileID: 2887565040518092645, guid: b4c2300da3b95441a9589e29794d4125, type: 3}
4167-
m_PrefabInstance: {fileID: 5893921238204685658}
4168-
m_PrefabAsset: {fileID: 0}

Assets/_Project/Scripts/Data/DataManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ private void Start()
5555

5656
endpoint = "feed/range/plusStream/1/day/"; // last 5 days
5757

58+
59+
// start everything
60+
GetNewData();
5861
}
5962

6063

Assets/_Project/Scripts/Physics/FloatPhysicsCoroutine.cs

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,41 @@ public class FloatPhysicsCoroutine : MonoBehaviour
66
{
77
Collider worldContainerCollider;// boundary
88
Rigidbody rb; // rb to apply force
9-
float forceRange; // use to generate new force directions
10-
public bool applyNewForce; // should we apply new force on loop?
11-
public float newForceTime; // the time before the current force expires
12-
public Vector3 force; // the force vector (speed + direction)
13-
public Vector3 forceInfluence; // influence direction of force vector if too close to boundaries
14-
public float maxSpeed = 30f; // max speed of rb
15-
169

10+
// thrust to give the game object
11+
public float thrust = 20f;
12+
// current heading
1713
public Vector3 facingDirection;
14+
// extra influence to keep in camera view
15+
public Vector3 forceInfluence;
16+
1817

19-
void Awake()
18+
private void Awake()
2019
{
2120
worldContainerCollider = GameObject.Find("WorldContainer").GetComponent<Collider>();
2221
rb = GetComponent<Rigidbody>();
2322

24-
// set the multiplier to generate new force
25-
forceRange = 20.0f;
26-
// start the force loop
27-
StartCoroutine(ForceVectorGenerator());
23+
// start rotation timer
24+
StartCoroutine(RotateToNewDirection(facingDirection, 0.25f));
2825
}
2926

30-
void FixedUpdate()
31-
{
32-
if (rb.velocity.magnitude > maxSpeed)
33-
{
34-
rb.velocity = rb.velocity.normalized * maxSpeed;
35-
}
36-
if (applyNewForce)
37-
{
38-
// change facing direction
39-
//transform.Rotate(force);
40-
facingDirection = RandomDirectionFromCurrent(10.0f);
41-
// rotate to new
42-
StartCoroutine(RotateToNewDirection(facingDirection, 0.25f));
43-
4427

45-
rb.AddForce(Vector3.forward + force + forceInfluence);
4628

47-
// add whatever force is stored in the vector
48-
//rb.AddForce(force + forceInfluence);
49-
// finished
50-
applyNewForce = false;
51-
}
29+
private void FixedUpdate()
30+
{
31+
// keep on keepin' on
32+
rb.AddRelativeForce(Vector3.forward * thrust);
5233
}
5334

54-
Vector3 RandomDirectionFromCurrent(float distance)
35+
36+
37+
// pick random Vector3 from current direction
38+
Vector3 RandomDirectionFromCurrent(Vector3 distance)
5539
{
5640
return new Vector3(
57-
Random.Range(-distance, distance),
58-
Random.Range(-distance, distance * .8f), // slowly sink
59-
Random.Range(-distance, distance)
41+
Random.Range(-distance.x, distance.x),
42+
Random.Range(-distance.y, distance.y),
43+
Random.Range(-distance.z, distance.z)
6044
);
6145
}
6246

@@ -78,22 +62,16 @@ IEnumerator ForceVectorGenerator()
7862
while (true)
7963
{
8064
// pick new time to wait before generating new force vector
81-
newForceTime = Random.Range(3.0f, 8.0f);
65+
float waitTime = Random.Range(3.0f, 8.0f);
8266

8367
// if the GameObject has left the scene then push it back
8468
forceInfluence = ForceAwayFromWall(worldContainerCollider.bounds, 3.0f);
8569

86-
// generate new force vector
87-
force = new Vector3(
88-
Random.Range(-forceRange, forceRange),
89-
Random.Range(-forceRange, forceRange * .8f), // slowly sink
90-
Random.Range(-forceRange, forceRange)
91-
);
92-
93-
applyNewForce = true;
70+
// change facing direction
71+
facingDirection = RandomDirectionFromCurrent(new Vector3(0f, 0f, 0f) + forceInfluence);
9472

9573
// wait for before next loop
96-
yield return new WaitForSeconds(newForceTime);
74+
yield return new WaitForSeconds(waitTime);
9775
}
9876
}
9977

@@ -103,37 +81,36 @@ Vector3 ForceAwayFromWall(Bounds bounds, float multiplier)
10381
Vector3 newForce = new Vector3(0, 0, 0);
10482

10583
// X
106-
if (gameObject.transform.position.x < bounds.min.x)
84+
if (transform.position.x < bounds.min.x)
10785
{
10886
newForce.x += multiplier;
10987
}
110-
else if (gameObject.transform.position.x > bounds.max.x)
88+
else if (transform.position.x > bounds.max.x)
11189
{
11290
newForce.x -= multiplier;
11391
}
11492

11593
// Y
116-
if (gameObject.transform.position.y < bounds.min.y)
94+
if (transform.position.y < bounds.min.y)
11795
{
11896
newForce.y += multiplier;
11997
}
120-
else if (gameObject.transform.position.y > bounds.max.y)
98+
else if (transform.position.y > bounds.max.y)
12199
{
122100
newForce.y -= multiplier;
123101
}
124102

125103
// Z
126-
if (gameObject.transform.position.z < bounds.min.z)
104+
if (transform.position.z < bounds.min.z)
127105
{
128106
newForce.z += multiplier;
129107
}
130-
else if (gameObject.transform.position.z > bounds.max.z)
108+
else if (transform.position.z > bounds.max.z)
131109
{
132110
newForce.z -= multiplier;
133111
}
134112
return newForce;
135113
}
136114

137115

138-
139116
}

0 commit comments

Comments
 (0)