C# Projects

Mission: Orbiter - 3D/2D Space Shooter

 

I took the initiative to design and code an independent video game project during the summer of 2011.
I created a 3D side-scrolling web based game, complete with music, physics, and particle effects. I made use of the Unity3D engine along with C# scripts. The project took about 4 months to complete, which I then published to an online gaming website (Kongregate).

Check Out My Game!

  • Player Movement & Control
  • Solution Screen:

    Player Movement & Control

    // -----------------------------[ DETECT MOVEMENT]-------------------------------------------

    moveDir = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);

    Vector3 boostPos = playerTransform.position;

    Vector3 boostDir = new Vector3(-Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), 0);

     

    float curBoostSpeed = playerMaxSpeed;

    float origAccel = playerAccel;

    float curAccel = playerAccel;

     

    // ------------------------------[ BOOST EFFECT ]--------------------------------------------

    // Instantiate Booster Effect

    if (boostDir != Vector3.zero)

    {

    Quaternion boostRot = Quaternion.LookRotation(boostDir, Vector3.back);

    Instantiate(BoosterPrefab, boostPos, boostRot);

    }

     

    // Detect ANY movement

    if (moveDir.magnitude > 0.1f)

    {

    // If ALLOWED to use BOOSTER

    if (AllowBooster)

    {

    // Smooth the speed based on the current target direction

    curBoostSpeed = playerMaxSpeed;

    float curSmooth = boostSmooth * Time.deltaTime;

    float curBoostMax = playerMaxSpeed;

    float accel = origAccel;

     

    // If pressed SPACE BAR

    if (Input.GetButton("Jump") && boostAmt > 0.02f)

    {

    curBoostMax = boostMaxSpeed;

    accel = origAccel + origAccel * boostPercent;

    boostAmt -= boostTotal * 0.017f;

    }

    else

    {

    curBoostMax = playerMaxSpeed;

    accel = origAccel;

    boostAmt += boostTotal * 0.004f;

    }

     

    if (boostAmt >= boostTotal)

    boostAmt = boostTotal;

     

    // Apply booster speed

    curBoostSpeed = Mathf.Lerp(curBoostSpeed, curBoostMax, curSmooth);

    //curAccel = Mathf.Lerp(curAccel, accel, playerAccel * Time.deltaTime);

    curAccel = accel;

      }

    // ---------------------------------------------------------------------------------------

    }

    else

    {

    if (AllowBooster)

    boostAmt += boostTotal * 0.004f;

    }

    // Apply movement in detected DIRECTION

    // Include deltaTime to base speed off of realtime rather than CPU speed

    fTranslation = playerSpeed * Time.smoothDeltaTime * curAccel;

    playerTransform.rigidbody.AddForce(moveDir.normalized * fTranslation);

    // ------------------------------------------------------------------------------------------------

     

    // ------------------------------------[ CLAMP SPEED ]---------------------------------------------

    float sqrDragStartVelocity = dragStartVelocity * dragStartVelocity;

    float sqrDragVelocityRange = (curBoostSpeed * curBoostSpeed) - sqrDragStartVelocity;

     

    if (playerTransform.rigidbody.velocity.sqrMagnitude > sqrDragStartVelocity)

    playerTransform.rigidbody.drag=Mathf.Lerp(originalDrag,maxDrag,

    Mathf.Clamp01((rigidbody.velocity.sqrMagnitude - sqrDragStartVelocity) / sqrDragVelocityRange));

    else

    playerTransform.rigidbody.drag = originalDrag;

    // -------------------------------------------------------------------------------------------------