Forum rules - please read before posting.

Player's "Sprite child" spins on Z-axis during movement

So, I've been bangin' my head for a couple days but cannot figure this one out. I've just gotten into Unity/AC without much knowledge, so please bear with me!

My plan is to have movable vehicles that bounce/jiggle as they go over objects, with the 'player' itself loaded in and set as a child of the [current] vehicle. Essentially, the 'player' will have no movement at all, but instead stick onto a parent that is producing movement. This way I can animate the player, without having to animate the entire vehicle, as it would be much simpler.

Here is an image of it mid-rotation: https://imgbox.com/Px3x8Hly

As it stands, I have gotten an OnStartGame ActionList that successfully attached the player inside the vehicle. It follows along perfectly on the X- and Y-axis, BUT I'm facing a situation where the 'Sprite Child' of the Player spins on it's Z-Axis -- it slowly spins on load, and spins with each 'bump' the vehicle hits, but does stop when vehicle returns to idle.

My only goal is to get 'Sprite child' to not rotate.

Things checked / changed -

  • AC Settings set to "Movement: None"
  • with Camera perspective is set to 2D, and Unity 2D moving and turning.
  • Player prefab does not spin, nor does any other component spin... only the 'Sprite child.'
  • Sprite on it's own outside of the script/prefab, in the same spot, does not spin.
  • When Player.cs script is turned off, the Sprite does not spin.
  • I've turned off/on Rigidbody 2Ds, but to no affect.
  • I've also added a Rigidbody 2D to the 'Sprite child' and set it to lock X/Y/Z but that also did nothing.

I'm stuck on where to look next. Any help is appreciated! Thank you!

Comments

  • Welcome to the community, @CDSK. Apologies for the delay in your post being visible - I've verified your account so it shouldn't happen again.

    Uncheck Turn root object in 3D? in your Player's Inspector if it's enabled, and then set the Motion control field at the top to Manual. This should prevent AC from moving the character at all.

    Remove any Rigidbodies on the Player and their sprite as well, since this may interfere with the physics of the vehicle.

    If the Player is able to exit the vehicle, you'll likely want to set their "Motion control" back to "Automatic", so that they can move around under AC control again. This can be done through script:

    AC.KickStarter.player.motionControl = AC.MotionControl.Automatic;
    
  • edited November 2022

    Thanks for the response! I really do appreciate you taking the time.

    Unfortunately, that didn't seem to do it. But I have narrowed it down a bit more:

    My assumption is that 'Sprite child' is seeing itself as both a child of the vehicle but also a separate entity, and thereby being affected by the movement script [of the vehicle] twice.

    So where the vehicle says "tilt up" on hitting an obstacle, the 'Sprite child' hears "tilt up, tilt up." This ends up being exponential and completely spinning the 'Sprite child' incrementally. So, it's not truly spinning in place but instead receiving the same instructions twice/multiple, when it shouldn't be getting them at all.

    Is there any way to stop the prefab from grabbing the script when I set it as a child? I don't know if this is so much a AC issue, but more so Unity's?

  • Adding: I was thinking about it, and it's not the prefab that's getting an extra of the parent's script, but only the 'Sprite child.' In this instance being 'barry-blankface': https://imgbox.com/DwJklW5d

    Adding a sprite to either the Hotspot or Sound shows that they are not affected. So now I'm more confused!

  • Is there any way to stop the prefab from grabbing the script when I set it as a child?

    Sorry, I don't really follow - can you re-phrase?

    It'd be worth trying to move your sprite to the character's root. If you've made the changes I mentioned above, then the sprite itself doesn't technically need to be on the sprite child object - though the object should still exist to keep AC happy.

    If your sprite child also has the Animator, you can move that to the root as well.

    The other way would be to counter the effects of the vehicle by brute-force, i.e. reset the local rotation in LateUpdate each frame:

    void LateUpdate ()
    {
        transform.localEulerAngles = Vector3.zero;
    }
    
  • Aha! The brute force way seems to have worked. Thank you for that.

    If it comes up again I'll look into other options a bit more, but for the time being this'll allow me to move forward.

    In the end, I'm not entirely sure what the issue is/was. What I do know is that it was entirely a conflict related to my vehicle mover, it just didn't play well with some other script -- whether from AC or just Unity in general.

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.