View Single Post
Old 02-16-15, 11:03 AM   #25
nsomnia
Weps
 
Join Date: Nov 2012
Location: Canada
Posts: 370
Downloads: 44
Uploads: 0
Default

Well this is.. how.. freaking... far.. I got all... freaking.. day yesterday. AT least for code that worked and I didnt even get the function to return the speed. Trying to graph it I got no where and I tried every asset I owned that might be able to do it, Vectrosity, GraphMaker, A* pathfinding, and even just using unitys own LineRenderer functions none were clear enough to me. I mean it works it would be easy enough to detect a change in temperature at a certain depth/temp by either changeing the equation to use depth and speed of sound (I havnt even graphed various depths yet I think its a fairly linear plot except around 100-300 feet (30-100m) so could just read from a text file that already has all the data every 10 ft. There really is no variable here, its just simple math. I went and confused myself the day I started with a goal, and ended up with a first day computer sciences class calculator.

Could go something like

Code:
//calll this function every 60 seconds using Time.time or Time.sincelevelstarted
void function speedSoundOneMinuteAgo(float depth,  float temp)
{
//same equation goes in here
}

void Compare()
{
if (speedSoundOneMinuteAgo(currentDepth, currentTemp) - SpeedSound(currentDepth, currentTemp) > 200)
ReportFavorableSonarConditions()
}
Of course you could solve for temp by using the known speed of sound in water which is easily found on wikipedia, also why not just write the data for every 25feet into a .txt file and read from it was it my other idea, no sense constantly calculating it, I just wanted a "screen" that showed it, one more of my outlandish ideas.

Code:
using UnityEngine;
using System.Collections;

/*This script prints to the console the speed of sound in feet per second taking in two arguments temperate in f and depth in feet. ie. SpeedSound(32.0f,521.5f); will tell you the speed of sound in ft/s in the ocean at 521 feet 6 inches deep with a water temp of 32 f */

public class EquationTest : MonoBehaviour 
{
    //Global Variables
    public float soundSpeed;

    // Use this for initialization
    void Start () 
    {
        SpeedSound(32.0f, 1.0f);
        Debug.Log(SpeedSound);
    }

    void SpeedSound(float temp, float depth)
    {
        //Speed of sound in feet per second = this equation. temp is in F. Depth is in feet. Assumes average salinity of 35 ppt.
        soundSpeed = (4388 + (11.25f * temp) + (0.0182f * depth));
    }
}
I'm spending the day doing something more productive... optimizing the under/above water system and getting it commited to GitHub properly.
__________________
Current Project [ Operation Trident (Working Title: Project RedWater) ColdWar Subsim] :: Development Log w/ Dwnloads
nsomnia is offline   Reply With Quote