Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Eve online movement

Discussion in 'Scripting' started by pheekle, Aug 13, 2013.

  1. pheekle

    pheekle

    Joined:
    Aug 10, 2013
    Posts:
    12
    Hey guys. So I had a topic on this but it was going all over the place so I wanted to re organize what I'm asking for in a new topic. So basically In EVE, the double click to move in space is done by getting a direction vector from where you click on the screen. You aren't actually moving to a point, just in a direction. How exactly can I get this to work.

    So far I have a basic setup. A plane, and a cube. I have a Camera.ScreenToWorldPoint in debug mode to show the mouse coordinates, and it shows them. Now getting the movement in that direction is my problem. I don't even know how to start the code. All I want it to do is, left click anywhere in the game up, down,left, right, diagonal, wherever and it moves in the direction till you switch directions or a create a button that will stop the ship.

    Thanks in advanced!
     
  2. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    with this one, you will need to use your camera. When you are looking from the top, double clicking should make the ship move "down". So you will need to always know your camera.transform.up.

    Then, you will need to know where the click is, relative to the ship. You can do this without a plane, just get the 2d point of the click, and the ships 2d point. if you are looking at it with the camera up = world up, left side of ship, clicking under it will make it go down. You will know this because the 2d point of click is -y (origin - click).

    Well, there is probably an easier way to do it.. but here is a start for ya
     
  3. pheekle

    pheekle

    Joined:
    Aug 10, 2013
    Posts:
    12
    Ok so what am I doing wrong? I'm getting an unknown identifier.

    Code (csharp):
    1. #pragma strict
    2. function Start () {
    3. }
    4. function Update () {
    5. var mousePos = Input.mousePosition;
    6. mousePos.z = 10; // select distance = 10 units from the camera
    7. Debug.Log(camera.ScreenToWorldPoint(mousePos));
    8. var direction = (mouseRayPoint - transform.position).normalized;
    9. transform.position += direction * Time.deltaTime;
    10.  }
    11.  
     
  4. pheekle

    pheekle

    Joined:
    Aug 10, 2013
    Posts:
    12
    Ok I got it! Now I just need the block to rotate into that directon. I guess a better term. Click in a direction, rotates to that direction than moves.