Example #1
0
 // Use this for initialization
 void Start()
 {
     startPosition = transform.position;
     startRotation = transform.rotation;
     rb            = GetComponentInChildren <CustomRigidbody>();
     localHeadPos  = rb.transform.localPosition;
 }
 // Use this for initialization
 void Awake()
 {
     DebugTestManager = GetComponent <PhysicsManager>();
     physicsText      = GameObject.Find("DebugPhysicsText").GetComponent <Text>();
     player           = GameObject.FindGameObjectWithTag("Player").GetComponent <CustomRigidbody>();
     debugPath        = DebugTestManager.dPath;
 }
Example #3
0
 public ProjectileODEData(CustomRigidbody rb)
 {
     this.rb         = rb;
     Position        = rb.transform.position;
     Velocity        = rb.Properties.Velocity;
     Mass            = rb.Properties.Mass;
     Area            = rb.Properties.Area;
     DragCoefficient = rb.Properties.DragCoefficient;
 }
Example #4
0
    public bool IsColliding(CustomRigidbody rb)
    {
        // check that an entity is colliding with the attack area
        for (int j = 0; j < entityBoundingBoxes.Count; j++)
        {
            colliderTest1 = rb.GetComponent <AABB>();
            colliderTest2 = areaOfEffect;

            if (TestAABBOverlap(colliderTest1, colliderTest2))
            {
                //Debug.Log("collision");
                isTargetInside = true;
                return(true);
            }
        }
        return(false);
    }
Example #5
0
    private void OnCollisionEnter(Collision collision)
    {
        Sleep = true;
        return;

        CustomRigidbody rigid = collision.gameObject.GetComponent <CustomRigidbody>();

        if (rigid)
        {
            rigid.AddForce(Mass * _acceleration);
            AddForce(rigid.Mass * rigid._acceleration - _currentForce);
        }
        else
        {
        }
        //_acceleration = Vector3.zero;
        AddForce(-_currentForce);// = -Gravity;
    }
Example #6
0
    public Vector2 GetDirection(CustomRigidbody rb)
    {
        Vector2 t = rb.attackDirection;

        return(t);
    }
    void Update()
    {
        // start game
        if (Input.GetMouseButtonDown(1))
        {
            Color c = beginText.color;
            c.a             = 0f;
            beginText.color = c;
            debugText.color = c;
            Time.timeScale  = 1f;
        }
        if (Input.GetKeyDown("left alt"))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(2);
        }

        int score = 0;

        // calc all physics for this frame first
        physicsManager.PhysicsUpdate();

        /*if (playerHealth <= 0)
         * {
         *  UnityEditor.EditorApplication.isPlaying = false;
         * }*/

        //check if player and/or enemy has hit a boundary and been removed
        // reset rigidbodies, camera targets
        if (!physicsManager.isPlayerActive)
        {
            m_Targets.Remove(player.transform);

            GameObject newPlayer = Instantiate(Resources.Load("player")) as GameObject;
            player.transform.position = playerSpawn.transform.position;
            physicsManager.entityBoundingBoxes.Add(newPlayer.GetComponent <AABB>());
            physicsManager.rigidBodiesInScene.Add(newPlayer.GetComponent <CustomRigidbody>());
            rb = newPlayer.GetComponent <CustomRigidbody>();
            rb.InitBody();
            rb.m_MaterialType.m_StaticFriction  = 0f;
            rb.m_MaterialType.m_DynamicFriction = 0f;
            rb.m_Mass = 1f;

            // take away one life from player
            // and check player current health for game state
            playerHealth--;
            if (playerHealth == 2 || rb.m_PlayerHasBeenHit)
            {
                Color temp = heart1.color;
                temp.a       = 0f;
                heart1.color = temp;
            }
            if (playerHealth == 1)
            {
                Color temp = heart2.color;
                temp.a       = 0f;
                heart2.color = temp;
            }
            if (playerHealth <= 0)
            {
                Color temp = heart3.color;
                temp.a          = 0f;
                heart3.color    = temp;
                Time.timeScale  = 0f;
                temp.a          = 255f;
                beginText.color = temp;
                beginText.text  = "Your score was: " + playerScore;
                debugText.color = temp;
                debugText.text  = "Press Escape To Quit.";
            }

            m_Targets.Add(newPlayer.transform);
            player = newPlayer;

            physicsManager.isPlayerActive = true;
        }
        // respawn enemies that have been removed
        if (!physicsManager.isEnemyActive)
        {
            m_Targets.Remove(enemy.transform);
            int        rand     = Random.Range(0, enemySpawn.Count);
            GameObject newEnemy = Instantiate(Resources.Load("enemy")) as GameObject;
            newEnemy.transform.position = enemySpawn[rand].transform.position;
            physicsManager.entityBoundingBoxes.Add(newEnemy.GetComponent <AABB>());
            physicsManager.rigidBodiesInScene.Add(newEnemy.GetComponent <CustomRigidbody>());
            rb = newEnemy.GetComponent <CustomRigidbody>();
            rb.InitBody();
            rb.m_MaterialType.m_StaticFriction  = 0f;
            rb.m_MaterialType.m_DynamicFriction = 0f;
            rb.m_Mass = 1f;

            m_Targets.Add(newEnemy.transform);
            enemy = newEnemy;

            physicsManager.isEnemyActive = true;
        }

        //update UI
        score = (int)Time.timeSinceLevelLoad;
        playerScoreText.text = "Score: " + score;
        playerScore          = score;

        FindAveragePosition();
        // Update camera position based on positions of entities
        m_Camera.transform.position = physicsManager.UpdateCameraPos(m_Camera.transform.position, m_DesiredPosition);
    }
 private void OnEnable()
 {
     sprite = GetComponent <SpriteRenderer>();
     rb     = GetComponent <CustomRigidbody>();
 }
 // Start is called before the first frame update
 void Start()
 {
     customRigidbody = GetComponent <CustomRigidbody>();
 }