Search Unity

[RELEASED] Corgi Engine - Complete 2D/2.5D Platformer [new v6.3 : throw objects, pressure pads]

Discussion in 'Assets and Asset Store' started by reuno, Dec 18, 2014.

  1. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    74
    @reuno Hey, is it possible to create an enemy that could crawl on walls and ceilings with your asset?
     
  2. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @TimNedvyga > It's absolutely possible if you implement it. If you're asking if it's something that is built-in right now, then no. I seem to recall that a few users did that already and shared their solution, so that shouldn't be much of a problem.
     
    BossClaw likes this.
  3. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    Just a small message to let you know that I keep getting support questions from people using Unity 2019.3.x. While I reproduce all their issues, none of them are due to the engine, and are just, sadly, bugs with Unity editor. Even the latest "pre release" is in a sorry state, and I wouldn't recommend switching to it right now. I'm sure all these bugs will be fixed for the actual release of .3, but until then I'd recommend waiting.
     
  4. bingbing642

    bingbing642

    Joined:
    Aug 19, 2019
    Posts:
    4
    @reuno - loving the engine, it's fantastic - a masterpiece asset.
    From the get-go I wanted to use this with the new Universal Rendering Pipeline (URP/LWRP) and I'm using 2019.3 beta. The issue everyone using URP is the various 'Ui Camera' prefabs will show a blue background and block out the 'Regular Camera' (which is in the respective 'CameraRig' prefab for various demos). The reason is because 'camera stacking' is still not supported in URP/LWRP. edit - URP 7.2.1 has camera stacking and it means you can just change the 'render type' of the UICamera to 'overlay' and then add it to the 'Regular Camera's 'stack' - see https://docs.unity3d.com/Packages/c...nes.universal@7.2/manual/camera-stacking.html

    Generally you can just change the 'culling mask' on the camera with the blue background to include everything, but this doesn't work for Corgi Engine.
    What I did instead is just removed the 'Flair Layer' and 'Camera' components from each of the 'Ui Camera' prefabs, and changed the 'Render Camera' value on the 'Canvas' (where the inventory and health meter reside) to reference the 'Regular Camera' instead of the 'Ui Camera'.
    This seems to work more or less flawlessly, as now only the 'Regular Camera' is actually rendering and the inventory/health etc is still superimposed over it via the Canvas.
    I'd assume that there's some features that having the 'Ui Camera' provides which I don't get anymore, but I like having the option of being able to use URP - so this solution works fine for me.
    I'm curious what your thoughts are on this being a good workaround for others who want to use the new Universal Rendering Pipeline?

    Also - if people using the 3d demos are having trouble with the pink colored objects using URP/LWRP, they can just select all of the materials in \Assets\CorgiEngine\Demos\Corgi3D\Materials and replace the shader with the 'SpeedTree8' shader which is under 'Packages\Universal RP\Shaders\Nature'.
     
    Last edited: Mar 14, 2020
  5. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @bingbing642 > Yes, that's a valid way of solving the stacking issue.
    As for "pink" materials, Unity also provides an option to update all materials in a project to their U/HD/LW RP equivalent automatically (Edit > Render Pipeline > Update Project (or Selected) materials to whatever RP), which works with varied results depending on your context. That can help batch most of them.
     
  6. Kektastic

    Kektastic

    Joined:
    Apr 6, 2018
    Posts:
    6
    Heya, I'm not sure if this was brought up before, but I accidentally stumbled across what I assume is a bug. But basically, if a character is ever set into a frozen or paused state while on the ground, the "hit the ground" effects/feedback are triggered again despite already being on the ground.

    In my case, the landing animation just plays again. I did some investigation and all I can really figure out is that the "JustHitTheGround" check is still being called and is still returning true. I tested to see if this was also true in the examples, I only checked a few but it happens there too, it's just not noticeable because the characters in those examples have no feedback for hitting the ground.

    I assume it has something to do with switching from any non "Normal" state, back to "Normal", but I figured I'd mention it and get some insight on it.

    3yKB7r37qS.gif
     
  7. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Kektastic > I don't reproduce your problem, even if most playable characters actually do have quite visible animations and/or feedbacks on hit the ground. Here's the RetroCorgi with default feedbacks (in this case more noticeable than yours) not reproducing the issue, in a fresh install of the latest version :



    In general, if you think you've found a bug, please use the support form to report it, and provide exact repro steps, as well as basic context information (Unity version, engine version, etc). If the issue persists, don't hesitate to drop me a line providing these infos, maybe there's a use case I'm not aware of.
     
  8. Kektastic

    Kektastic

    Joined:
    Apr 6, 2018
    Posts:
    6
    Hm, I think I figured it out, but I'll have to do some more digging. It looks like my player character's "Grounded" flag gets set to false when pausing/freezing, sometimes jumping and landing again can "fix" this and will stay grounded when pausing/freezing. Now it's just a matter of figuring out why that's happening. In case I end up figuring out the issue (and I'm able to replicate the problem/bug), where is the support form?

    EDIT: So apparently it had something to do with the player's collider, I don't know why but the size/offset values weren't rounded. So I had values like "0.24593992", and I guess Unity/Corgi Engine didn't like that. At least, it's not playing the landing animation after pausing/freezing anymore

    I was trying to tackle a completely different issue, and accidentally fixed this one. Funny how that works xD
     
    Last edited: Dec 13, 2019
  9. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Kektastic > I doubt it has something to do with the unroundedness (not sure if it's a word). There's nothing on my side of things that would consider that an issue, and it's quite frequent to have to deal with numbers like that. But I'm glad it's working now. If you ever need the support form, it's on the asset's website.
     
  10. Kektastic

    Kektastic

    Joined:
    Apr 6, 2018
    Posts:
    6
    I’ll try to experiment some more and if I find any correlation I’ll be sure to send a report and let you know. Thanks for the help though!
     
  11. bingbing642

    bingbing642

    Joined:
    Aug 19, 2019
    Posts:
    4
    Sorry to continue posting, but this information will be helpful for others who wish to use 'corgi engine' with 2019.3 and URP. It's completely compatible, but there are 2 main problems.

    1. Camera stacking is unsupported/implemented differently - you can't freely have 2 cameras superimposed over one another and all of the demo scenes have 'Regular' and 'UI' Cameras, as described in the documentation - the result is a blue background beneath the 'UI Camera' that covers up the 'Regular Camera'.
    2. The 'Flare Layer' component can break the build - it causes this error "Component of type GUI Layer is no longer available in Unity".

    edit - camera stacking is supported in URP 7.2.1 - see https://docs.unity3d.com/Packages/c...nes.universal@7.2/manual/camera-stacking.html - you can skip everything described here and just make 'UICamera's 'render type' set to 'overlay' and add it to the 'Regular Camera's 'stack'

    These problems are solvable by going into each of the Camera prefabs for all of the demos and first removing the 'Flare Layer' components, and then going into each of the 'UI Camera' prefabs and removing all of the 'Camera' prefabs as well. Note that removing the 'Flare Layer' component first is necessary as its requiring the 'Camera'. Even one 'Flare Layer' remaining on any Camera on any scene that's included in your build will result in the #2 error - remove them all or uncheck the scenes that have them from your 'scenes in build' in the 'build settings'.

    Also inside of each of the 'UI Cameras', you need to change the 'Render Camera' field in each 'Canvas' to 'Regular Camera'. This applies to 'Inventory Canvas' as well in some of the demos.

    If you are building for mobile, you will also want to change the 'Target Camera' field in each 'MM Touch Joystick' to 'Regular Camera' as well.

    Also, it's possible to selectively import the project settings that come with 'corgi engine' - you might want to do this if your intent is to use URP because 'corgi engine' will overwrite the 'linear' graphics setting in your build options and set it back to 'gamma' (which means you're using standard rendering again) among other things (graphics apis, apk signing etc). There are a few requirements to get the demos to work though.

    1. You must install '2d pixel perfect', 'cinemachine', and 'post processing' via the 'package manager' as described in the documentation.
    2. You need the TagManager.asset file from the 'corgi engine' package - it contains all of the required layers and tags the demo scenes need.
    3. You need the InputManager.asset file from the package - it contains all of the input keys 'corgi engine' needs.
    4. You need the EditorBuildSettings.asset file from the package - this makes it so all 58 demos are added in your 'scenes in build' in the build settings.

    Finally, you need the Physics2dSettings.asset file from the corgi engine package. The default 'y gravity' setting is -9.81, and the 'y gravity' in the corgi engine package is -30. If you don't have the gravity set that way, you'll find that for each of the 'retro' demos if the player dies, they go into a death loop where they are re-spawned and die, respawned and die forever.

    These are the things I did to get the demos working on 2019.3.0f3 using the URP template. I hope these notes help other people who are trying to do the same thing with the wonderful corgi game engine!
     
    Last edited: Mar 14, 2020
    BossClaw, yakka and reuno like this.
  12. Zoo4125

    Zoo4125

    Joined:
    Oct 5, 2019
    Posts:
    7
    Hi, I've been using the Corgi Asset for a little while now and have a scene in Unity which is fully functional (character moves around the world I've created no problem in the "play window" However I recently tried to build it and my character can move but falls through all the platforms and ground I have in the built version of the game help attached is the error log for the build
     

    Attached Files:

  13. yunusbbayram

    yunusbbayram

    Joined:
    Jan 10, 2017
    Posts:
    3
    Proposal, request (situations to unlock level locks)

    for example, coin 30 to move to the next level.
    or if you finish the level at this time, the next level is unlocked.
    and if these features can be shown on level cards.
    these features may be in later corgi engine versions.
    I apologize my English is not very good.
     

    Attached Files:

  14. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Zoo4125 > According to the log, looks like an error related to squash & stretch. I have to admit I have no idea what you can do to get it, and without more info there isn't much I can do. If the error persists, please provide more info via the support form, thanks.
    @yunusbbayram > What you describe can already be implemented, the engine comes with an API to lock / unlock levels. I don't plan on implementing all possible unlock conditions in demos though, it's too game specific, and that'd be a ton of demos.
     
  15. Reactorcore

    Reactorcore

    Joined:
    May 19, 2011
    Posts:
    96
    Question:

    How would I make a character that can shoot a held weapon while climbing on a ladder?

    Would the best way to do this be to make an invisible character that only handles weapon and inventory stuff as a child gameobject of the actual player character that does all the rest, like movement, health and collisions?
     
  16. Reactorcore

    Reactorcore

    Joined:
    May 19, 2011
    Posts:
    96
    Another thing. I'm confused about is how do I replace animations in the Animation Controller / Animator.

    The documentation says this:

    "In most cases you’ll need an Animation Controller to setup your animations. The asset includes a bunch of these, I’d recommend using the RectangleAnimator one as a starting point for yours as it includes all animation parameters, so you won’t have to enter them all again. You can simply duplicate it, and then drag your animations into it, replacing the Rectangle ones as you go."

    So I followed the unity tutorial on how to make sprite animations, which was -
    1. Select player character
    2. Open animation window
    3. Drag animation frames from assets to animation window
    4. Name the animation clip as player_[action name]. When done, this creates an animation controller for the player character.
    5. Then keep adding more animation clips to populate the animation controller. this happens via animation window with the "create new clip" option.


    Ok. Makes sense for regular unity stuff. But in regards to Corgi Engine, I feel lost. How do I replace the existing animation of the RectangleAnimator without losing the existing parameters? What is the step by step process to do this correctly?

    What if my sprites are smaller size than the rectangle's sprites are?
    What if I have less frames than the rectangle does?
    How do I do the blendtree part in the RectangleAnimator? (like jumpAndFall)
     
    Last edited: Dec 20, 2019
  17. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Reactorcore > You could certainly create an invisible character and all that, but that seems quite complicated, when you can just extend the shoot ability to have it allow shooting from ladders. That's a one line change basically :)
    And regarding the animation questions, I'm not sure I understand them. Frame count has no impact whatsoever. If your sprites are smaller you'll probably want to resize your collider. And I'm sure Unity has a blendtree documentation (yes, they do : https://docs.unity3d.com/Manual/class-BlendTree.html). Don't hesitate to read a bit more than one tutorial, animation in Unity can get quite complex. If you have more questions like that please use the support form, thanks.
     
  18. Zoo4125

    Zoo4125

    Joined:
    Oct 5, 2019
    Posts:
    7
    I'm having an error that has to do with the Standing on Variable being unassigned. When on a moving platform and attempting to jump the character will get stuck on the moving platform and not be able to move vertically any longer, he can however move horizontally. If I build the game the character gets stuck on any platform type not just moving ones. Any idea on how I might be able to fix this? The Link is an image of the character being stuck and the error
    https://prnt.sc/qdmq0f
     
  19. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Zoo4125 > I'm not aware of any situation that could cause this, and without any context it's hard to guess what you could have done to do so. But please send me more info and repro steps via the support form and I'll be happy to have a look.
     
    Reactorcore likes this.
  20. Reactorcore

    Reactorcore

    Joined:
    May 19, 2011
    Posts:
    96
    Thanks, hearing that editing the shooting ability is easy gives me confidence to try it.

    I'll use the support form next time, got it. I'll just finish this topic here.

    About the animations, its just I'm overwhelmed and fearful of how to actually do it. It often feels like a blackbox, I have no idea what is automated and what isn't - both regarding Corgi and Unity - and what can be done with an editor tool and what requires scripting?

    My animation question was more about this:

    "ok so I want to make a brand new character, and the CE documentation tells me to copy the rectangle and replace the animations as I go, but my character's spritesheets are way smaller, have less frames and maybe the timing is different too when compared to the rectangle character.

    Do I need to tell Unity's Animator or Corgi Engine in some inspector field that my sprites are of X size and only have Y frames compared to the minimal rectangle character - so that it would work properly - or does it just work automatically somehow when I make the animation clip and slot it in there?

    Meanwhile in the "jumpAndFall" blendtree it has threshold values -13 and 5. Where did it get those? What if my jump is longer and slower than rectangle's? Does it matter? Will it just automatically update the values somehow when I tweak the character ability? The documentation didn't say anything about this."
     
  21. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    There is a whole section of the documentation dedicated to the few specifics of the engine when it comes to animation. As explained there, all the engine does is send and update animation parameters (including the ones used by the blend tree to answer your question). The rest is just regular Unity, absolutely nothing else. Again, I’d recommend reading Unity’s documentation as it will answer all your questions. And again, please, use the support form for support questions, thanks!
     
    Reactorcore likes this.
  22. Reactorcore

    Reactorcore

    Joined:
    May 19, 2011
    Posts:
    96
    Thank you, this helps!
     
  23. yunusbbayram

    yunusbbayram

    Joined:
    Jan 10, 2017
    Posts:
    3
    Collect 130 coins to unlock the next level.
    Many games use this feature.
    This feature is not with a new demo scene.
    Maybe you could incorporate this feature into retro advanture.
    It would be very easy for you. But for us it is very difficult. I couldn't do that I tried too.
     
    Last edited: Dec 22, 2019
  24. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @yunusbbayram > I can't implement all possible scenarios. You'll want to collect 130 coins (why 130?), others will want to collect 3 stars, others will want to kill X enemies, etc. That's why there's an API, and that's why it's documented. In this case all you have to do is store an int per level, which is actually exactly how it's done with stars. So technically you just have to replace a 3 with 130. I wouldn't say it's "very difficult". And if you've got trouble with that, don't hesitate to use the support form, I'll be happy to help you out.
     
  25. Muppo

    Muppo

    Joined:
    Sep 28, 2016
    Posts:
    236
    I use a similar idea for my project, player must collect a fixed amount of item in order to open new worlds. What I did is using the Score value to keep the amount of collected ones, and the doors to next worlds have a custom extension of ButtonActivated which read the score and open the way if the requirement are fulfilled.

    I used Score but you can use whatever value you like to store progress, or maybe taking coins or items from inventory... it's up to you.
     

    Attached Files:

    reuno and Boom_Shaka like this.
  26. yunusbbayram

    yunusbbayram

    Joined:
    Jan 10, 2017
    Posts:
    3
    I think I told you wrong.
    I didn't say it was necessarily 130. I gave an example. it doesn't matter what the number is. Ok thank you for your interest.
     
  27. Boom_Shaka

    Boom_Shaka

    Joined:
    Aug 31, 2017
    Posts:
    107
    Forgive me for interjecting, but you're right: coding is very difficult. That's why we use a tool like Unity and an asset like Corgi Engine in the first place! That said, it does get easier and this is actually a good project to hone your coding skills.

    For starters, think about what you're trying to do and map it out. You did most of that already in your posts - you have a desired outcome and the conditions to reach that outcome. All you have to do is put it together in a step-by-step list. I'm old skool so I use pen/paper but use whatever works for you. Once you have that list, you'll know what game objects you need and which variables you'll have to track.

    Be sure to bookmark the API document as it will be your best friend. It has a reference to every class, every variable, every script in the engine. Use it to find out if the variables you need already exist and how/where to access them. It's also a good idea to review script comments.

    Ask Google. Most of the customization you'll want to do with the engine isn't specific to the engine but rather Unity itself. 99.9% of your questions will have already been asked and answered online. It just takes a little legwork to find them. Yes, there's a learning curve, but the more you learn about Unity the more you'll realize how much you can do with Corgi Engine. I came into Unity with some coding and game design experience but no knowledge of c# - after about 300 hours, I'm just getting to the point where I feel like I can produce a commercial quality release (I still consider myself a noob).

    Once you've done all your research, you'll be ready to write your code! Thanks to Corgi Engine, you can usually do it with just a few lines. If you get stumped, try the Discord server, it's pretty active. Just remember that everybody else has their own projects and real life to deal with, so try to be as specific as possible with your questions.

    Hope this helps. Good luck with your project(s)!
     
  28. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    18
    I'm pondering about all the layers that are prefilled if you load the MinimalLevel scene. There are 'just' 31 layers but Corgi uses about 27 of them. Is there a good way to know which ones are really needed?
     
  29. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Emphy > There is a part of the Collisions section of the documentation that goes in details over each layer, and which ones are mandatory. And of course you can know what each one is used for by using your IDE's search features if that's not enough and you want more details.
     
  30. hippobob

    hippobob

    Joined:
    Feb 26, 2017
    Posts:
    25
    upload_2019-12-27_0-25-9.png
    When players glide through OneWayPlatforms, characters pass through OneWayPlatforms. In addition, if you finish sliding on both sides, the player will be bounced far away.
     
    Last edited: Dec 26, 2019
  31. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @hippobob > If you think you've found a "BUG" (why the caps?), please use the support form to report it, and provide a bit of context and repro steps, ideally in any of the demo scenes, no changes made from a fresh install, to make sure you don't just have a setup issue somewhere, thanks.
     
  32. hippobob

    hippobob

    Joined:
    Feb 26, 2017
    Posts:
    25
    In addition, if you finish sliding on both sides, the player will be bounced far away.
     

    Attached Files:

  33. hippobob

    hippobob

    Joined:
    Feb 26, 2017
    Posts:
    25
    @o@
    You were quick to answer the question.!
    Sorry, my English is not good. This is translated by the translation software. Ha ha

    That's weird. I tried another scene. No problem. I haven't made any changes. I'm just learning.
     
  34. hippobob

    hippobob

    Joined:
    Feb 26, 2017
    Posts:
    25
    Scenes in the Retro folder are fine.
    Problems with the RetroAdventure3 scene in the RetroAdventure folder.

    Glide in from this Angle. If you release the space bar on the edge, it will bounce off!

    I didn't make any changes to the plugin! Really, I'm just learning! In addition, my English is poor, I will learn to report the mistakes with the form.

    upload_2019-12-27_0-45-27.png
     
  35. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @hippobob > As I said, please use the support form to report bugs, not the forum, thank you.
    And again, I'll need context (what version of Unity you're using, what version of the engine, etc). It's all listed next to the form. Please do so and I'll be happy to have a look.
     
  36. KDB44

    KDB44

    Joined:
    Feb 12, 2017
    Posts:
    4
    @reuno - Hello.

    I have a question about respawning enemies. The auto respawn script doesn't account for the initial AI behavior/Animation States correct?
    Not a big deal just checking before I do my own solution.
     
  37. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @KDB44 > No, it doesn't, they're two separate systems.
     
  38. javi_unity402

    javi_unity402

    Joined:
    Nov 29, 2018
    Posts:
    20
    Code (CSharp):
    1. void OnCollisionEnter(Collision collision)
    2.   {
    3.         if (collision.gameObject.tag == "Player")
    4.         {
    5.             Debug.Log("Happy New Year” +  collision.gameObject.Name);
    6.        }
    7. }
    Remember to attach to 2020 year gameObject!
     
    reuno likes this.
  39. Luremaster

    Luremaster

    Joined:
    Dec 17, 2016
    Posts:
    9
    Hi Reuno!!!

    I haven't checked Corgi Engine updates for a long time. Theres any build in solution for level mapping like in Castlevania 2D games where you press a button and a map is show with the player position?
    I'm not gona lie, i'm little lazy and didn't check all the new stuff. :D

    Keep doing this amazing work!!!

    Happy New Year!!!
     
    Last edited: Dec 31, 2019
  40. Muppo

    Muppo

    Joined:
    Sep 28, 2016
    Posts:
    236
    It doesn't yet but it must be on his ToDo list because it was requested quite a bit, aswell as Castlevania stairs like system.
     
    reuno likes this.
  41. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    914
    @reuno Evening friend!

    I am attempting to make the new unity input system work with the corgi engine and wondering if there are plans to make this asset and the unity package work together?
     
  42. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Kellyrayj > Sure, if/when it gets released out of preview one day and finally works as promised, then I'll definitely add support for it. Right now it's still a bit too unstable and unfinished to spend time on it.
     
    Kellyrayj likes this.
  43. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    28
    I'm trying to create a character selector that carries multiple Characters over to the level by extending the game and level managers. However, I'm having issues getting it to recognize the new GameManagerExtended class instead of just the regular GameManager class. I'm probably missing something obvious, any suggestions?
     
    Last edited: Jan 5, 2020
  44. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    You should probably check the dedicated section of the documentation, it explains exactly how to do that.
    In this case, as the errors in your console are probably telling you, you're trying to call methods on a class that doesn't have them. You'll want to cast your manager as a GameManagerExtended.

    As explained in the documentation, it's done like this :
    (NewGameManager.Instance as NewGameManager).Hello();
     
    Boom_Shaka and Meowx like this.
  45. javi_unity402

    javi_unity402

    Joined:
    Nov 29, 2018
    Posts:
    20
    Hi,

    Here is what I'm using for my game. Based on AIActionPatrol. Hope it serves as a point from which to start.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using MoreMountains.Tools;
    5.  
    6. namespace MoreMountains.CorgiEngine
    7. {
    8.     /// <summary>
    9.     /// Inherits from AIActionPatrol but also detects walls and holes and allows character to crawl them
    10.     /// </summary>
    11.     public class AIActionPatrolCrawl : AIActionPatrol
    12.     {
    13.         /// <summary>
    14.         /// BoundsMethods determine whether the bounds will be defined based on the starting position of the Character, or the position it was at when entering the state
    15.         /// </summary>
    16.  
    17.         // Force initial base rotation
    18.         private string currentBaseRotation = "up";
    19.  
    20.         // When movement is reserve, we need to move hole detection to othe side
    21.         private Vector3 HoleDetectionOffsetReverse;
    22.  
    23.         /// <summary>
    24.         /// On init we create a hole detection for reverse movement (down and right directions)
    25.         /// </summary>
    26.         protected override void Initialization()
    27.         {
    28.             base.Initialization();
    29.             HoleDetectionOffsetReverse = new Vector3(-1 , 1, 0);
    30.         }
    31.  
    32.         void Update()
    33.         {
    34.             CheckForWall();
    35.         }
    36.  
    37.         /// <summary>
    38.         /// Checks for a wall, if found rotate character and update base rotation
    39.         /// </summary>
    40.         protected void CheckForWall()
    41.         {
    42.             if (!ChangeDirectionOnWall)
    43.             {
    44.                 if (_controller.State.IsCollidingLeft)
    45.                 {
    46.                     transform.RotateAround(transform.position, Vector3.forward, -90);
    47.                  
    48.                     if (currentBaseRotation == "up")
    49.                     {
    50.                         currentBaseRotation = "right";
    51.                     }
    52.                     else if (currentBaseRotation == "right")
    53.                     {
    54.                         currentBaseRotation = "down";
    55.                     }
    56.                     else if (currentBaseRotation == "down")
    57.                     {
    58.                         currentBaseRotation = "left";
    59.                     }
    60.                     else
    61.                     {
    62.                         currentBaseRotation = "up";
    63.                     }
    64.                 }
    65.  
    66.                 if (_controller.State.IsCollidingRight)
    67.                 {
    68.                     transform.RotateAround(transform.position, Vector3.forward, 90);
    69.                  
    70.                     if (currentBaseRotation == "up")
    71.                     {
    72.                         currentBaseRotation = "left";
    73.                     }
    74.                     else if (currentBaseRotation == "left")
    75.                     {
    76.                         currentBaseRotation = "down";
    77.                     }
    78.                     else if (currentBaseRotation == "down")
    79.                     {
    80.                         currentBaseRotation = "right";
    81.                     }
    82.                     else
    83.                     {
    84.                         currentBaseRotation = "up";
    85.                     }
    86.                 }              
    87.             }
    88.         }
    89.  
    90.         /// <summary>
    91.         /// Checks for a hole, if found, calls function to rotate character, update base rotation and move position one tile
    92.         /// </summary>
    93.         protected override void CheckForHoles()
    94.         {
    95.  
    96.             if (currentBaseRotation == "up")
    97.             {
    98.                 if (_character.IsFacingRight)
    99.                 {
    100.                     HoleRotator(HoleDetectionOffset, -90, 1, -1, "right");
    101.                 }
    102.                 else
    103.                 {
    104.                     HoleRotator(HoleDetectionOffset, 90, -1, -1, "left");
    105.                 }
    106.             }
    107.          
    108.             if (currentBaseRotation == "left")
    109.             {
    110.  
    111.                 if (_character.IsFacingRight)
    112.                 {
    113.                     HoleRotator(HoleDetectionOffsetReverse, -90, 1, 1, "up");
    114.                 }
    115.                 else
    116.                 {
    117.                     HoleRotator(HoleDetectionOffset, 90, 1, -1, "down");
    118.                 }              
    119.             }
    120.  
    121.             if (currentBaseRotation == "down")
    122.             {
    123.  
    124.                 if (_character.IsFacingRight)
    125.                 {
    126.                     HoleRotator(HoleDetectionOffsetReverse, -90, -1, 1, "left");
    127.                 }
    128.                 else
    129.                 {
    130.                     HoleRotator(HoleDetectionOffsetReverse, 90, 1, 1, "right");
    131.                 }
    132.             }
    133.  
    134.             if (currentBaseRotation == "right")
    135.             {
    136.  
    137.                 if (_character.IsFacingRight)
    138.                 {
    139.                     HoleRotator(HoleDetectionOffset, -90, -1, -1, "down");
    140.                 }
    141.                 else
    142.                 {
    143.                     HoleRotator(HoleDetectionOffsetReverse, 90, -1, 1, "up");
    144.                 }
    145.             }
    146.         }
    147.  
    148.         protected void HoleRotator(Vector3 HoleDetection, float turn, float x, float y, string RotationDirection)
    149.         {
    150.          
    151.             // prevents more than one execution, if base rotation is correct, exits function
    152.          
    153.             if (currentBaseRotation == RotationDirection)
    154.             {
    155.                 return;
    156.             }
    157.          
    158.  
    159.             // we send a raycast at the extremity of the character in the direction it's facing, and modified by the offset you can set in the inspector.
    160.             Vector2 raycastOrigin = new Vector2(transform.position.x + _direction.x * (HoleDetection.x + Mathf.Abs(GetComponent<BoxCollider2D>().bounds.size.x) / 2), transform.position.y + HoleDetection.y - (transform.localScale.y / 2));
    161.             RaycastHit2D raycast = MMDebug.RayCast(raycastOrigin, -transform.up, HoleDetectionRaycastLength, _controller.PlatformMask | _controller.MovingPlatformMask | _controller.OneWayPlatformMask | _controller.MovingOneWayPlatformMask, Color.red, true);
    162.  
    163.             // if the raycast doesn't hit anything
    164.             if (!raycast)
    165.             {
    166.                 // we rotate character
    167.                 transform.RotateAround(transform.position, Vector3.forward, turn);
    168.  
    169.                 // set new position one tile more
    170.                 transform.position = new Vector2 (transform.position.x + x, transform.position. y + y);
    171.  
    172.                 // update base rotation of the character
    173.                 currentBaseRotation = RotationDirection;
    174.             }
    175.  
    176.         }
    177.  
    178.     }
    179. }
    180.  
    Note: It's not designed for all games. BoxCollider2D must have the same size of the sprite, for example.
     
  46. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    28
    It looks like right now, the character switch script never actually returns to the initially instantiated character.

    In the MinimalCharacterSwap scene, the LevelManager instantiates the Rectangle player character, but when you start switching through characters, it never goes back to that initial character - just a duplicate created by CharacterSwitchManager (CharacterSwitch_0). IE any damage etc applied to that first character is no longer relevant since it never gets switched back to.



    Is this intended behaviour?
     
  47. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    @Meowx > CharacterSwitch and CharacterSwap are two different things, I'm not sure what you mean. MinimalCharacterSwap doesn't switch characters or create duplicates, it swaps control over different characters.
    CharacterSwitch completely replaces a prefab by another, it's not supposed to carry over damage.
    And in general if you think you've found a bug, please use the support form to report it, and provide exact repro steps, I'll be happy to have a look.
     
  48. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    28
    Oops! Sorry, I mean the MinimalCharacterSwitch scene.

    Correct; while the CharacterSwitch function changes prefabs completely, it never switches back to the prefab initially instantiated by the level manager. So in the case of your demo scene, when running, there are two completely different instances of the "Rectangle" player character prefab - one labeled "Rectangle" and one labeled "CharacterSwitch_0".

    The code is functioning just fine, I was more wondering if never being able to switch back to the original character was your intention with the function.
     
    Last edited: Jan 5, 2020
  49. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    3,366
    Yes, that's what the class is designed to do.
     
  50. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    914
    Running into a strange bug! When I restart the scene, the input manager seems to get lost and I get this error:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. MoreMountains.CorgiEngine.CharacterJump.HandleInput () (at Assets/CorgiEngine/Common/Scripts/Agents/CharacterAbilities/CharacterJump.cs:178)
    3. MoreMountains.CorgiEngine.CharacterAbility.InternalHandleInput () (at Assets/CorgiEngine/Common/Scripts/Agents/CharacterAbilities/CharacterAbility.cs:126)
    4. MoreMountains.CorgiEngine.CharacterAbility.EarlyProcessAbility () (at Assets/CorgiEngine/Common/Scripts/Agents/CharacterAbilities/CharacterAbility.cs:151)
    5. MoreMountains.CorgiEngine.Character.EarlyProcessAbilities () (at Assets/CorgiEngine/Common/Scripts/Agents/Core/Character.cs:330)
    6. MoreMountains.CorgiEngine.Character.EveryFrame () (at Assets/CorgiEngine/Common/Scripts/Agents/Core/Character.cs:294)
    7. MoreMountains.CorgiEngine.Character.Update () (at Assets/CorgiEngine/Common/Scripts/Agents/Core/Character.cs:283)

    Everything works normally and as it should when I switch to a new scene. This only occurs when I use the MMSceneRestart.
     
unityunity