Friday, September 30, 2022
HomeGame Developmentunity - Easy Maths - Multiplying and including fractions

unity – Easy Maths – Multiplying and including fractions


I am attempting to calculate the velocity of a ship, relying on many components.

  • 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’

Easy 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 needs to be divided by every sail, and actually every sail calculates its personal measurement and its sizePercetage out of all sailSizesTotal.

So mainly I am attempting to.

  1. verify the relative angle of mast/wind
  2. verify state of sail beneath 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 beneath that mast)
  6. calculate ship velocity (all masts)

The best option to present what I am attempting to realize is by wanting on the code beneath I feel:

    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; // Vary: 0.0f - 1.0f for these variables.
        mizzenMastSpeed += thisSailSpeed;

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

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

Particularly this line is what I need assistance with because it would not work as supposed:

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

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

Mainly 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 proper 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 method.

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

I hope somebody can assist 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); // Vary 0f - 1f
        sailC.SetSizePercentage(sizePercentage);
        totalPercentage += sizePercentage;
    }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments