public override void Update(GameTime gametime) { // steerRotationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 0.75f) * 0.5f; min = MIN + currentPosition; max = MAX + currentPosition; tankBox = new BoundingBox(min, max); turretRorationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds); if (Mouse.GetState().LeftButton == ButtonState.Pressed && mousepick.GetCollisionPosition().HasValue == true) { pickPosition = mousepick.GetCollisionPosition().Value; } distanceTopickPosition = Vector3.Distance(pickPosition, currentPosition); if (distanceTopickPosition > atDestinationLimit) { speed = velocity.Length(); rotationAngle = (float)Math.Atan2(velocity.Z, velocity.X); moveAngle = rotationAngle - currentAngle; rotation = Matrix.CreateRotationY(-moveAngle); wheelRotationValue = (float)gametime.TotalGameTime.TotalSeconds * 10; canonRotationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 0.25f) * 0.333f - 0.333f; hatchRotationValue = MathHelper.Clamp((float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 2) * 2, -1, 0); velocity += steer.seek(pickPosition, currentPosition, velocity) * (float)gametime.ElapsedGameTime.TotalSeconds; currentPosition += velocity * (float)gametime.ElapsedGameTime.TotalSeconds; translation = Matrix.CreateTranslation(currentPosition); } }
public override void Update(GameTime gametime) { // steerRotationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 0.75f) * 0.5f; // turretRorationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds); if (Mouse.GetState().LeftButton == ButtonState.Pressed && mousepick.GetCollisionPosition().HasValue == true) { pickPosition = mousepick.GetCollisionPosition().Value; } distanceTopickPosition = Vector3.Distance(pickPosition, currentPosition); if (distanceTopickPosition > atDestinationLimit) { wheelRotationValue = (float)gametime.TotalGameTime.TotalSeconds * speed; canonRotationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 0.25f) * 0.333f - 0.333f; hatchRotationValue = MathHelper.Clamp((float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 2) * 2, -1, 0); moveDirection = pickPosition - prePosition; moveDirection.Normalize(); if (moveDirection.Z <= 0) { rotationAngle = (float)Math.Atan(moveDirection.X / moveDirection.Z) + MathHelper.Pi; } else { rotationAngle = (float)Math.Atan(moveDirection.X / moveDirection.Z); } moveAngle = rotationAngle - currentAngle; if (moveAngle > AngleLimit) { currentAngle += rotateSpeed; rotation = Matrix.CreateRotationY(currentAngle); } else if (moveAngle < 0 && Math.Abs(moveAngle) > AngleLimit) { currentAngle -= rotateSpeed; rotation = Matrix.CreateRotationY(currentAngle); } else { currentPosition = moveDirection * speed * (float)gametime.ElapsedGameTime.TotalSeconds + prePosition; prePosition = currentPosition; translation = Matrix.CreateTranslation(currentPosition); } } }