KucherenkoSerhiy / Microworld

4 stars 0 forks source link

Make ThrowChip work as intended #25

Open scastlara opened 6 years ago

scastlara commented 6 years ago

The chip should be thrown as a parabola, with a force dependent on the time pressed, and with the possibility of slightly adjusting the aim.

See comment by @adriaaula on issue #2 :

float timePressed = 0f;

void Update(){

      if (Input.GetKeyDown(KeyCode.N)){
            timePressed = Time.time;
        }

      if(Input.GetKeyUp(KeyCode.N))
        {
            timePressed = Time.time - timePressed;
            Fire(timePressed);

        }

      keyPressedTimer();
    }

void Fire( float presstime = 1){
    // Create the Bullet from the Bullet Prefab
    var bullet = (GameObject)Instantiate (
        Bullet,
        bulletSpawn.position,
        bulletSpawn.rotation);

        // create the velocity vector in local space
        Vector3 localVelocity = new Vector3(-10f * presstime, 5f * (1/(2+presstime)));

        // transform it to global vector
        Vector3 globalVelocity = transform.TransformVector(localVelocity);

        // launch the cube by setting its initial velocity
        bullet.GetComponent<Rigidbody2D>().velocity = globalVelocity;

    // Add velocity to the bullet. Aixo seria anant nomes recte sense
    // bullet.GetComponent<Rigidbody2D>().velocity = bullet.transform.right * bulletSpeed;

    // Destroy the bullet after 4 seconds
    Destroy(bullet, 4.0f);
}