Ball layer, balls dont collide with each other

main
Benjamin Kraft 1 year ago
parent 644e9f3418
commit 7225357dc9
  1. 5
      Assets/Prefabs/Ball.prefab
  2. 4
      Assets/Scripts/Game/AIPlayer.cs
  3. 19
      Assets/Scripts/Game/Ball.cs
  4. 4
      Assets/Scripts/Game/GameManager.cs
  5. 2
      Assets/Scripts/Game/Player.cs
  6. 4
      ProjectSettings/DynamicsManager.asset
  7. 2
      ProjectSettings/TagManager.asset

@ -16,7 +16,7 @@ GameObject:
- component: {fileID: 7041796185663956337} - component: {fileID: 7041796185663956337}
- component: {fileID: 7286884547159090166} - component: {fileID: 7286884547159090166}
- component: {fileID: 8029731608843643848} - component: {fileID: 8029731608843643848}
m_Layer: 0 m_Layer: 3
m_Name: Ball m_Name: Ball
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -102,7 +102,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 267dfd77302043669cc125190ddfb575, type: 3} m_Script: {fileID: 11500000, guid: 267dfd77302043669cc125190ddfb575, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
rb: {fileID: 0}
--- !u!114 &8059693774009316043 --- !u!114 &8059693774009316043
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -177,7 +176,7 @@ Rigidbody2D:
m_LinearDrag: 0 m_LinearDrag: 0
m_AngularDrag: 0.05 m_AngularDrag: 0.05
m_GravityScale: 0 m_GravityScale: 0
m_Material: {fileID: 0} m_Material: {fileID: 6200000, guid: 2d231bbc8208f52c797c91aa2030f60f, type: 2}
m_Interpolate: 0 m_Interpolate: 0
m_SleepingMode: 1 m_SleepingMode: 1
m_CollisionDetection: 1 m_CollisionDetection: 1

@ -75,6 +75,8 @@ namespace Game {
float requiredDistance = Mathf.Abs(futurePosition - X()) - Width / 2; float requiredDistance = Mathf.Abs(futurePosition - X()) - Width / 2;
if (requiredDistance < 0) if (requiredDistance < 0)
return true; return true;
if (Mathf.Abs(futurePosition) > Border)
return false;
return Speed * seconds > requiredDistance; return Speed * seconds > requiredDistance;
} }
@ -132,7 +134,7 @@ namespace Game {
} }
// No intersection -> Ball outside of field -> dont simulate further // No intersection -> Ball outside of field -> dont simulate further
return origin.x; return IdlePosition;
} }
private float GetTargetPosition() { private float GetTargetPosition() {

@ -1,26 +1,20 @@
using System; using System;
using Unity.Netcode; using Unity.Netcode;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
namespace Game { namespace Game {
public class Ball : NetworkBehaviour { public class Ball : NetworkBehaviour {
public Rigidbody2D Rb { get; private set; } public Rigidbody2D Rb { get; private set; }
private CircleCollider2D Collider { get; set; } private CircleCollider2D Collider { get; set; }
public float Radius { public float Radius {
get => transform.localScale.x * Collider.radius; get => transform.localScale.x * Collider.radius;
set => transform.localScale = new Vector3(1, 1, 1) * value * 2; set => transform.localScale = new Vector3(1, 1, 1) * value * 2;
} }
public bool IsAlive { public bool IsAlive { get; private set; } = true;
get {
float y = transform.position.y;
float y1 = BorderSize.Singleton.y1;
float y2 = BorderSize.Singleton.y2;
return y > y1 && y < y2;
}
}
private void OnEnable() { private void OnEnable() {
Rb = GetComponent<Rigidbody2D>(); Rb = GetComponent<Rigidbody2D>();
Collider = GetComponent<CircleCollider2D>(); Collider = GetComponent<CircleCollider2D>();
@ -28,11 +22,14 @@ namespace Game {
private void Start() { private void Start() {
Rb.velocity = new Vector2(0, 25); Rb.velocity = new Vector2(0, 25);
Rb.position = new Vector2(1, 0); Rb.position = new Vector2(Random.Range(-2, 2), 0);
} }
private void FixedUpdate() { private void FixedUpdate() {
//TODO remove this and use triggers for death zone
if (Rb.position.y > BorderSize.Singleton.y2 || Rb.position.y < BorderSize.Singleton.y1) {
IsAlive = false;
}
} }
} }
} }

@ -53,8 +53,8 @@ namespace Game {
} }
private void Start() { private void Start() {
Settings.Type = Type.AI; Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.VeryHard; Settings.AIDifficulty = Difficulty.Easy;
var ball = Instantiate(ballPrefab).GetComponent<Ball>(); var ball = Instantiate(ballPrefab).GetComponent<Ball>();
Balls.Add(ball); Balls.Add(ball);

@ -19,7 +19,7 @@ namespace Game {
protected float Speed => 10; protected float Speed => 10;
// Unit distance from zero // Unit distance from zero
private float Border => 10; protected float Border => 10;
private SpeedModification speedModification; private SpeedModification speedModification;
private BorderModification borderModification; private BorderModification borderModification;

@ -7,6 +7,7 @@ PhysicsManager:
m_Gravity: {x: 0, y: -9.81, z: 0} m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0} m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2 m_BounceThreshold: 2
m_DefaultMaxDepenetrationVelocity: 10
m_SleepThreshold: 0.005 m_SleepThreshold: 0.005
m_DefaultContactOffset: 0.01 m_DefaultContactOffset: 0.01
m_DefaultSolverIterations: 6 m_DefaultSolverIterations: 6
@ -17,7 +18,7 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0.1 m_ClothInterCollisionDistance: 0.1
m_ClothInterCollisionStiffness: 0.2 m_ClothInterCollisionStiffness: 0.2
m_ContactsGeneration: 1 m_ContactsGeneration: 1
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_LayerCollisionMatrix: fffffffffffffffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1 m_AutoSimulation: 1
m_AutoSyncTransforms: 0 m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 1 m_ReuseCollisionCallbacks: 1
@ -32,5 +33,6 @@ PhysicsManager:
m_FrictionType: 0 m_FrictionType: 0
m_EnableEnhancedDeterminism: 0 m_EnableEnhancedDeterminism: 0
m_EnableUnifiedHeightmaps: 1 m_EnableUnifiedHeightmaps: 1
m_ImprovedPatchFriction: 0
m_SolverType: 0 m_SolverType: 0
m_DefaultMaxAngularSpeed: 50 m_DefaultMaxAngularSpeed: 50

@ -8,7 +8,7 @@ TagManager:
- Default - Default
- TransparentFX - TransparentFX
- Ignore Raycast - Ignore Raycast
- - Ball
- Water - Water
- UI - UI
- -

Loading…
Cancel
Save