Author Topic: Do any of you code for your jobs?  (Read 8459 times)

0 Members and 1 Guest are viewing this topic.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #180 on: April 08, 2022, 09:01:31 PM »
Wow, tilemaps are so cool. So much easier to drag and drop to draw the environment than all the dumb stuff I was doing with copy & paste single tile game objects in my first game.

Like that first stage with those wall tiles had like hundreds of gameobjects and crashed unity the first time.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #181 on: April 08, 2022, 10:14:43 PM »
Making rule tiles is a pain in the ass, though once you're done it's absolutely worth it for the ease of drawing tiles.

But we have to make all these rule tiles from various texture sets and ughhh, waste of time.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #182 on: April 09, 2022, 06:01:09 PM »
Animated tiles are fun:


Tasty

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #183 on: April 09, 2022, 06:01:53 PM »
Such a pain in the ass tho lol.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #184 on: April 09, 2022, 07:15:24 PM »


Was doing the animator states tutorial and couldn't figure out why this wasn't working and went through the script and all the bools were lowercase "i" for "isWalking" and stuff.

But turns out you can't rename bools in animator?? Only delete and make new ones? But I'd already set all the animator conditions and didn't want to redo them so I changed the script instead and hopefully it doesn't fuck anything else up.


Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #185 on: April 09, 2022, 07:20:27 PM »
hmmm, I skimmed the rest of this class for the 2d platformer project and it's still not getting much into scripting and leaving that to the students to learn coding on their own outside the class :\

It sure looks like the first week of the 4 weeks is tech stuff like tilemaps/animator/camera/player controls,

But then it sure looks like weeks 2-4 are straight out just general game theory class on "how to make fun levels, how to write a plot, how to write good characters" etc...which is alright, but I don't want 3/4ths of the class to be on that.

Currently working through all the week 1 technical learning this weekend and then I guess it's back to youtube tutorials/Unity manual for trying to learn more actual technical stuff instead of Unity level drag and dropping stuff.

Probably time to start on a C# coding book doing the practices from it.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #186 on: April 09, 2022, 10:29:20 PM »
Welp, figured out why my text scaling was all messed up in my first game. Didn't see this option on the canvas objects I'd make that my text objects would go under



I had it on constant pixel size for everything outside the UI. Still has nothing to do with the UI issue I was having of trying to move the Score/Fear UI elements at the same pace in windowed and full-screen, but for all the other text this was the solution.

At least I know now. This is why I keep learning things.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #187 on: April 09, 2022, 11:38:36 PM »
Ok, finished all the technical programming part of the 2d platformer class. It was ok. Some very helpful stuff, but for a lot of the more interesting things like making pick up items, key cards, doors associated with key cards, moving platforms, enemies that move around and turn at walls, etc... they just gave us the prefabs already made vs actually teaching us how to make them.

So basically will need to reverse engineer their code (which seems pretty small for these type of things) and try to learn how to make this stuff myself.

At least we did an example of interacting scripts. They had us do a single script from scratch which was a full health pickup item. Still use the Health script, but at least used GetComponent which I wanted to practice with.

Code: [Select]
public class FullHealthPickup : MonoBehaviour
{

   
    private void OnTriggerEnter2D(Collider2D collision)
    {   
        // Only Heal if colliding with the player
        if(collision.tag == "Player")
        {
            Health playerHealth = collision.gameObject.GetComponent<Health>();
            playerHealth.ReceiveHealing(playerHealth.maximumHealth);
            Destroy(this.gameObject);
        }
    }

But like I looked at their pickup code for items you can pick up. I would have thought you'd do them as like a list? You create a list and add pickups to your list and remove them as used [like keys and stuff])

But this is their code for picking up items:

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// This is the base class for other pick up scripts to inherit from
/// </summary>
public class Pickup : MonoBehaviour
{
    [Header("Settings")]
    [Tooltip("The effect to create when this pickup is collected")]
    public GameObject pickUpEffect;

    /// <summary>
    /// Description:
    /// Standard unity function called when a trigger is entered by another collider
    /// Input:
    /// Collider2D collision
    /// Returns:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collider2D that has entered the trigger</param>
    private void OnTriggerEnter2D(Collider2D collision)
    {
        DoOnPickup(collision);
    }

    /// <summary>
    /// Description:
    /// Function called when this pickup is picked up
    /// Input:
    /// Collider2D collision
    /// Return:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collider that is picking up this pickup</param>
    public virtual void DoOnPickup(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            if (pickUpEffect != null)
            {
                Instantiate(pickUpEffect, transform.position, Quaternion.identity, null);
            }
            Destroy(this.gameObject);
        }
    }
}

Since

Quote
Instantiate(pickUpEffect, transform.position, Quaternion.identity, null);

Is basically the only line of real code in there, I'm trying to understand what they're doing. With pickUpEffect they're handing off the "what do I do with this" to a different prefab that it'll run at that current objects position and rotation, right? So this code is basically doing nothing other than say "on collision with pickup do whatever prefab you slot in"? Also why is there a null there?

And by putting the Destroy at the end it's saying if you collide with a pickup that has no prefab slotted in telling what to do with it, just destroy the pick up object and do nothing. Right?

Code: [Select]
protected virtual void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.tag == "Player")
        {
            AttemptToOpen();
        }
    }

Also looking at the code for how Doors work in this, why is it using a protected virtual void vs just void? Haven't seen protected and virtual before.
« Last Edit: April 09, 2022, 11:48:14 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #188 on: April 09, 2022, 11:42:05 PM »
I created my initial list of stuff I want to self-learn & practice for this project. I'll definitely add things as I am making my game and think of stuff I want to do that is outside what I've learned already and these:

-Lifebars -> practice adding a lifebar for players and enemies

-Transition effects -> practice a transition into scene for player/enemies

-particules -> watch a tutorial on particles and make a particle effect around player when transitioning into a stage and out of a stage

-Figure out how to make nice little in-game pop up windows to put text logs in that scale appropriately

-Figure out how to make a graphic at the corner of pop up windows

-Figure out how to get & various fonts to the textmeshpro for these text logs

-Figure out how to make a pickup item from scratch

-Figure out how to make a power up item that adds new player abilities

-Figure out how to make doors and keycards from scratch

-Figure out how to make a moving platform from scratch

-Figure out how to make checkpoints from scratch

-Figure out how to make enemies turn at walls from scratch


Will get to practicing this stuff starting tomorrow and then start to work on my next game project as I have a few more tools I can use.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #189 on: April 09, 2022, 11:43:28 PM »
Also I will try to comment on all code in this project.

I am terrible and did not write a single comment in all my code in my first game.

Sorry, I know that's extremely bad practice :shh

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #190 on: April 10, 2022, 09:14:48 AM »
For someone who writes software using C#, VB.NET, and Javascript (accounting/business software), how easy is Unity to pick up and learn?

Unity (the editor) is really easy to pick up and learn; you basically only need to know three things - what the hierachy is, what the project window is, and what the inspector is to get up and running.
Its the programming side of things people mostly struggle with, and as it natively supports C# you already have a head start on that (although might find some conceptual difficulties moving to a component based design, which fundamentally Unity uses).

Oh and I want to do a PnC Adventure Game and it falls into the same question of 2d rpgs and VNs of whether it makes any sense to do a 2d PnC Adventure game in Unity vs just using Adventure Game Studio?

Yeah, if you want to make a generic (without the implicit sneer of people who misuse the term) type of game, an engine specific for that genre will do literally exactly what you need.
Having said that, if that engine isn't new and / or fairly regularly maintained, or if you want to go 'outside the box' you're going to hit arbitrary limitations that will annoy you (eg AFAIK AGS is capped to some really shitty low res SD resolution for builds)

The advantages people seem to say about GameMaker Studio vs Unity is that you can do stuff quicker, and it has a better interface, so you can get it running and prototype your game fast and see what works and that it's easier to match things up consistently because it uses pixels instead of units. Disadvantages is that GML is less versatile for larger projects. Also GMS isn't good for projects with multiple people working on it, whereas Unity is.

You can do stuff 'quicker' in GMS, because it has some drag and drop logic shit for people who literally know nothing about programming; and yeah, you can 'learn' programming, but you're learning a language only used by gamemaker, so I'd honestly question if thats a good use of your time long term.
Also, NGL, Game Makers licencing is kinda expensive and shitty since their 2.0 upgrade, and its anti-piracy checks are kinda needlessly aggressive. I'm pretty sure Godot is eating its fucking lunch right now.

But ultimately, the 'best' engine is the one you personally like the best, so try a bunch out and see what sticks; think about things like minor annoyances you're going to have to routinely deal with in every single project and how much of a ballache thats going to be longterm.


Quote
Instantiate(pickUpEffect, transform.position, Quaternion.identity, null);

Is basically the only line of real code in there, I'm trying to understand what they're doing. With pickUpEffect they're handing off the "what do I do with this" to a different prefab that it'll run at that current objects position and rotation, right? So this code is basically doing nothing other than say "on collision with pickup do whatever prefab you slot in"? Also why is there a null there?

Okay, so if they're not explaining this shit, they're not doing a great job at teaching you this shit tbh; what's going on here is called an OVERLOAD.

When you create a method, you can create different like... flavours of the same Method, that all basically do the same thing, but that you can send different inputs to, depending on what you need that method to do.

So if you look at the docs for Instantiate:
Quote
Declaration
public static Object Instantiate(Object original);
Declaration
public static Object Instantiate(Object original, Transform parent);
Declaration
public static Object Instantiate(Object original, Transform parent, bool instantiateInWorldSpace);
Declaration
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
Declaration
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);

depending on what parameters you send the Instantiate command, it will do something slightly different; just spawn something, spawn something as a child, spawn something at a particular place and rotation, etc
Hopefully you can see what its doing with each of those different 'variants'.

They're using the last variant, but they're also sending the 'parent' overload, but sending it as 'null' so it has no parent. If you remove the null completely, shits gonna work just as well.

Also looking at the code for how Doors work in this, why is it using a protected virtual void vs just void? Haven't seen protected and virtual before.

This also falls under the "They really should be explaining this shit" umbrella; what they're doing there is a virtual method; if you try and drag and drop it onto a gameobject, it straight up wont let you (and will probably give you an error about not deriving from monobehaviour).

This is because they're using Inheritance for their pickup scripts; that script there is the 'template' for how all 'pickups' will work, but theyre then going to add slight modifications to each one to be slightly different in code.

Like... I assume they're doing this specifically to fucking teach you about inheritance, because it's not a particularly intuitive way of doing things, and its not like its super efficient to justify doing it like that either.


Also I will try to comment on all code in this project.

I am terrible and did not write a single comment in all my code in my first game.

Sorry, I know that's extremely bad practice :shh

real talk: I can't even count the number of times I've gone back to a piece of old code and been "what the actual fuck is THIS doing?" then found a comment by past me saying something like "this shit here is only so it compiles without complaining, because it wanted a quaternion rather than a rotation" (or whatever), or seen me add a comment like "If I wanna expand this, I'd add blahblahblah here" and been, like, "Damn, thanks past me, you're a bro". It's like the end of Bill & Ted.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #191 on: April 10, 2022, 01:19:54 PM »
Yeah, after two of these classes, it's pretty clear the course I'm taking is a "how to make games in Unity without doing coding" with the unspoken bit of "if someone gives you a bunch of prefabs and pre-written scripts".

Kind of a class for if you're working on a dev team with other people in Unity and someone else is the programmer and doing the code, and someone else is the artists/musician doing the art/music.

It's teaching you how to be a game designer/director with just the most minimal understanding of these other areas to understand how to do some basic things.

The total amount of class lectures on coding in the first game was about 20 mins, the total amount of class lectures in this second game was a single 15 minute video on writing one small script.


When I'm done with this class, and some time frees up, the next class I'll take is a beginners C# in Unity pure coding class. For these months though I'm basically self-teaching myself C# through reverse engineering the provided code and tutorials. To be fair, it is working somewhat this way as non-intuitive as it is. When I read their code now I understand the majority of it and can follow along with what they're doing which I can then use to write my own code for similar objects & actions.

But as you said, they often are doing things in weird ways so it's also teaching me how to do things in not the best and sometimes convoluted ways.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #192 on: April 10, 2022, 02:17:47 PM »
Honestly, that is OK for a first-class.  If you do coding first, it would take a very long time to get into the fun bits.
NtGay

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #193 on: April 11, 2022, 10:01:39 AM »
Honestly, that is OK for a first-class.  If you do coding first, it would take a very long time to get into the fun bits.

I dunno, I'm not really sure of the benefit of doing 'extra' stuff like object pooling in a My First Unity Project that you're specifically pitching as a 'My First Unity Prohect' when you're not going to be hitting any of the reasons why object pooling is a long-term good thing to know; likewise, you really don't need to understand things like polymorphism or virtual classes / interfaces / inheritance to make basic trigger volumes open doors and pick up power ups.

Like... you can show someone how to make a fun platform game in unity just explaining the basics of rigidbodies; you don't need to go into the details of things like character controller collision flags, until you need to start differentiating between things like 'istouchingfloor' and 'istouchingwall' to do things like wall slides / wall jumps, or mario style brick bashing.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #194 on: April 11, 2022, 03:37:28 PM »
Honestly, that is OK for a first-class.  If you do coding first, it would take a very long time to get into the fun bits.

I dunno, I'm not really sure of the benefit of doing 'extra' stuff like object pooling in a My First Unity Project that you're specifically pitching as a 'My First Unity Prohect' when you're not going to be hitting any of the reasons why object pooling is a long-term good thing to know; likewise, you really don't need to understand things like polymorphism or virtual classes / interfaces / inheritance to make basic trigger volumes open doors and pick up power ups.

Like... you can show someone how to make a fun platform game in unity just explaining the basics of rigidbodies; you don't need to go into the details of things like character controller collision flags, until you need to start differentiating between things like 'istouchingfloor' and 'istouchingwall' to do things like wall slides / wall jumps, or mario style brick bashing.

Tbf, the class didn't teach anything about object pooling or even mention it. That's something I learned when doing the bullet patterns tutorial on youtube as that's the method they were using to store and re-use bullets by setting them inactive and active again. One of my friends who does non-gaming coding was really unhappy with that and basically said you should not be setting things inactive instead of destroying them unless you really need to, because that's just more stuff that is going on and needs to be kept track of and managed by the system.

And with the collision stuff within 2d collider I think it's because they do want us to understand their code which uses "istouchingground, istouching wall" and stuff to modify and use for our own. Like they provide enemies you can kill by jumping on their head and it's setup in a way of feet & head having their own tag and collider recognizing if feet of player are touching head of enemy then do damage.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #195 on: April 11, 2022, 03:44:34 PM »
Anyhow, I'm hitting a wall/burnt point trying to get started on my 2nd project.

I have the concept for the game, but it's very art/music/writing focused over gameplay mechanics which are probably pretty simple and I don't expect any issue pulling off. Whether people like the game or not will depend 90% on if the art/music/writing resonates.

Spent so many hours last week and over the weekend trying to learn piano and trying to translate short tunes I'd make on a virtual piano to a midi note program. Never sounds the same. I figured if I can make the title screen song it'll get me going for the whole project, but no luck. It's supposed to be a slow sad melancholic piano tune, but I haven't really learned how to make those. As a side effect I've made a couple decent songs that I can use elsewhere in the future.

Also spent time on main character sprite & animations. It's ok but it's not looking as good as I want. In my mind I'm imagining like SNES quality sprite-work but what I'm making is like GB/NES quality. I thought I'd sidestep running animations with using wheels for feet but trying to animate a tiny 8 pixel wheel when a wheel looks the exact same at every rotation was really hard. Had to find some examples and ended up making the wheels larger than I wanted to have a couple pixels that would move every frame to show the direction of motion in the wheel. I honestly think feet probably would've be easier haha.


I've been spending all my time outside work on this stuff and all I dream every night is of trial & error coding adjustments. Feeling a bit stressed and down by the quality of progress on the music/art side.


I think I need to take a break for a bit and enjoy other games and things to get some ideas flowing again.


Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #196 on: April 11, 2022, 07:03:29 PM »
Uncle

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #197 on: April 11, 2022, 08:09:14 PM »
Yeah, I saw that. I don't really have a use for icons at all right now since none of my game stuff has real interfaces yet. But I do eyeball them looking to see if there are icons I can import into a sprite editor and then turn into a non-icon sprite that I could use (like turning a sword icon into an actual sword in the game).

Didn't see any for my current project, also the icons are 256x256 which is way to high-res for the rest of the my art, but I could downsize it and see how it turns out.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #198 on: April 11, 2022, 08:13:10 PM »
I have been kind of skimming youtube vids be "creator" who talk about tips for getting started and not burning out in indie game dev. One guy basically said "for the love of god, just use pre-paid assets from the various stores" because otherwise trying to create all the art/music in addition to the game if you're not an artist will burn you out fast.

I definitely think yeah, it probably makes sense to use temp art/music from asset packs and just make your damn game first and then if the game is any good, you spend time replacing the temp stuff piece by piece with your own stuff and some of it you can leave in place like who cares if your grass looks generic 2d grass.

Problem is that there's no temp assets for writing  :lol
Still gotta write this thing that I want to do.

Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #199 on: April 11, 2022, 08:48:58 PM »
the trouble with pre-made temp assets is that you will find yourself getting locked into certain assumptions about their size, hitboxes, or number of animation frames, so if you do later try to replace them it may involve not-insignificant retooling of parts of the engine as well

but you should forge ahead anyway because the most important thing is getting shit done and having something that works and can be iterated on
Uncle

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #200 on: April 12, 2022, 07:34:12 AM »
Theres also a lot of incredibly good free assets out there, which is why I didn't rate that last humble asset bundle that highly.

Also worth mentioning if you're in a 'I'd rather just buy shit than L2code" mood, the Unity asset store has a spring sale on with a ton of high rated stuff half price, and some flash deals at 70-80% off.
Most of the stuff you buy off of the asset store is generally usable outside Unity as well, but you might have to do a bit of faffing (and check the specific licence ofc)

eg:
Spent so many hours last week and over the weekend trying to learn piano and trying to translate short tunes I'd make on a virtual piano to a midi note program. Never sounds the same. I figured if I can make the title screen song it'll get me going for the whole project, but no luck. It's supposed to be a slow sad melancholic piano tune, but I haven't really learned how to make those. As a side effect I've made a couple decent songs that I can use elsewhere in the future.

quick search on good old incompetech;
https://incompetech.filmmusic.io/song/3440-bittersweet/

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #201 on: April 12, 2022, 03:47:50 PM »
Yeah, grabbing a few things in the sale.

As I've never done anything in 3d besides some Quake & Unreal 9? levels within their engines, I'm hesitant to spend any money on 3d assets because I just don't know if I'll spend a month in 3d and give up and not want to deal with it.

Like I've never used a 3d modeler program like Blender or anything and never made a 3d model.

But there's some cheap nice little 3d asset packs of tons of varied stuff I could just pop in and use in a later project:

https://assetstore.unity.com/packages/3d/props/low-poly-ultimate-pack-54733

https://assetstore.unity.com/packages/3d/characters/humanoids/low-poly-animated-people-156748

So I'm kind of tempted to pick them up.

Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #202 on: April 12, 2022, 03:51:23 PM »
man that looks like it was used to make conduct together

Uncle

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #203 on: April 12, 2022, 04:06:19 PM »
Here's what I ended up buying:

https://assetstore.unity.com/packages/tools/ai/dialogue-system-for-unity-11672



If it's good enough for Disco Elysium and Lake and stuff, it's good enough for me. Especially at 70% off

https://assetstore.unity.com/packages/tools/game-toolkits/adventure-creator-11896



Was always going to pick up Adventure Creator, so 50% off is good.

https://assetstore.unity.com/packages/templates/systems/corgi-engine-2d-2-5d-platformer-26617



This seems like a good flexible 2d/2.5d side scrolling toolkit that I could find use for.

https://assetstore.unity.com/packages/templates/systems/topdown-engine-89636



Same with their top-down engine which is 70% off

https://assetstore.unity.com/packages/templates/packs/2d-rpg-kit-163910



Until RPGMaker Unite comes out, this seems like something can play with for turn-based 2d rpgs in Unity. $30 ain't that much.

https://assetstore.unity.com/packages/tools/game-toolkits/rpg-editor-ork-framework-3-209685



ORK Framework seems to be the best real rpg tool solution for 2d/3d system management and 70% off is much more affordable ($30) than $100. This is supposedly very steep learning curve because it's extremely flexible so this is more for further down the line to have around.

https://assetstore.unity.com/packages/2d/environments/2d-isometric-tile-starter-pack-27944



This was $12.50 and too cool to not want to play around with. I do want to make an isometric 2d FFT tactics game at some point, so should be helpful to just test ideas, especially if I can learn that Ork framework and combine that to a turn-based grid based isometric thing. But at the end of the day it's $12. Even if it's just too oogle some nice pixel art I'm ok with that.

https://assetstore.unity.com/packages/3d/gui/modular-3d-text-in-game-3d-ui-system-159508



Also $12.50 and kinda gives me something I want at this point which is an easy to drop in 3d text gameobject I can drag around the scene. Not sure if I'll be able to use it in a 2d project, but probably helpful for my 3d projects. This was definitely the most skippable one I bought, but at $12.50 I'm not gonna be hurting if I don't end up using this.

Finally, this wasn't on sale (I wish it was), but I actually want to use this on my current 2d platformer game with a heavy story focus because I really like the extra polish of animated text.

https://assetstore.unity.com/packages/tools/gui/text-animator-for-unity-158707




My main interests in the long-term are dialogue heavy adventure and rpgs, so that's basically the stuff that appealed to me. I do want to make a visual novel, and there is this VN engine in Unity called Naninovel at 50% off

https://assetstore.unity.com/packages/tools/game-toolkits/naninovel-visual-novel-engine-135453



But $75 is a lot of money and I googled around and people seemed to say that if you just want some static backgrounds and characters and dialogues with a few branches use Ren'Py which is free over Naninovel. So I plan on using that:

https://www.renpy.org/latest.html



The one thing I do like in that Naninovel vid is the rain/snow sfx and animated video backgrounds like if I filmed locations with my phone camera and used them as the backgrounds for my VN. But yeah, $75 is a lot and apparently it's a lot more code heavy than Ren'Py, though if you want to do anything interesting in Ren'Py you need to learn some Python which is what Ren'Py uses.



« Last Edit: April 12, 2022, 04:12:58 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #204 on: April 12, 2022, 04:54:08 PM »
Also, I spent last night with Mixcraft and LMMS. It's very different from loop based Bosca Ceoil, but with some time and effort and piano classes and music theory classes I could see myself getting somewhere with it. It's just finding the time, while working full time, to:

-Learn music theory
-Learn piano keys
-Learn how to replicate the chords you want by string (I know Em/G/C/A/D/etc... on guitar fingering, but in digital keys I can't currently translate it)
-Learn how to use a real DAW like Mixcraft/Ableton, including learning how to use plugins

along with

-Learn how to draw
-Learn how to animate
-Learn more about how to use Aesprite features

along with

-Learn how to code C#
-Learn how to use Unity
-Learn how to game design/create

-Learn how to write dialogue
-Learn how to write game scenario

etc...it's definitely more than overwhelming trying to learn jack of all trades at the same time. Would be much smarter to focus on learning one aspect at a time.

But my problem with using pre-made music assets is basically a consistency issue. First it's tough to get exactly the sound you're looking for with some pre-made music and second of all there's no way to have your whole game be musically consistent unless you're using an entire pack by the same musician in which case you're gonna be extremely limited in how your game sounds.

Whereas with visual assets it's pretty easy to pick and choose and mix in with the rest of your assets. Same with sfx. Really just music that sticks out if it's not consistent in style. Like my chiptune music ain't gonna work with a clear orchestra piece.
« Last Edit: April 12, 2022, 04:58:48 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #205 on: April 13, 2022, 01:34:10 AM »
Ok, back to actual coding stuff and questions. Worked on the actual game a little tonight.


1. So for my texts in my platformer, since I am just going with what I've done in the past and has worked, I'm having text pop ups be inactive children under an invisible gameobject with a collider so when you walk past it sets the canvas child to active and the text pops up. I also have the canvas on world space so you can walk past the text and it doesn't stick with the camera.

Is there a better way I should be doing this for text pop ups as I walk by stuff?

2. I got A LOT of red scary errors every scene in my first game doing this because at times there were no children (because the text pop ups were on self-destruct timers) and the code said to "set child active". The game still compiled and ran fine, but if I want cleaner code ideally I would like to add a statement that says:

"If (gameobject childCount != null) { set child active }"

But after spending 20-30 mins on google I can't find a way to make an if statement that checks if the object's childCount is 0 or null.

Transform.getChildCount is supposed to return an int telling the # of children, right? So why does visual basic not let me say if Transform.getchildCount != 0).

It says

"Error   CS0019   Operator '!=' cannot be applied to operands of type 'method group' and 'int'"   

How do I make this if statement to clean up my code so it has fewer errors?

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #206 on: April 13, 2022, 06:11:27 AM »
if you wanna dabble with 3D modelling but without getting into 3d modelling, have a play with MagicaVoxel which is literally 3D pixel art and real easy to get decentish results with.

For your VN aspirations, do you need to buy anything more than that dialogue system you already bought?
Seems to me, that's most of the heavy lifting - store/recall options and choices and display on screen?
Also you might wanna check this out, I dunno why its been delisted from the unity asset store...?

for your code stuff, its telling you you cant assign a value check to a method like that; you could do something like
Code: [Select]
for (int i = 0; i < object.GetChildCount(); ++i)
{
     setactive(object.GetChild(i)(true);
}

or on the child object you could just have something like
Code: [Select]
gameobject yourUICanvasForYourPopUp;
Oncollisionenter()
{
     yourUICanvasForYourPopUp.setactive(true);
}

Oncollisionexit()
{
     yourUICanvasForYourPopUp.setactive(false);
}

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #207 on: April 13, 2022, 03:26:36 PM »
I get the first piece of code you wrote. Still seems silly that if childcount is returning an int that you can use in a < for statement that you can't use it in a < if statement, but w/e works.

For the second bit, isn't the problem that the child object will be set active false as default so you can't have the collision occur to active it and set it true? That's why I'm attaching it as a child to a gameobject that's active with colliders (but invinsible opacity).


Oh and on the VN bit, yeah I could easily make a VN right now just by even making a scene, throwing on a raw jpg background, a character sprite in front of it, throw in an audio source BGM, and then put some text that you can advance and move to the next scene. But the point of VN engines is to enable developing and iterating and testing that extremely quickly like you're just writing stuff in Word and then you have your game. Since they are very low level game interaction design, it's basically just whatever lets you type in a bunch of text and get it to display and move between scenes the quickest.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #208 on: April 14, 2022, 04:19:45 AM »
For the second bit, isn't the problem that the child object will be set active false as default so you can't have the collision occur to active it and set it true? That's why I'm attaching it as a child to a gameobject that's active with colliders (but invinsible opacity).

I think I said earlier, getting used to unity, think of it like pumbing or electrical engineering, where you can have triggers and components as seperate things, and then 'wire them up' in the inspector - you don't have to turn the trigger volume 'off' ever, you just need to 'plumb' the thing you want to turn on/off into in the inspector.

Lemme give you my generic trigger script; just drag and drop whatever you want to be enabled/disabled into the slot, then set how you want the trigger to work
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// this is a box trigger, so it needs a box collider
[RequireComponent(typeof(BoxCollider))]
public class BasicTrigger : MonoBehaviour
{
    // cache collider
    BoxCollider col;

    // expose trigger target
    [SerializeField]
    GameObject targetObject;

    // drop down for trigger behaviour
    enum TriggerType
    {
        OneShotActivate, // run once, then stop
        Destroy, // destroy target then stop
        ToggleOnOff, // turn thing on while in trigger area, turn off when you leave
        ToggleOffOn // turn thing off while in volume, on when leave
    };

    // expose in editor
    [SerializeField] TriggerType triggertype;

    // boolean to stop scripts after a one shot has activated
    bool oneShot;

    // on awake cache references
    void Awake()
    {
        col = GetComponent<BoxCollider>();
    }

    // setup default values
    void Start()
    {
        col.isTrigger = true;
        oneShot = false;
    }

    // unity specific method; will draw the outlines of the trigger volume in an obvious red colour in the editor window
    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireCube(transform.position, new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z));
    }

    // what do we do when something enters this trigger volume?
    void OnTriggerEnter(Collider other)
    {
        if (oneShot) { return; } // stop if it was a oneshot thats fired
        else if (triggertype == TriggerType.OneShotActivate){ OneShotActivate(); }
        else if (triggertype == TriggerType.Destroy)        { OneShotDeactivate(); }
        else if (triggertype == TriggerType.ToggleOnOff)    { TargetTurnOn(); }
        else if (triggertype == TriggerType.ToggleOffOn)    { TargetTurnOff(); }
        else Debug.Log("Entered Trigger");
    }

    // what do we do when something leaves this trigger volume?
    void OnTriggerExit(Collider other)
    {
        if (oneShot) { return; } // stop if it was a oneshot thats fired
        else if (triggertype == TriggerType.OneShotActivate){ return; }
        else if (triggertype == TriggerType.Destroy)        { return; }
        else if (triggertype == TriggerType.ToggleOnOff)    { TargetTurnOff(); }
        else if (triggertype == TriggerType.ToggleOffOn)    { TargetTurnOn(); }
        else Debug.Log("LEft Trigger");
    }

    void OneShotActivate() { oneShot = true; TargetTurnOn(); }

    void OneShotDeactivate() { oneShot = true; TargetTurnOff(); }

    void TargetTurnOn() { targetObject.SetActive(true); }

    void TargetTurnOff() { targetObject.SetActive(false); }
}

You can have an absolute fucking ton of trigger volumes in a scene; if they don't have a meshrenderer enabled they 'cost' fuck all in terms of rendering, and if they're set as triggers they cost almost fuck all until they're actually interacted with (there's a nominal 'cost' in that they exist in the scene and are pre-allocated accordingly).
You can gain a minor performance saving by setting them to 'static' in the inspector checkbox too (so the engine knows to never bother trying to do any physics or lighting calculations on them) - that's just a good practice to get into for things that will never move.
« Last Edit: April 14, 2022, 04:23:46 AM by GreatSageEqualOfHeaven »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #209 on: April 14, 2022, 04:32:09 AM »
Appreciate the code.

Do you have to put the targetObjects as children? Or can you target other objects in the scene that aren't placed as children of this?

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #210 on: April 14, 2022, 04:50:27 AM »
Generally speaking, you only want things as children if they make sense as children (although its super common to have 'master' objects called _scenery or whatever that then parent everything in a scene for organisation).

'plumbing' things together means you don't need any actual connection links other than the ones you make in code

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #211 on: April 14, 2022, 02:42:02 PM »
So I get the plumbing analogy and the code your wrote, but I think what I'm missing is the real world piece that ties it all together.


Let's say I have a scene that is a hallway, I want a trigger on the left side that when the player passes through it, a wall of flame appears on the opposite side blocking their path.

Using your code, if I put the Wall_of_Flame object as a the first child to an empty gameobject which I attach your script to, and set the last two lines to read

Code: [Select]
  void TargetTurnOn() { transform.GetChild(0).gameObject.SetActive(true); }

    void TargetTurnOff() { transform.GetChild(0).gameObject.SetActive(false);; }

This should work.


But if I had Wall_of_Flame game object not as a child and just sitting separate in the scene hierarchy. How would I write those two lines of code?






GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #212 on: April 14, 2022, 04:19:39 PM »
I think you've got hung up on the idea of child objects...?



If you just have 2 objects in a scene - no children in either - and ones the trigger and ones the target (wall of fire as requested), you can literally drag and drop anything in the hierarchy into the slot for that variable in the inspector with the trigger selected.

Basically everything in Unity is a Gameobject, so if in doubt you can manually assign anything to a gameobject variable, and then get any / all required components from that  (its not the best way, but its the easiest to start with).

Anything already in the scene, you can direct assign in the inspector
Anything you instantiate you can assign at instantiation
Anything with a collider you can assign on collision

there's other ways of getting scripts talking to each other, but like... the above 3 are your bread and butter until you start moving into completely different design patterns, like observers or delegates

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #213 on: April 14, 2022, 05:20:29 PM »
 :neo

Woah, it all makes sense now.

I'd been using scripts with public gameObject variables for like instantiating death effects and you plug and play drop the death effect you want to be spawned.

But I didn't realize that once you drop a gameObject into there that you can control it with your script like turning it off & on. This is great and opens up a lot of potential, plus compiling errors relying on children objects.


Can you run methods on it that aren't contained in your script and change the gameObject internally that way? Like say instead of setting targetObject to active(true), can you tell targetObject to givepoints_and_die() if targetObject has a script on it that contains the method called givepoints_and_die()?

Or if there is a health script on the object with a public currenthealth int variable and you want to take that currenthealth and subtract 5 HP? Like you walk by a switch and WallofFire goes from 10HP -> 5HP without actually colliding and contacting WallofFire?

And can you change the internal parts of that Gameobject? Like say you want to change it's size and it scales to 1.5x size when you pass through the trigger.
« Last Edit: April 14, 2022, 05:25:19 PM by Bebpo »

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #214 on: April 14, 2022, 05:38:20 PM »
yeah, if you have a pointer to it, and its a public method - so like, if you have a script called EnemyHealth which has a
Code: [Select]
Public int TakeDamage(int dmg)
{
     int deathValue=100;
     myHealth-=dmg;
     if (myHealth<=0) { DoDeathAnim(); return(deathValue); }
     else return(0);
}

then on a playerscript that hits that enemy, you can do
Code: [Select]
gameobject enemy;
currentScore+=enemy.getcomponent<EnemyHealth>().TakeDamage(bulletDamage);

or whatever


Everything in Unity is essentially a GameObject, and every GameObject has at least 1 component (Transform).
You can cache pretty much anything as a variable, even scripts, as a variable of <T> (type) Scriptname, and if you have a pointer to it, you can modify or run anything at an appropriate access level (so public means anything can access it with a pointer).

Its usual to have public GET and private SET stuff, so you never directly modify varaibales from another script, but have public getters and setters to do that for you with whatever safety checks you need in that script

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #215 on: April 14, 2022, 05:51:07 PM »
What's an example of SET? Or do you just mean the initial settings of variables as private? Though they need to be public to be gotten so yeah a bit confused on what you mean by SET.


That's a very helpful example of getcomponent and running a method from within it. Pretty sure I understand how to do that now.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #216 on: April 14, 2022, 06:09:07 PM »
yeah, I just capsed it as a keyword, its not an acronym.

You can use { get; set; } on a variable to create a property in a class as an autoproperty, where you actually have 2 variables (one public which you can get, one private which you can set) accessible from the same call, depending on what you're doing (kind of like Overloads, which we looked at earlier with the instantiate function).

But let's say... we don't want anything modifying PlayerHealth (script or variables) directly for safety / sanity reasons.
Instead of making playerHealth public, and potentially fucking things up by going into sub-zero health and becoming unkillable or whatever (it happens to the best of us, although any health checks should do <=0 rather than =0 just as good practice) we'd just have some public methods instead, like
Code: [Select]
public int GetHealth()
{
     return(currentHealth);
}

public void SetHealth(int change)
{
     currenHealth+=change;
     if (currentHealth > maxHealth) {  currentHealth = maxHEalth; return; }
     else if (currentHealth <= 0) { currentHealth = 0; DoDeathSequence(); return; }
}

to ensure any checks you need to do are always run

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #217 on: April 14, 2022, 06:19:56 PM »
But...both of those methods are still public and the variable currentHealth can still be messed with. What's private there?


Also why do you put return at the end of the if statements? Since it's void, doesn't that mean nothing is returned back to whatever is calling it? Does return stop it from running the next else if statement?

Because I mentioned in my first game I would have if/else statements where it would do the IF and then go ahead and do the ELSE after and I'm like wtf. But I didn't use "return" at the end of my if statements.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #218 on: April 14, 2022, 06:32:20 PM »
the difference is basically you only have one thing that can change the var currentHealth rather than being able to do PlayerHealth.currentHealth = whatever if it was a public variable; its generally safer to restrict what can access what to things that only need to when needed, and that goes doubly for setting stuff

using return; and break; as soon as I'm done is just my bad habits  :lol

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #219 on: April 14, 2022, 06:59:05 PM »
Got it!

Thanks.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #220 on: April 14, 2022, 09:48:27 PM »
So kind of in addition to this stuff, been working on a game plan of learning art/music.

I've watched a few pixel art guides on youtube. HOLY FUCK are the streamers ADHD youngin' that are annoying at times, but if you can ignore the cringe, they're very helpful to see art & animation being made step by step. Where they add shadows, texturing, highlights, what keyframes they use, how they animate inbetweens.










The house one was really, really helpful. I wanna try to recreate this on the weekend. Beanie guy isn't particularly annoying.



This dude is annoying AF, but very helpful tips for keyframing and doing small but expressive animations.

I haven't watched this one yet on designing character sprites, but will do so:





Also one nice thing about Coursera is you don't pay per class, you pay $50/month and it seems like all the classes are free and there are courses in any subject you are interested in. So in addition to this game design class I signed up for a pixel art one and a music theory one:

https://www.coursera.org/learn/develop-your-musicianship/

https://www.coursera.org/learn/pixel-art-video-games/home/

The only problem with the pixel art one is it's based off photoshop whereas like every online tutorial says don't use photoshop for pixel art and stick with stuff like Aesprite. The fundamentals will still be the same but it may be harder to follow and match up with without photoshop.

The first guy in my links has a 3 hour fundamentals in Librasprite/Aesprite for $20, so I might go through that as well:
https://www.gamedev.tv/p/pixel-art-fundamentals/?coupon_code=SPRING

One thing Coursera didn't have is a videogame music making class. I'm sure there are those, but I guess if I can just learn some basic music making in general I can translate that over.


Anyhow, from what I've seen and done, I feel like getting ok at pixel art isn't something out of reach and I feel for making indie videogames that if you can make pixel art/textures and you can code and game design then you can pretty much make games. Music is a thing too for sure, but you can't make a game without art and you can make a game with just art and no game. So I'd like to get halfway decent at pixel art and coding/game design as I think that'll take me pretty far and let me make whatever I can think of into actual game stuff.

If I can make some ok music too after classes/tutorials that will be nice as well, but if I totally fail there I am ok passing the torch to a musician. Same with art if I was making a game that I'd sell for like real $10 kind of money, I'd probably hire an artist to redo all my pixel art but better, but my art would be good enough for prototypes and free indie games.




Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #221 on: April 14, 2022, 09:51:32 PM »
https://2dwillneverdie.com/tutorial/

Also I read all the blogs at 2dwillneverdie. Lots of good stuff though it's more for intermediate/advanced level. Was interesting reading how to go from vector art piece to like a SF2/MvC background piece.

https://2dwillneverdie.com/tutorial/pixel-a-capcom-background/

https://2dwillneverdie.com/tutorial/instant-pixel-art-backgrounds-with-the-dan-fessler-method/

They also recommended this 242 page book on pixel art fundamentals which I picked up and started reading:

https://michafrar.gumroad.com/l/pixel-logic


GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #222 on: April 15, 2022, 07:43:52 AM »
https://www.youtube.com/c/MortMort

this dude had some pretty good pixel art tuts for when I was trying to get the basics down for gamejams etc to not produce shit

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #223 on: April 16, 2022, 04:02:53 AM »
I don't know why I do this to myself, I guess I just like buyer's remorse or something, but I find myself googling and reading lots of articles on best beginner game engines and a lot of people seem to think Godot with its Javascript-ish language and GameMaker with its own GDL language are better entry level stuff for solo devs on 2d projects than Unity and it's faster and easier to iterate. People are like "I watched a couple of tutorials and then within a few hours in Godot I had my own cool game running" which makes me do a double take because wat. From scratch to a game took me a while in Unity. Apparently some games are even made in Phaser.

Then again, since I'm getting past the initial hump of C#/Unity and figure out how to use sceneloader, timers, triggers, tilemaps, etc..., I wonder if that kind of talk is less relevant because when people recommend the other stuff they mean for like getting going right away and not learning any of this?

Idk. Everyone seems to say if you're making a 3d game Unity is the way to go, so maybe when I move to 3d projects I'll feel less unsure if I'm spending my time using the right engine. Also learning C# and Unity for 2d stuff will be helpful for doing 3d stuff in C# and Unity so it's still good to learn/use/get comfortable with.

In other news Steam recommended me this software from 2015 called Crocotile that is a low-poly 3d editor with tilemaps. The reviews are good and say it's sort of the Aesprite of 3d, like if you want to dip your toes in 3d art without learning Blender and Maya and serious shit, then this is a good way to quickly and easily make low-poly 3d assets that you can export and use in your Unity/Godot/GameMaker/whatever game.



Looks neat. When I get to my 3d project next I may give this a try to make some 3d models for my 3d fps project game that is after this 2d platformer game. Low-poly is perfect for FPS since it's in style with stuff like Dusk and what not.

archnemesis

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #224 on: April 16, 2022, 05:46:31 AM »
There are pros and cons with all game engines.

I've tried Godot. It's pretty neat, especially when you're working from, or are targeting, weaker computers. After a while I realized that I would rather improve my C# (Unity) or C++ (Unreal) skills and went back to those alternatives.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #225 on: April 16, 2022, 01:12:01 PM »
For me, it's like I don't have any need to learn marketable skills for future job stuff and I don't think I'll ever work with a team larger than like 4 people and only that if I have a good prototype which feels like I could sell it for $20 and I'd invest in hiring a few people for a 1-2 year dev job. So idk. But Unity is fine for now. It's what I'm already onboard with and starting to get some initial grasps of.

Anyhow, finally have some free time this weekend so spending the whole weekend prototyping 1-2 room ideas to try to find a concept that is fun for my current project. As a side effect I came up with some really fun/doable ideas for future projects but they aren't a fit for this, they need to wait until I hit 3d and learn some 3d skills and they aren't a "make the whole game in 2 weeks" kind of ideas and probably need a few proper months to do.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #226 on: April 16, 2022, 01:54:28 PM »
For the second bit, isn't the problem that the child object will be set active false as default so you can't have the collision occur to active it and set it true? That's why I'm attaching it as a child to a gameobject that's active with colliders (but invinsible opacity).

I think I said earlier, getting used to unity, think of it like pumbing or electrical engineering, where you can have triggers and components as seperate things, and then 'wire them up' in the inspector - you don't have to turn the trigger volume 'off' ever, you just need to 'plumb' the thing you want to turn on/off into in the inspector.

Lemme give you my generic trigger script; just drag and drop whatever you want to be enabled/disabled into the slot, then set how you want the trigger to work
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// this is a box trigger, so it needs a box collider
[RequireComponent(typeof(BoxCollider))]
public class BasicTrigger : MonoBehaviour
{
    // cache collider
    BoxCollider col;

    // expose trigger target
    [SerializeField]
    GameObject targetObject;

    // drop down for trigger behaviour
    enum TriggerType
    {
        OneShotActivate, // run once, then stop
        Destroy, // destroy target then stop
        ToggleOnOff, // turn thing on while in trigger area, turn off when you leave
        ToggleOffOn // turn thing off while in volume, on when leave
    };

    // expose in editor
    [SerializeField] TriggerType triggertype;

    // boolean to stop scripts after a one shot has activated
    bool oneShot;

    // on awake cache references
    void Awake()
    {
        col = GetComponent<BoxCollider>();
    }

    // setup default values
    void Start()
    {
        col.isTrigger = true;
        oneShot = false;
    }

    // unity specific method; will draw the outlines of the trigger volume in an obvious red colour in the editor window
    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireCube(transform.position, new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z));
    }

    // what do we do when something enters this trigger volume?
    void OnTriggerEnter(Collider other)
    {
        if (oneShot) { return; } // stop if it was a oneshot thats fired
        else if (triggertype == TriggerType.OneShotActivate){ OneShotActivate(); }
        else if (triggertype == TriggerType.Destroy)        { OneShotDeactivate(); }
        else if (triggertype == TriggerType.ToggleOnOff)    { TargetTurnOn(); }
        else if (triggertype == TriggerType.ToggleOffOn)    { TargetTurnOff(); }
        else Debug.Log("Entered Trigger");
    }

    // what do we do when something leaves this trigger volume?
    void OnTriggerExit(Collider other)
    {
        if (oneShot) { return; } // stop if it was a oneshot thats fired
        else if (triggertype == TriggerType.OneShotActivate){ return; }
        else if (triggertype == TriggerType.Destroy)        { return; }
        else if (triggertype == TriggerType.ToggleOnOff)    { TargetTurnOff(); }
        else if (triggertype == TriggerType.ToggleOffOn)    { TargetTurnOn(); }
        else Debug.Log("LEft Trigger");
    }

    void OneShotActivate() { oneShot = true; TargetTurnOn(); }

    void OneShotDeactivate() { oneShot = true; TargetTurnOff(); }

    void TargetTurnOn() { targetObject.SetActive(true); }

    void TargetTurnOff() { targetObject.SetActive(false); }
}

You can have an absolute fucking ton of trigger volumes in a scene; if they don't have a meshrenderer enabled they 'cost' fuck all in terms of rendering, and if they're set as triggers they cost almost fuck all until they're actually interacted with (there's a nominal 'cost' in that they exist in the scene and are pre-allocated accordingly).
You can gain a minor performance saving by setting them to 'static' in the inspector checkbox too (so the engine knows to never bother trying to do any physics or lighting calculations on them) - that's just a good practice to get into for things that will never move.

Hey GreatSage, so I'm trying to use your trigger and it's not working. No compiling errors, but just...it's not doing anything and the object has the box collider on it. Doesn't even reach the debuglog of the collision happening.

I think it has to do with

"void OnTriggerExit(Collider other){}

    void OnTriggerEnter(Collider other){}"

Is OnTriggerEnter/Exit built into Collider? Because otherwise if we're creating those methods, they look identical. How can the game tell if you are entering or exiting a collider box?

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #227 on: April 16, 2022, 01:59:41 PM »


Just for a test I have a blue keycard right past the trigger set inactive and set that as targetobject.

But walking through the red volume box nothing happens. The debuglog doesn't show "entering trigger" so it's not activating.


I tried changing Collider other to Collider2d collision which is what the class script uses for pickup item collisions but that doesn't seem to be working.

*edit* maybe because it's using Box Collider and not Box Collider2d? I'll try changing that in the script.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #228 on: April 16, 2022, 02:12:06 PM »
Ok got it working by using the OnTriggerEnter2D(Collider2D collision) methods instead that my other scripts use:

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// this is a box trigger, so it needs a box collider
[RequireComponent(typeof(BoxCollider2D))]
public class BasicTrigger : MonoBehaviour
{
    // cache collider
    BoxCollider2D col;

    // expose trigger target
    [SerializeField]
    GameObject targetObject;

    // drop down for trigger behaviour
    enum TriggerType
    {
        OneShotActivate, // run once, then stop
        Destroy, // destroy target then stop
        ToggleOnOff, // turn thing on while in trigger area, turn off when you leave
        ToggleOffOn // turn thing off while in volume, on when leave
    };

    // expose in editor
    [SerializeField] TriggerType triggertype;

    // boolean to stop scripts after a one shot has activated
    bool oneShot;

    // on awake cache references
    void Awake()
    {
        col = GetComponent<BoxCollider2D>();
    }

    // setup default values
    void Start()
    {
        col.isTrigger = true;
        oneShot = false;
    }

    // unity specific method; will draw the outlines of the trigger volume in an obvious red colour in the editor window
    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireCube(transform.position, new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z));
    }

    // what do we do when something enters this trigger volume?
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (oneShot) { return; } // stop if it was a oneshot thats fired
        else if (triggertype == TriggerType.OneShotActivate) { OneShotActivate(); }
        else if (triggertype == TriggerType.Destroy) { OneShotDeactivate(); }
        else if (triggertype == TriggerType.ToggleOnOff) { TargetTurnOn(); }
        else if (triggertype == TriggerType.ToggleOffOn) { TargetTurnOff(); }
        else Debug.Log("Entered Trigger");
    }

    // what do we do when something leaves this trigger volume?
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (oneShot) { return; } // stop if it was a oneshot thats fired
        else if (triggertype == TriggerType.OneShotActivate) { return; }
        else if (triggertype == TriggerType.Destroy) { return; }
        else if (triggertype == TriggerType.ToggleOnOff) { TargetTurnOff(); }
        else if (triggertype == TriggerType.ToggleOffOn) { TargetTurnOn(); }
        else Debug.Log("LEft Trigger");
    }

    void OneShotActivate() { oneShot = true; TargetTurnOn(); }

    void OneShotDeactivate() { oneShot = true; TargetTurnOff(); }

    void TargetTurnOn() { targetObject.SetActive(true); }

    void TargetTurnOff() { targetObject.SetActive(false); }

Question: What's the point of col? It's set as col.isTrigger = true at start, but then never used again?

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #229 on: April 16, 2022, 03:49:11 PM »
Ughhh, I just can't even start on this stupid project and it's driving me a bit nuts.

The base template they provided for the platformer just feels BAD. I hate the camera, I hate the player movement, I hate the jumping and sounds, I hate the tilemap collision. It also feels a bit input laggy.

https://dkclassdesign.itch.io/platformer-room1-test

This is a test room just using their preset assets. Just made a few jumps and a goal. You can see how shitty it feels. I just can't get motivated to come up with any fun concepts from this base.

I'm also using player size 1.5x because the default player is so small compared to the tilemaps that a single step is like a monumental jump. But this throws off the physics a bit. The template allows me to adjust movement speed, jump strength, and normally has a double jump which I made a toggle and removed. But I can't find any movement that actually feels decent.

Also painting rooms with tilemaps feels really tedious. I preferred building levels from objects.


Any suggestions on modifying this base template to make the core feel better to actually make a game out of it?


Also another reason I'm running into headaches on this is l don't know how to make 2d room levels. I've never been a mario maker person. Give me an FPS and I can design a level with obstacles and enemies and scenic viewpoints, give me a house to design some puzzles and make a story, ok, but figure out what jumps are fun to jump from one platform to another? I have no idea.

I think I'd probably be better removing jumping and just using switches and triggers to get around things with moving platforms/puzzles.
« Last Edit: April 16, 2022, 03:53:12 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #230 on: April 16, 2022, 04:59:10 PM »
So, adding some heavier gravity to the rigidbody helps come down quicker and feel better and I adjusted the collider box on the feet to be tighter so less floating in the air when not on a step.

The main control issue I'm having now is if you hold forward mid-jump while hitting a wall you just...stick to the wall instead of falling down like nothing happened. Looking through the scripts and stuff not sure what causes this. I guess you need a script that checks if you're hitting a wall and tells the movement to move downwards?

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #231 on: April 16, 2022, 06:05:00 PM »
Oh whoops, the link wasn't working.

https://dkclassdesign.itch.io/platformer-room1-test

Yeah, just messing around this is where I'm at with the template before I even start trying any ideas. Issues I have with the basic movement is the sticking to walls in air problem mentioned in my last post and uh, how do you make moving platforms actually move the player as well?

Also for moving platforms at first I tried attaching a movement script to tilemaps so it would fit in, but that didn't not work because it moved the entire stage on that tilemap layer I made.

So I did it the old fashioned way with game objects and tried to use the ground texture but then I'm stuck with just one texture instead of left side/center/right side texture you'd see in a tilemap on a row that is 3 blocks long. I guess I could just open aesprite and max a texture of those 3 tiles together and use that. I wonder if there's any easier way.

Wait, there is a script called playerChilder which is supposed to move the player while on moving platforms, but it doesn't work? Weird. Just read through it and outside comments it's like 4-5 lines. Not sure why this wouldn't work when the script is on the platform and the player has the player tag.

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// This class will make the player a child of whatever it is attached to
/// It is meant to be used with the moving platform to keep the player moving along with the platform
/// </summary>
public class PlayerChilder : MonoBehaviour
{
    /// <summary>
    /// Description:
    /// Built-in Unity function that is called whenever a trigger collider is entered by another collider
    /// Input:
    /// Collider2D collision
    /// return:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collider that entered the trigger</param>
    private void OnTriggerEnter2D(Collider2D collision)
    {
        MakeAChildOfAttachedTransform(collision);
    }

    /// <summary>
    /// Description:
    /// Built-in Unity function that is called whenever a trigger collider stays inside another collider
    /// Input:
    /// Collider2D collision
    /// return:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collider that is still in the trigger</param>
    private void OnTriggerStay2D(Collider2D collision)
    {
        MakeAChildOfAttachedTransform(collision);
    }

    /// <summary>
    /// Description:
    /// Built-in Unity function that is called whenever a collider exits a trigger collider
    /// Input:
    /// Collider2D collision
    /// return:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collider that exited the trigger</param>
    private void OnTriggerExit2D(Collider2D collision)
    {
        DeChild(collision);
    }

    /// <summary>
    /// Description:
    /// Makes the passed collider a child of the transform that this script is attached to
    /// Works only for the player character but could be expanded to work for non-player characters
    /// Input:
    /// Collider2D collision
    /// Return:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collision to make no longer a child</param>
    private void DeChild(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            collision.gameObject.transform.SetParent(null);
        }
    }


    /// <summary>
    /// Description:
    /// Makes the passed collider a child of the transform that this script is attached to
    /// Input:
    /// Collider2D collision
    /// Return:
    /// void (no return)
    /// </summary>
    /// <param name="collision">The collision whos transform will be childed</param>
    private void MakeAChildOfAttachedTransform(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            collision.gameObject.transform.SetParent(transform);
        }
    }
}

Ok, solved it. Platform has 2 box colliders, one for physical collision stopping you from falling through it and another for triggering and the one for triggering has two green boxes? one causes the trigger and the other is like a wall? 

nm, this fixed the wall sticking:

« Last Edit: April 16, 2022, 06:27:23 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #232 on: April 16, 2022, 06:48:52 PM »
Wrote a small teleport object script in a few mins and it worked. Not sure if there's a better way than just plugging in the player object and the destination but it works.

Code: [Select]
public class Teleporter : MonoBehaviour
{
    public GameObject teleportPoint;
    public GameObject Player;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (teleportPoint != null) { Player.transform.position = new Vector2 (teleportPoint.transform.position.x, teleportPoint.transform.position.y+1); }
    }
}

Also I'm guessing for buttons you step on, you'd just put an invisible collider trigger a bit above the button and on triggerenter you'd have it swap sprites to a pressed button (maybe also instantiate a transition animation and sound effect) and then trigger whatever you want (like a platform moving) and then on colliderexit swap it back to the original sprite with the transition effect? Need to look up how to code a sprite transition. Or maybe you just swap between two different game objects that you plug in beforehand in the inspector? (pressed button, non-pressed button).
« Last Edit: April 16, 2022, 07:04:48 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #233 on: April 16, 2022, 08:23:30 PM »
So this code uses it's own playerinput instead of the built in Unity one to get keys. So like normal Input.getKeyDown no longer works.

So I just spent like an hour reverse engineering so I can get other inputs and have other scripts use them if I want. Works, but man that was way too much of a pain in the ass. Good learning though. But why use your own playerinput grabber?

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #234 on: April 16, 2022, 09:02:50 PM »
Got pushable crates interacting with switches and crates riding moving platforms.

I guess the one thing I still haven't figured out is the best way to just deform a button so your character actually sinks down with it when it's depressed. Unfortunately all google searches for "button" just give results about UI buttons not in-game buttons you can step on. Like I get I could trigger an animation of it depressing and swap out sprites with a sound effect, but that would just be flat stuff happening that wouldn't physically interact with the player.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #235 on: April 16, 2022, 09:58:31 PM »
Spent 40 mins watching vids on how to make a conveyer belt only to discover the way player input is handled in this game overrides the rb velocity so conveyer belt works for crates but not the player :(

Guess I won't have conveyer belts in this project unless your just pushing something that goes and does stuff without you.

Just like project #1 while all the stuff pre-built into the template they've given me saves dozens of hours and building it all out (movement/camera), it's also going to constantly restrain design ideas because they do methods in their own ways which don't jive with how online tutorials do things.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #236 on: April 16, 2022, 11:09:30 PM »
Been making various scripts that seem like they could be useful.

GreatSage, any idea what is going on here? I used your on/off trigger to enable a crate spawner. On the first enable it spawns a normal crate, but then every enable afterwards it spawns a really thin crate wtf?





The spawner code is super simple:

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    public GameObject Spawnitem;

    void OnEnable()
    {
        if (Spawnitem != null)
        {
            Instantiate(Spawnitem, transform.position, Quaternion.identity, null);
        }
    }

Well, switching it to the prefab crate instead of some random crate in the map seems to fix it so who knows, but it's fine.
« Last Edit: April 16, 2022, 11:21:37 PM by Bebpo »

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #237 on: April 17, 2022, 03:15:02 AM »
I don't know why I do this to myself, I guess I just like buyer's remorse or something, but I find myself googling and reading lots of articles on best beginner game engines

I'm just gonna repeat myself again on this one; there is no 'best engine', there's a best engine for you. My best fit is Unity.

Give everything you can a try, and see what fits your style best; pay particular attention to any little niggles that you can see might become dealbreakers - like, I hate how fucking long it takes Unity to boot up on initial load, but if I'm working on a project, I'm not stop starting enough for that to be a problem while I have a coffee and check emails and stuff at start of the day; the pros far outweigh the cons for me, and I'm used to it.
Having said that, some of their recent decisions have had me questioning sticking with it, because jfc their multiple render pipeline shit is a hot fucking mess, but it looks like they're walking back some of that shit and focussing on stability and speed again with the latest release, instead of wtf they were chasing for the last couple of years because Unreal had them shook.

You're gonna find a lot of cheerleaders for Godot not so much for what it is, but for what it represents, for the same exact same reasons you'd find a lot of linux cheerleaders in the early 2000s on just giving up on windows and going full linux instead, and those people might have been happy to do that but I'm not (no shade, linuxians).

Game Maker fucking sucks nowadays tbh, I think most recommendations are leftover goodwill from the old version; I really don't see why someone would pick it up over the competition nowadays. If you want drag & drop coding, you're better off with construct and if you want an actual IDE you're better off with godot.

In other news Steam recommended me this software from 2015 called Crocotile that is a low-poly 3d editor with tilemaps. The reviews are good and say it's sort of the Aesprite of 3d, like if you want to dip your toes in 3d art without learning Blender and Maya and serious shit, then this is a good way to quickly and easily make low-poly 3d assets that you can export and use in your Unity/Godot/GameMaker/whatever game.

Looks like Blockbench jacked their style and freewared them  :lol

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #238 on: April 17, 2022, 03:19:19 AM »
Ok got it working by using the OnTriggerEnter2D(Collider2D collision) methods instead that my other scripts use:

<snip>

Question: What's the point of col? It's set as col.isTrigger = true at start, but then never used again?

Oh, yeah, that wasn't stuff I wrote for you, it's a code snippet I use a bunch because its real useful - just assume anything I write is using 3D physics and swap accordingly for 2D for your purposes.

I set the collider to be a trigger volume rather than a collision volume at the start of my script so I don't have to bother doing it in the inspector (same reason as I use requirecomponent).
I can just place and resize a cube where I want my trigger to be, then drag and drop my trigger script onto it, turn off the mesh renderer, drag on the target, then set what kind of trigger it is and I'm good to go.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #239 on: April 17, 2022, 03:40:35 AM »
Ughhh, I just can't even start on this stupid project and it's driving me a bit nuts.

The base template they provided for the platformer just feels BAD. I hate the camera, I hate the player movement, I hate the jumping and sounds, I hate the tilemap collision. It also feels a bit input laggy.

Any suggestions on modifying this base template to make the core feel better to actually make a game out of it?

I'm guessing your platform code is like...
left / right movement = rigidbody.setvelocity(movespeed);
jump = rigidbodyaddforce(up, 30f, impulse);
type stuff?

Soooooo..... yeah.
Here's the problem; if you want 16bit type movement, you can't use 2020 2D physics systems to get it; its gonna feel a lil laggy, and a lil floaty, and most people don't notice / care.
Like... if you find yourself doing shit like cranking up the gravity to living on jupiter levels and adding frictionless skins so you don't get stuck on walls and shit... that's your signal that you want to do something that the thing designed to make like, angry birds type games, isn't going to auto-handle for you.

So, what you're gonna want to be making is a kinematic 2D character controller, throwing 'real world' physics (which is what the inbuilt system is trying to mimic) in the bin, and rolling your own simplified physics systems to get the feel you want, not trying to mimic IRL object interactions.

So, bad news is - that's a bunch of work, and a bunch of more complicated code doing shit like resolving fallspeeds versus jump powers, and raycasting / boxcasting a 'skin' around the player to figure out what and where they're colliding.

Good news is, there's a bunch people have already made, all fairly similar up on places like github with various different usage licences as reference, and also didn't you just buy a platforming engine off the asset store? Because just use that if thats got good gamefeel! You'll have more fun learning how to use that than magpieing bits of youtube tutorials and trying to stitch them together.
If you have a robust 2D character controller, its also super extensible into doing, well, pretty much any fucking thing you've ever seen a platform type game do; grappling hooks, jetpacks, picking up enemies to throw at other enemies, etc etc etc

e:


found this with a lil google-fu, which looks okay.
Bear in mind when they say its a 'no rigidbody' controller, you're probably gonna want a rigidbody in there so collisions can happen even if youre not using any rigidbody commands

Also I'm guessing for buttons you step on, you'd just put an invisible collider trigger a bit above the button and on triggerenter you'd have it swap sprites to a pressed button (maybe also instantiate a transition animation and sound effect) and then trigger whatever you want (like a platform moving) and then on colliderexit swap it back to the original sprite with the transition effect? Need to look up how to code a sprite transition. Or maybe you just swap between two different game objects that you plug in beforehand in the inspector? (pressed button, non-pressed button).

You could do something like an IRL button, where there's a spring collider for the 'button' and the bottom / middle of the collider button activates a trigger volume when its got weight on top of it - like, youre literally pushing the button down for it to activate.

GreatSage, any idea what is going on here? I used your on/off trigger to enable a crate spawner. On the first enable it spawns a normal crate, but then every enable afterwards it spawns a really thin crate wtf?

Well, switching it to the prefab crate instead of some random crate in the map seems to fix it so who knows, but it's fine.

Id guess the input object you were using was paired with another one using a shared collider, so it returned a size of '1' when next to another, which then made it halfwidth when instantiated?
« Last Edit: April 17, 2022, 04:06:04 AM by GreatSageEqualOfHeaven »