private void UpdateOnPlaneWhenExit(Collider other) { PhysicsPlane plane = other.GetComponent <PhysicsPlane>(); if (plane != null) { onPlane = null; } }
private static bool ApplyCollision(PhysicsPlane plane, PhysicsSphere sphere) { Vector3 planeOffset = plane.GetPositionOffset(); Vector3 planePos = plane.physicsObject.state.position + planeOffset; Vector3 planeLastPos = plane.physicsObject.state.lastPosition + planeOffset; Vector3 sphereOffset = sphere.GetPositionOffset(); Vector3 spherePos = sphere.physicsObject.state.position + sphereOffset; Vector3 sphereLastPos = sphere.physicsObject.state.lastPosition + sphereOffset; //Debug.LogError("Object Pos: " + sphere.physicsObject.state.position + " Offset Pos: " + spherePos); float distanceCur = plane.GetDistanceToPoint(spherePos); float distanceLast = plane.GetDistanceToPoint(sphereLastPos); //Check if there could be a collision - fast check if (distanceCur >= sphere.Radius && distanceLast >= sphere.Radius) { float dotCur = Vector3.Dot(plane.Normal, (planePos - spherePos).normalized); float dotLast = Vector3.Dot(plane.Normal, (planeLastPos - sphereLastPos).normalized); if ((dotCur > 0) == (dotLast > 0)) { return false; } } //Now check step by step int steps = 10; Vector3 planePath = planePos - planeLastPos; Vector3 spherePath = spherePos - sphereLastPos; for (int i = 0; i <= steps; i++) { Vector3 planeStepPos = planeLastPos + ((planePath / (float)steps) * i); Vector3 sphereStepPos = sphereLastPos + ((spherePath / (float)steps) * i); //Debug.Log("SpherePos: " + spherePos + "SpereLastPos: " + sphereLastPos); if (plane.GetDistanceToPoint(planeStepPos, sphereStepPos) <= (sphere.Radius + 0.01)) { Vector3 newVelocity = Vector3.Reflect(sphere.physicsObject.state.velocity, plane.Normal); newVelocity *= sphere.GetCombinedBounciness(plane); plane.physicsObject.state.position = planeLastPos - planeOffset; sphere.physicsObject.state.position = sphereLastPos - sphereOffset; sphere.physicsObject.state.velocity = newVelocity; //Debug.LogError("new Velo: " + newVelocity + " Plane: " + plane.name + " Sphere: " + sphere.name); return true; } planeLastPos = planeStepPos; sphereLastPos = sphereStepPos; } return false; }
private static bool ApplyCollision(PhysicsPlane planeA, PhysicsPlane planeB) { //Debug.LogError("Not yet implemented! Have fun scripting it! Muahahahahahahahaha - Eule"); return false; }
private void UpdateOnPlaneWhenStay(Collider other) { onPlane = other.GetComponent <PhysicsPlane>(); }
/// <summary> /// Assuming the initial velocity is 0 /// </summary> /// <returns></returns> public float VelocityOnGround(PhysicsPlane plane) { return(Mathf.Sqrt(2f * Physics.gravity.magnitude * (transform.position.y - plane.transform.position.y))); }