private void HandleInput(Vector2 aimDirection) { if (Input.GetMouseButton(0)) //if (index == 0) // if (!ropeAttached) // testing neural net { // if (index != 0) // return; //aimAngle = (0.52f + 0.88f * outputs[index]) * Mathf.Rad2Deg; // neural net //aimDirection = Quaternion.Euler(0, 0, aimAngle) * Vector2.right; // neural net if (aimAngle < .52 || aimAngle > 1.4) { return; // setting the range for aiming angle, non neural net } //if (aimAngle < 30 || aimAngle > 80) return; // setting the range for aiming angle, neural net if (ropeAttached) { return; // Prevent creating a new rope when already swinging } if (!gameStarted) { return; // Preventing creating rope when game hasn't started } ropeRenderer.enabled = true; var hit = Physics2D.Raycast(playerPosition, aimDirection, ropeMaxCastDistance, ropeLayerMask); if (hit.collider != null) // if the rope hits a valid target { ropeAttached = true; if (!ropePositions.Contains(hit.point)) { if (!playerMovement.groundCheck) { character.velocity = new Vector2(character.velocity.x, character.velocity.y * 0.25f); // speed up the swing and slowdown freefall to prevent the rope from stretching too much ropeJoint.distance = Vector2.Distance(playerPosition, hit.point); } else { ropeJoint.distance = Vector2.Distance(playerPosition, hit.point) - 0.1f; // lift the character from the ground to swing playerMovement.groundPull = true; } //Debug.Log("ropeattached"); ropePositions.Add(hit.point); ropeJoint.enabled = true; ropeHingeAnchorSprite.enabled = true; ropeHingeAnchorRb.transform.position = hit.point; } } else { ropeRenderer.enabled = false; ropeAttached = false; } float aimOutput = (aimAngle - 0.52f) / 0.88f; float[] correctOutput = { aimOutput, 0f, 0f, 0f }; network.Train(correctOutput); // correctOutputs.Add(aimOutput); } else if (Input.GetMouseButton(1)) // non neural net //else if (index == 1) // neural net { ResetRope(); // right click to disable the rope float[] correctOutput = { 0f, 1f, 0f, 0f }; //correctOutputs.Add(1f); network.Train(correctOutput); } else if (Input.GetKeyDown("space")) //else if (index == 3) // neural net { TurnOnShield(); float[] correctOutput = { 0f, 0f, 0f, 1f }; //correctOutputs.Add(3f); network.Train(correctOutput); } else { float[] correctOutput = { 0f, 0f, 1f, 0f }; //correctOutputs.Add(2f); network.Train(correctOutput); } }