Forum rules - please read before posting.

Player Rotating Problem in 2D

edited September 2014 in Technical Q&A
Hey Chris,

I've just started using Adventure Creator and I can't believe how good it is! Thank you so much for it!

I'm having a problem with the Player character in a 2D point and click game. The root object rotates whenever I click to move, even though the scene is set to Unity 2D and the character is using "Sprites Unity" for the Animation Engine. It seems to rotate to try to face wherever I clicked instead of keeping the sprites facing the camera.

I've looked through the tutorials for creating 2D characters and I believe I have all the settings correct, but I'm not sure what else it could be. Oddly enough, I also have an NPC who animates correctly and doesn't rotate away from the camera. So it's just the Player that has the problem.

Hopefully there was something simple I missed! This might not be enough information so I can post a screenshot with my settings too if necessary.

Thanks for you help!

Comments

  • I had this issue as well,

    any custom scripts on the player?
    whats your camera perspective set to in settings manager?

    (nick)
  • You're welcome!  Have you properly assigned the sprite as a child of the object that has the Player script?  That's a very important step - the base still rotates in 3D space, and it's the "sprite child" that's supposed to face the camera.  Once the sprite is a child, you have to actually assign the "Sprite child" field within the Player's inspector.

    Otherwise, post a screenshot of your Player prefab (in-game) and Inspector.
  • The camera perspective is set to 2D!

    I don't have any custom scripts on the player except for a free addon called "Sprites and Bones" which just adds IK bones for my characters' legs. I was thinking this was the problem, but my NPC has the exact same set-up and seems to work fine, so I'm confused!

    The sprite child is assigned properly, as far as I know! Here's an image which includes a few different things - the prefab in game, the hierarchy, and the child of the prefab in the inspector. I hope this helps!

    http://imgur.com/PuSIQXX

    Thank you for your help!
  • uncheck the custom component and see if it makes a difference,

    the player script is meant to zero out rotation when in 2d mode,

    cool character btw !
  • Thank you!

    I tried unchecking the scripts, they don't make any difference. I'm not sure what else it could be!
  • edited September 2014
    so when you hit play and rotate the "MaskPrefab" object it rotates the "Mask_Transforms" graphics ?

    for me the rotation values on the parent prefab don't effect the sprite child graphic when in play mode

    maybe try removing the player component and adding it again

    I have to do this whenever I switch between Sprites Unity and Sprites Unity Complex modes

  • I see that your Camera's in 2D space, but is your game set up to be Unity 2D mode?  Check the Moving and turning setting in your Settings Manager - if you've assigned your sprite child, I'm not sure what else other than that could be the problem.

    Failing that - if your NPC is working correctly, then there must be some difference, however small, between the NPC and Player.  Have another look at both to see if it's any clearer what that is.
  • Thanks for the help guys, I finally figured it out! In one of my animations I had rotated the sprite child 180 degrees as a way to flip the animation, and that seemed to mess everything up, even when that specific animation wasn't being used. I added another child and rotated that instead, and it all works perfectly!

    I did have one last question, is there any way to get a sorting map to work with the root prefab object instead of the sprite child? Because of the IK bone script I'm using, scaling only works properly with the root of my character. But I'm guessing it's not a simple thing to change and I'd have to get a custom script to do that?

    Thanks again!
  • I'm not familiar with the script, but if that's the case - better wait for 1.39 to see if this fixes the issue.  The next update will cause the root object to scale, rather than the sprite child, to ensure that things like Colliders etc are also scaled correctly.
  • @ksavory - thanks a lot, was trying to figure out why my NPC was rotating, and it was for the same reason that you mentioned - I'd used sprite rotation for one of the animations. When I got rid of it, it fixed the problem! :)
  • edited June 2020

    Same problem here, but my player start "rotating" because I've unchecked "isTrigger" on the collider attached to the root object.

  • @nova1337 Let's see screens of your character's Inspector, as well as details of when exactly the issue occurs.

    Try unchecking Turn root object in 3D? in the Inspector. Also be aware that a Rigidbody component is not strictly necessary on a 2D character unless you want wall collisions when moving around using the "Direct" movement method.

  • edited June 2020

    @ChrisIceBox See attachment.

    https://ibb.co/h7py3VT

    It happens when I switch the player. Even if I cannot say exactly what triggered this event. I'm trying to remove RB because I don't need wall collision. Thx

  • Removing Rigid Body solved the issue.

  • edited June 2020

    Yes, you'll get better performance too without a RB component.

    Likely you can also remove the Box Collider too. In general, you should add a small Circle Collider 2D by their feet (set to Is Trigger) to aid with character evasion - and leave any Box Collider (for Hotspot interactions) on the sprite child.

    See the 2D Demo's Brain2D prefab for an example on how the Circle Collider 2D can be set up on a Player prefab.

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.