Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[RELEASED] Rex Engine: A Unity 2D Platformer Engine

Discussion in 'Assets and Asset Store' started by BeeZee, Jun 20, 2017.

  1. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    All good! I'm here to help.

    The first thing I'd do is put the dash particle code in your player class itself, rather than adding to DashState.cs. This should keep your code safe from being overwritten when Rex Engine updates are released. Here's what I'd do:
    • Create your own class, named after your player character (or whatever else you'd like to name it.) Extend RexActor in that class.
    • Replace the existing RexActor class on your Player with that. Rex has a built-in convenience function for that: after creating your new script, click on your Player prefab, and in the inspector on its RexActor component, there should be an "Editor Options" field at the bottom. Expand that, then expand "Swap RexActor Script." You can then type in the name of the script you just made into the "New Script Name" field, then hit the "Swap RexActor Script" button, and it should replace it for you and automatically fill all the required slots.
    In your new script: RexActor has a virtual method you can override called "OnStateChanged." This will be called whenever your character performs any actions, and you can use it like this:

    Code (CSharp):
    1. public override void OnStateChanged(RexState newState)
    2.         {
    3.             if(newState.id == DashState.idString)
    4.             {
    5.                 //Spawn your particles here
    6.             }
    7.         }
    That code is basically intercepting that your player performed an action, and then checking to see if that action is a Dash. Then, you can do whatever you'd like, including spawning your particles.

    For your dash particle, feel free to just use a regular Unity ParticleSystem if you'd like; you can just call "Play" on it. RexParticles are designed to work in concert with regular Unity ParticleSystems, and they mostly just add the option to pull some extra data out of them. As such, I like using them for certain things, but in this case, it sounds like they're overcomplicating things, and they're not necessary.
     
    duke2go likes this.
  2. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    AWESOME!!!! Thank you so much for the input!! I'll definitely post an update when I get it worked out!!
     
    BeeZee likes this.
  3. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    131
    Awesome! Since Rex uses cameras instead of overlay for everything, it should be fairly easy to use Unity's new pixel-perfect script with all of the cameras, shouldn't it?
     
    BeeZee likes this.
  4. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    I'm pretty sure, yeah. If that's something you're planning to check out, I'd be interested to hear how it goes! I'd love to add that to the demo.
     
  5. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Okay, so I was planning (again) to release no more updates prior to the AI update, but the response to the Cyber Monday sale has been so positive that I wanted to do something special for y'all. Look for a new update coming early next week, this time featuring NPC's!

     
    CHEMAX3X likes this.
  6. CHEMAX3X

    CHEMAX3X

    Joined:
    Jan 8, 2018
    Posts:
    231
    Omg !!! thanks a lot for this, i really appreciate it, you're da bestest of them all <3 !!!
     
  7. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    131
    Quick question about tilemaps again! Does Rex work well with Super Tilemap Editor, and would you recommend Unity built-in tilemap or Super Tilemap for use with Rex? Thanks!
     
    BeeZee and CHEMAX3X like this.
  8. CHEMAX3X

    CHEMAX3X

    Joined:
    Jan 8, 2018
    Posts:
    231
    I'm using Unity's tilemaps and work great, just one thing, don't use tiles as one-way platforms, cuz it wont work, who knows why, for those use regular sprites.

    Hope it helps =D
     
    BeeZee likes this.
  9. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    131
    Yeah, it's a bug that's occurred in every other platform engine I've used outside of Unity, I was actually hoping Rex would do one-way tiles okay! It's usally because of the collision detection treats all the tiles as the same one-way; it also tends to have issues detecting the top of the one-way if your height is smaller than the one-way tile. These are the bugs I've encountered with other engines, I haven't tried one-way tiles with Rex yet, though I imagine it will be something similar.
     
    BeeZee likes this.
  10. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Yep, Rex will recognize anything as Terrain as long as it's on the "Terrain" layer, so it works well with TileMaps or with other plugins like Ferr2D terrain (a personal favorite of mine -- I'll evangelize that all day every day!)

    For one-way platforms, the trick is just not to use TileMaps and make those regular objects with a BoxCollider, like the one-way platforms used in the Rex demo scenes. Works like a charm!
     
  11. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    131
    Did you figure out why tilemaps don't work for one-ways with Rex/Unity? As I say, I haven't had a look into it yet, but I'm intrigued what the issue is that doesn't allow tilemaps to be used for one-ways. It would be handy if it could be possible!
     
  12. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    I haven't had a chance to do a deep dive on it yet. I mostly export Rex in a pre-TileMap version of Unity -- 5.6 -- so that the widest range of people can use it, so although I've done compatibility testing with TileMaps, I haven't had them front-and-center enough to explore it too deeply. That said, I'm intrigued by it too! One of the things on my eventual to-do list is to set up some demo TileMaps and offer them as a free download (or something to that effect), so maybe I'll get a chance to investigate more then.
     
    Lars-Steenhoff likes this.
  13. henkesky

    henkesky

    Joined:
    May 23, 2015
    Posts:
    36
    Hello, can i used 3d model and 2d environment in the same project with rex ? does it support using 3d character in 2d environment ?
     
    BeeZee and Lars-Steenhoff like this.
  14. smika78x

    smika78x

    Joined:
    Dec 22, 2013
    Posts:
    15
    Hi there @BeeZee,

    nice update, I really like them, good job!
    long time not working on my game :( but now I'm back again :)
    Will show some new ingame-footage later on.

    Just found 2 bugs (or I did somethin wrong :D)
    1) The WallCling Animation is not playing, it's always just showing the first frame of the animation, also tried with booster.
    2) When dying in the air, the player stays in the air. Is it possible to let him fall down?

    3) Is it possible to just activate WallJump without Cling? So you can only jump up between two walls on not jump up a single wall?

    I also have BuildErrors:
    Assets/RexEngine/Scripts/RexEngine/_Helpers/InspectorHelper.cs(50,35): error CS0103: The name `EditorStyles' does not exist in the current context
    Assets/RexEngine/Scripts/RexEngine/_Components/RexParticle.cs(10,27): warning CS0109: The member `RexParticle.animation' does not hide an inherited member. The new keyword is not required

    thx in advice
    greetings
     
    Last edited: Dec 1, 2018
    Lars-Steenhoff likes this.
  15. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    I figured out what was wrong when I received the error:

    NullReferenceException: Object reference not set to an instance of an object

    CameraHelper.GetLeftEdgeOfCamera () (at Assets/RexEngine/Scripts/RexEngine/_Helpers/CameraHelper.cs:52)

    CameraHelper.CameraContainsPoint (Vector3 point, Single buffer) (at Assets/RexEngine/Scripts/RexEngine/_Helpers/CameraHelper.cs:11)

    RexEngine.RexPhysics.StepPhysics () (at Assets/RexEngine/Scripts/RexEngine/_Abstracts/RexPhysics.cs:529)

    RexEngine.PhysicsManager.MovePhysics () (at Assets/RexEngine/Scripts/RexEngine/_Managers/PhysicsManager.cs:159)

    RexEngine.PhysicsManager.FixedUpdate ()


    When I extended the Rex script it deleted my player dropdown in Project Settings. I re-inserted the player as "player1 prefab" and saved and it cleared the error. I just wanted to share for anyone else who might run into that problem in the future.
     
  16. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    I've also been receiving an error when my player dies. I thought I had set up the scene with Rex, but when the player dies it gives me the error:

    MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    RexEngine.RexCamera.ApplyLookAhead (Vector3 position) (at Assets/RexEngine/Scripts/RexEngine/_Camera/RexCamera.cs:181)
    RexEngine.RexCamera.UpdateCameras () (at Assets/RexEngine/Scripts/RexEngine/_Camera/RexCamera.cs:131)
    RexEngine.RexCamera.LateUpdate () (at Assets/RexEngine/Scripts/RexEngine/_Camera/RexCamera.cs:109)


    I've been receiving these 4 errors that might be related.

    1: Assets/RexEngine/Scripts/RexEngine/_Actors/Checkpoint.cs(20,32): warning CS0414: The private field `RexEngine.Checkpoint.checkpointSpriteRenderer' is assigned but its value is never used

    2: Assets/Standard Assets/Utility/SimpleActivatorMenu.cs(10,16): warning CS0618: `UnityEngine.GUIText' is obsolete: `This component is part of the legacy UI system and will be removed in a future release.

    3: Assets/Standard Assets/Utility/ActivateTrigger.cs(57,33): warning CS0618: `UnityEngine.Object.DestroyObject(UnityEngine.Object)' is obsolete: `use Object.Destroy instead.'

    4: Assets/Standard Assets/Utility/TimedObjectDestructor.cs(24,13): warning CS0618: `UnityEngine.Object.DestroyObject(UnityEngine.Object)' is obsolete: `use Object.Destroy instead.'


    I don't know if any of these problems are causing conflicts, but every time I try to "fix" something, I cause 10 more problems, so I just wanted to say "hey, got these errors" before I went rooting around. I was having problems with Unity updating and corrupting Rex scripting, so I haven't updated Unity recently, but I did get the last Rex updates.
     
  17. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Yep, sure does. As long as your colliders are all 2D, you can use any style of art you'd like, whether it's 2D or 3D.
     
  18. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Good to hear from you! Welcome back.

    1. Oh, wow, this is indeed a bug! I can't believe I never noticed it. I've fixed it and I'll push the fix with the next update.
    2. This is hard-coded at the moment; you can see where it is starting on line 750 of RexActor.cs. You can comment out lines 750-753 and that should allow physics to keep going after death. I'll include some Inspector options for this in the future.
    3. Yep. Here's what you do:

    • Remove the Animation slotted for Wall Cling State.
    • Set the Wall Slide Speed equal to whatever the regular fall speed is for your player. (This step, coupled with the one above, will essentially get rid of the wall clinging/sliding.)
    • Look under Wall Jump > Wall Jump Kickback. The higher the number, the further your player will be pushed back from the wall when they wall jump.
    For the build errors -- does deleting InspectorHelper.cs fix it? (Make sure you keep a copy handy just in case when deleting it!)
     
  19. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Just looked into this. Weirdly, I'm not able to replicate the error, so I'm not sure why you're seeing it. The errors you pasted below are just warnings, so they shouldn't affect anything.

    That said, I think this should fix the camera error (still odd that you're seeing it to begin with, but at least the fix should help):

    Open up RexCamera.cs

    Change line 179 to this:

    Code (CSharp):
    1.             if(lookAhead.useLookAhead && focusObject != null)
    2.  
     
  20. CHEMAX3X

    CHEMAX3X

    Joined:
    Jan 8, 2018
    Posts:
    231
    Hello all, i just wanted to show you a little sneak peek of what i'm working, and really without Rex engine and @BeeZee help, it would be just a dream:

    1.png 2.png 4.jpg 3.jpg

    there's still a loooong way to finish or have a gameplay, but i'm happy with the result (so far xD).

    Everything in the pics was created with plasticine, at the beginning, i was "painting" with clay, cuz i though, would be faster to remove backgrounds and animate, and it was, but it usually takes more time than sculpting, so i started again and created everything with clay, and yeah it took less time.. the problem (i know i know u__u) was that removing backgrounds and animating took me more time, so, for like 2 weeks i didn't know what to do.

    One day i was checking what i had and creating something in Photoshop, and i realized that mixing "painted" clay with real sculptures looked really good, so that's how i ended with these kind of style n_n'


    Btw, @BeeZee, i have problems with the health bar, it's kinda confusing, when i replace sprites i end with a mess, and idk what to do, could you explain me, what is what .__. ?


    Thanks n__n.
     
    smika78x likes this.
  21. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    Thanks for the assist with the respawn error. I don't even know how to explain where the error came from, its just my luck.

    I am happy to report that I was able to use the override function like you recommended and was able to spawn the particle. Unfortunately, when I made the override it turned off the ability to dash. ;-(

    I was actually just trying to create a particle or animation that would spawn when the player dashed, to complement the dash function, not to remove it... I was happy to have watched your video on extending the Rex Scripts though since it gave me a much better understanding of how to actually do it correctly.
     
  22. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Nice, your art is looking super slick! It's cool to hear about your process, as well. I'm always really impressed by cool art, since that's something I've never been great at.

    So for the health bar:

    It has a few different SpriteRenderers:

    • Main: This is the "energy" part of the bar, which decreases when the player gets hit. It's the yellow part of the bar in Rex's demo graphics.
    • Frame: This is the frame that goes around the health bar. It's mostly optional.
    • Red: This is the little bit that shows up under the Main sprite temporarily after you take damage. Its job is to show how much damage you just took.
    • Backing: This goes under Main and Red. It's just a background.
    • End: This isn't even used in the demo. It's for putting something like a cap graphic on the right side of the health bar.

    In the demo's PlayerHP prefab, I'd look at the sprite used for Main (and also Red, since it's a very similar sprite, just tinted.) It's just a 5x10 rectangle, essentially. It's actual sprite image is called "hp_bar," and if you look at that in the Inspector, you'll see a few things of note: primarily, that its pivot is set to "Left." This is because the growing/shrinking of the health bar as you gain or lose health is accomplished by scaling the health bar graphic.

    For the purposes of reskinning it, I'd probably start out with the default health bar, and then replace it piece by piece with graphics which are the same size as the demo ones. Once those are all in place, you can experiment with resizing them one at a time, if you'd like.
     
    CHEMAX3X likes this.
  23. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Were you able to get this fixed?

    This one's a bit weird, because OnStateChanged doesn't have anything to do with the *ability* to perform an action -- it's just a thing that gets notified once the action itself happens, so it's reactive. It sounds like something else is going on there. Do you still have a Dash State on your player, and is it set to "Is Enabled"?
     
  24. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Just a reminder, today's the last day to get Rex at 50% off!
     
    CHEMAX3X likes this.
  25. CHEMAX3X

    CHEMAX3X

    Joined:
    Jan 8, 2018
    Posts:
    231

    Ohh thanks, i was missing to set the pivot to "left", that's why it was filling to the other side x), thanks again =D.
     
    BeeZee likes this.
  26. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Happy holidays, all!

     
    Lars-Steenhoff and CHEMAX3X like this.
  27. CHEMAX3X

    CHEMAX3X

    Joined:
    Jan 8, 2018
    Posts:
    231
    Happy holidays to you too, wish you have a great time with your beloved ones =D !!
     
    BeeZee likes this.
  28. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Here's a sneak-peek at the demo enemy I'll be using to showcase the upcoming AI system. (Note that this is just raw art, and it's not running in-engine, although this should be pretty close to how it will look!)

     
  29. CHEMAX3X

    CHEMAX3X

    Joined:
    Jan 8, 2018
    Posts:
    231
    Hey @BeeZee, im trying to make a build but i'm getting this error:

    Assets\RexEngine\Scripts\RexEngine\_Helpers\InspectorHelper.cs(58,40): error CS0103: The name 'EditorStyles' does not exist in the current context

    And tons of warnings about Rex, do you know how to solve it =O ?


    *Edit*

    I commented 3 lines of code with 'EditorStyles' and i was able to biuld, idk if i should but it worked x)
     
    Last edited: Dec 13, 2018
  30. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    Nope, still trying to figure everything out. I'm still getting an error when I die in the level. It doesn't seem like its setting a spawn point for some reason, even if I die after activating a checkpoint that I generated in that scene.... I've been watching a lot of Unity tutorials and I feel like I've got a better handle on extending scripts and such, so I'm going to try again. I was also thinking of trying to extend the player script, or something, to just override and set a respawn point when the level first starts and then from checkpoints. I really don't understand why I've been having these errors. Oh yeah, I can't duck and attack with my main player either. I had it working just fine before I rebuilt everything, and I directly compared to what I had there, so I have no idea what I've managed to do.

    On a lighter note, I'm really stoked about the new enemy AI stuff coming up. Building on the basic Rex Enemy AI should be really dynamic actually since it is pretty robust already. If you ever decide to do another script extension video, which I think would really benefit a lot of people (like me) who were really struggling with that concept, I would like to suggest extending Rex Physics to add a range that can be adjusted for the medusa head movement. I literally spent the whole day trying to learn how to extend the movement script just so if the Rex Actor reached the vertical clamp it would switch its vertical direction. Thought it would be simple, but coding is definitely a skill that requires patience. You deserve a medal for as much work as you've already put in on the engine. God bless you though. =-)

    p.s. Any suggestions for adding a sub-weapon icon like in Ninja Gaiden and Castlevania to show what you have? I got all the weapons coded successfully, but couldn't figure out how to change the UI image.
     
  31. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    I had a lot of conflicts with Rex after I kept updating Unity's free version. I ended up removing the newer versions of Unity to roll back to a version I knew didn't conflict with Rex before BeeZee started going hard with the updates. A lot of times it would let me play and test, but I'd come out of it with 999 errors. The problems of companies trying to be helpful hahaha
     
  32. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Yep! Here ya go:

     
  33. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    I test Rex pretty regularly on a lot of versions of Unity, and it works fine, so my guess is that it's probably related to changes you're making to files. I'll definitely do some more tutorials on extending Rex's classes, though! I'm planning to do more tutorials in general once this AI thing is done, but that's turned into such a massive beast that most of my attention is on that in the meantime. Making tons of progress, though!
     
  34. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Here are some more AI goodies for you guys! This is the upcoming Waypoints system, which lets you set up enemies to move between different positions. You can also set them up to perform actions when they reach those waypoints!

     
  35. RushingEntertainment

    RushingEntertainment

    Joined:
    Sep 28, 2018
    Posts:
    14
    Looks really cool, can't wait to test it.

    I wanted to share with you guys what I have been working on with Rex Engine

    Bloodsong: Arthur's Revenge is a 2D action-platformer based on the VictorianEra/IndustrialRevolution. Inspired by Nes classic games like Castlevania and Ninja Gaiden, we wanted to create a challenging experience for the player and rewarding them with a compelling story about England criminal gangs back then.

    Beta will come up by December 28th hopefully, and every kind of feedback is welcomed :D

    Here are some screenshots (sorry for the bad quality pics lol):

    06a2166c-52c9-4377-907c-183bee4340a6.jpg bed93f23-43f8-4819-a757-41101a3397cf.jpg 06a2166c-52c9-4377-907c-183bee4340a6.jpg bed93f23-43f8-4819-a757-41101a3397cf.jpg
     
    BeeZee, FunkyBuddha and CHEMAX3X like this.
  36. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    This is awesome! Can't wait to play it.
     
  37. RushingEntertainment

    RushingEntertainment

    Joined:
    Sep 28, 2018
    Posts:
    14
    It could not have been possible without your huge help BeeZee. Here is the pre alpha of the game, there is some art that belongs to you but don't worry, it is just a pre alpha to test the mechanics, all the Rex Engine art will be replaced.

    https://rushing2600.itch.io/bloodsong-prealpha

    Have a wonderful new year!
     
    BeeZee and Lars-Steenhoff like this.
  38. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    1,807
    There is one bug in the latest version, I can't make a build because InspectorHelper.cs trows an error.
    I fixed it by moving the #endif after
    #if unity_editor

    to the end of the script
     
    BeeZee likes this.
  39. Zerofield

    Zerofield

    Joined:
    Jul 26, 2014
    Posts:
    19
    Hi, BeeZee. I found that the "Will snap to floor on Start" doesn't work with player. By the way, is there any way to play a spawn animation before spawn the play?
     
    smika78x likes this.
  40. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Heya all, hope you had an excellent holiday! I took a little bit of time away to spend with the family, but I'm back now. I'll be getting to your questions, showing you new tidbits of AI, and fixing bugs and whatnot shortly.

    How was everyone's holiday? Do anything fun? I replayed Bloodborne for the (sixth?) time, joined a new gym close to my new apartment, and ate way too many sugar cookies. How about you?
     
  41. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Fixed! Thank you.
     
    Lars-Steenhoff likes this.
  42. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    That's by design -- the player is going to be positioned either by the Player Spawn Point icon or by the SceneLoader they entered the room with.

    As for the spawn animation, great idea! I just implemented it. You can expect to see it in the next version, hopefully later this week or early next week.
     
    CHEMAX3X likes this.
  43. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Want to set up a character select screen? Here's how!

     
  44. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Version 1.37 is now available on the Asset Store. It's got tools for switching characters, as well as a new ability to give your player a spawn animation!

     
  45. FunkyBuddha

    FunkyBuddha

    Joined:
    Aug 17, 2017
    Posts:
    62
    Awesome update, been waiting for this feature, anyway, wondering when will the engine have the AI update?
     
  46. LordMystirio

    LordMystirio

    Joined:
    Apr 8, 2017
    Posts:
    5
    Hello everyone and happy new year

    I'm still new to Rex engine and still learning the very basics. I would like to know if beside this forum, there is also a discord channel.

    Thank you in advance for your time ^^
     
    BeeZee likes this.
  47. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Happy New Year! There's no Discord -- I primarily use this forum, and then I put tutorials and such on the YouTube channel: https://www.youtube.com/channel/UCLaQOB8mAXzcDrsb-3uPs3g/videos
     
    LordMystirio likes this.
  48. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    402
    Getting very, very close to beta for the AI! This has been a long haul, but I'm pumped for it.



    This is Rex AI Routine. It's the nucleus of the Ai system. The design is still being polished for this; I ended up going all-out on custom editor stuff.

    A Rex AI Routine is made up of three major parts: Movements, Sequences, and Events.

    • A Movement defines how the actor moves; this can include different patterns, like moving left/right, following a target, or moving between waypoints.
    • A Sequence lets you string together a sequence of actions to play one after the other. For example, you could set up a sequence so an actor attacks, then waits for 0.5 seconds, then jumps, then turns around, then loops that sequence from the start, or begins an entirely new sequence.
    • Events let the actor react to different outside events. These can include things like another actor coming within a certain distance of it, HP falling below a certain threshold, or a timer hitting a certain time. Once the event is triggered, you can perform an action, including enabling/disabling other events, movements, or sequences.

    I've been doing a ton of testing with all of this, and it feels really robust. You can build super complex enemies and bosses. The coolest part is, the system is expandable, so new types of events, movements, and actions can be continually added in future updates. I can't wait to share this with everyone.
     
  49. duke2go

    duke2go

    Joined:
    Nov 1, 2018
    Posts:
    13
    Hey BeeZee,
    Happy belated holidays. I have a gift for you, and the followers of this thread, because you're always so good at helping us with our problems. I made some alterations to the checkpoint script to make it so a checkpoint could basically be "idle" and not do anything, but start an animation once the player had contacted the collider. I was basically trying to make it so I had a "dark" crystal that started to glow once the player went past. I wanted to share it honestly because it was one of the first scripts I wrote that worked correctly.

    Code (CSharp):
    1. public class CheckpointController : MonoBehaviour {
    2.  
    3.     public string id = "A"; //Every checkpoint in a room needs a unique ID so the game knows which one to load the player into
    4.     public Direction.Horizontal playerSpawnDirection; //Whether the player faces left or right when spawned into this checkpoint
    5.     public Animator anim;
    6.     public Animations animations;
    7.     public AudioSource audioSource;
    8.     public AudioClip activateSound;
    9.  
    10.     [HideInInspector]
    11.     public bool hasBeenActivated;
    12.  
    13.     [System.Serializable]
    14.     public class Animations
    15.     {
    16.         public AnimationClip redFlag;
    17.         public AnimationClip greenFlag;
    18.     }
    19.  
    20.     void Awake()
    21.     {
    22.         anim = GetComponent<Animator>();
    23.  
    24.     }
    25.  
    26.     void Start()
    27.     {
    28.         CheckForPriorActivation();
    29.     }
    30.  
    31.     // Update is called once per frame
    32.     void Update () {
    33.         if (!hasBeenActivated)
    34.         {
    35.             hasBeenActivated = false;
    36.             LowerFlag();
    37.         }
    38.     }
    39.     protected void OnTriggerEnter2D(Collider2D col)
    40.     {
    41.         if (col.tag == "Player")
    42.         {
    43.             if (!hasBeenActivated)
    44.             {
    45.                 if (audioSource && activateSound)
    46.                 {
    47.                     audioSource.PlayOneShot(activateSound);
    48.                 }
    49.  
    50.                 hasBeenActivated = true;
    51.                 RaiseFlag();
    52.                 GameManager.Instance.SetSavedScene(RexSceneManager.Instance.GetCurrentLevel(), id); //Save our progress at this checkpoint
    53.                 ScoreManager.Instance.SetScoreAtCheckpoint(ScoreManager.Instance.score);
    54.                 DataManager.Instance.Save();
    55.             }
    56.         }
    57.     }
    58.  
    59.     //Check to see if the player is already registered at this checkpoint; if so, disable it for future collisions
    60.     protected void CheckForPriorActivation()
    61.     {
    62.         if (LivesManager.Instance.lastSavedScene == RexSceneManager.Instance.GetCurrentLevel() && LivesManager.Instance.lastCheckpointID == id)
    63.         {
    64.             hasBeenActivated = true;
    65.             RaiseFlag();
    66.         }
    67.     }
    68.  
    69.     public void RaiseFlag()
    70.     {
    71.         anim.Play(animations.greenFlag.name);
    72.     }
    73.  
    74.     public void LowerFlag()
    75.     {
    76.         anim.Play(animations.redFlag.name);
    77.     }
    78. }


    Sorry, I didn't really know how to shorten that to just show what I had changed. You inspired me to take some Udemy courses though on Unity and C# programming, so I hope this helps you or someone else using Rex. Hope your New Year is awesome and keep up the great work with Rex!!
     

    Attached Files:

    Last edited: Jan 11, 2019 at 5:56 AM
  50. RushingEntertainment

    RushingEntertainment

    Joined:
    Sep 28, 2018
    Posts:
    14
    I freaking love you