KucherenkoSerhiy / Microworld

4 stars 0 forks source link

Possession ability through collision #2

Open adriaaula opened 6 years ago

adriaaula commented 6 years ago

Right now P1 can posses through the L button, but we are interessted in triggering the possession by the collision with a chip that it shoots.

Implement the shooting efficiently and POSSESSSS. Points to improve for establishing a correct possesion.

  1. Establish a system of collision for possesion. 1.1 Possession will be on touch. This means, logics will be on touch (Collide) and not on key press (Activate). 1.2 Projectile of Player 1 will be Character with the PossessionAbility.

  2. A projectile is created and the collision of the projectile (a chip) triggers the possesion.

scastlara commented 6 years ago

Will need to create:

Player will have 1 new Ability:

adriaaula commented 6 years ago

The parabola should change by the time the key is pressed. I share here a chunk of code that I used for that purpose:

   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);
}

Most of it is crap! And outadated from the Shootability in develop. But maybe it is useful.

Take care also on the properties associated at the rigidbody! If gravity is affecting to much it will fell too fast, etc.