Search Unity

2D question: How to to align a character's rotation to the rotation of a sprite in a prefab?

Discussion in '2D' started by Deleted User, Nov 25, 2018.

  1. Deleted User

    Deleted User

    Guest

    Hi, following problem:

    I have some 2D NPCs. The style is kinda like that of the old adventure game Dreamweb:

    https://www.scummvm.org/data/screenshots/other/dreamweb/dreamweb-cd-2-full.png

    As you can see, the red character on the right faces a terminal.

    I want the player to be able to place similar objects (terminals, computers...), and the NPCs going to those objects and rotate themselves to face these objects. That alone would be somewhat easy I think. But here's another caveat:

    Sometimes, those computers, terminals etc. wouldn't be their own prefabs, but just sprites, i.e.: multiple terminals on a round desk. I need to rotate and position the NPC characters based on the rotation and position of the terminal-sprites of the desk-prefab.

    How to accomplish that? Is it possible to set a marker (which has its own rotation, position properties) on top of a sprite in a prefab or something like that?

    I am somewhat at a loss how to accomplish that.

    Would the new 2018.3 feature of prefabs-on-prefabs help here?
     
    Last edited by a moderator: Nov 25, 2018
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    you can add an empty gameobject at this place and rotate it as needed. Then just rotate the player as this gameobject:
    player.transform.up = - terminal.transform.up
     
  3. Deleted User

    Deleted User

    Guest

    Thanks.