Forum rules - please read before posting.

Custom controls for 2d platformer wip

Hi, I'm working on a prototype here and there and experimenting with 2d platformer integration. However the 2dplatformer controls are built from the ground up. I want to start integrating parts of the more immediate platformer elements from AC to the custom system.

Right now I'm facing 2 problems.
1. I don't know how to get the AC NavCam(main) to face direction. My controls flip MY character visuals, but not AC Player direction. So the camera offset is a problem. The offset doesn't flip to the left when I face left.

2. AC seems to be turning the 2d MeshRenderer from Spline animation 90 degrees. I'm overriding this for now, but knowing what's going on would help as I can imagine this being a problem down the road. Especially with problem 1, facing direction.

I tried looking through the script guide at the Player class, and the tutorial site, but didn't find an answer. Probably just overlooking something though. Any help would be much appreciated.

Comments

  • 1) This is not clear to me.  NavCam and MainCam are two different entities.  What offset are we talking about, exactly?  As this is a visual problem, screenshots will benefit.

    2) If you assign your sprite child as the Char script's spriteChild, AC will rotate this object to face the camera at all times.  This is because, to allow for 2D/3D systems to merge, the base gameobject will rotate in 3D space (around the y-axis) - therefore the sprite child has to be compensated.  If you are taking care of all this manually, try unsetting the spriteChild variable.
  • 1. Sorry. I'm refering Horizontal Movement script on the Ac default created camera. I set the default to look ahead of the player. But I don't know how inform the AC.Player script on my object that it's facing left, not right. 

    2. Thank you, With your help I was able to figure it out. SpirteChild wasn't set at all, I missed it.
  • 1. This should be sorted out automatically by AC - the camera will simply refer to the character's forward vector, which again is rotated in 3D space.  Bear in mind you also have the option of creating a custom camera script if you need to - just create a new class deriving from _Camera, or duplicate an existing one (e.g. GameCamera2D) and tailor it to your own needs.
  • Thanks for help so far.

    Ok, so I figured away to flip the character with AC. Great :). However the GameCamera2D still doesn't track direction. 
    I use
    AC.KickStarter.player.SetSpriteDirection(AC.CharDirection.Left);
    But the camera won't lead with the xOffset in that direction.

    My settings are 
    Animation settings: Sprites Unity(this is because I'm using flipping)
    Motion Control: Manual

    Standard2D animations
    MultipleDirections: True
    Sprite child: a child object that is using Spine(Hero's 2d pack, and is using Meshs not sprites)
    Multiple directions: True
    Fame flipping: Left Mirrors Right
    Flip custom animation: true
    Rotate sprite to: Relative Position to Camera
    [everything else is default or off]

    If I have to make a custom camera I can, but ideally I would like to run mostly with AC in built features except for the 2d platforming.




  • edited March 2016
    The SetSpriteDirection function only locks a sprite's animation, it doesn't control which direction the character is facing.  Instead, try the SetLookDirection function, making sure to set the "isInstant" parameter to "true".  You can look in the ActionCharFaceDirection script to see this in action.
  • Great awesome thanks that helped a lot.
  • And, I have another problem. This time with Hotspot vicinity. 

    Since the controls are completly custom and designed for mobile I set.
    Movement method: Direct
    I do this because when it's set to None. I don't get the options for Hotspots in vicinity. However even doing soI can't get any hotspots to show when standing in the collider area.

    My player has hotspot detector as child, the child has a collider and script. the Player script has the hotspot detector set to to the child obejct. And the Player root is set to Ignore raycast as is all the  children.Is there something I'm missing because I'm doing manual control of the player?
  • What version are you using?  The Hotspot detection method option should stil be visible even when Movement method is set to None.  You should update to v1.51 if you haven't already.
  • Well the
    Hotspot dection method is visible.
    however it's the
    Hotspots in vicinity: that I want to use Nearest Only 
    that I would like to see.

    Ok. Maybe if I'm clear about how I want this to work would be best. I would like to only show Interaction Hotspot icons when the character is standing near by/or within the hotspot box. The idea is that my character walks up, then show the icon so the player can only interact with the hs when they manually move up to the hs.

    I would assume that I would require
    Hostpot dection method: Player vicinity
    Nearest Only
    Display Hotspot icons: When highlighting

    The thing is I managed to this before in a different project that was in 3d. But I can't figure out how to do this in 2d and with custom controls.Even after copying the settings over :(





  • Let's work on getting it working in 2D before introducing custom controls, as it's not clear if this is the source of the problem.  Keep your Movement method as Direct, and use e.g. the Brain2D player prefab to test with.  You'll have to make sure your Hotspot Detector also has a Rigidbody2D component on it.  Once we've got it working in "AC" 2D controls, we'll then see about re-introducing the custom controls.
  • edited March 2016
    Alright. So Brain2D is now the player. I've added a Hotspot Object, BoxCollider2d, RigidBody2d as a child to Brain2D. The controls in settings are set to Direct.  I'm not using the custom controls. Not working as of yet.

    The only strange thing is that Brain only walks right. But I'm ok with this since the HS I'm testing is only right.
  • You shouldn't be adding a Hotspot as a child of Brain - the only new child should be a Collider2D with a Rigidbody2D + DetectHotspots script, then have that assigned as the Hotspot detector child in the Player Inspector.
  • My mistake, I meant to wright DetectHotspot, not Hotspot scrip. I do not have a hotspot scrip on the detector child.
  • Is the hotspot detector a child of the sprite also?  Apologise for not suggesting that earlier - if it isn't then it will be rotating in 3D space as the character turns (around Y-axis), and Unity doesn't like rotated 2D colliders.

    Making it a child of the sprite will keep it's rotation correct, however this will mean that the location is not dependent upon facing-direction (i.e. it will not be positioned more to the left if the player is also facing left).  If you wanted more control over it like this, you could make it a direct child of the root (alongside the sprite), and write a script that auto-corrects the rotation and positions it based on the facing direction.
  • Thank you so much. Finally got it to work. It does need to be part of the sprite child and the RB2d needs to be set to kinematic. With both of those it now works. Both with Brain2D and my custom control system... yay :)

    I know I'll be back. But thank you that's one more step down :)



  • And i'm already back :\ that was quicker than I was expecting and hoping for :( 

    So now that the HS is working on vicinity :). I can't get it to interact when I click on the icon or HS area. There is also another problem that's related.

    1. The AC cursor location on screen does not match up with the mouse cursor. They are largly offset by exponential move. So even if I align them say on the left side because AC cursor  will stop going left on the border. Moving the mouse right will move AC cursor farther than the mouse.

    2. The interaction button, AND the AC GUi Menu button in the Lower left corner doesn't work. I can get the Menu to green highlight, but clicking on it won't open the menu. However the Inventory bar does show on AC cursor over.

    I'm thinking I might have some kind of camera ui issue here. 
  • What is your input method set to?  If it's set to Keyboard Or Controller, then the system cursor won't match up with the game cursor in the way you described - as it'll be controlled by input displacements in the manner of e.g. thumbsticks.  Set it to Mouse And Keyboard and see if it works then.  Again, I'd recommend leaving any customisation out of the scene before you've got AC working the way you want.
  • I feel like a toddler some times. Thank you :) I will going forward turn off the custom stuff when there is a problem. 

    But you were right on the nail. I had no idea there would be a different between the input methods.

    Thank you... again.
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.