Home Game Development unity – Simple Maths – Multiplying and including fractions

unity – Simple Maths – Multiplying and including fractions

0
unity – Simple Maths – Multiplying and including fractions

[ad_1]

I’m attempting to calculate the velocity of a ship, relying on many elements.

  • the velocity of the wind
  • the relative angle between the sails ahead and the wind ahead. reworked into angleSpeed
  • the ‘measurement of the sail relative to complete measurement of all sails of that mast’
  • the sail’s ‘state’

Simple system for the sail’s ‘state’:

  • 0 – sail is furled (packed) – not in use
  • 1 – sail is unfurled and raised – not in use however nonetheless catching wind as its unpacked
  • 2 – sail is unfurled and set – in use and catching full wind.

Then the calculation of velocity must be divided by every sail, and in reality every sail calculates its personal measurement and its sizePercetage out of all sailSizesTotal.

So mainly I’m attempting to.

  1. verify the relative angle of mast/wind
  2. verify state of sail below that mast
  3. calculate velocity of that sail based mostly on the sail’s sizePercentage, the relativeAngle and the sail’s state
  4. all these values are between 0.000f and 1.000f
  5. calculate mast velocity (all sails below that mast)
  6. calculate ship velocity (all masts)

The best solution to present what I’m attempting to attain is by trying on the code under I believe:

    float mizzenMastAngle = mizzenMast.localEulerAngles.y;

    float relMizzenToWindAngle = GetRelativeAngle(mizzenMastAngle, windAngle);

    float mizzenMastAngleSpeed = WindManager.occasion.GetSpeedFromWindAngle(relMizzenToWindAngle);

    float mizzenMastSpeed = 0f;
    foreach (SailControl sailControl in mizzenMastSails)
    {
        float sailSizePercentage = sailControl.GetSail().sizePercentage;

        float sailStateMultiplier = 0.1f;
        swap (sailControl.GetSail().state)
        {
            case 0:
                sailStateMultiplier = 0.1f;
                break;
            case 1:
                sailStateMultiplier = 0.25f;    //Debug values, change later to smaller
                break;
            case 2:
                sailStateMultiplier = 1f;
                break;
        }
        float thisSailSpeed = sailSizePercentage * sailStateMultiplier * mizzenMastAngleSpeed; // Range: 0.0f - 1.0f for these variables.
        mizzenMastSpeed += thisSailSpeed;

    }
    float mainMastAngle = mainMast.localEulerAngles.y;
    float foreMastAngle = foreMast.localEulerAngles.y;

...
ship.velocity = mizzenMastSpeed + mainMastSpeed + foreMastSpeed;

Specifically this line is what I need assistance with because it would not work as meant:

float thisSailSpeed = sailSizePercentage * sailStateMultiplier * mizzenMastAngleSpeed; // Range: 0.0f - 1.0f for these variables.

I believe right here mizzenMastSpeed ought to have a max of 1?

Basically if all mizzen sails are getting used it ought to be maxspeed for mizzenmastSpeed.

If solely half the sails are getting used, however some are furled and a few are set, all these calculations ought to return the right velocity for that mast, then for the opposite masts, based mostly on what states, angle and proportion of complete is getting used.

Then I need to apply all these speeds collectively to the ship in an accurate approach.

So if I take down a single sail on 1 mast it ought to lower the general velocity of the ship based on the scale of that sail, the angle of the wind it was catching and its state.

I hope somebody may help me with this.

Code for getting complete measurement and particular person measurement of sails:

    int totalsize = 0;
    foreach (SailControl sailC in mizzenMastSails)
    {
        int measurement = sailC.GetSail().measurement;
        totalsize += measurement;
    }

    float sizePercentage = 0;
    float totalPercentage = 0;
    foreach (SailControl sailC in mizzenMastSails)
    {
        int measurement = sailC.GetSail().measurement;
        sizePercentage = (((float)measurement) / totalsize); // Range 0f - 1f
        sailC.SetSizePercentage(sizePercentage);
        totalPercentage += sizePercentage;
    }

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here