Search Unity

Script for hovering ship.

Discussion in 'Scripting' started by wrm186, Jun 2, 2011.

  1. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    Hello, I am in great need for a script that is a 3rd person view and can drive/hover around in a map. It should be able to turn/rotate by following the position of the mouse (only side to side not up and down) and going forward, reverse, with "W" and "S"

    Here is a little preview.

    http://dl.dropbox.com/u/20233101/New folder/WebPlayer/WebPlayer.html

    And if its possible I am also in great need of a script for entering and exiting the ship.

    In return, if you help me with the script I will return the favor of some models that you need, or some art work, like textures (still learning GIMP though)

    Thank you,
    Wade
     
    Last edited: Jun 2, 2011
  2. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    Anyone?

    I will also include your name in the credits of DA HUB as this is going to be a game option. Going to call the game "Little".

    if you want some models you can first view my work if you want: http://wademorrison.blogspot.com/
    DA HUB's website (Little is going to be an in-game) http://www.dahubworldgame.webs.com/

    This will be greatly appreciated! :)
     
  3. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Hey wade,
    Do you want this coded in JavaScript or C#?
     
  4. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    Java script please :)
     
  5. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Ok.... here's the script:
    Code (csharp):
    1.  
    2. var speed : float = 4.0;
    3. var rotateSpeed : float = 3.0;
    4.  
    5. function Update () {
    6. var controller : CharacterController = GetComponent(CharacterController);
    7.  
    8. // Rotate around y - axis
    9. transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    10.  
    11. // Move forward / backward
    12. var forward : Vector3 = transform.TransformDirection(Vector3.forward);
    13. var curSpeed : float = speed * Input.GetAxis ("Vertical");
    14. controller.Move(forward * curSpeed);
    15. }
    16.  
    17. @script RequireComponent(CharacterController)
    18.  
    Attach this to the ship, and you are good to go! :D
    Feel free to change the values at the top, they just change the speed.
     
  6. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    Awesome! Thank you so much! :)

    Anything in return? :D

    And do you maybe know the script for entering and exiting the ship?
     
  7. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Hey! A mention of PhilliamApps in the credits is all I ask, and I'm working on a script that'll let you enter/exit ship.

    Also--- I saw your models, they're great! What program do you use, and how could I get a download of one of your structures?
     
  8. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
  9. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    My script is more simple, easier to modify... Not to put down your project lol.

    The script I posted is exactly what he wanted, I think he needed a script he didn't need to modify to suit his needs. Some times simple gets the job done. :)
     
  10. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    I will mention you in the credits, as for the models just PM me and I will send whatever ones you want, but all I ask is to put me in the credits that you are using it for, and do not sell them. :)
     
  11. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    Also, one little problem (or big not good with scripting) When I push W or S it does not move.
    But when I push A or D it just goes around in a circle. (around the x-axis not the y-axis)
    And the ship does not turn if I move the mouse.
     
  12. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    And BigMisterB your script just glitched out on my and did a whole bunch of sideways twitching.
     
  13. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    wait.... is the script that I gave you working? is the glitching happening on my script or on BigMisterB's?
     
  14. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Heres the vehicle enter/exit script:
    Code (csharp):
    1.  
    2. var car : Transform;
    3. var player : Transform;
    4. var exitPoint : Transform;
    5. var doorTriggerLeft : Transform;
    6. var PlayerCamera : Camera;
    7. var ShipCamera : Camera;
    8. var isPlayerVisible : boolean;
    9.  
    10.  
    11. function Update(){
    12.     if (Input.GetKeyUp("e") isPlayerVisible){
    13.         // make player invisible and still standing
    14.         player.gameObject.SetActiveRecursively(false);
    15.         player.gameObject.active = false;
    16.         // parent player to Exit Point
    17.         player.parent = exitPoint.transform;
    18.         player.transform.localPosition = Vector3(-1.5,0,0);
    19.         // parent PlayerParent to car
    20.         exitPoint.parent = car.transform;
    21.         exitPoint.transform.localPosition = Vector3(-0.5,0,0);
    22.         // Enable Car as controllable object
    23.         GameObject.Find("ship").GetComponent("ShipMove").enabled=true;
    24.         PlayerCamera.enabled = false;
    25.         CarCamera.enabled = true;
    26.         }
    27.         else
    28.         {
    29.     if (Input.GetKeyUp("x")){
    30.         // make character visible again --- this happens when the x button is pressed.
    31.         player.gameObject.SetActiveRecursively(true);
    32.         player.gameObject.active = true;
    33.         // unparent player from everything
    34.         player.transform.parent = null;
    35.         // parent Exit Point to door Trigger-- the door trigger is the door to the ship, pretty much.
    36.         exitPoint.parent = doorTriggerLeft.transform;
    37.         // disable car as controllable-- making the player controllable
    38.         GameObject.Find("ship").GetComponent("ShipMove").enabled=false;
    39.         PlayerCamera.enabled = true;
    40.         ShipCamera.enabled = false;
    41.  
    42.         }  
    43.     }
    44. }
    45.  
    46. function OnTriggerEnter(Player : Collider) {
    47.     isPlayerVisible = true;
    48.     }
    49.  
    50. function OnTriggerExit(Player : Collider) {
    51.     isPlayerVisible  = false;
    52.     }
    53.  
    You should change the "shipmove" to whatever you saved the first script as, and should change the "ship" to whatever you named the ship in your game. Then create a trigger for the door, and an exit point. After this, assign the trigger for the door and the exit point to the slots in the editor. This script should be attached to the ship.

    Hope this helps! :D
     
  15. wrm186

    wrm186

    Joined:
    Apr 4, 2010
    Posts:
    661
    Big's is the one glitching out, but yours is working, but is only making me rotate around the x-axis if I push A or D. Why?

    Thank you for the scripts! :)
     
  16. ar0nax

    ar0nax

    Joined:
    May 26, 2011
    Posts:
    485
    you can cast a ray from the main camera to the mousepoint on the screen, then get a point on that ray at a certain distance, then you can make your hovercraft LookAt that point's coordinates (this will rotate your hovercraft based on mouse movement)

    and for the WS controlls you can use the script Philip gave you to move forward or backwards, this part:

    Code (csharp):
    1.  
    2. // Move forward / backward
    3. var forward : Vector3 = transform.TransformDirection(Vector3.forward);
    4. var curSpeed : float = speed * Input.GetAxis ("Vertical");
    5. controller.Move(forward * curSpeed);
    6.  
     
  17. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Yeah it should be working.... by the way I sent you a pm :).... check inbox lol