Search Unity

A little problem i can't solve...

Discussion in 'Getting Started' started by CyberInteractiveLLC, Apr 26, 2018.

  1. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    1. a Ray shoots from a Ship, the end of the ray line is represented by the black cube

    2. Here's how it looks from the game view, the black ray end can me rotated on Y (left, Right) Axis via mouse.


    3. The problem, when the ship is tilted (turning) and the ray is also going that direction , this happens


    4. the Ray end is on a lower level, than of the ship (ship Y position will always be 0 though, Ray end y position is 0 as well)

    5. here's how it looks game view (Ship is tilted while turning, ray is moved to left)



    One of the solutions i came up with is while turning only rotate the camera but not the ship, but before i have to do that i would like to see if there's other workaround for this? (ray stays same level as ship) and i'am fairly new to unity so not sure what exactly i should do..
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    What exactly is the problem? What specifically is the difference between what's happening, and what you would like to happen?
     
  3. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    I want the end of the ray (black cube) to always be at the same level of the ship. currently when turning, the black cube goes at a lower Position as you can see from the picture.

    also need to say the ray start & end are child of the ship.

    here:
     
    Last edited: Apr 26, 2018
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    If you want to position the cube at right above the spot where the ray intersects the ground, then simply assign the y value of the ship to hit point, before assigning it to the cube.

    Code (CSharp):
    1. Vector3 pos = hit.point;
    2. pos.y = ship.transform.position.y;
    3. cube.transform.position = pos;
     
  5. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    I don't think that's what i meant,

    if you made a cube, then another one as a child.. then rotated main cube on X axis, the second one would go down, this is normal for Unity but i need a way for this not to happen, i think this is the problem in my case?

     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    If you don't want the second cube to rotate with the first, then you should simply not parent them that way. If you want the second cube to track the first one's position but not rotation, then just add a script that, in LateUpdate(), copies the position of the thing it's following (plus some offset) to its own position.
     
    Schneider21 likes this.
  7. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    I did other method, a Ray from screen to MousePosition, and another Ray from the ship to the End of the first ray.. i don't know if this is efficient or not but it seems to be fine for now

    now when rotating the ship, the ray coming from the ship wouldn't go on a lower level .
     
    JoeStrout likes this.
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Glad you found a solution. Not to hijack your thread, but can I ask how you did that cool, seemingly-infinite ground? Is it just a really big textured plane, or is there something more clever to it?
     
    CyberInteractiveLLC likes this.
  9. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    haha, it's just a texture on a plane
     
    JoeStrout likes this.