Search Unity

Facing and Moving toward an Object

Discussion in 'Editor & General Support' started by Sakar, Apr 11, 2009.

  1. Sakar

    Sakar

    Joined:
    Feb 12, 2009
    Posts:
    141
    I know this is probably a very simple question, but how would I get an object to face the cursor? Also, how would I get an object to move towards another object?

    Like I said, this is probably very simple to do but I haven't the slightest idea of what to do.


    Thanks for any help
     
  2. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    That's a good question. The beginning of Advent Fate has that effect; I've wondered how that was accomplished as well.....
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Convert screen to world coords, then use LookAt().

    --Eric
     
  4. Sakar

    Sakar

    Joined:
    Feb 12, 2009
    Posts:
    141
    Ok, I'll see what I can come up with tomorrow. Thanks for the help.
     
  5. Sakar

    Sakar

    Joined:
    Feb 12, 2009
    Posts:
    141
    Another question, how do I get the object (a cube in this case) to only rotate on the Y axis?
     
  6. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Use transform.rotate and only specify a y-rotation? Or are you asking this in conjunction with wanting to look at some point? If so then you have to determine your point of interest, the modify that point so it's in the model's x-z plane then look at that modified point instead.