Search Unity

large ship moveing script eve online style.

Discussion in 'Scripting' started by orindoomhammer, Nov 16, 2009.

  1. orindoomhammer

    orindoomhammer

    Joined:
    Oct 6, 2009
    Posts:
    113
    ok seeing as how i got my bearbones movement script for fighters its time to move on to bigger ships seeing as how i now have a concept i can use for larger ships.

    i will post my code in this thread so others can see and learn from what im trying to accomplish i will also use this thread to ask questions about the mechanics of said script.

    script outline:

    here are the things i want the script to do.

    >orbit cam around the ship while holding a mouse button down. and nothing is under the mouse pointer.

    > double click to set the direction that the ship will take. speed will be ajusted by clicking on the speed indicator on the gui.(this will come later right now im just going to put in a quick slider for this nothing fancy till i get to gui. when the user double clicks on a direction the ship rotates to face the direction then moves if in motion continues at the speed while turning.
    > detects objects in proximity of the ship and avoids them.


    the turret script will work on these big ships. the turrets will acuire hostile targets and fire on the one closest to it.

    this is just what i want it to do. so now with question on how to atain such a way to do things.


    first question about click and point.

    i know i am going to need to use raycasting to do this and i can figure out the commands but some questions i need to ask is.

    will i need to set up a plain or some kind to check the ray cast hit. or will i be able to just use it seting the distance only?

    should i have waypoint marker for when you double click to move? or should i just leave it as behind the sceans? i ask cause i personaly have no care one way or the other.
     
  2. DMJ

    DMJ

    Joined:
    Nov 5, 2009
    Posts:
    83
    Just off the top of my head, could you use Camera.ScreenPointToRay

    Code (csharp):
    1. function ScreenPointToRay (position : Vector3) : Ray
    to return a Ray, then make the ship turn towards the Ray's direction as an orientation? You would have to construct a Vector3 out of the mouse cursor's current position and a suitable Z-value, but that doesn't sound hard.

    If you already have turret code, you're probably half way there since turning a turret towards a target and making a ship turn towards a direction sound like similar tasks.
     
  3. orindoomhammer

    orindoomhammer

    Joined:
    Oct 6, 2009
    Posts:
    113
    yes very simular. but alas the only bit of code i got i ripped from the camera orbit script and some bits to check for a double click that some one wrote for me. so far the rest is coming slowly as i trial and error my way threw. my big problem is i dont know how to put every thing together so i write some test if it works i keep it if it doesnt i delete it. that and i use all the help i can get from anyone willing to throw some lines of code at me. lol.

    but in answer to your question what im trying to do is create a waypoint type object on the screen where i double click and have the ship rotate and move to it.

    the ScreenPointToRay may work im trying it out but i gotta figure out how all this works. and then take it one step further and figure out how to make it all work together.

    lol im not a coder im an artist trying to learn how to code. so far i have some of what i want but its not easy going by anymeans.