public void TestMoveForward(float speed, float direction) { var startingPosition = new Vector2(5, 5); var movableMock = new Mock <IForwardMovablePhysicalEntity>(); /*movableMock.Setup(x => x.Position).Returns(startingPosition); * movableMock.Setup(x => x.ForwardSpeed).Returns(speed); * movableMock.Setup(x => x.Direction).Returns(direction);*/ movableMock.SetupAllProperties(); movableMock.Object.Position = startingPosition; movableMock.Object.ForwardSpeed = speed; movableMock.Object.Direction = MathHelper.ToRadians(direction); IForwardMovablePhysicalEntity movable = movableMock.Object; m_movementPhysics.Move(movable); if (speed == 0f) { Assert.True(movable.Position == startingPosition); } else if (speed == 1f) { switch ((int)direction) { case 0: Assert.True(CompareVectors(movable.Position, new Vector2(5, 6))); break; case 90: Assert.True(CompareVectors(movable.Position, new Vector2(4, 5))); break; case 180: Assert.True(CompareVectors(movable.Position, new Vector2(5, 4))); break; case 270: Assert.True(CompareVectors(movable.Position, new Vector2(6, 5))); break; case 135: Assert.True(movable.Position.X < 4.5f && movable.Position.Y < 4.5f); break; } } else if (speed == -1f) { if (direction == 135) { Assert.True(movable.Position.X > 5.5f && movable.Position.Y > 5.5f); } } }
public void ResolveSlideCollission45() { var initPosition = new Vector2(0.5f, 0f); var shape = new RectangleShape(initPosition, new Vector2(1, 1)); float angle = 135f; var angleRads = MathHelper.ToRadians(angle); IForwardMovablePhysicalEntity pe = new ForwardMovablePhysicalEntity(initPosition, shape, 1, angleRads) { InelasticCollision = true }; ICollisionChecker collisionChecker = new CollisionCheckerMock(new List <IPhysicalEntity>() { pe }); var movementPhysics = new MovementPhysics(); ICollisionResolver collisionResolver = new MomentumCollisionResolver(collisionChecker, movementPhysics); movementPhysics.Move(pe); collisionResolver.ResolveCollisions(); Assert.Equal(pe.Position.X, 0f, 2); Assert.Equal(pe.Position.Y, -0.71f, 2); }
// Update is called once per frame void FixedUpdate() { FindTargetLocation(); if (physics.collisions.above || physics.collisions.below) { velocity.y = 0; } float targetVelocityX = 0; if (transform.position.x > targetLocation.x) { targetVelocityX = (-1) * stats.moveSpeed; } else if (transform.position.x < targetLocation.x) { targetVelocityX = stats.moveSpeed; } if (canJump && targetLocation.y < collider.bounds.min.y && physics.collisions.below) { velocity.y = jumpVelocity; } velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (physics.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); velocity.y += gravity * Time.deltaTime; if (velocity.y < gravity) { velocity.y = gravity; } physics.Move(velocity * Time.deltaTime); }
private void FixedUpdate() { if (physics.collisions.above || physics.collisions.below) { velocity.y = 0; } velocity.y += 5 * Time.deltaTime; physics.Move(velocity * Time.deltaTime); if (physics.collisions.left || physics.collisions.right) { } }
public void ResolveSlideCollissionOrthogonal() { var initPosition = new Vector2(0.5f, 0f); var shape = new RectangleShape(initPosition, new Vector2(1, 1)); IForwardMovablePhysicalEntity pe = new ForwardMovablePhysicalEntity(initPosition, shape, 1, MathHelper.Pi / 2); pe.InelasticCollision = true; ICollisionChecker collisionChecker = new CollisionCheckerMock(new List <IPhysicalEntity>() { pe }); var movementPhysics = new MovementPhysics(); ICollisionResolver collisionResolver = new MomentumCollisionResolver(collisionChecker, movementPhysics); movementPhysics.Move(pe); collisionResolver.ResolveCollisions(); Assert.Equal(pe.Position.X, 0, 2); Assert.Equal(pe.Position.Y, 0, 2); }
private void FixedUpdate() { if (controller.collisions.right) { direction = -1.0f; sprite.flipX = true; } if (controller.collisions.left) { direction = 1.0f; sprite.flipX = false; } velocity.x = Mathf.SmoothDamp(velocity.x, speed * direction, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); velocity.y += gravity * Time.deltaTime; if (velocity.y < gravity) { velocity.y = gravity; } controller.Move(velocity * Time.deltaTime); }
void FixedUpdate() { if (stats.GetPlayerAlive() != true) { animator.SetBool("isAlive", false); return; } updatePlayerPhysics(); hInput = Input.GetAxisRaw("Horizontal"); if (physics.collisions.above || physics.collisions.below) { velocity.y = 0; } Vector2 input = new Vector2(hInput, Input.GetAxisRaw("Vertical")); // hInput is NOT buffered if (!hInputBuffered) { if (vInput != 0) { stats.aimingDirection.x = 0; stats.aimingDirection.y = input.y; } else { stats.aimingDirection.y = 0; if (sprite.flipX == true) { stats.aimingDirection.x = -1; } else { stats.aimingDirection.x = 1; } } isRunning = false; } else //hInput is buffered { isRunning = true; stats.aimingDirection.x = input.x; stats.aimingDirection.y = input.y / 2; if (hInput > 0) { sprite.flipX = false; } if (hInput < 0) { sprite.flipX = true; } } if (jumpBuffered && physics.collisions.below) { velocity.y = maxJumpVelocity; sound.Play(); isGrounded = false; jumpBuffered = false; } if (jumpReleaseBuffered) { if (velocity.y > minJumpVelocity) { velocity.y = minJumpVelocity; jumpReleaseBuffered = false; } } float targetVelocityX = input.x * stats.GetMoveSpeed(); velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (physics.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); velocity.y += gravity * Time.deltaTime; // Player cannot fall faster than our gravity if (velocity.y < gravity) { velocity.y = gravity; } physics.Move(velocity * Time.deltaTime); if (physics.collisions.below) { isGrounded = true; } updateAnimationState(); }
// Update is called once per frame void Update() { if (stats.GetPlayerAlive() != true) { return; } if (physics.collisions.above || physics.collisions.below) { velocity.y = 0; } Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (input.x == 0 && input.y == 0) { stats.aimingDirection.y = 0; if (sprite.flipX == true) { stats.aimingDirection.x = -1; } else { stats.aimingDirection.x = 1; } } else { stats.aimingDirection.x = input.x; stats.aimingDirection.y = input.y / 2; if (input.x > 0) { sprite.flipX = false; } if (input.x < 0) { sprite.flipX = true; } } if (Input.GetKeyDown(KeyCode.Space) && physics.collisions.below) { velocity.y = maxJumpVelocity; } if (Input.GetKeyUp(KeyCode.Space)) { if (velocity.y > minJumpVelocity) { velocity.y = minJumpVelocity; } } float targetVelocityX = input.x * stats.GetMoveSpeed(); velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (physics.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); velocity.y += gravity * Time.deltaTime; if (velocity.y < gravity) { velocity.y = gravity; } physics.Move(velocity * Time.deltaTime); }
// Update is called once per frame void Update() { controller.Move(Vector3.Lerp(transform.position, new Vector3(rightTargetNode.transform.position.x, rightTargetNode.transform.position.x, transform.position.z), Time.deltaTime)); }