Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Vector2 moveVector = Vector2.zero;

        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            playerParticle.AddForce(player.transform.up * speed);
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            //point = transform.worldToLocalMatrix.MultiplyPoint3x4(new Vector2(-.9f, -.9f));
            // this is wonky af still
            Vector2 point = playerParticle.centerOfMassLocal + new Vector2(-1f, -1f);
            playerParticle.AddTorque(Vector2.up * rotationSpeed, point * player.transform.localScale, true);
        }
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            //point = transform.worldToLocalMatrix.MultiplyPoint3x4(new Vector2(.9f, -.9f));
            // this is wonky af still
            Vector2 point = playerParticle.centerOfMassLocal + new Vector2(1f, -1f);
            playerParticle.AddTorque(Vector2.up * rotationSpeed, point * player.transform.localScale, true);
        }
        if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            playerParticle.AddForce(player.transform.up * -speed);
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        // Has the D key been pressed?
        if (Input.GetKey(KeyCode.D) && particle.rotation >= -maxRotation)
        {
            // If yes, then add torque in the right direction
            particle.ApplyTorque(new Vector2(-thrustSpeed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y));
        }

        // Has the A key been pressed?
        else if (Input.GetKey(KeyCode.A) && particle.rotation <= maxRotation)
        {
            // If yes, then add torque in the left direction
            particle.ApplyTorque(new Vector2(thrustSpeed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y));
        }

        // Has the lander reached it's maximum rotation?
        else if ((particle.rotation > maxRotation || particle.rotation < -maxRotation) && GameManager.manager.isRunning)
        {
            // If yes, then stop it in place
            particle.angularVelocity = 0;
        }

        // Has the W key been pressed and there is enough fuel?
        if (Input.GetKey(KeyCode.W) && fuelLeft > 0 && GameManager.manager.isRunning)
        {
            // If yes, then subtract fuel
            fuelLeft -= amountOfFuelLostPerBurn;

            // Add a force in the upward direction of the lander
            particle.AddForce(speed * transform.up);

            // Enable flame particle effect
            flame.SetActive(true);
        }
        else
        {
            // If no, then disable the flame particle effect
            flame.SetActive(false);
        }

        // Has the S key been pressed and there is enough fuel?
        if (Input.GetKey(KeyCode.S) && fuelLeft > 0)
        {
            // If yes, then subtract the fuel
            fuelLeft -= amountOfFuelLostPerBurn;

            // Add a force in the downward direction of the lander
            particle.AddForce(speed * -transform.up);
        }
    }
Exemplo n.º 3
0
    public void Start()
    {
        Particle2D particle = GetComponent <Particle2D>();

        particle.AddForce(transform.up * laserSpeed);
        CollisionSystem.Instance.AddCollisionHull(GetComponent <CollisionHull2D>());
        camera = Camera.main;
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        // Has the D key been pressed?
        if (Input.GetKey(KeyCode.D))
        {
            // If yes, then add a force and torque in the right direction (opposite direction for torque)
            particle.AddForce(new Vector2(speed, 0));
            particle.ApplyTorque(new Vector2(-speed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y));
        }

        // Has the A key been pressed?
        if (Input.GetKey(KeyCode.A))
        {
            // If yes, then add a force and torque in the left direction (opposite direction for torque)
            particle.AddForce(new Vector2(-speed, 0));
            particle.ApplyTorque(new Vector2(speed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y));
        }
    }
    void GetInput()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            //particle.AddForce()
            Debug.Log("Rear Thruster");
            Vector2 angledThrust = (Vector2)transform.up * linearThrusterStrength.magnitude;
            particle.AddForce(angledThrust);
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            Vector2 angledThrust = -(Vector2)transform.up * linearThrusterStrength.magnitude;
            particle.AddForce(angledThrust);
            Debug.Log("Forward Thruster");
        }

        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow))
        {
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                Debug.Log("Port Thruster");
                particle.AddRotationForce(-rotationThrusterStrength);
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                Debug.Log("Starboard Thruster");
                particle.AddRotationForce(rotationThrusterStrength);
            }
        }
        else
        {
            particle.AddRotationForce(-0.5f * particle.angForce);
            particle.angularVelocity *= 0.95f;
            particle.velocity        *= 0.95f;
        }
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void FixedUpdate()
    {
        theta      = hull.currentRotation;
        forwardVec = CollisionHull2D.getRotatedPoint(new Vector3(0.0f, 1.0f), new Vector3(0.0f, 0.0f), theta);

        if (Input.GetKey(KeyCode.W))
        {
            //Debug.Log(forwardVec);
            thrust.AddForce(forwardVec * speed);
        }
        if (Input.GetKey(KeyCode.A))
        {
            thrust.applyForceAtLocation(turnPosition, -turnPower);
        }
        if (Input.GetKey(KeyCode.D))
        {
            thrust.applyForceAtLocation(turnPosition, turnPower);
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            FireCanons();
        }
    }
Exemplo n.º 7
0
 public void ApplyForce(Particle2D particle)
 {
     particle.AddForce(Force);
 }