Forum rules - please read before posting.

Rotate Sprite to Camera Facing Direction in 3D project not working

Hello, I just started using Adventure Creator and I am trying to create an adventure game where the characters are 2D sprites on 3D geometry.  I'd like the sprites to always face the camera and this appears to be controlled within Player > Standard 2D animation > Rotate sprite to : Camera Facing Direction.  However, when I made my character and set this up properly the character does not rotate to face the camera.  While playing the game in editor if I change Rotate Sprite to : Relative Position of Camera and then back to Camera Facing Direction it then properly rotates the player to the camera.  I am wondering if there is a bug in how this code updates or if I have set it up incorrectly?

Here is what I'm working with:
Unity 5.3.6f1
AC 1.53

I have a 3D project setup via the new project wizard and created a player via the character wizard.  The player animations setting are set to:

Animation Engine: Sprites Unity
Motion Control: Automatic

Sprite Child: characterSprite
Idle name: idle
(no other animations set)
Multiple directions? No
Crossfade animation? No
Only move when sprite changes? No
Rotate Sprite To: Camera Facing Direction

The sprite child is setup with a sprite rendere and an Animator with a Controller that only has an 'idle' animation. 

I then play the game using a the Main Camera and  GameCamera that has its X and Y axis unlocked.  I have a simple flat plane to test the character walking on top of.

With all this setup the character will not be rotated to face the camera on start.  I also tried switching the camera via a trigger volume and noticed the character also does not update to the rotation of the new camera.

I believe I tracked the character sprite rotation code to line 2315 in the Char.cs script and it appears to be finding the proper camera transforms so I don't understand why it would not properly rotate the sprite.

Anyway, hopefully I'm just setting something up wrong, any help would be greatly appreciated!

Comments

  • Welcome to the forum, @Math_The_Wizard - I apologise you're having some frustration this early on.

    The set-up you've described all sounds correct.  Normally this'll be down to the Camera perspective in the Settings Manager not being 3D, or their being more than one MainCamera in the scene, but they don't seem to be the case here.

    Check that the "idle" animation you've created doesn't key the rotation of your sprite child.  The code you've come across in Char.cs affects the sprite child's rotation directly, so if your animation also controls it then there'll be a conflict.

    Failing that, we'll need to determine if this is an issue with the character, or the scene.  Try dropping the 2D Demo player prefab, found in /Assets/AdventureCreator/2DDemo/Resources/Brain2D, into the scene before running it and then test the scene.  If he works OK there, we'll know the problem lies with your character.

    If that doesn't work, try dropping your own player prefab into the 3D Demo scene, found in /Assets/AdventureCreator/Demo/Scenes/Basement.  Unset the "OnStart" Cutscene field in the Scene Manager so that you skip straight to the gameplay when you run the scene, and see if your player works correctly there.  If he works OK, we'll know the problem likes with your scene.
  • Thanks for the quick response! I think I found the problem after some debugging in Char.cs.  I tried the two tests - using Brain2D in my scene and using my testPlayer in the 3D demo and both still failed to rotate the sprite properly. 

    My character hits a breakpoint at line 2315 in Char.cs every frame:

    spriteChild.rotation = Quaternion.Euler (spriteChild.rotation.eulerAngles.x, KickStarter.mainCamera.transform.rotation.eulerAngles.y, spriteChild.rotation.eulerAngles.z);

    It looks like the rotation is only being set in the Y axis and my camera was rotated along the X axis.  I changed the code so the sprites rotation transform also took the cameras transform on x and z:

    spriteChild.rotation = Quaternion.Euler (KickStarter.mainCamera.transform.rotation.eulerAngles.x, KickStarter.mainCamera.transform.rotation.eulerAngles.y, KickStarter.mainCamera.transform.rotation.eulerAngles.z);

    and now the character always faces the camera!  Is there a reason we would only want to change the y rotation?  
  • Only taking into account the y-rotation is the standard "billboard" effect seen in games when 2D sprites move in 3D worlds.  Unaffecting the X and Z angles also allows those to be keyed as part of your animations should you wish.  I will consider adding an additional option to make use of the full rotation of the camera in a future release.
  • Awesome! It definitely helps for a game where the camera is pitched down in a more isometric or 3/4 perspective.  Thanks for the prompt responses.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.