// Update is called once per frame public override void Update() { base.Update(); if (awakened) { playerdist = (playerobj.transform.position.x - transform.position.x); if (facing * playerdist > 0) { facing *= -1; transform.rotation *= Quaternion.Euler(0, 180, 0); } if (Mathf.Abs(playerdist) < 2 * stopdist) { stabtime += Time.deltaTime; if (stabtime > maxStabInterval) { limbScript.Stab(Random.Range(0.1f, 0.9f)); stabtime -= Random.Range(maxStabInterval / 2f, maxStabInterval); } if (playerShieldRelHeight < crouchThreshold) { limbScript.SetCrouch(0.5f); } else { limbScript.SetCrouch(1f); } } else { limbScript.SetCrouch(1f); } if (Mathf.Abs(playerdist) < stopdist) { limbScript.SetSpeedFraction(0f); advancing = false; } else { limbScript.SetSpeedFraction(speed); advancing = true; } //playerShieldRelHeight /*shieldHeight = Mathf.Lerp(shieldHeight, * Mathf.Clamp(playerShieldRelHeight, 0, 1), shieldT*Time.deltaTime);*/ limbScript.SetShieldHeight(playerShieldRelHeight); } }
void Start() { inputvector = Vector2.zero; dead = false; facing = 1; rb = GetComponent <Rigidbody>(); //shieldrb = shield.GetComponent<Rigidbody>(); //shieldpos = shieldrb.position - rb.position; //swordpos = sword.transform.localPosition; //swordangle = sword.transform.localRotation; //swordbox = sword.GetComponent<BoxCollider>(); //swordbox.enabled = false; //swordrb = sword.GetComponent<Rigidbody>(); //bodyrend = GetComponent<LineRenderer>(); //bodyverts = new Vector3[bodyrend.positionCount]; //bodyrend.GetPositions(bodyverts); //facing = Vector3.right; transform.parent = null; nocontrol = false; //transform.position += Vector3.up;// * 0.5f; //statCanvas = statCanvasObj.GetComponent<PlayerStatCanvas>(); limbScript = GetComponent <SwordAndShieldUser>(); limbScript.SetSpeed(maxspeed); limbScript.SetSpeedFraction(0f); //limbScript.facing = -1; }
// Use this for initialization public override void Start() { base.Start(); stabtime = Random.Range(0, maxStabInterval); limbScript = GetComponent <SwordAndShieldUser>(); limbScript.SetSpeed(speed); limbScript.SetSpeedFraction(0f); facing = 1; }
void Update() { if (dead) { return; } // inputs horizaxis = Input.GetAxisRaw("Horizontal");// * acceleration * Time.deltaTime; vertaxis = Input.GetAxisRaw("Vertical"); inputvector[0] = horizaxis; inputvector[1] = vertaxis; if (inputvector.sqrMagnitude > 1) { horizaxis = inputvector.normalized[0]; vertaxis = inputvector.normalized[1]; } vertaxis = vertaxis * 0.8f + 0.5f; if (Mathf.Abs(horizaxis) > 0) { if (!attacking) { // change facing, but only if not mid-attack if (horizaxis > 0) { facing = 1; rb.MoveRotation(Quaternion.LookRotation(Vector3.back)); } else { facing = -1; rb.MoveRotation(Quaternion.LookRotation(Vector3.forward)); } } // Accelerate! //horizspeed += horizaxis;//Input.GetAxis("Horizontal") * acceleration * Time.deltaTime; horizspeed = Mathf.Lerp(horizspeed, horizaxis * maxspeed, (acceleration / maxspeed) * Time.deltaTime); if (horizspeed > maxspeed) { horizspeed = maxspeed; } else if (horizspeed < -maxspeed) { horizspeed = -maxspeed; } } else { // No input, slow down! if (Mathf.Abs(horizspeed) < (acceleration * Time.deltaTime)) { horizspeed = 0f; } else { horizspeed -= acceleration * Time.deltaTime * Mathf.Sign(horizspeed); } } limbScript.SetSpeedFraction(horizspeed); // Move shield based on vertical axis, but only if not attacking if (!attacking) { currentShieldHeight = vertaxis; // Move shield smoothly /*if (Mathf.Abs(vertaxis - currentShieldHeight) > shieldSpeed * Time.deltaTime) * { * currentShieldHeight += shieldSpeed * * Time.deltaTime * Mathf.Sign(vertaxis - currentShieldHeight); * } * else * { * currentShieldHeight = vertaxis; * }*/ // Set shield height here /*shieldrb.MovePosition(rb.position + 0.5f * facing * Vector3.right + * Vector3.up * (currentShieldHeight / 2f));*/ limbScript.SetShieldHeight(currentShieldHeight); if (currentShieldHeight < crouchThreshold) { limbScript.SetCrouch(0.5f); } else { limbScript.SetCrouch(1f); } } // If not jumping already, do a jump! if (jumping == false && Input.GetButtonDown("Jump")) { rb.AddForce(Vector3.up * maxJumpSpeed, ForceMode.VelocityChange); jumping = true; } // Slow down jump on release. Allows variable jump height. if (Input.GetButtonUp("Jump") && rb.velocity[1] > minJumpSpeed) { rb.AddForce(Vector3.down * (rb.velocity[1] - minJumpSpeed), ForceMode.VelocityChange); } // Attack! if (!attacking && Input.GetButtonDown("Fire1")) { limbScript.Stab(currentShieldHeight, false); //StartCoroutine(Stab(currentShieldHeight)); } }