private void FixedUpdate() { Vector3 rbv = rb.velocity; //Debug.Log("ttt " + Time.fixedDeltaTime); //Debug.Log("velct" + rbv); float stepSize = 6f; float jumpStepSize = 6f * 0.8f; Vector3 dv = moveController.CalcMovement(); dv.Scale(new Vector3(stepSize, jumpStepSize)); //Debug.Log("dvy" + dv.y); if (falling) { //Debug.Log("Falling" + rbv.y); falling = rbv.y < 0f; dv.y = 0; } else { //start falling? if (((rbv.y * Time.fixedDeltaTime) + dv.y) < 0) { dv.y = 0; rb.velocity = rb.velocity.ChangeY(0); falling = true; } } dv.x = rb.velocity.RetrieveAdditionByIndexLimited(dv, 0, -stepSize, stepSize); Vector3 vy = new Vector3(0, rb.velocity.RetrieveAdditionByIndexLimited(dv, 1, -jumpStepSize, jumpStepSize)); dv.y = 0; rb.AddForce(dv, ForceMode.VelocityChange); rb.AddForce(vy, ForceMode.VelocityChange); //if (!Vector3.zero.Equals(dv)) { Debug.Log("move:" + dv); // rb.MovePosition(rb.position + dv * Time.fixedDeltaTime); //} //Debug.Log("imp_before:" + dv); //Debug.Log("vx:" + rb.velocity.RetrieveAdditionByIndexLimited(dv, 0, -stepSize, stepSize)); //Debug.Log("imp_after:" + dv); //rb.AddForce(dv, ForceMode.VelocityChange); Debug.Log("velct" + rb.velocity); }
private void FixedUpdate() { //Debug.Log("start:" + rb.velocity); CalcFlyStateInFixUpdate(); float stepSize = 6f; float jumpSpeedSize = 6f * 0.8f; Vector3 move = moveController.CalcMovement(); //dv.Scale(new Vector3(stepSize, jumpStepSize)); if (fallingDown || waitForFallingDown) { move.y = 0; isJump = false; jumpTime = 0f; } if (isJump) { jumpTime += Time.fixedDeltaTime; } float upSpeed = 0f; if (move.y > myEpsilon) { int multiplier = (jumpTime < 0.5f) ? 1 : 0; if (!isJump) { isJump = true; upSpeed += move.y * multiplier * jumpSpeedSize; } rb.AddForce(Vector3.up * 9.81f * multiplier, ForceMode.Acceleration); } else if (!fallingDown) { waitForFallingDown = true; } Vector3 dv = new Vector3(rb.velocity.RetrieveAdditionByIndexLimited(move * stepSize, 0, -stepSize, stepSize), upSpeed, 0); rb.AddForce(dv, ForceMode.VelocityChange); if (Mathf.Abs(rb.velocity.y) < myEpsilon) { waitForFallingDown = false; if (move.y < myEpsilon) { isJump = false; if (!grounded) { grounded = true; Debug.Log("Grounded event");//can we recalculate horizontal acceleration after this ground event? } } } //Debug.Log("End:" + jumpTime); //Debug.Log("End:"+rb.velocity); }
private void FixedUpdate() { //if (Input.GetKey(KeyCode.W)) { // rb.AddForce(Vector3.right * Time.fixedDeltaTime,ForceMode.Force); //} //if (Input.GetKey(KeyCode.S)) { // rb.AddForce(Vector3.right * Time.fixedDeltaTime, ForceMode.Acceleration); //} //if (Input.GetKey(KeyCode.A)) { // rb.AddForce(Vector3.right * Time.fixedDeltaTime, ForceMode.Impulse); //} //if (Input.GetKey(KeyCode.D)) { // rb.AddForce(Vector3.right * Time.fixedDeltaTime, ForceMode.VelocityChange); //} //Debug.Log("rb:" + rb.position); //speed += moveController.CalcMovement() * Time.fixedDeltaTime; //speed += gravity; //rb.transform.Translate(speed * Time.fixedDeltaTime, Space.World); //if (rb.transform.position.y < -1) { // Vector3 position = rb.transform.position; // position.y = -1; // rb.transform.position = position; // speed = speed.ChangeY(0); //} Vector3 rbv = rb.velocity; if (this.name == "FirstUint") { //Debug.Log("ttt " + Time.fixedDeltaTime); //Debug.Log("velct" + rbv); float stepSize = Time.fixedDeltaTime * 10f; Vector3 dv = moveController.CalcMovement(); dv.Scale(new Vector3(stepSize, stepSize * 0.8f)); //Debug.Log("dvy" + dv.y); if (falling) { //Debug.Log("Falling" + rbv.y); falling = rbv.y < 0f; dv.y = 0; } else { //start falling? if (((rbv.y * Time.fixedDeltaTime) + dv.y) < 0) { dv.y = 0; rb.velocity = rb.velocity.ChangeY(0); falling = true; } } rb.MovePosition(rb.position + dv); //Debug.Log("imp_before:" + dv); //Debug.Log("vx:" + rb.velocity.RetrieveAdditionByIndexLimited(dv, 0, -stepSize, stepSize)); //dv = dv.Change(rb.velocity.RetrieveAdditionByIndexLimited(dv, 0, -stepSize, stepSize), null, null); //Debug.Log("imp_after:" + dv); //rb.AddForce(dv, ForceMode.VelocityChange); //Debug.Log("velct" + rb.velocity); } //if (rb.transform.position.y < -1) { //Vector3 position = rb.transform.position; //position.y = -1; //rb.transform.position = position; //rb.velocity = rb.velocity.ChangeY(0); //} }