THE BORE

General => The Superdeep Borehole => Topic started by: Bebpo on March 23, 2022, 12:36:32 AM

Title: Do any of you code for your jobs?
Post by: Bebpo on March 23, 2022, 12:36:32 AM
I'm taking a basic game design intro class and we got to code/writing scripts (C# in Unity) and wondering if anyone here knows like very basic week 1 kind of stuff because some of it is pretty confusing even though I took some C++ classes like 20 years ago and made calculators and basic programs and stuff.

Like I don't understand how to pull an integer variable from one script (i.e. "currentPlayerHealth") and use it in another script in the same game/scene? Like as a test I wanted to write a script that just pulled that value and displayed it in the console log. But when I try to do that it has no idea what currentPlayerHealth is since it's a variable in another script. I feel like this is the most simple 101 stuff since you write modular and keep various pieces in their own scripts.

Gonna be watching lots of youtube tutorials this weekend and trying to write some scripts.

Also another basic example is I have this piece of code on moving a projectile on screen as it updates:
Quote
private void MoveProjectile()
    {
        transform.position = transform.position + transform.up * projectileSpeed * Time.deltaTime;
    }

I understand everything in that sentence except what "transform.up" is doing? It's saying the new position is the old position + speed x time. Which makes sense. I just don't get what transform.up is doing there.
Title: Re: Do any of you code for your jobs?
Post by: Skullfuckers Anonymous on March 23, 2022, 01:48:29 AM
Been a few years since I’ve messed with unity so apologies if anything is outdated or wrong.

For 1, make sure the scripts are attached to two different objects and then in one object you reference the other object to see that value. Make sure the field is publicly assessable via get, not set.
Code examples: https://stackoverflow.com/questions/35657376/c-sharp-unity-trying-to-access-a-variable-from-another-script

For 2, transform.up is a vector2 (x,y grid) or vector3 (x,y,z grid) object that defines the up direction. For vector2 <x,y>; up is <0,1>, down is <0,-1>, left is <-1,0>, right is <1,0>.
Direction.up * speed * time is you distance the object should move from its current location on the grid.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 23, 2022, 02:11:53 AM
Been a few years since I’ve messed with unity so apologies if anything is outdated or wrong.

For 1, make sure the scripts are attached to two different objects and then in one object you reference the other object to see that value. Make sure the field is publicly assessable via get, not set.
Code examples: https://stackoverflow.com/questions/35657376/c-sharp-unity-trying-to-access-a-variable-from-another-script

For 2, transform.up is a vector2 (x,y grid) or vector3 (x,y,z grid) object that defines the up direction. For vector2 <x,y>; up is <0,1>, down is <0,-1>, left is <-1,0>, right is <1,0>.
Direction.up * speed * time is you distance the object should move from its current location on the grid.

Thanks, both are really helpful.

So if you used transform.down the projectile would go backwards in reverse? aka up moves it forward in a positive distance.

Yeah for the first one it seems like it has to do with this GameObject.find thing. Will mess around but at least that gives me a starting point.
Title: Re: Do any of you code for your jobs?
Post by: remy on March 23, 2022, 06:22:37 AM
Uhh I don't think there is a transform.down. You just transform.up with a negative value

Quote
Like I don't understand how to pull an integer variable from one script (i.e. "currentPlayerHealth") and use it in another script in the same game/scene? Like as a test I wanted to write a script that just pulled that value and displayed it in the console log. But when I try to do that it has no idea what currentPlayerHealth is since it's a variable in another script. I feel like this is the most simple 101 stuff since you write modular and keep various pieces in their own scripts.

Put the currentPlayerHealth variable script on an object in the scene (maybe something like gameManager?) by making an empty or whatever and clicking add component. You can also drag scripts onto objects.

Put the second script on another object

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

public class gameManager : MonoBehaviour
{
   
    public int playerHealth;
    // Start is called before the first frame update
    void Start()
    {
        playerHealth = 20;
    }

    // Update is called once per frame
    void Update()
    {
         if (Input.GetKeyDown("s"))
        {
            playerHealth--;
        }
        if (Input.GetKeyDown("w"))
        {
            playerHealth++;
        }
    }
}



Then in the other script have something like this

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

public class healthCheck : MonoBehaviour
{
    public GameObject manageObj;
    public gameManager manager;
      public int health;
    // Start is called before the first frame update
    void Start()
    {
        manager= manageObj.GetComponent<gameManager>();
     
    }

    // Update is called once per frame
    void Update()
    {
    health= manager.playerHealth;
    }
}
Drag the gameObject that has the manager script on it onto the one the has the second script in the field that will have appeared. Apparently this is the best way to do this in unity.


(https://i.imgur.com/yI08Bsp.png)

You can do it in script but everyone says to just do it like this. The reason I've put get component in the start method and made a random object to use in update is because... calling getcomponent all the time is bad... apparently.

After that if you press w and s the number will change on both in the inspector. You could even add an input.GetKeyDown to the update method on script 2 to Debug.Log the variable if you want.

sorry if my explanation is moronic, i did this stuff as a hobby
Title: Re: Do any of you code for your jobs?
Post by: Nintex on March 23, 2022, 06:49:06 AM
It's been a while since I coded anything in Unity but Remy is right.

It's a bit like LEGO. You first create all the seperate elements you need to build your game (objects and scripts to handle player health, damage, spawning, cloning etc.) and then you use those elements to create the actual game.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 23, 2022, 11:36:39 AM
Thanks Remy, yeah I guess the initial learning curve that I'll need to get past in Unity coding is getting used to mixing pure code with visual unity pieces dragging & dropping together.

My only past experience with code was pure code with no visuals so this whole writing piecemeal scripts to attach to objects as components thing in currently hard to process. But I've only taken like two one hour classes on Unity coding basics so far.

For the first 3 weeks of this class we didn't do any coding and it was all just drag and dropping stuff in Unity with pre-made scripts and textures/audio/prefabs. That was all straight forward. We're just now getting into modifying and writing scripts and that's a big jump there. I'm hoping to get a foothold quickly on basic script writing so I can use their pre-made materials to do some fun stuff.

Also we're supposed to start making our own sprites & animations & music. I know how to do basic music with apps, but gonna have to watch some youtube tutorials on how to make and animate a sprite this weekend because that's something I have zero experience with my entire life so far.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on March 23, 2022, 11:59:14 AM
for better understanding of transform.up:

you can think of it as a constant, it's literally just a stand-in for a number as skullfuckers said

you use transform.up instead of the literal number value because there could be a situation where your game might need to change what is considered to be "up," and in those cases you could change transform.up, rather than needing to track down all the places in the code where you typed a magic number that meant "up" at the time
Title: Re: Do any of you code for your jobs?
Post by: Propagandhim on March 23, 2022, 12:12:01 PM
sounds like fun, bebpo.  post your project when your done!
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 23, 2022, 05:54:51 PM
for better understanding of transform.up:

you can think of it as a constant, it's literally just a stand-in for a number as skullfuckers said

you use transform.up instead of the literal number value because there could be a situation where your game might need to change what is considered to be "up," and in those cases you could change transform.up, rather than needing to track down all the places in the code where you typed a magic number that meant "up" at the time

Thanks, so I'm guessing you define transform.up somewhere? That might be the issue, the code I'm working with from my class doesn't define it anywhere and uses it like a built in command in Unity.

I'm gonna assume the default for transform.up is like 1 unit?  So transform.up + speed (3) x distance (5) = go forward 18 units.

The reason I'm having a hard time understanding this initially is without defining transform.up, if transform.up = 1, then it seems extrafloues? Like if I would think you'd do transform.position (which say is (5,10) = transform.position + speed (3) x distance (5) and you'd still get 18, so from (5,10) you'd move to (23, 28)?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 23, 2022, 05:55:31 PM
sounds like fun, bebpo.  post your project when your done!

hahahahaha, ok but it will be beyond bad.

I'll feel more comfortable positing my next class project after this one since at least I'll have a better understanding of what I'm doing next time.
Title: Re: Do any of you code for your jobs?
Post by: Nintex on March 23, 2022, 07:11:40 PM
Use floats for your calculations so they can be more precise.

This is something Satoru Iwata taught the INT heathens at Nintendo EAD  :heart
Title: Re: Do any of you code for your jobs?
Post by: tiesto on March 23, 2022, 07:45:56 PM
Just curious, which class are you taking? I want to get into Unity dev (I do C# and .NET coding from time to time at work) but was looking for some good tutorials.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 23, 2022, 11:50:40 PM
Just curious, which class are you taking? I want to get into Unity dev (I do C# and .NET coding from time to time at work) but was looking for some good tutorials.

I searched around on Coursera reading reviews of various game development classes and went with this from Brian Winn at Michigan State University.

https://www.coursera.org/specializations/game-design-and-development

It's a 5 month course of 5 separate courses that build on each other.

Month 1 - Intro to game design, intro to Unity, build (or basically modify) an overhead 2d twin-stick shooter template into your own game.
Month 2 - Move into how to design 2d platformers in Unity. Should be more useful since it's an entire month course on just them. Make a 2d platformer by the end.
Month 3 - Move into FPS games in Unity. Make an FPS by the end.
Month 4 - Move into 3d platformers in Unity. Make a 3d platformer by the end.
Month 5 - Make your own original game

I'm at the end of Month 1. I've actually been running it at 2x speed because I enjoy this stuff so I got through all 4 weeks in about 2 weeks and just have the final project to do now which is due in about 10 days. I think it's pretty good so far. The reviews were quite good and most complaints were basically that it skips some of the lower level stuff that the lessons build on top of, so to understand the prefabs and stacks and stuff you need to spend some time on your own googling and youtubing certain things.

But I'd rather have that than a slow course where you spend hours doing basic stuff that puts you to sleep. I can't deal with that stuff and want to speedrun things at my age when learning new stuff. I'm willing to put the energy/time in in batches to get there.

From just looking around at how to do some of this stuff, there's tons of free youtube guides and other classes, but for me I like the idea of having deadlines and actually having to make 5 games in 5 months. Otherwise I probably would lose interest at some point after tinkering around. I'd never done Coursera before, it ain't exactly cheap at like $50/month (though you can take multiple classes at a time if you have the time), but a real class would be a couple hundred bucks for a semester so seems fair and putting money down is another thing that will motivate me to actually put the work in and get this done. I basically need the structure for my own way of learning, but that's different for everyone.

Also the main instructor for the class is pretty good! Good speaker and does a good job making sense of it and he's not too VIDEOGAMEZ cringy or anything. His TA who does some of the stuff though sounds dead inside and is much less entertaining.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 24, 2022, 12:33:16 AM
Quote
Do any of you code for your jobs?

Nah, I got out of that shitshow and now I only code for fun (http://www.thebore.com/forum/index.php?topic=45694.0). ;)
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 24, 2022, 05:52:29 AM
Quote
private void MoveProjectile()
    {
        transform.position = transform.position + transform.up * projectileSpeed * Time.deltaTime;
    }

I understand everything in that sentence except what "transform.up" is doing? It's saying the new position is the old position + speed x time. Which makes sense. I just don't get what transform.up is doing there.

Like Uncle says, that transform.up is a constant for Vector3(0,1,0) - Vectors are basically directions. I'm not sure if they're built in to Unity, or Monobehaviour (I'd guess Unity) but you see that Using... stuff at the top of your script? That's where transform.up is defined for you (probably). Also transform.down, transform.left, transform.forward, etc.

So breaking that script down 100% for you:
Code: [Select]
private void MoveProjectile()
 {
     transform.position += transform.up * projectileSpeed * Time.deltaTime;
 }

 - Thats a private method (can only be accessed from that script) that has no return value (its void) and has no input parameters (that empty brackets at the end)

 - It will move the gameobject it is attached to
      - In Unity's Y-axis
      - by variable projectileSpeed per frame
      - every averaged frame per second (Time.deltatime returns your FPS, and then averages it out so that the movement is smooth regardless of framerate or computer spec - if your PC was running this shit at 100fps, it might move 10 units per frame, if your PC was running it at 10fps it would move it 100 units per frame)

So I can tell that that method is being (or should be being) called from the Update() loop, because Update runs every frame - if you didn't actually want framerate indepedent movement (eg you're deliberately trying to recreate old school bullet hell shmup slowdown when shit gets frantic) you wouldn't be using Time.deltatime at all

I can also tell thats a pretty bad way of doing a projectile, because anything you're going to want to collide with things or be collided with that also moves in Unity is best done using a Rigidbody - manually changing somethings transform is a cheap way of moving something, but can and will fuck up physics interactions at a certain point / speed, and there's not really a good reason to not use even a simple physics movement (or a rb.position over a transform.position).

Like I don't understand how to pull an integer variable from one script (i.e. "currentPlayerHealth") and use it in another script in the same game/scene? Like as a test I wanted to write a script that just pulled that value and displayed it in the console log. But when I try to do that it has no idea what currentPlayerHealth is since it's a variable in another script. I feel like this is the most simple 101 stuff since you write modular and keep various pieces in their own scripts.

Gonna be watching lots of youtube tutorials this weekend and trying to write some scripts.

A lot of YT tuts fucking suck, because they literally go "Wassup guys, did you ever wanna make this mechanic? Cool, ok, do this, then do this, then do this, now hit play, cool huh? Don't forget to like and subscribe!" and don't explain shit, and even worse a lot of them have blatant fuck ups in their code they don't even acknowledge.
So if you got Q's, I can help with A's!

Getting scripts to talk to each other, there's a lot of different ways, but generally speaking, you're going to have some kind of trigger wanting to access a variable, and a LOT of those triggers are going to be collision based, so you just need to have a public method that things colliding with the gameobject can access; for example:

if you've got
Code: [Select]
public class BulletScript : monobehaviour
{
     [serializefield] float bulletSpeed, bulletDamage;

     void Update()
     {
          this.transform.position += vector3.forward * time.deltatime * bulletSpeed; // yeah I know what I said before about this being the bad way of doing this, but you know how to do this
     }

     public void DeleteBullet()
     {
          // you can call this from another script, eg when you spawn it with instantiate set it to self destruct after n seconds if it doesnt hit anything
     }

    void OnCollisionEnter(Collision col) // whatever you hit will be accessible from *this* script as col
    {
        if (col.gameObject.name == BadGuy)
        {
            col.EnemyScript.TakeDamage(bulletDamage);
            // you have a pointer to 'col' because the bullet just hit it, so you can access scripts on the things you just hit,
            // and trigger its EnemyScript via its public TakeDamage method, which takes a paramter youre sending from this bullet
            // - ie how much damage its doing
        }
    }
}

and

Code: [Select]
public class EnemyScript: monobehaviour
{
     [serializefield] float myHealth;

    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.name == bulletPrefab)
        {
            col.BulletScript.DeleteBullet();
            // delete the bullet that just hit you
            // Note I wouldn't actually do this code this way, because order of execution might mean you delete the bullet before it does the damage,
            // but I'm just reinforcing how you can get a couple of scripts to talk to each other on a collision
        }
    }

     public void TakeDamage(float damage)
     {
          // this is called from the bullet hitting
          myHealth -= damage;
          if (myHealth<=0) { fuck im dead }
     }
}

as soon as the Bullet hits the Enemy, they can talk to each others scripts
Title: Re: Do any of you code for your jobs?
Post by: Uncle on March 24, 2022, 08:11:20 AM
for better understanding of transform.up:

you can think of it as a constant, it's literally just a stand-in for a number as skullfuckers said

you use transform.up instead of the literal number value because there could be a situation where your game might need to change what is considered to be "up," and in those cases you could change transform.up, rather than needing to track down all the places in the code where you typed a magic number that meant "up" at the time

Thanks, so I'm guessing you define transform.up somewhere? That might be the issue, the code I'm working with from my class doesn't define it anywhere and uses it like a built in command in Unity.

I'm gonna assume the default for transform.up is like 1 unit?  So transform.up + speed (3) x distance (5) = go forward 18 units.

The reason I'm having a hard time understanding this initially is without defining transform.up, if transform.up = 1, then it seems extrafloues? Like if I would think you'd do transform.position (which say is (5,10) = transform.position + speed (3) x distance (5) and you'd still get 18, so from (5,10) you'd move to (23, 28)?

well I am far from an expert and very rusty

but in this specific case, you are working with a vector3 data type, which is a set of 3 values typically used as coordinates in 3D space in the form (x,y,z)

you're proposing just adding to it, but what happens if you add one number to a set of 3 numbers?

I honestly forget, either the program will throw you an error for mixing data types, or it will add that number to all three components of the vector3

so if you're at (5,10,0) and you add speed (3) * distance (5), that seems like it would result in adding 15 to each element, resulting in (20,25,15), so the object has moved in 3 ways at once in 3D space



instead, what the code is doing is multiplying transform.up by speed (and factoring in time)

so if speed is 3, and you multiply (0,1,0) by 3, you get (0,3,0), and when you add that to your position (5,10,0) you get (5,13,0), a movement only in the y direction (up)

(the multiply by deltaTime is going to shrink the value a lot to some small decimal value, because it's how much it moved in that one frame, 60 frames per second or whatever)



transform.[direction] vectors are intended to be multiplied, and the fact that they have zeroes in them is a way to say, "look I don't care what else is going on in this line of code, but we are only talking about this specific direction here, we're zeroing out everything else"
Title: Re: Do any of you code for your jobs?
Post by: Uncle on March 24, 2022, 08:34:46 AM
I see you were the most recent person to mention Bad Rats on the bore a few months ago  :lol

it's a good example along these lines, one of its many issues is that it's a 2D game that doesn't always apply proper limitations to the Z direction, so objects can fall forward or backward out of the level and completely ruin the whole puzzle

there are many good, easy ways to solve this problem in Unity using its built-in physics controls/constraints, but just as an example here, you could say they DIDN'T multiply their objects' movement by transform.up or transform.right -- they didn't make sure that absolutely 0 movement can happen along the Z axis, and look what happens

https://www.youtube.com/watch?v=4wY4NNGW8LM
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 24, 2022, 01:21:05 PM
Haha, ok that does make sense! I was wondering how Unity would apply a single digit transform to a vector3 and yeah if it applies to the Z axis you're gonna be bad rats fucked. So that makes sense.

Though for this 2d shooter project, being 2d and all I should just be using vector2s the whole time I think?

[lots of good stuff]

Thanks, this is extremely informative. A lot of what you wrote in the code sections is flying over my head but will spend time and try to parse and understand it all later when I have some time.

One comment though, you said the way the projectile code is written is bad and you should be using 2drigidbody. The thing is that my class project using the assets they give us (including that projectile code, which they say is the most simple script included), is using 2drigidbody. Like we had a whole session on rigidbody because when we first made the ship player and put an enemy with projectiles in the projectiles would just pass through the player ship until we added 2drigidboy and definied the hitbox.

Not sure what that means because this is beyond my scope of understanding that the projectile code is setup that way along with using rigidbody for collision.

Also I want to understand what you're saying about time.delta and shmup slowdown because if I can add shmup slowdown to this with a ton of bullets/enemies that would be kind of cool.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 24, 2022, 02:19:44 PM
Though for this 2d shooter project, being 2d and all I should just be using vector2s the whole time I think?

You theoretically could, except there's a bunch of stuff that assumes a vector3 and will error if you give it a vector2 - off the top of my head, transform.position is one of them, and if you send it a vector2 it'll complain.

It'd be easy enough to make a method that takes a Vector2 input and spits out a Vector3 output to fix any of those examples though.


Thanks, this is extremely informative. A lot of what you wrote in the code sections is flying over my head but will spend time and try to parse and understand it all later when I have some time.

the only things you might not be immediately familiar with are
[serializefield] in my variables, and Oncollisionenter() having a Collider callback

[serializefield] is an attribute, that basically means the variable shows up in the unity inspector so you can mess with it outside of code, but you don't have to expose the variable as public (ie you don't need to let other scripts mess with it directly).

OnCollisionEnter is a prebuilt method (like Update() ), but it returns a pointer to the thing it collided with as a variable of type Collider, so you can access it.

One comment though, you said the way the projectile code is written is bad and you should be using 2drigidbody. The thing is that my class project using the assets they give us (including that projectile code, which they say is the most simple script included), is using 2drigidbody. Like we had a whole session on rigidbody because when we first made the ship player and put an enemy with projectiles in the projectiles would just pass through the player ship until we added 2drigidboy and definied the hitbox.

Not sure what that means because this is beyond my scope of understanding that the projectile code is setup that way along with using rigidbody for collision.

Basically, Unity is running 2 simultaneous timers; one is the rendering timer, which by default runs at 60 ticks per second and is called from Update()
The other is the Physics timer, which by default runs at... 25? ticks per second, and is called from FixedUpdate()

A rigidbody component basically just tells Unity the thing its attached to has 'physics' and it should keep an eye on it for things like collisions.

Generally you want to put anything physics related into FixedUpdate rather than Update, so Unity knows about it and is checking on the physics tick, not the rendering tick.

So if you just wanted to have like... clouds and shit flying past in the background, you could use a basic transform.position on them in the Update() loop.

Something like a bullet though, you probably want to move the rigidbody (which the simplest movement is just rigidbody.position) rather than the thing the rigidbodys attached to, and do that in FixedUpdate().
Its basically more reliable in terms of 'catching' collisions, as you can probably imagine moving stuff thats supposed to interact with each other at entirely different tick rates is kinda sketchy.

Also I want to understand what you're saying about time.delta and shmup slowdown because if I can add shmup slowdown to this with a ton of bullets/enemies that would be kind of cool.

Time.deltatime is there to give the impression of smooth framerate, even when its not, and anything in Update() is directly tied to framerate - oldschool games didn't have two different timers, they had one thread, so when that shit got busy, the whole game slowed down because the framerate was the speed the game was actually running at.
With Unity (and most modern engines I think) having rendering done separately to game logic means you get gameplay independent of framerate, so your dude moving at 10m/s at 100fps is the same 10m/s as someone else playing at 10fps, they just move each of you a different amount per frame so it averages out over a second.

For deliberate bullet time type shit, you can mess with time.timescale which will slow / speed up time itself; this will fuck with time.deltatime, but if you still need that for smoothing during bullet time or whatever, you can make your own version based on uhhhhhh time.realtimesincestartup or something, then average that out to get your own averaged time per second value.
(I only know this because the UI animations used to be linked to Time.deltatime, and if you did ez mode pause button of timescale=0 the fucking ui stopped working :rofl )
Title: Re: Do any of you code for your jobs?
Post by: Uncle on March 24, 2022, 03:10:50 PM
Haha, ok that does make sense! I was wondering how Unity would apply a single digit transform to a vector3 and yeah if it applies to the Z axis you're gonna be bad rats fucked. So that makes sense.

Though for this 2d shooter project, being 2d and all I should just be using vector2s the whole time I think?

I am pretty sure the way it works is that Unity is always inherently 3D under the hood, even in a 2D project, so technically all positions are vector3s, but if you use vector2s it just treats the Z axis as 0

I think they even implicitly convert between the two, so you can set a vector2 equal to a vector3 and it will just grab the X and Y
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 24, 2022, 08:11:03 PM
Brainstorming a bit on my walk today for some ideas that may be relatively intro level/simple to program for a 2d shooter,

One idea is like you can absorb bullets (aka visible bullet counter goes up on collision) which makes your bullets stronger (bulletStrength = BulletStrength x BulletCounter) but you die after like 5 bullets (if oncollision bullet counter = 5; you ded), so you can either glass cannon it with 3-4 bullets absorbed doing 3-4x damage, or you can take it slow and have some extra hits.

This seems like it should be easy to program in, but idk if it would be much fun for gameplay considering the stages/enemies at a basic intro level game are not going to have the depth to make that balancing act meaningful. You'd need to have a lot of bullets and maybe some sub-system to add depth.

Like if you could purge your bulletcounter and gain invuln for 1/4th second for each bullet purge. So if maximum bullets you can hold is 4 before dying at 5, purging all 4 gives 1 full second of invuln.

Not sure if that would be too much complexity in programming for me, but maybe those sub-systems would be enough for 3 short stages vertical slice game jam kinda thing.


The other idea I had was doing an absurd comedy using public domain images of old famous people from like 1800s or earlier. Basically "this is the future where famous artists have been cloned and now there is an alien attack at an artist convention in 21xx" and you play a shmup where at various points in the stage a random number generator throws out a random little ship with a HUD pop up of some photo/painting of like BEETHOVEN and he's like "RED-5 I'M GO FOR LAUNCH" and a little audio clip of Beethoven plays and you can catch him and he joins your ship squadron (no real AI, just attachs to your ship at an offset position and maybe shoots forward) or you can shoot him and he blows up with a scream and you get his unique power up.

At the end of the game the victory screen lists off artists killed this run, along with a scream for each name that appears, and then you get an ending which is based on which squadron mates survived. Like there'd be a dozen famous people and they'd each have their own ending clip SF2 win screen style with them talking to you for a line. They'd all have unique power-ups.

So you can murder them all and have a bunch of cool power-ups and the ending is you all alone in darkness, or you can save them all and have the best ending where a bunch of classical artists are having a party with you.

From a programming perspective, once I could get one AI pod working, there wouldn't be much programming to just keep adding more and more (mostly just figuring out scripting power-ups) and would be more on the art side of adding art/audioclip/ending screen.

Oh and the name of the game would be "Every Ship is Sacred" punning the every sperm is sacred Monty Python song. I was thinking of an every bullet is sacred game where every bullet that is shot by you has a name and when it collides with something the game says like JERRY HAS DIED and there's a wilhelm scream on collision but I feel like to make that work you'd need a fire rate of like 1 bullet per 20 seconds or something and idk how I'd make that even work and fun in a gameplay loop. If you could have a random name generator I guess you could get by with like every second it scrolling through all the names of people dying as you are shooting them out and the ending screen could be a credit scroll listing the name of every person you killed by firing them as bullets. Would be kind of dark haha and need a story reason for why you are firing people out of your ship.
Title: Re: Do any of you code for your jobs?
Post by: archnemesis on March 25, 2022, 02:08:23 AM
This Udemy Course (https://www.udemy.com/course/the-ultimate-guide-to-game-development-with-unity/) is quite good for 2D shooters. It introduces some more advanced concepts, e.g. using coroutines for power-ups. It's definitely worth the €15.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 25, 2022, 06:18:34 PM
Ok, done with work for the week. Got no plans this weekend so gonna start working on code for the next 2.5 days and try to understand everything in GreatSage's posts.
Title: Re: Do any of you code for your jobs?
Post by: therealdeal on March 25, 2022, 06:20:35 PM
Unity is dope af. I've made just like, a 3d maze runner, and 3d parkour level with obstacles. But I'd like to spend more time with it again, finish the course I was doing
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 04:18:09 AM
Been working on this and first thing was trying to figure out how to get an enemy to move left & right. Watched a youtube vid and it made sense (it put left & right waypoints as GameObjects so you could put them on the screen borders or platform borders and then it basically said move right until right border then move left until left border)

spoiler (click to show/hide)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test_Move : MonoBehaviour
{
    public float EnemyMoveSpeed = 1.0f;
    Transform leftWayPoint, rightWayPoint;
    Vector3 localScale;
    public bool movingRight = true;
    Rigidbody2D rb;


    void Start()
    {
        localScale = transform.localScale;
        rb = GetComponent<Rigidbody2D>();
        leftWayPoint = GameObject.Find("LeftWayPoint").GetComponent<Transform>();
        rightWayPoint = GameObject.Find("RightWayPoint").GetComponent<Transform>();
    }


    // Update is called once per frame
    void Update()
    {
   
        if (transform.position.x > rightWayPoint.position.x)
            movingRight = false;
        if (transform.position.x < leftWayPoint.position.x)
            movingRight = true;

        if (movingRight)
            moveRight();
        else
            moveLeft();

    }

    void moveRight()
    {
        movingRight = true;
        localScale.x = 1;
        transform.localScale = localScale;
        rb.velocity = new Vector2(transform.localScale.x * EnemyMoveSpeed, rb.velocity.y);

    }

    void moveLeft()
    {
        movingRight = false;
        localScale.x = -1;
        transform.localScale = localScale;
        rb.velocity = new Vector2(transform.localScale.x * EnemyMoveSpeed, rb.velocity.y);
    }
}
[close]

I understand pretty much everything in that code, outside rb.velocity which I guess is a built in Unity thing about movement that I should look up the Unity help to see what it does.

This code worked and my little enemy sprite moves back and forth like space invaders now.

So then I looked up the script my class has for enemy which includes movement modes. One thing is the class I'm taking doesn't use localScale but like every tutorial I see online uses localScale. I like how in the code above you just set the localScale for x as either positive (1) or negative (-1) to determine the direction on the X movement.

Without localScale...I don't know how to simply set right x = 1, or x = -1 for movement direction.

The way my class script does it is...complicated. The enemy script is really long and maybe I'll put more of it up later since I tried going through it and understanding each line (that's one way I'm trying to learn, is read all the scripts provided and try to understand each line). For movement on a scrolling movement the code is:

spoiler (click to show/hide)
private void MoveEnemy()
    {
        // Determine correct movement
        Vector3 movement = GetDesiredMovement();

        // Determine correct rotation
        Quaternion rotationToTarget = GetDesiredRotation();

        // Move and rotate the enemy
        transform.position = transform.position + movement;
        transform.rotation = rotationToTarget;
    }

    protected virtual Vector3 GetDesiredMovement()
    {
        Vector3 movement;
        switch(movementMode)
        {
            case MovementModes.FollowTarget:
                movement = GetFollowPlayerMovement();
                break;
            case MovementModes.Scroll:
                movement = GetScrollingMovement();
                break;
            default:
                movement = Vector3.zero;
                break;
        }
        return movement;
    }

    protected virtual Quaternion GetDesiredRotation()
    {
        Quaternion rotation;
        switch (movementMode)
        {
            case MovementModes.FollowTarget:
                rotation = GetFollowPlayerRotation();
                break;
            case MovementModes.Scroll:
                rotation = GetScrollingRotation();
                break;
            default:
                rotation = transform.rotation; ;
                break;
        }
        return rotation;
    }

   private Vector3 GetScrollingMovement()
    {
        scrollDirection = GetScrollDirection();
        Vector3 movement = scrollDirection * moveSpeed * Time.deltaTime;
        return movement;
    }
 
    private Quaternion GetScrollingRotation()
    {
        return Quaternion.identity;
    }

    private Vector3 GetScrollDirection()
    {
        Camera camera = Camera.main;
        if (camera != null)
        {
            Vector2 screenPosition = camera.WorldToScreenPoint(transform.position);
            Rect screenRect = camera.pixelRect;
            if (!screenRect.Contains(screenPosition))
            {
                return scrollDirection * -1;
            }
        }
        return scrollDirection;
    }
[close]

Now I can follow that until this part which is all gibberish to me and seems highly complex for just figuring the direction to go left or right?
Quote
    private Vector3 GetScrollDirection()
    {
        Camera camera = Camera.main;
        if (camera != null)
        {
            Vector2 screenPosition = camera.WorldToScreenPoint(transform.position);
            Rect screenRect = camera.pixelRect;
            if (!screenRect.Contains(screenPosition))
            {
                return scrollDirection * -1;
            }
        }
        return scrollDirection;

"Rect screenRect = camera.pixelRect"

Creates a rectangle called screenRect, ok I get that. But I don't know what camera.pixelRect means. Also that if statement kinda breaks my brain.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 04:20:48 AM
Also just figuring out movements and stuff already feels like hard maths and I am so bad at maths :(

I actually started college as a comp sci major taking C++ classes and what got me to quit the major was I got As in programming but Ds in higher level math and you needed both for the major. I'm ok with math when it has numbers, but when it's variables it breaks my brain  :'(
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 04:23:55 AM
One thing I don't like btw in the script stuff the class provides is the enemy projectile that is fired bounces off the walls (but doesn't have hit collision on the player on the ricocheted bullets. I have no idea what is wrong with their physics (using rigidbody2d) that would make the projectile shots bounce off the walls instead of being destroyed upon hitting a wall.

Definitely something I want to try to fix as I'm modifying this project. It's a little thing but it looks sloppy.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 27, 2022, 07:35:22 AM
I understand pretty much everything in that code, outside rb.velocity which I guess is a built in Unity thing about movement that I should look up the Unity help to see what it does.

Its using the inbuilt physics system (the rb is a cached RigidBody, so its applying it to that Rigidbody) to set the velocity immediately to the var you provided - ie, its ignoring any initial friction or acceleration or deceleration values to just make the thing ROOOOOOOOOOOLLLLLLLLLLLLLLLLLLLLLLING STAAAAAAAAAAAAAAAAART

This code worked and my little enemy sprite moves back and forth like space invaders now.

Another way you could do this without the 'edge of screen' gameobjects is to specify your Bounds manually;
eg if you know 'top of screen' is 8Y, bottom is -8Y, left is -12X and right is 12X (or whatever) you could do something like (pseudocode)
Code: [Select]
bool goingLeft=true;
if (pos.X>=12) { goingLeft=false; }
else if (pos.X<=-12) { goingLeft=true; }

if (goingLeft) { transform.pos += speed; }
else { transform.pos -= speed; }

// same again for Y boundaries if you need them

// you can also do somthing like
movementX = mathfclamp(-12,12)(input.getaxis("horizontal"));
movementY = mathfclamp(-8,8)(input.getaxis("vertical"));
// to lock player movement to bounds
You can also automagically generate those bounds by getting camera information (ie what the camera can see = playspace boundaries)
solid edge colliders are a good idea for other reasons though, like you can use them to get rid of stuff thats out of bounds so you dont have ghost bullets a thousand miles offscreen etc

So then I looked up the script my class has for enemy which includes movement modes. One thing is the class I'm taking doesn't use localScale but like every tutorial I see online uses localScale. I like how in the code above you just set the localScale for x as either positive (1) or negative (-1) to determine the direction on the X movement.

adjusting transform.localscale -1 is usually used because it 'flips' the gameobject, so if it has a different left / right sprite, or an irregular collider, it will be completely mirrored by doing that - I suspect that's why they're doing it that way more than just the movement aspect

Without localScale...I don't know how to simply set right x = 1, or x = -1 for movement direction.

Like my pseudocode above, you can just set a boolean for 'am I going in the right direction?' and flip it when you want them to.
Also don't forget you've got Vector.Right and Vector.Left if you want to be super explicit, eg
Code: [Select]
if (movingRight) { transform.pos += Vector2.Right * Movespeed * Time.deltatime; }
else { transform.pos += Vector2.Left * Movespeed * Time.deltatime; }
The way my class script does it is...complicated. The enemy script is really long and maybe I'll put more of it up later since I tried going through it and understanding each line (that's one way I'm trying to learn, is read all the scripts provided and try to understand each line). For movement on a scrolling movement the code is:
...
Now I can follow that until this part which is all gibberish to me and seems highly complex for just figuring the direction to go left or right?
Quote
    private Vector3 GetScrollDirection()
    {
        Camera camera = Camera.main;
        if (camera != null)
        {
            Vector2 screenPosition = camera.WorldToScreenPoint(transform.position);
            Rect screenRect = camera.pixelRect;
            if (!screenRect.Contains(screenPosition))
            {
                return scrollDirection * -1;
            }
        }
        return scrollDirection;

"Rect screenRect = camera.pixelRect"

Creates a rectangle called screenRect, ok I get that. But I don't know what camera.pixelRect means. Also that if statement kinda breaks my brain.

So I guess what that code is doing is moving the enemies AND also the background?  ???
The camera stuff is - like I hinted above, about setting the boundaries of the playspace to what the camera can see - finding the 'edges' of the camera viewpoint, and I would guess what its then doing thats not shown is jumping the background image from one 'side' of the camera to the other to give the illusion of a seamless scrolling BG?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 01:54:14 PM
Ooooh, thanks! I actually am starting to get this. I tested the boundaries you talked about and then modified the script so now you can just set boundaries for anything in Unity as a public entry.

And it works!

I think this is the first piece of code I've written myself that's worked lol. Next I'm going to try removing localScale and using vector.left, vector.right to simplify it more since pretty sure scale doesn't matter in this project.


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

public class Test_Move : MonoBehaviour
{
    public float EnemyMoveSpeed = 1.0f;
    Vector3 localScale;
    public bool movingRight = true;
    public float leftBoundary = -1.0f;
    public float rightBoundary = 1.0f;
    Rigidbody2D rb;


    void Start()
    {
        localScale = transform.localScale;
        rb = GetComponent<Rigidbody2D>();
    }


    // Update is called once per frame
    void Update()
    {
   
        if (transform.position.x > rightBoundary)
            movingRight = false;
        if (transform.position.x < leftBoundary)
            movingRight = true;

        if (movingRight)
            moveRight();
        else
            moveLeft();

    }

    void moveRight()
    {
        movingRight = true;
        localScale.x = 1;
        transform.localScale = localScale;
        rb.velocity = new Vector2(transform.localScale.x * EnemyMoveSpeed, rb.velocity.y);

    }

    void moveLeft()
    {
        movingRight = false;
        localScale.x = -1;
        transform.localScale = localScale;
        rb.velocity = new Vector2(transform.localScale.x * EnemyMoveSpeed, rb.velocity.y);
    }
}

Also I wonder what happens if I get rid of rigidbody & velocity. Will try & see...
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 01:57:06 PM
Also is there an easy way to backup versions of code before you fuck with them and potentially break them and forget how it was setup before you broke it?

Right now I'm doing Unity right click "show in folder" -> copy .cs file to desktop & rename as backup. Feel like there must be an easier way to do this.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 27, 2022, 01:57:49 PM
(https://c.tenor.com/kVWht4ZbHocAAAAd/obi-wan-kenobi-thats-good.gif)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 02:11:31 PM
So I got rid of localscale & truncated the code and it still works.

I'm trying to get rid of rigidbody and make the code as short and simple as possible. I know this doesn't work, but logically can someone explain why this doesn't work?

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

public class Test_Move : MonoBehaviour
{
    public float EnemyMoveSpeed = 1.0f;
    public bool movingRight = true;
    public float leftBoundary = -1.0f;
    public float rightBoundary = 1.0f;


    void Update()
    {
   
        if (transform.position.x > rightBoundary)
            movingRight = false;
        if (transform.position.x < leftBoundary)
            movingRight = true;

        if (movingRight)
            transform.position.x + (1 * EnemyMoveSpeed);
        else
            transform.position.x + (-1 * EnemyMoveSpeed);

    }

}

Why can't you just tell it, if you're moving right, change the X position of the object to say X+1 each update and if you're moving left change the position of X to X-1 each update? Logically that should mean the enemy moves from 4 to 5 to 6, though I'm guessing even if this did work the enemy would teleport from 4 to 5 to 6 each frame without actually moving in the .0 space between since this doesn't give it any actual velocity.

So this code would suck, but I'm trying to figure out why logically it won't work. Visual studio tells me "only assignment, call increment, decrement, await and new object expressions can be used as a statement"

Well, I want to increment going right and decrement going left, so how do you do that?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 02:13:41 PM
btw, this is as truncated as I've gotten this without using localscale and still having it function as intended.

spoiler (click to show/hide)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test_Move : MonoBehaviour
{
    public float EnemyMoveSpeed = 1.0f;
    public bool movingRight = true;
    public float leftBoundary = -1.0f;
    public float rightBoundary = 1.0f;
    Rigidbody2D rb;


    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }


    // Update is called once per frame
    void Update()
    {
   
        if (transform.position.x > rightBoundary)
            movingRight = false;
        if (transform.position.x < leftBoundary)
            movingRight = true;

        if (movingRight)
            moveRight();
        else
            moveLeft();

    }

    void moveRight()
    {
        movingRight = true;
        rb.velocity = new Vector2(1 * EnemyMoveSpeed, rb.velocity.y);

    }

    void moveLeft()
    {
        movingRight = false;
        rb.velocity = new Vector2(-1 * EnemyMoveSpeed, rb.velocity.y);
    }
}
[close]
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 02:18:04 PM
Also next thing I'm trying to learn this morning is how to spawn bullet hell patterns instead of just like the enemy shooting 1 shot forward. I want an explosion of bullets coming from certain enemies Cave style.

Then will look into designing power-ups.

Then will try to implement my bullet retention & damage up & purge invincibility concept I thought of.

Then will try to learn to make a sprite enemy for my bullet hell dispersement and make a power-up sprite.


Pretty much goals for today. If I can learn this stuff I can start trying to make some stages tomorrow after work from it.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 27, 2022, 02:20:47 PM
Also I wonder what happens if I get rid of rigidbody & velocity. Will try & see...

So you know that
Code: [Select]
transform.position += direction * speed * Time.deltatimemovement code you posted earlier, and had figured out how it works?

You can pretty much literally rewrite that to use a rigidbody rather than a transform and do the same type of movement, but onto your physics object rather than setting it a velocity (especially if you don't need to inherit velocity.y as you are doing, ie gravity).
Try putting:
Code: [Select]
rb.position += direction * speed * Time.fixeddeltatimeinto your fixed update loop - if you're not trying to use Full Fat Physics, often 'rolling your own' Reduced Fat Physics (ie just the collisions part, and writing your own specific movement code) can get nicer results - you'll notice this especially when you're doing shit like creating frictionless physics materials to avoid inertia, or making gravity ridiculously high, or fucking with your players mass to try and get the 'feel' you want; when you start doing stuff like that, thats the time to just set things up how you want them from scratch.

Also is there an easy way to backup versions of code before you fuck with them and potentially break them and forget how it was setup before you broke it?

Right now I'm doing Unity right click "show in folder" -> copy .cs file to desktop & rename as backup. Feel like there must be an easier way to do this.

Githubs free :idont
If you dont wanna / can't, you can just go to the Assets menu and Export a package then use that as version control

Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 27, 2022, 02:24:11 PM
Visual studio tells me "only assignment, call increment, decrement, await and new object expressions can be used as a statement"

VS is being as helpful as VS knows how to be - look at the previous working one, where you're saying "Set this value to be a blank value, but with these bits changed" and what your not-working code is saying is "this value Adds bits changed"

e: what you want to be saying is "set this value to be the old value, plus the changed bit" - not gonna post the code, see if you can figure it out.
Also don't forget adding a negative to a positive can result in a negative, so you don't necessarily need 2 lines of code to handle the actual movement of going left / right.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 02:32:07 PM
Oh I'm dumb, guessing I should be doing the +=, will try that out in a bit.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 03:49:49 PM
Hmmm, starting to come together mentally even without watching tutorials.

Like for bullets, rather than thinking of them as projectiles from enemies, I could make a spawner that spawns bullet objects in whatever directions at whatever speed I want and then just attach that spawner to an enemy.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 05:35:58 PM
See if you can figure it out.

Hey I did it!

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

public class Test_Move : MonoBehaviour
{
    public float EnemyMoveSpeed = 1.0f;
    public bool movingRight = true;
    public float leftBoundary = -1.0f;
    public float rightBoundary = 1.0f;


    void Update()
    {
   
        if (transform.position.x > rightBoundary)
            movingRight = false;
        if (transform.position.x < leftBoundary)
            movingRight = true;

        if (movingRight)
            transform.position = new Vector2(transform.position.x + (1* EnemyMoveSpeed * Time.deltaTime), transform.position.y);
        else
            transform.position = new Vector2(transform.position.x + (-1* EnemyMoveSpeed * Time.deltaTime), transform.position.y);

    }

}

Doesn't even skip around like I expected it to but smoothly moves just like when using rb velocity? Not sure conceptually why it's not teleporting units but I guess it's calling update like 60 times a second and incrementally teleporting it 60 movements in a second so to the eye it looks like it's moving smoothly.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 05:40:29 PM
So I watched this video and for the most part understood it and made a bullet which moves at a speed & in a direction, a bulletpool that keeps refilling bullets as they are destroyed, and a firebullet that fires the bullets at a set angle spread (the angle stuff is just a bit beyond my math understanding so I'm just stealing that bit without fulling understanding how to set a spread rotation).

https://youtu.be/Mq2zYk5tW_E

I then added 2d rigid body to the bullet prefab and added my class's damage script to it so it can do damage to the player ship on collision.


It all works good except I'm running into 1 problem that I need help figuring out. Basically the bullet script for the bullet prefab gives them a life of 3 secs and then the gameobject is destroyed. Bulletpool then refills on new bullets.

But if a bullet hits my ship or hits a border and the bullet gameobject is then destroyed, it's being destroyed early and the bulletpool gets an error because one of the gameobjects it was using "bullet" is missing and the game crashes.

How do I get around this? I guess the abstract question of this, is if you destroy a gameobject that has stuff connected to it, how do you avoid a runtime error. Can you just go through all the attached codes and add "if alive" before it or is there an easier way to deal with the issue.

*edit* I think I'll try to figure this out myself looking at the bullet destroy object method and the destroy on damage object method and see how they do things differently.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 08:05:54 PM
Ok, I figured out the issue. The way I'm spawning bullets and firing them using the above video method, the bullet objects aren't being destroyed. They being setactive(false) when they're done and then returned back to the queue to be set active and fired again. So if you're firing 20 bullets at a time, it's the same 20 bullets firing or something over and over.

The damage script actually destroys the bullet gameobject that's created and is in the hierarchy.

Thus when it's destroyed, it's no long in existence and the bulletpool is looking for a bullet #3 on the list which it expects to be false to requeue, but the bullet has vanished because it's been destroyed.

I can fix this by changing the damage method to setActive(false) instead of destroy. And the game works fine and bullets destroy on impact and don't crash the game. But I also get a few warnings that there's some script fuck ups going on because the destroy reference in damage has now vanished.

Not sure how I can leave destroy in and adjust the bulletpool since it would just the entire bulletpooling method if the bullets are destroyed. Seems better to try to change anything referencing the damage script and destroys line.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 09:26:43 PM
Let's see.

I got the asteroids wall boundaries to kill my character, which is good.


But otherwise spent the last two hours trying to get chasing bullets working. Don't even care about the spread, I just want stationary bullets fired from turrets to point in the player ships direction when initializing and shoot in a straight line in that direction.

There's a sample code here:
https://answers.unity.com/questions/1785183/how-to-make-3-bullets-fire-at-different-angles.html

And it works on its own scene but it doesn't work with my scene. The main issue I think is that this code uses a script called "Player" for the Player, whereas the Player ship in my game doesn't have a Player script, it just has a controller script.

I cannot for the life of me figure out how to get this script to work in my game:

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

public class Enemy : MonoBehaviour
{
    Player _target;
   
    public Bullet BulletPrefab;
    public float SideBulletAngle = 30f;
    public float FireInterval = .2f;

    void Awake()
    {
        _target = FindObjectOfType<Player>();     
    }

    private void OnEnable()
    {
        StartCoroutine(Fire());
    }

    private IEnumerator Fire()
    {
        while(enabled)
        {
            Fire(-SideBulletAngle);
            Fire(0);
            Fire(SideBulletAngle);

            yield return new WaitForSeconds(FireInterval);
        }
    }

    void Fire(float angle)
    {
        var bullet = Instantiate(BulletPrefab, transform.position, Quaternion.identity);
        bullet.Initialize(_target.transform.position, angle);
    }
}

I just want to get that bullet.Initialize (at my player.transform.position, angle) for my own bullet types. But I can't figure it out and getting a bit frustrated at the wasted time and no progress (which I guess is pretty normal when coding).

Should move on to something else at this point. I'm trying to learn the whole kitchen sink of shmups for my first project in like 1.5 weeks I have when all the project is asking me to do is take their basic game template and make 3 minor mods to it (either with new script actions, new sprites or new music). Maybe I should save making an entirely different game for the next game when I have 4 weeks to do it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 09:34:11 PM
At this point, in terms of like a game plan, if I wanted to learn everything that I want to have the basic tools to make a shmup I'd need to learn:

1. How to make a vertically scrolling 2d main camera that either kills your player ship or drags them along the bottom if they try to go out of bounds.

2. How to make that camera stop at a boss.

3. How to make stage victory condition being to kill a boss which goes to stage score screen (this seems like it should be pretty easy)

4. How to give a boss multiple phases, so on awake, start with patterns 1 & 2, at 50% move to patterns 3 & 4

5. How to make power-ups (spread shot, extra stationary support ships that fire forward, shield, etc...)

6. How to make pick up objects for power-ups (probably just gameobjects that destroy on collision but instead of causing damage give power-up)

7. How to implement the gameplay system I want.

8. How to make enemies spawn in a vertical stage (this should be pretty straight-forward with a spawner that creates them in time intervals and moving in a direction)

9. How to make sprites for enemies/power-ups/ship

10. How to animate sprites.

11. How to make stage music.

12. How to make multiple different types of bullet patterns (what I'm working on now, basically have straight down shot and bullet hell circle shots, just need chaser shots really)


I think that's the bulk of the tools I'd want to get under my belt to then sit down and design out a couple of levels and boss patterns. But that's a lot of stuff and my project's due at the end of the week and at most I have a few hours each weeknight. Soooo, yeah maybe gonna keep it simple and try something more like this on the next project.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 27, 2022, 11:48:34 PM
Well I made a vertically scrolling BG loop. Didn't figure out player boundaries so I can just fly out of the game area or any way to drag a player who is falling out of the scrolling BG. Mainly because the player movement script controller is weird and I can't just set min/max movement positions at the start based on the game canvas.

Spent the last 90 mins trying to fix this dumb respawn in the base code provided. The ship instantly respawns while the old death animation is still playing and it looks bad. Plus the ship jumps to the initial starting spot on each respawn which is jarring. Tried to fit in WaitforSeconds delay timer but couldn't make it work.

I definitely feel like trying to use this code base provided which does things its own non-orthodox way with original code and stuff I'm learning online is just a frankenstein nightmare of a mess and it's pretty disheartening spending all this time and very little ever works. I think I'd make more progress just starting from scratch outside art assets and making my own code instead of trying to use the classes' weirdly complex with lots of quirks code.

Maybe next project I'll just do everything from scratch instead of using their code.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 28, 2022, 01:52:04 AM
I remember the excitement coding my first games. :uguu

First trying DarkBasic, then C++, then C#, then XNA, then finally JavaScript.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 28, 2022, 02:00:03 AM
Yeah, I talked with a coder friend and this is just a bad idea the way I'm approaching learning C# & Unity. Basically trying to reverse engineer code I don't understand and google and ask people and reading the Unity help website.

I've only been coding Unity/C# for like...less than one week and I'm trying to do essentially intermediate tactics and even the Udemy 2d shmup guide says it's for intermediate C# programmers and after one week I am definitely not there.


Instead of trying to make the best full fledged shmup ever in my first week of code. I really need to learn the basics and practice and do them over and over until I'm comfortable with the simple stuff before delving into the intermediate things you'd actually want to use to make a game. Learn what the hell enum means, get comfortable with serializedlists and all kinds of transform positioning and rotations, learn what yield does, etc...etc....

Now maybe the next part of this class I'm taking will start to do that. It's a 5 month class and this just the end of month 1. I'll give it a shot and if it's not explaining the basic stuff then I'll look into picking up a book on beginner level C# and/or take a class on it.

Probably need to spend at least 2-3 months on beginner C# and put my time in. Otherwise just gonna keep getting frustrated trying to jump straight into intermediate coding where I only vaguely understand what's going on and am constantly stumped and frustrated.


Gonna take a break from the coding-side and focus next session on learning some basic beginner pixel sprite stuff. Should at least be able to swap/edit/create a few simple sprites and a music loop before turning in this project.
Title: Re: Do any of you code for your jobs?
Post by: Nintex on March 28, 2022, 03:54:43 AM
Kill half your features.
Fake the rest

Welcome to game development  8)
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 28, 2022, 01:36:21 PM
Instead of trying to make the best full fledged shmup ever in my first week of code. I really need to learn the basics and practice and do them over and over until I'm comfortable with the simple stuff before delving into the intermediate things you'd actually want to use to make a game.

Yeah, this is probably a good idea; what I'd suggest you do is:
 - Using your Frankenstein script for reference if you need it (but try using docs.unity.com as a first point of reference) try and recreate a SHMUP at its most basics, with the stuff you're secure you know
 - so rb.position += inputs * movespeed * time.fixedelattime movement for your player
 - rb.position += vector2.right * movespeed for a bullet script thats always moving
 - instantiate(bulletprefab,firepoint.position,bullet.rotation) to shoot bullets
 - clamping movement to the screen bounds
 - bullets self destruct if they go outside the bounds (ignore object pooling for now)
 - bullets do damage to a thing they hit when they hit it, then self destruct

when you've got those down, and can pretty much recreate from memory, then start freestyling new mechanics onto your solid code base.


Having said that, if you want me to explain anything in particular better, let me know - I'm not doing a multiline quote of your like, 10 posts in a row though  :lol
Title: Re: Do any of you code for your jobs?
Post by: demi on March 28, 2022, 03:01:27 PM
Dedicate your energy towards rom translations instead
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 28, 2022, 03:44:26 PM
Having said that, if you want me to explain anything in particular better, let me know - I'm not doing a multiline quote of your like, 10 posts in a row though  :lol

I think I just want to get clamping working for movement.

The player movement code in my template is very complicated and there is no clamping because it was meant for a top-down free roam kind of map where the camera follows the player and you build actual walls on the outside.

This does not work for my vertically scrolling shmup stage I made.


My guess is there are 3 approaches to get clamping working on this stage:

1. I try to understand the player controls code provided and try to figure out how to work clamping into their complex code.
 -Most likely this will fail and be hours of frustration because I don't understand a lot of the code provided and there is no explanation in the class for it since we weren't supposed to be messing with it yet.

2. I uncheck the player controller script and just write a simple 6 line one with clamping.
-This seems easy and should work, but the problem is if some of the other template game scripts are referencing stuff in the player controller script I just disabled. I can at least try this and see.

3. I don't do clamping and for my vertical stage I create an actually thin border object that frames the main camera and has collision physics checked (but no damage) and therefore create a wall that keeps boundaries even with the scrolling stage. Instead of being giant wall of asteroids like the template stage it'll just be a thin line that looks like a natural HUD frame border.
-This should work if #2 fails and shouldn't be too much work.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 28, 2022, 03:45:32 PM
Dedicate your energy towards rom translations instead

Hasn't everything decent been translated already?

I used to do translations for things I was passionate about that weren't available in English. I can't think of any game that's JPN only still that I'd care about enough to want to spend the time. We are in a pretty good time for jrpgs in English.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 28, 2022, 08:33:21 PM
I found out that you can make a boundaries script and attach it to objects to keep them within boundaries. I borrowed some code online for clamping boundaries and put it on my player.

It works for the left/right/top but not the bottom which I assume has to do with the scrolling background moving downwards. I think I'm just going to set a wall of fire at the bottom that is chasing the player or something.

This is the code I grabbed:

Code: [Select]
public class Boundaries : MonoBehaviour
{
    private Vector2 screenBounds;
    private float objectWidth;
    private float objectHeight;

    void Start()
    {
        screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
        objectWidth = transform.GetComponent<SpriteRenderer>().bounds.size.x / 2;
        objectHeight = transform.GetComponent<SpriteRenderer>().bounds.size.y / 2;
    }

    void LateUpdate()
    {
        Vector3 objectPosition = transform.position;
        objectPosition.x = Mathf.Clamp(objectPosition.x, -screenBounds.x + objectWidth, screenBounds.x - objectWidth);
        objectPosition.y = Mathf.Clamp(objectPosition.y, -screenBounds.y + objectHeight, screenBounds.y - objectHeight);
        transform.position = objectPosition;
    }
}

Is there an easy fix to boundary the bottom with a scrolling BG that moves downwards (I have a script on the BG image that scrolls down and loops it).
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 29, 2022, 02:17:02 PM
If you just want to 'move' a BG image, you could just make it a texture and just scroll it?
It would then work with your bounds stuff if I understand you correctly, as it won't actually be moving anywhere, it will just look like it is.

https://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html

(this is also a pretty nice way of doing parallax scrolling in a 2D game)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 29, 2022, 02:26:51 PM
If you just want to 'move' a BG image, you could just make it a texture and just scroll it?
It would then work with your bounds stuff if I understand you correctly, as it won't actually be moving anywhere, it will just look like it is.

https://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html

(this is also a pretty nice way of doing parallax scrolling in a 2D game)

That's actually what I'm doing haha.

Yeah, I have no idea why the bounds doesn't work for the screen bottom. Because you are right. The scrolling BG is just a background texture moving and should have no effect with the actual camera and play zone. Very weird, but I don't really understand how clamping code works (it grabs your screen dimensions and then halves them? why? Shouldn't it grab your screen dimensions and then just set max X/Y as the max X/Y of your screen?).
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 29, 2022, 02:37:01 PM
(it grabs your screen dimensions and then halves them? why? Shouldn't it grab your screen dimensions and then just set max X/Y as the max X/Y of your screen?).

its getting the data from the centre position, so keep in mind a bounding box of size 10 will look like

-5 -4 -3 -2 -1 0 1 2 3 4 5

on its X-axis, so your range is gonna be (-5,5) even though your size is 10
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 29, 2022, 03:00:40 PM
Thanks, that makes sense.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 29, 2022, 10:51:59 PM
I read some tutorials and picked up Aesprite on Steam. Made a 16x16 pixel enemy sprite with a 4 frame animation loop. Got it working in the game and then did a 4-5 frame death animation on hit that matched the enemy.

Then since I was figuring out animation, I imported the player death animation into Aesprite and edited the sprites into some other animation and then imported it back into Unity replacing the ship death animation. Yay.

Now when you hit something it looks less crappy, but I still don't like that the ship warps back to the initial start point when you die. I wish I had the time/skill to figure out how to make it respawn in place and just blink for the 2-3 sec invuln state. I could probably do the blink animation (just set it blank every other frame?), but I don't know how to code that change.

At this point I'm starting to get there. I need to figure out how to make a music loop for the first stage and figure out how to make a title and win screen and then I have a title screen, a stage with enemies, music, a win condition, a win screen and that's enough and then time to tidy up stage 2 with some unique features and new enemies/music. Doubt I'll have time for a stage 3 before turning in the project. So probably just 2 stages. 1 top-down free roam, 1 vertically scrolling.

Sprites are pretty fun. I have zero x 00000 art drawing skills and I still made a decent enemy that animates and looks ok moving around with my move script. My biggest problem with art is going to be that I don't know how to do shade/lighting to give a less flat/basic look. I just never took art courses to understand how things should look with lighting.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on March 30, 2022, 02:25:23 PM
I still don't like that the ship warps back to the initial start point when you die. I wish I had the time/skill to figure out how to make it respawn in place and just blink for the 2-3 sec invuln state. I could probably do the blink animation (just set it blank every other frame?), but I don't know how to code that change.

The best way of doing this would be a coroutine, but lets do baby steps with shit you're familiar with already:
Code: [Select]

// lets declare some variables
int spawnCooldown=120;
bool spawnProtection=false;
Transform deathPos;
Renderer rend; // cache a reference to this in your Awake() method, because you're about to abuse the shit out of it

void OnDeath() // call this when ya die
{
     deathPos = transform.position;
     spawnProtection=true;
     spawnCooldown=120;
}

// on your respawn call, teleport the player to deathPos;

void Update() // lets put the rest of this shit in your update loop
{
     if (spawnProtection) // add this check to your takedamage call with a return, so if they have spawn protection enabled, no damage is done.
     // you might want to turn off collision too while its active...?
     {
          if (spawnCooldown <= 0) { rend=enabled=true; spawnprotection=false; return; }
     }
     spawnCooldown --; // this decreases this variable by 1; at 60fps, this will be 2 secs of invulnerability at a default value of 120
     if ((spawncooldown % 2) == 0) // this is a Modulo; its basically the 'remainder' after a division. In this case, if the cooldown timer is an odd number it wont run, if its even it will; ie it will turn the sprite on / off rapidly.
     {
           rend.enabled=true;
     }
     else { rend.enabled=false; }
}



Sprites are pretty fun. I have zero x 00000 art drawing skills and I still made a decent enemy that animates and looks ok moving around with my move script. My biggest problem with art is going to be that I don't know how to do shade/lighting to give a less flat/basic look. I just never took art courses to understand how things should look with lighting.

The good thing about pixelart is the skill ceiling is much lower than, say, hand drawn art, and also you don't have to get into the fucking wizardry shit people like 90s era Square were pulling off knowing about colour bleed and non-square pixels and shit on CRTs.
There are a bunch of good youtube videos on pixel art for newbies, and also a decent selection on twitter, which are usually espcially good as the pixelart is the tutorial;
(https://pbs.twimg.com/media/FInWA8aXIAYLOft.png)

this is the kind of 'doing shit on twitter for internet clout' I approve of  :wow
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 30, 2022, 03:32:51 PM
Yep, excited to get more into the world of pixel art tutorials.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 30, 2022, 08:51:38 PM
Ok, made a song in Bosca Ceoil, which was surprisingly made by Terry Cavanaugh (vvvvv, super hexagon, dicey dungeons). People recommended it as the best free song making software for PC.

It's good but it's missing some QoL stuff like autosaving your project. Lost my first hour and track when it saved absolutely nothing. :|

It's probably good for a start and I will save OFTEN, but may end up putting down money for FL Studio or Ableton Live at some point. Garage Band is supposed to be tops but I don't want to make stuff on my ipad, I want to make it on my PC with my mouse and KB.

Next up will be figuring out some splash screens. Probably will try to make one today before closing out for the day.



One issue is when I finally made a sorta entry level ok midi tune it doesn't fit my game at all and is like a chill visual novel at the beach tune  :lol
I figure I'll use it for the title track and try to make some stuff that fits my game more next.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 04:42:47 AM
Man, getting addicted to making sprites, sprite animations and music. Can stay up all night doing this. This is way more fun than the actual game making haha

My splash screen art is fucking terrible though. Cannot do art larger than like 16x16.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 05:14:24 AM
(https://i.imgur.com/XprQnn3.gif)

Like it's nothing special, but given that I have no artistic ability and I've been jumping into sprites & music entirely on my own and in a day I can pull off stuff like this pretty quick and no problem gives me some hope for cool stuff I can do in the future.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 04:41:38 PM
Also I fixed the respawn code in kind of a cheat shortcut way. I found where it tells it to respawn in the script and it says transform.position = respawn.position so I just changed it to transform.position = new Vector3(transform.position.x-1, transform.position.y-1, transform.position.z) and that fixed it so you just knock a bit to the side when you get killed and watch the explosion in the spot you were.

And yes, I've learned enough to know this code has a problem, because if you're at the lowest bounds of X or Y and you get hit you'd respawn 1 degree out of bounds. So if I was doing a public, good code, release I'd clean it up with some type of check if transform.x -1 is greater (or maybe less than since we're dealing with negatives) than x boundary && if tranform.y -1 is great than y, then do the code, else, respawn at transform.position.

Also I was trying to test the game over splash screen and realized at some point in all my script editing I broke the game and the player doesn't lose lives on death and it's impossible to game over. No idea how this happened but was able to debug fix it by finding the int variable for currentLives and that death is basically "on hit if currentLives > 0 respawn, else do game over" so I threw in another line at hit code that says currentLives -= 1 and it fixed it.

Nice being able to figure out quick fixes for stuff! Last weekend was rough trying to get my head around basic coding with a lot of wasted time not figuring things out. But starting to feel confident and able to do some basic code, art, music. So I think this weekend will be real productive since I just need time to actually make the game.
Title: Re: Do any of you code for your jobs?
Post by: Nintex on March 31, 2022, 04:49:06 PM
Sounds like we can finally get "Dudebro III: The Ding Dong Slappening of GaaS" off the ground  :thinking
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 31, 2022, 07:22:08 PM
Oh man, remember Dudebro. :lol
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 31, 2022, 07:28:20 PM
The Verge Proudly Presents

'DUDEBRO II': THE INCREDIBLE JOURNEY
FROM INTERNET JOKE TO VERY REAL GAME
(https://www.theverge.com/2012/10/25/3543204/dudebro-2-meme-to-game)




...It's still unreleased vaporware. :dead
Title: Re: Do any of you code for your jobs?
Post by: Nintex on March 31, 2022, 07:30:39 PM
(http://www.grimoireassemblyforge.com/dudebro2/site/wp-content/uploads/2010/12/nintexpost.jpg)

:salute

That's 13 years ago now.

I know exactly how the Rivet woman feels with her creation being taken away from her.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 31, 2022, 07:31:59 PM
(http://www.grimoireassemblyforge.com/dudebro2/site/wp-content/uploads/2010/12/nintexpost.jpg)

:salute

That's 13 years ago now.

(https://i.imgur.com/6hpVm19.gif)
Title: Re: Do any of you code for your jobs?
Post by: Tasty on March 31, 2022, 07:41:24 PM
Sorry to highjack your thread Bebps. But...

https://en.wikipedia.org/wiki/Dudebro_II

Quote
Cuyahoga made up the title to mock another user who accused him of being a pedophile because he purchased and enjoyed the game Imagine: Babyz Fashion.

:doge

Quote
The game, originally scheduled for release in summer 2010

:lol

Quote
was later pushed to 2011

:rofl

Quote
The developers published for free level codes that allow users to download those [two custom Super Mario Maker] levels. They cautioned against spoiler culture when playing through these levels, as they might potentially ruin some crucial story beats from the yet-to-be-released Dudebro II.

:gurl

Quote
[In 2017] they announced plans to purge all references to NeoGAF, and start work under a new team on a spiritual successor. No further statements confirming the game is in active development were ever issued.

 :whatsthedeal
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 10:05:51 PM
My first level is the most terrible thing I've ever seen in my life but it's done. The biggest issue is holy cow there are hundreds of collision issues of going through everything even though there's no difference in the game object between an object you can't go through and one you can. Don't have time to deal with it for this project so will just file that under bugs. Also some enemies stick around after dying and you have to kill them twice even though all the enemies are just copy & paste prefabs, yet some are fine and some are fucked. Again, no time so this will just be a shit level and time to move on to level 2.

Now I'm trying to make a text intro to the level with a few dialogues popping up. I don't know how to do this yet in scenes so I'm making them as a series of splash screens one after another to then load into level 1.

I followed this guide which seems straight forward enough script to make each scene load and wait for a few seconds and then scenemanager loads the next scene.
https://www.youtube.com/watch?v=ADJ2SYm0oBU

But it's not working at all for me? No errors in the C# code or in the game but the scenes just sit and don't move to the next one.

here's my code:
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Splash_Screens : MonoBehaviour
{

    public static int SceneNumber;
   
    void Start()
    {
        if (SceneNumber == 1)
        { StartCoroutine(ToSplashTwo());
        }
        if (SceneNumber == 2)
        { StartCoroutine(ToSplashThree());
        }
        if (SceneNumber == 3)
        { StartCoroutine(ToSplashFour());
        }
        if (SceneNumber == 4)
        {
            StartCoroutine(ToLevelOne());
        }
    }

    IEnumerator ToSplashTwo()
    {
        yield return new WaitForSeconds(3);
        SceneNumber = 2;
        SceneManager.LoadScene(2);
    }

    IEnumerator ToSplashThree()
    {
        yield return new WaitForSeconds(3);
        SceneNumber = 3;
        SceneManager.LoadScene(3);
    }

    IEnumerator ToSplashFour()
    {
        yield return new WaitForSeconds(3);
        SceneNumber = 4;
        SceneManager.LoadScene(4);
    }

    IEnumerator ToLevelOne()
    {
        yield return new WaitForSeconds(3);
        SceneNumber = 5;
        SceneManager.LoadScene(5);
    }
}

I created an empty game object in each splash screen and put the script in and saved for each splash screen.

(https://i.imgur.com/WcGSMO6.jpg)

Mainmenu is scene 0 in my build, so starting with scene = 1. I set the first splash screen to level 1, then scene #2 is level1 intro A, scene #3 level1 intro B, scene #3 level 1 IntroC, scene #4 is level 1 introD, and scene #5 is level1_game which is the actual gameplay level.

Sage, any idea why nothing is happening?


Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 10:11:59 PM
So I rewrote that script without the if statements to see if it would work if it just says "wait 3 seconds then load scene 2" and I stick it in an object in scene 1.

And it works. So something about the if statement is making it not work...
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 10:13:17 PM
Aha, I figured it out.

When I did int SceneNumber up top, by not giving it a value it starts at 0 and there's no if for 0. Need to set it as 1 in this case;
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on March 31, 2022, 10:39:21 PM
Actually having something that sequentially works from main menu -> intro credits -> level that is winnable (or game over screen back to title) -> level 2 is a nice feeling even if the game itself is shit.

All about learning first and making it work even if it's held together by stitches. Cleaning up and improving starts from there!

Next up is learning how to write a level script that loads enemies at certain points for level 2. Then if I have time I'll try to make a level 3 that's just a single boss fight -> ending.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 01, 2022, 06:17:05 AM
I've made so many songs and I dislike them all  :'(

Making music is not hard. Making good music that comes out the way it is in your head is hard. I used to play guitar so I have some sense of this but there I just play notes on guitar without thinking of where on the scale they are. Never was good at reading music. Trying to find the note I'm looking for here can be tough!
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 01, 2022, 09:59:19 AM
Yeah, I would definitely suggest while you're still learning things you are very strict with your logic flow by - for example - always having an
Code: [Select]
else { Debug.log("I fucked up somewhere because this shouldn't run!"); }(or a more relevant error message) in every IF block to get into the habit of evaluating all code paths

Also, I can't say that's a bad tutorial, and if nothing else you can use it as an example of using coroutines as timers, but its a bit weird because Unity has had built in Splash Screens for uhhhh quite a few fucking editions now

(https://i.imgur.com/6NQW6UY.png)

But like I say, nothing wrong with knowing how to do scene transitions; I'd have probably made those coroutines actually check the levels loaded before moving on rather than fixed wait times, but like I say thats useful info to know how to do anyway
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 01, 2022, 01:17:49 PM
I've made so many songs and I dislike them all  :'(

Making music is not hard. Making good music that comes out the way it is in your head is hard. I used to play guitar so I have some sense of this but there I just play notes on guitar without thinking of where on the scale they are. Never was good at reading music. Trying to find the note I'm looking for here can be tough!

keep an eye out for humble bundles that give packs of pre-made assets for developers, I know that feels like cheating but I mean, that's what those resources are for, some guy made a bunch of music loops and said "I hope somebody who needs them can use them"

or just buy some now if you find ones you like

https://www.bitbybitsound.com/royalty-free-music/

you probably already own this guy's music if you bought any of the giant bundles during recent humanitarian causes:

https://itch.io/b/520/bundle-for-racial-justice-and-equality

https://itch.io/b/902/indie-bundle-for-palestinian-aid

https://itch.io/b/1316/bundle-for-ukraine
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 01, 2022, 03:49:06 PM
Yeah, I would definitely suggest while you're still learning things you are very strict with your logic flow by - for example - always having an
Code: [Select]
else { Debug.log("I fucked up somewhere because this shouldn't run!"); }(or a more relevant error message) in every IF block to get into the habit of evaluating all code paths

Great point. Will try to do that in the future.

Quote
Also, I can't say that's a bad tutorial, and if nothing else you can use it as an example of using coroutines as timers, but its a bit weird because Unity has had built in Splash Screens for uhhhh quite a few fucking editions now

(https://i.imgur.com/6NQW6UY.png)

But like I say, nothing wrong with knowing how to do scene transitions;

Yeah, I have no idea all the features already in Unity. There are a lot of things and still learning. That said since I don't know/have photoshop or any image editor that can even do layers outside this sprite editor, so building my text screens as scenes was actually kind of helpful and like you said learning how to scene change is really important for making anything.

Quote
I'd have probably made those coroutines actually check the levels loaded before moving on rather than fixed wait times, but like I say thats useful info to know how to do anyway

Tbh at this point I don't know the difference between a coroutine and a method.

If the code said:

Code: [Select]
If {posting on Bore, doPost(); Else debugLog"why aren't you posting on Bore;}"

void doPost(){
Type up blah blah blah;}

How is that different than

Code: [Select]
If {posting on Bore, StartCoRoutine(doPost()); Else debugLog "why aren't you posting on Bore;}

IEnumerator doPost {
Type up blah blah balh;}

I don't think I ever did CoRoutines in my C++ class and my Unity class hasn't covered CoRoutines yet so I know nothing about them but they just seem like methods but people prefer using them?


Also in your post you say you'd have it check the levels, what does that mean?

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 12:37:31 AM
So I want to add a "Lives: 0" display in the UI to show the current lives outside of the debug screen.

The int with currentLives is in the health.cs script attached to the player.

The UI Display is in a separate script and using the class UIElements to override updateUI to display a text string. I can't get this to work under the health.cs script since it won't let me have the script be a child of MonoBehaviour and UIElement.

The simple thing would be to figure out how to grab that int currentLives that is on the Player in the Health.cs script from my Display script. But this is a bit beyond me and goes back to trying to get separate scripts to interact. I can find the gameObject that is player with Find.gameObject.Player, right? So how do I go from there to getting the variable from a script that's attached to it?
Title: Re: Do any of you code for your jobs?
Post by: Transhuman on April 02, 2022, 02:29:46 AM
I always wanted to make a game that took elements from top-down zelda GBA games like Link's Awakening, Oracle of Age, etc, and I started watching tutorials and shit, but that shit is hard. If I had to do my life over again i'd definitely learn 2 code though. I remember in highschool I managed to make a little Zelda movement simulator in flash (walking around, bunping against walls, being carried by water) but I can't even imagine being able to learn how to do that now.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 03:52:48 AM
Been coding after work for like 6-7 hours straight last few nights. Just got stage 2 done, outro to stage 3 (minus an animation I want to put in) and ending story bit done.

Feels good have 2 full micro-stages complete. Still a shit game, but great learning experience. Gonna try to do a stage 3 tomorrow and then add a bunch of tweaks and then it'll all polishing clean up to make it slightly less shit before I turn it in.

It's good Unity doesn't have like gameplay time log. I'm probably gonna be somewhere between 50-100 hours on this first real project over like 10 days.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 03:59:04 AM
I always wanted to make a game that took elements from top-down zelda GBA games like Link's Awakening, Oracle of Age, etc, and I started watching tutorials and shit, but that shit is hard. If I had to do my life over again i'd definitely learn 2 code though. I remember in highschool I managed to make a little Zelda movement simulator in flash (walking around, bunping against walls, being carried by water) but I can't even imagine being able to learn how to do that now.

I keep reading these books/articles over the last year or two of all these famous artists and people who didn't publish their first book/movie/album or whatever until their 40s and it gives me hope that I can still maybe get into game making even as an old dude. Never too late!

When I was a kid I was really into coding and game making stuff. I remember making like king kong on a tower you have to climb game in QBasic and a jumpman clone. The one area I was legit credible was I used to design levels for Doom II/Quake/Duke 3d/Unreal 99 and I used to actually be pretty good at it. I made one breakout Doom II level that actually got played a bit online at the time called Rooftops where it's a bunch of skyskraper rooftops and you jump from building to building including going through the interior of buildings and there are warp points all around to reset you back up to spots higher up since as you keep going from building you generally are moving downwards. Was a good fucking level and I was like 12 or something. Wish I still had my old floppy disks somewhere. Was definitely considering trying to be a level designer. Just ended up going in a different direction.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 03:13:22 PM
Sage, any chance you're available for a bit today to help me on some stuff? There's just a link of code that I don't know yet which is blocking off a ton of possibilities by having things interact with each other and I need help figuring that out if I want to do more interesting things with my game.


Like I'm trying to have a 3d polygon object attack the player in this 2d game. The problem being the physics colliding interaction between a 3d object and 2d object. Initially my bullets passed right through the 3d object even with the 3d collider on. I googled it and the get around I found was you make a hidden 2d object within the 3d object (as a child gameobject) and throw on the 2d rigid body & collider.

Doing that makes my 3d object appear solid and bumping into it kills you and bullets stop at it because they collide with the hidden 2d object underneath.

But I want to be able to destroy the 3d object with my bullets and putting a health script on the 2d object just kills the hidden 2d object and putting the health script (which includes take damage/check death) on the 3d object does nothing since it is not interacting with anything.

I feel like it should be possible to write a script that says "If my child gameobject becomes setActive(false), then destroy.this" and have the health script on the child game object set active to false when shot.

But the missing link again is my ability to figure out how to get two separate scripts & objects to interact. I have no idea how to write a script you put on a gameobject that looks to its child each update to see if it's been set active(false)? I would assume the code would be

Code: [Select]
blah blah Update()
{
   check child();
]

void check child();
{ if GameObject.Child = SetActive(true)
{debugLog("Still Alive");
Else
{Destroy(gameObject);}

I just don't know for that "GameObject.Child" spot what I write to have it look into the child attached?

I think it has something to do with this. Just need to figure out how to name things and code them.
https://docs.unity3d.com/ScriptReference/Transform.GetChild.html
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 03:29:57 PM
Going to see if this code works?

 void Update()
    {
      if (gameObject.transform.GetChild(0).gameObject.SetActive(false);)
        { Destroy(gameObject); }
    }

*edit* doesn't work, says can't convert a true/false bool to a void.

I also tried having update say checkinnerbody();

and make a non-void checkinnerbody() method that did that check but it is giving me the same error.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 04:05:34 PM
Got it checking now but still running into some issue. Trying to figure it out.

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

public class PlanCheck2d : MonoBehaviour
{
    void Update()
    {
        checkInnerody();
    }

    private void checkInnerody() {
        Debug.Log("test" + transform.GetChild(0).gameObject.activeSelf);
        if (transform.GetChild(0).gameObject.activeSelf == (false))
        {
            Destroy(gameObject);
        }
        else
        {
            // do whatever you want if child is inactive

        }
    }

}

It's disappearing on collision with player, but not with bullets and not sure why but debugging it now.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on April 02, 2022, 04:10:57 PM
I always wanted to make a game that took elements from top-down zelda GBA games like Link's Awakening, Oracle of Age, etc, and I started watching tutorials and shit, but that shit is hard. If I had to do my life over again i'd definitely learn 2 code though. I remember in highschool I managed to make a little Zelda movement simulator in flash (walking around, bunping against walls, being carried by water) but I can't even imagine being able to learn how to do that now.

I remember captivating (well, holding) my freshman high school CS class' attention for like 5 minutes at the end of the year with... my single-screen, non-scrolling recreation of Super Mario Bros. 1 in Visual Basic 6. Had basic movement but not jump physics (pressing "up" moved Mario up). The teacher rolled her eyes a little. Everyone else went back to playing Unreal Tourney behind her back.

Simpler times...
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 04:45:25 PM
I give up on this effect. This was supposed to be a productive day and I've spent the last 3 hours just trying to get one effect that doesn't even matter in the stage to work and I have no idea why it doesn't. I enjoy the game making but this is the stuff that burns me when I waste so many hours trying to get one little thing to work and cannot do it for the life of me and cannot understand why.

Basically I can get my child 2d sphere to setfalse on ship hitting collision before destroying and that setfalse destroys the 3d parent. COOL.

But I cannot get this to work with bullets and damage and health. I can get the child to take damage from bullets and die but it always just destroys and then the parent breaks the game with error that child is out of bounds. I put a million "gameObject.SetActive(false);" every fucking where in the script trying to get the child to set false before dying after taking damage from bullets but nope, nothing is working.

I can't even get the child to not destroy. There is no where in the code telling it to destroy... it's something hidden within this code I'm using that is making this impossible.

I need to take a break and get lunch and then do something else. Man, when you're making progress it's exciting and encouraging and you just want to keep creating and when you're stuck against a wall it just makes everything shit.  :'(
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 04:50:21 PM
Nevermind, I put some debuglogs in and fixed it. Though this may break a lot elsewhere...
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 05:10:59 PM
So yeah, by changing how health script works stage 2 broke. I got around it in stage 3 by not destroying the objects and just setting them false (bad I know, but for a small amount of objects should be fine)


So now on stage 2 the enemies keep firing bullets after they are dead because they are false and not destroyed.


Is there a simple way to use different health scripts between levels?

Like level 2 uses the original health script, level 3 uses my modified one called health_two.cs? Because I swear when I tried that it broke everything because everything else in the game is setup to look for health.cs.

If only I could make the levels act like completely separate games using unique scripts and transition between them.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 05:19:49 PM
Yeah, I literally have 2 scripts on the same gameobject called Health and Health_1, both are 100% the same code. This is the only script on the game object. When I enable Health.cs the object dies after x amount of bullet shots. When I enable Health_1.cs the object doesn't take damage or die. This is so bizarre.

It has to be something in the gamemanager that is referencing health?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 05:36:12 PM
Uhhhh, I fixed the entire problem and I don't know why it works, but ok?  :doge

The health code has teamIds built in.

So originally the code section that killed things when shot read:

Code: [Select]
Destroy(this.gameObject);

Which I modified to
Code: [Select]
Debug.Log("GettingHere2");
gameObject.SetActive(false);

To fix my issue of parent getting out of bounds errors because child was destroyed before it could read the child as inactive. This did not work:
Code: [Select]
Debug.Log("GettingHere2");
gameObject.SetActive(false);
Destroy(this.gameObject);

I'm guessing because it's too fast and still destroyed the object because update could be called with the parent to check if the child was active.

 
So anyhow, I tried using this for teams:

Code: [Select]
Debug.Log("GettingHere2");
gameObject.SetActive(false);
       
        if (teamId == 1)
        { Destroy(this.gameObject); }
        else
        { Debug.Log("Team ID: " + teamId); }

Thinking I could have the normal enemies in stage 1/2 be team 1 and be destroyed
While my special enemies in stage 3 could be a team 2 and not destroyed and just set false instead.

This did fix my enemies in stage 1/2 and destroys them, yay.

And if I set my special enemies in stage 3 to team 1 I get the out of bounds error like before

but if I set my special enemies to Team 2, they setactive(false), the parent sees that and destroys itself AND the child destroys itself instead of just being set inactive (which was originally happening using my set false code).

So the end result is perfect, but I have no idea why team 2 is still destroying itself but just a little slower so there's time for the parent to check active/inactive state of the child??

Anyhow, now that everything is working again, time for lunch and then actually designing stuff for the rest of the day since I got the code I wanted to do the stage effects I want.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 02, 2022, 05:36:29 PM
Tbh at this point I don't know the difference between a coroutine and a method.

Also in your post you say you'd have it check the levels, what does that mean?

Coroutines don't run on the main thread, so they run 'when they can' (which is pretty much instant on modern multithreaded cpus) but in terms of flow control are pretty useful as they don't stop until their condition is met; so you've probably seen them mostly being used as mini-timers, with something like
Code: [Select]
[ienumerator,thing]
dostuff;
yield return new wait for seconds 5;
do some more stuff;
end code block

but you can make the yield condition pretty much anything you want; they're pretty useful.

For the level stuff, you can check level load progress, and instead of doing fixed time waits could do it as like, level loaded 20% this, level loaded 40% that, etc is what I meant.

Oh yeah if you need free photoshop: check out www.photopea.com its basically web based photoshop

So I want to add a "Lives: 0" display in the UI to show the current lives outside of the debug screen.

The int with currentLives is in the health.cs script attached to the player.

The UI Display is in a separate script and using the class UIElements to override updateUI to display a text string. I can't get this to work under the health.cs script since it won't let me have the script be a child of MonoBehaviour and UIElement.

The simple thing would be to figure out how to grab that int currentLives that is on the Player in the Health.cs script from my Display script. But this is a bit beyond me and goes back to trying to get separate scripts to interact. I can find the gameObject that is player with Find.gameObject.Player, right? So how do I go from there to getting the variable from a script that's attached to it?

Not sure I'm following this, and it might just be using different terms, so lemme try and break this down with how I'd do it at beginner level;

So first off, when you say 'child', in Unity, a child object is like, attached to a 'parent' object, and its like a physical relationship in the heirachy; they're like folders and subfolders in windows explorer.

in code, when you do myclass : monobehaviour, youre not making it a child of monobehaviour, you're using whats called inheritance to get default code that you can overwrite - so like, all the builtin methods like update() onstart() oncollision() etc are all premade monobehaviour methods.
If you really want to inherit from multiple classes, you actually can't, but you kinda sorta can by using whats called an interface, but tbh I think this is a running before you can walk type of thing you don't need to do just to do UI stuff, so lemme show you an alternative and I'll cover interfaces if you do really need it?

You're best off - to start with - thinking about unity almost like plumbing; you set up the variables you're gonna want in script, but you then manually connect up the object refernce onto your script by literally dragging and dropping it, rather than doing finds for everything.

So if you have a UI Text component onscreen, you can make this script;

Code: [Select]
using Unity.UI; (this lets you acces the UI.Text directly)
class UI_Timer : Monobehaviour
{
     public Text uiTextElement;
     int timerValue=0;

     Update()
     {
          uiTextElement.Text = "Timer: "+ timerValue;
          timerValue++;
     }
}

and drag and drop your Text Gameobject onto the Text variable space, and when you run it you'll have a running timer in that text field

Does that make sense? For updating UI information, as its onscreen all the time anyway, you dont actually need to 'search' for it, you can just point directly to the gameobject - this really is the easiest way of doing this stuff at this stage and for low complexity games

Sage, any chance you're available for a bit today to help me on some stuff? There's just a link of code that I don't know yet which is blocking off a ton of possibilities by having things interact with each other and I need help figuring that out if I want to do more interesting things with my game.


Like I'm trying to have a 3d polygon object attack the player in this 2d game. The problem being the physics colliding interaction between a 3d object and 2d object. Initially my bullets passed right through the 3d object even with the 3d collider on. I googled it and the get around I found was you make a hidden 2d object within the 3d object (as a child gameobject) and throw on the 2d rigid body & collider.

I've been drinking, so lemme get back to this tomorrow, but just make sure you're seperating 'FORM' and 'FUNCTION'; if you wanna combine 2D objects and 3D objects, that don't mean shit if its only the visuals you're talking about, but you're gonna fuck stuff up if you start trying to use both Collider and Collider2D and Rigidbody and Rigidbody2D in the same script (or at the very least gonna make stuff way more complicated than it needs to be

So let's break this down to basics again; (also I don't think you need to care about child shit - if you destroy the parent object, the child goes with it)

So make a 3D Cube game object in the hierachy, then right click it and make a Sprite (or a Quad if your image is a texture not a Sprite).
When you right clicked it, you made it a Child of the based 3D cube.

Turn off / remove the mesh renderer on your cube, and you have an invisible 3D box as your parent.
If you put your movement script on that invisible box (and a Rigidbody), all your collisions and code will affect that invisible 3D cube, but from the players perspective, all they see is the 2D child object (because the 3D cube is invisible).

My best guess why your stuff isn't working with your 3D object, is because the script is called Rigidbody2D and Oncolision2D events rather than Rigidbody and Oncollision events?
Because the '2D' system in Unity is basically an entirely seperate physics engine bolted onto the existing one - IIRC, Unity uses Havoc for its 3D physics and Box2D for its 2D, so although they share a lot of similar commands in the API for interoperability reasons (and so its easy for coders to move from pseudo2D to actual 2D code) the two systems won't actually interact
Title: Re: Do any of you code for your jobs?
Post by: Madrun Badrun on April 02, 2022, 05:39:21 PM
I really like your excitement about this Bebpo. 
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 05:43:40 PM
Sage, I'll parse that when I get back from lunch.

One thing I want to do conceptually but I'm ok turning this project in without it because it might be too advanced for me.

I want the hud to say one thing in the top-corner like

"SCORE" (which it currently does)

and then mid-boss fight after a certain point (phase transition)

I want that SCORE UI text to fall off the screen (put a move script on it?)

And then be replaced by a new phrase that is like

"EROCS" 

Not sure how to do that in terms of transitioning. I'm guessing if I can figure out how to work with timers or other object interactions I can say after health reaches 50, run the score movement drop script and then spawn EROCS text which would just be a duplicate of the score text with different text in the field).
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 02, 2022, 06:32:07 PM
Not sure how to do that in terms of transitioning. I'm guessing if I can figure out how to work with timers or other object interactions I can say after health reaches 50, run the score movement drop script and then spawn EROCS text which would just be a duplicate of the score text with different text in the field).

Yeah, pretty much exactly like that - its like ragdolling something; hide the 'real' thing, then drop in a dummy copy of it at that position and let it drop.

It's a bit more complicated if you're not using a diegetic UI (which most aren't) because of stuff like, fonts rendering at different point sizes at different resolutions and shit, but, yeah
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 07:13:53 PM
Ok, back, Sage, I read your post and yeah I meant inheritance about classes.

That makes a ton of sense with IEnumerators and timers. I may use that right now for changing stuff during this boss fight since timers would help. Right now I'm thinking of just doing asynchronous scene transitions for each boss phase, so like when the boss "dies" you can't tell its died because it visually persists but the death of the boss at like 50% HP causes the next stage part to load and now the UI canvas can say "EROCS" instead of Score and the boss can be using a new moveset because it's an all new stage.

The thing with lives is the script I'm using has an int called "currentLives" in Health which is where the current # of player lives are stored. I put that on my player and in the debug window can have it update each time I lose a life and give me the current amount of player lives available.

It sounds like the easiest solution maybe within the same health script to create a public text element that = currentLives at any point?
Actually scratch that, that would make the text appear on the player ship since it's not its own object.

Still not sure how an object in the Canvas UI would be able to access that currentLives counter, but ehhh I can save this for later.


The collider situation was actually the opposite. I had 3d colliders in the 3d object which did nothing and 2d colliders in the 2d object which did the collision with the bullets and then I tied the lifetime of the 3d object to the life of the 2d hidden object so when that object which is having physic collisions with the 2d bullets dies the 3d object goes with it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 07:16:37 PM
One problem I have btw is that every enemy & the player uses the same enemy & health scripts which define a few things like HP and physics interactions and damage. So I can make changes to just effect one enemy without it fucking them all up. Though maybe this TeamId thing will help that.

Otherwise if the boss had a boss specific script I could say "when HP = 50% -> sceneload (20)" or whatever to move to phase 2.


A lot of my issues would be solved if I had written the enemy & player scripting from bottom up. Will do that next project.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 07:24:03 PM
I'm trying to use that Timer code you posted to display a timer text and I'm getting an error:

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

public class Timer : MonoBehaviour
{
    public Text uiTextElement;
    int timerValue = 0;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
   
    uiTextElement.[b]Text[/b] = "Timer: " + timerValue;
    timerValue++;
       
    }

}

The bold is giving me this error:

'Text' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'Text' could be found (are you missing a using directive or an assembly reference?)   

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 08:44:36 PM
Also one thing that would be real helpful is, is there a trick to using different versions of the same scripts in different scenes?


Like I want to change where my respawn respawns for stage 3 only and the respawn script effects all scenes. So I'm not sure how to make it only change respawn on stage 3. Like for stage 3 instead of respawning at -1/-1 from death position I want to respawn at death position just for that stage because you're not supposed to be moving at all in that stage.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 02, 2022, 09:54:49 PM
Ok, I've got a 3 phase final boss as 3 separate scenes. I just need to figure out how to write a script to change from one to another during the fight using the scene loader.
Title: Re: Do any of you code for your jobs?
Post by: remy on April 02, 2022, 10:26:45 PM
I'd have a variable that keeps track of the phase and then use a switch to change stuff based on which phase it is. Dunno if that's dumb tho
Title: Re: Do any of you code for your jobs?
Post by: remy on April 02, 2022, 10:30:16 PM
I'm trying to use that Timer code you posted to display a timer text and I'm getting an error:

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

public class Timer : MonoBehaviour
{
    public Text uiTextElement;
    int timerValue = 0;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
   
    uiTextElement.[b]Text[/b] = "Timer: " + timerValue;
    timerValue++;
       
    }

}

The bold is giving me this error:

'Text' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'Text' could be found (are you missing a using directive or an assembly reference?)   
Lowercase T https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Experimental.UIElements.TextElement.html ie uiTextElement.text
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 12:04:11 AM
I'd have a variable that keeps track of the phase and then use a switch to change stuff based on which phase it is. Dunno if that's dumb tho

I'm dumb and have been coding for like almost 20 hours straight. Can you post some example code? Brain is pretty gone.


I've just been cleaning up the game for the last few hours since I'm kind of stuck on some code bits. I now have everything up until stage 3 pretty smooth including loading stage 3 part 1. I just need to figure out how to combine these 3 phase scenes and outro to the ending. Then I gotta make a few more sprites and a few more songs and I'm done.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 12:09:06 AM
I'm trying to use that Timer code you posted to display a timer text and I'm getting an error:

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

public class Timer : MonoBehaviour
{
    public Text uiTextElement;
    int timerValue = 0;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
   
    uiTextElement.[b]Text[/b] = "Timer: " + timerValue;
    timerValue++;
       
    }

}

The bold is giving me this error:

'Text' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'Text' could be found (are you missing a using directive or an assembly reference?)   
Lowercase T https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Experimental.UIElements.TextElement.html ie uiTextElement.text

Thanks, it compiles now but I stick it on a gameobject either in the UI canvas or not and it's not doing anything?

Shouldn't a timer: 0 show up and start counting upwards?


I want to put dialogues into this boss fight and if I can figure out how to make text appear and change during the fight I should be able to do it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 12:11:05 AM
Gonna watch this and see if it answer that:

https://www.youtube.com/watch?v=LuAAzNDhVko

*edit* nm, that wasn't it. Was just showing permanent text on the main camera. I'm looking for like being able to make text a game object I can drop somewhere in the scene and have activate on a timer.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 12:27:22 AM
Ok, figured out that attaching a canvas to a bank 2d sprite with 0% opacity and then textmeshpro to that canvas gets the text to show up.
Now I just need to figure out how to make the text disappear and appear at certain times so I can change the dialogues. Actually I put a timed object destroyer script on it and that makes it go away.

Now I just need to figure out how to time it to appear?

Also got that timer code working. I wonder if I can use that timer as a way to trigger things through scripts since I can see what time it is when I want things to appear.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 12:50:52 AM
Gonna try this conceptually, making text objects with a script that sets them to active(false) at awake. Then this timer script should set them active at a certain time?

Code: [Select]
public class Timer2 : MonoBehaviour
{

    public Text uiTextElement;
    int timerValue = 0;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

        uiTextElement.text = "Insanity: " + timerValue;
        timerValue++;
        if (timerValue == 1000)
        { displayText(); }

    }

    public void displayText()
    { transform.GetChild(0).gameObject.SetActive(true); }
}
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 12:54:42 AM
Oh shit, it works!

I can now have things inactive that will active based on this timer code. Thanks Sage and remy, this will go a long way towards getting this done. I can even scene load at certain time points to change between phases. Conceptually this should finish the last of the coding I need to complete this game and I can just focus on art/music and polish.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 01:23:02 AM
Yeah, that was it. The missing link that's the game changer. Got text stuff going, my scene changes are working. Now that I have a timer I can do lots of stuff. Since the text childs destroy themselves after a few seconds the next one is always child(0), so the code was pretty easy!

Code: [Select]

        uiTextElement.text = "Insanity: " + timerValue;
        timerValue++;
        if (timerValue == 600)
        { displayText1(); }
        if (timerValue == 1000)
        { displayText1(); }
        if (timerValue == 1800)
        { displayText1(); }
        if (timerValue == 3100)
        { displayText1(); }
        if (timerValue == 6600)
        { displayText1(); }
        if (timerValue == 7900)
        { displayText1(); }
        if (timerValue == 8300)
        { SceneManager.LoadScene(17); }
    }

    public void displayText1()
    { transform.GetChild(0).gameObject.SetActive(true); }

About the only thing I still don't know how to do is display ship lives :|  Not a big deal, though players probably want to know how many lives they have left.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 02:47:16 AM
Actually, had one more final piece of code to figure out. Phase 2 of my boss fight requires you to kill the 2 parts of the boss to then load to phase 3.

Spent the last 45 mins trying to figure out how to get count of enemies on screen through the timer script (or a new script) so I could tell it to change scenes after the 2 enemies were killed.

After 45 mins, my end barely working result was going to the game manager and putting in:

public void IncrementEnemiesDefeated()
    {
        enemiesDefeated++;
       if (enemiesDefeated == 2 && SceneManager.GetActiveScene().name == "Level3_Game - Second Phase")
        { SceneManager.LoadSceneAsync(18); }


      if (enemiesDefeated >= enemiesToDefeat && gameIsWinnable)
        {
                LevelCleared();
            }

Bolded being what I put in which is extremely specific and can only be used on a case by case basis of putting in the scene name and the enemy count in game manager.

The problem is that their "levelcleared(); code pops up a victory splash screen with a "proceed to next level" button after all enemies are defeated. Which doesn't work when you want a seamless transition from one phase to another during a boss which is why I had to mickey mouse the whole thing. Sigh.

I need to make this transition work better but otherwise if I do this one more time to transition after the final boss final phase is killed to the ending that should be it for code for this project and it's just assets left for tomorrow.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 04:46:25 AM
Phew, finished ALL the coding for the game at like 12:49pm after coding all day from like 10am and doing very little asset work. I ran the game from start to finish and...I hit a weird game killing bug in stage 3 that only occurs if you've played four mins of stage 2 prior.

Took me so.long to debug, but I got it. Also fixed another bug with my splash screens after game overs or level select mixing up.

Finished it from start to finish. It's a complete game. Lasts about 5-7 mins. First game I've finished making since I was like 15 years old.


Now I'm still missing a bunch of assets and the project is due tomorrow night so gonna be hustling to get the rest of the art/music/sound effects/text/polish in, but creating that stuff is more fun than all these hours trying to figure out how to get stuff working and banging the head against the wall. So should be a good day provided I can get some sleep now lol. Didn't even get dinner tonight  :'(
Title: Re: Do any of you code for your jobs?
Post by: remy on April 03, 2022, 05:40:55 AM
About the only thing I still don't know how to do is display ship lives :|  Not a big deal, though players probably want to know how many lives they have left.
You have your lives stored as a variable somewhere right? And in your UI code you're displaying the value of the timer.

Lives are probably conceptually the same as the time. You just need to point your UI code to where you're storing the lives.

Awesome to hear you got it done though. I wanna play it.

This thread has also made me want to get back into making stuff as a hobby again lol. Maybe after I finish endwalker I'll do the course you're doing  :P
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 03, 2022, 08:16:33 AM
Also one thing that would be real helpful is, is there a trick to using different versions of the same scripts in different scenes?

If you feel like it when you're done, I'd really like you to rewrite this from the scratch but without the stuff thats already there, because I can't help but feel you're getting misled on some stuff or not quite getting the rationale behind why theyre doing what they're doing, because if you're breaking scripts up into effectively components that do things, you should be able to use basically the exact same script in hundreds of different places; like, a movement script can be used by players or enemies, its just getting its inputs from either the player or an AI controller, a health system is a health system, a damage system is a damage system etc.

Yeah, that was it. The missing link that's the game changer. Got text stuff going, my scene changes are working. Now that I have a timer I can do lots of stuff. Since the text childs destroy themselves after a few seconds the next one is always child(0), so the code was pretty easy!

...

About the only thing I still don't know how to do is display ship lives :|  Not a big deal, though players probably want to know how many lives they have left.

Like this is an example where I'm not sure you're getting it, but you're getting results you want so you're good...?
Because I was trying to show you how to connect up a UI element, and then update it via code, rather than write you a good timer, lol. That timer - although yeah it works! - is kinda awful, because its gonna hammer your UI at 400fps or whatever uncapped framerate is, lol.

So if you wanna show lives, you can just do this:

Code: [Select]
public Text livesTextUI;

void UpdateLivesUI(int lives) // call this method whenever you change the lives value, and send it your updated lives variable
{
     livesTextUI.text = "Lives Remaining: " + lives; // or however you want to phrase this; eg could be livesTextUI.text = lives + " / " + maximumLives;
}
dragging and dropping your lives UI text component into the variable field

For a more robust / readable Timer codesnippet, you could do something like;

Code: [Select]
float timerCurrent=0f; // timer value
bool runTimer=false; // for a simple start / stop toggle
public Text timerTextUI;

void StartTimer(float tickrate)
{
     runtimer=true;
     InvokeRepeating("MyTimer", 0, tickrate);
}

void MyTimer()
{
     if (!runtimer) { StopTimer(); return; }
     timercurrent++;
     timerTextUI.text = timercurrent;
}

void StopTimer()
{
     runtimer=false;
     CancelInvoke();
}

void RestartMyTimer(float tickrate)
{
     timercurrent=0;
     StartTimer(float tickrate);
}


which would take an input in seconds, and then run every tickrate seconds (and its a float, so you could do 0.5 if you wanted 2x per second or whatever)


Lives are probably conceptually the same as the time. You just need to point your UI code to where you're storing the lives.

yeah, exactly - the Text variable is just a UI Text string - you can make it say anything you want
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 01:17:13 PM
Couple of things from your post.

1. Yeah, re-writing the code to be all my code and more efficient and better understand stuff would be good. I'll try to do that while I'm taking my next class on 2d platformers before I get to the actual "write a 2d platformer" game part. That way I'll have time and will be good practice.

2. Multiple scripts, I do get that if you're efficient you can do things in one script which is mostly how my project is setup. Like you just need to put in public bool various checkboxes to modify that script to work in many different ways. A good example would be a gamemanger script that figures out how to end the level. You could have a checkbox that says "end level when enemies killed?" "enemies that need to be killed __", and "end level when specific enemy killed?" "enter name of specific enemy that will trigger this _______", "end level after X amount of time?" "enter what time the level will end ____", "do you want to go to a win screen when level ends Y/N (if not will instantly transition to next scene)" "do you want to wait before loading next level?" "if so how long to wait ____" etc... something like that would be very flexible.

One spot I need multiple scripts is for my story scenes because there is no good way to grab the currentscene number as an int? I googled and people had complex array division ideas for that, but built into scenemanager is only a way to get the currentscene name. So the problem with my splash screen scripts for my story between levels is to start the story chain of scene changes it needs to have an int that increases per scene. If you use that same script for different story sequences the int will get all messed up. So I ended up using a different version of the script for each story sequence and the first thing the script does is set an int that increases. Probably easier to explain with code than words though.

3. For showing lives. I understand how to show UI elements thanks to that timer script your wrote. The reason I said I don't know how to show lives is what "lives" are is a formula that depends on other scripts because it gets adjusted as you take damage and die. So currentLives is an int stuck within the health.cs script. I'd like to write a fresh script called "Showinglives.cs" that somehow was able to grab that currentLives variable from the health.cs script and show it to the UI but I don't know how to do that (how to grab that int currentLives from the health script in my showlives script). I can get around it though by putting the show UI lives code within the health.cs code where that variable is, so that's what I'll do.

When this is done, the next thing I want to do is read/watch some long detailed classes on how to get different scripts to talk to each other and to practice that a ton until I'm comfortable. Because it is one of the major things I still don't know how to do. Like in my game the gamemanager script freely calls methods that are in other scripts that if I tried doing that in my own script the game would balk saying that method doesn't exist in my script I wrote. Other scripts then send things to the game manager and back and forth. It seems the game manager can do that, but to do that with other scripts it's more complicated. If I want to write a fresh script that says "yo, give me the current values of variables in 5 different scripts running on this object right now" I don't know how to make that work?

4. Oh shit that is bad on the timer being cpu dependent because I have a combination of move speed objects mixed with timers and if the time is different for every computer that will completely break level 3. I guess first thing I'm doing this morning is re-writing my timer with delta.time instead and re-timing everything in stage 3.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 03, 2022, 01:37:59 PM
One spot I need multiple scripts is for my story scenes because there is no good way to grab the currentscene number as an int?

Nah, thats definitely not right...
Code: [Select]
SceneManager.LoadScene(int)specifically takes an int - I've literally never used a string for that stuff; you can get current scene with Scene.buildIndex by doing something like
Code: [Select]
int GetScene()
{
     scene = SceneManager.GetActiveScene();
     return(scene.buildIndex);
}

When this is done, the next thing I want to do is read/watch some long detailed classes on how to get different scripts to talk to each other and to practice that a ton until I'm comfortable. Because it is one of the major things I still don't know how to do. Like in my game the gamemanager script freely calls methods that are in other scripts that if I tried doing that in my own script the game would balk saying that method doesn't exist in my script I wrote. Other scripts then send things to the game manager and back and forth. It seems the game manager can do that, but to do that with other scripts it's more complicated. If I want to write a fresh script that says "yo, give me the current values of variables in 5 different scripts running on this object right now" I don't know how to make that work?

So without getting into stuff like observer patterns or delegates / subscribers, you can access public methods from other scripts if you have access to that other script.

So before we did that with colliders, as when things collide they can talk to each other?
If a thing you collide with has a Health.cs script on it, and in that script it has a public TakeDamage(int damage) method in the health script, you can do

Code: [Select]
OnCollisionEnter (Collider col)
{
     int damage=10;
     Health variableRepresentingAScriptCalledHealth = col.getcomponent<Health>();
     variableRepresentingAScriptCalledHealth.TakeDamage(damage);
}

If the scripts are on the same object, you can find them the same way, by checking the components the object this script is attached to (and might wanna have an 'if not null' check for safety).
You can also setup explicit references in the Unity inspector, as a Player script is likley to have a bunch of references setup for shit most players have, like movement, audio, UI elements etc
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 01:59:40 PM
Nah, thats definitely not right...
Code: [Select]
SceneManager.LoadScene(int)specifically takes an int - I've literally never used a string for that stuff; you can get current scene with Scene.buildIndex by doing something like

Yeah, that's what I use to load scenes, but I'm looking for the opposite. Scenemanager has tons of ways to load a scene, but getting the info on the current scene (i.e. we're in scene 5 now, I want to make an int = currentScene; and have that int come out starting at 5 because it's the current scene.

Quote
Code: [Select]
int GetScene()
{
     scene = SceneManager.GetActiveScene();
     return(scene.buildIndex);
}


Maybe this is it?

I don't understand that code though, it returns an int, so say it runs and returns = 5 because we are in scene 5. Where is the variable where that 5 is now stored? Would it be:

Int currentScene = GetScene();

Int Getscene();
{
     scene = SceneManager.GetActiveScene();
     return(scene.buildIndex);
}

?

That doesn't seem right...
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 03, 2022, 02:06:41 PM
yeah, a method with a return type will spit out what you return as a variable.

you could even do scenemanager.loadscene(GetScene()+1);
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 02:42:52 PM
Ok, so I'm working now and that fully decked out timer you posted is giving me a couple of compile errors.

   public int timerValue;
    public Text uiTextElement;
    public Text uiTextElement2;
    public string TypeTextHere = "Enter Text Here";

    float timerCurrent = 0f; // timer value
    bool runTimer = false; // for a simple start / stop toggle
    public Text timerTextUI;

    void StartTimer(float tickrate)
    {
        runTimer = true;
        InvokeRepeating("MyTimer", 0, tickrate);
    }

    void MyTimer()
    {
        if (!runTimer) { StopTimer(); return; }
        timerCurrent++;
        timerTextUI.text = timerCurrent;
    }

    void StopTimer()
    {
        runTimer = false;
        CancelInvoke();
    }

    void RestartMyTimer(float tickrate)
    {
        timerCurrent = 0;
        StartTimer(float, tickrate);
    }


The first bold it doesn't like because it's trying to convert an int (time) to a float (time text).

The second bold it doesn't like because it says you can't have "float" there.

And I'm assuming from this for my game events I'd use:



Also I see you're using tickrate instead of time.deltatime. Is this better for a more stable time between all different computers? I.e. I want big boss to jump out on screen at 5 seconds in on the level because at 5.5 secs something else will fall into the screen covering it and at 4.5 seconds the same thing so only during that 5 second window is the screen open for the boss to jump in.

Void start{startTimer (1.0f)}

Then if currentTime = 5 seconds = boss jump out?

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 02:52:04 PM
I fixed the 2nd bold by putting in 1.0f instead of float ticket rate in restart my timer. But code still doesn't like the text thing.

Fixed the first by looking at the previous timer and changing it to "timerTextUI.text = "Time: +" + timerCurrent;"

Will see if it works.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 02:57:11 PM
Ok, this works, retiming everything in the stage!
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 02:59:37 PM
Actually, is there a way to get the timer to display as a float with a 1.5 secs in the UI display? It's only displaying whole numbers which is a bit of a guessing game in timing this stuff compared to the other timer which was like in the millimillimillisecond on the UI display.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 03:05:07 PM
Ugh, this is acting way less accurate than the old timer. Not sure what's going on.

I have the first text/gamechild destroy at 2 secs and the next trigger at currentTime = 3 seconds, but it doesn't. Only at 4 secs or later. Same with trying like 3.5/3.6/3.7, I get nothing before 4 secs. It's like the timer isn't working before 4 seconds?

Basically limitations I'm seeing with this code currently is:

-Can't display anything before timer = 1
-Needs like an extra second to process between updates so need to space out time events by at least 2 seconds
-Can't timer stuff as a float, only whole number integer (which is bizarre because it's definitely a float)


Here's my code:

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

public class Timer2 : MonoBehaviour
{

    float timerCurrent = 0.0f; // timer value
    bool runTimer = false; // for a simple start / stop toggle
    public Text timerTextUI;

    void StartTimer(float tickrate)
    {
        runTimer = true;
        InvokeRepeating("MyTimer", 0, tickrate);
    }

    void MyTimer()
    {
        if (!runTimer) { StopTimer(); return; }
        timerCurrent++;
        timerTextUI.text = "Time: " + timerCurrent;
    }

    void StopTimer()
    {
        runTimer = false;
        CancelInvoke();
    }

    void RestartMyTimer(float tickrate)
    {
        timerCurrent = 0;
        StartTimer(1.0f);
    }


    // Start is called before the first frame update
    void Start()
    {
        StartTimer(1.0f);
    }

    // Update is called once per frame
    void Update()
    {

        if (timerCurrent == 1)
        { displayText1(); }
        if (timerCurrent == 4)
        { displayText1(); }
        if (timerCurrent == 8)
        { displayText1(); }
        if (timerCurrent == 12)
        { displayText1(); }
        if (timerCurrent == 20)
        { displayText1(); }
        if (timerCurrent == 41)
        { displayText1(); }
    }

    public void displayText1()
    { transform.GetChild(0).gameObject.SetActive(true); }

}
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 03, 2022, 03:11:06 PM
couple of compile errors.

        timerTextUI.text = timerCurrent.ToString();

        StartTimer(float, tickrate);

oops, my bad - the above should fix the above; I'm pseudocoding from my head, so don't have syntax highlighting and autocomplete XD

Also I see you're using tickrate instead of time.deltatime. Is this better for a more stable time between all different computers? I.e. I want big boss to jump out on screen at 5 seconds in on the level because at 5.5 secs something else will fall into the screen covering it and at 4.5 seconds the same thing so only during that 5 second window is the screen open for the boss to jump in.

Void start{startTimer (1.0f)}

Then if currentTime = 5 seconds = boss jump out?

Yeah, invoke / invoke repeating both use real time for their delays; the delays are basically artificial, the code runs, but then it gets told 'wait for x seconds first tho plz'.
For really fine tuning of order of events at specific times, you might want to consider a coroutine, because you can literally stack yields inside one and do

Quote
private IEnumerator BossSetup()
{
     yield return new WaitForSeconds(5f);       
     Boss.gameObject.SetActive(true);
     yield return new WaitForSeconds(0.5f);       
     BossAnimation();
     yield return new WaitForSeconds(0.5f);       
     OtherThingHappens();

which will wait half a sec between each chunk, but if you're otherwise good, you're otherwise good!

e:
Ugh, this is acting way less accurate than the old timer. Not sure what's going on.

I have the first text/gamechild destroy at 2 secs and the next trigger at currentTime = 3 seconds, but it doesn't. Only at 4 secs or later. Same with trying like 3.5/3.6/3.7, I get nothing before 4 secs. It's like the timer isn't working before 4 seconds?

just to be clear, are you using it like a stopwatch, or like a timeline? A tickrate of 1 should mean it runs the timer ~ once per second; if you want it more accurate, you can run it faster, and do like, a 0.1 tickrate with your timings multiplied by 10 - its still going to be more efficient than hammering in Update

e2:
you say nithing runs between 1 and 4 seconds, but thats the only thing you check in the code you posted...?
Code: [Select]
        if (timerCurrent == 1)
        { displayText1(); }
        if (timerCurrent == 4)
        { displayText1(); }
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 03:16:15 PM
Oh, ok, I didn't know what tickrate does. Will do it at .1 to get more accurate timings.

Yes, I'm using it like a stopwatch, watching the stage flow and writing down the # when I want each event to happen.


I like your coroutine concept, seems perfect for stage scripting of events. Will use that next time.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 03:27:15 PM
There's still a weird thing where it doesn't want to do anything before about 4 seconds real time. No idea why. I set the tickrate at .1f and trying to display first text at 10 and nothing happens. It starts with the next one at 40.

It's fine as I can set the first one to display under start();
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 03, 2022, 03:31:08 PM
yeah, unless you're checking the timer in another bit of code, the one you posted only does stuff at 1 second and 4 seconds, so it doing nothing between those is as intended...?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 03:42:44 PM
The one at 1 second doesn't run though...

But I got it all working just putting it under start for the first one and first timer related one being at 30 ticks (.1f tickrate) which is fine. Just seems like there's a brief lag with the tickrate before it can run commands?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 03:43:26 PM
Oh, speaking of multiple scripts. How would you write a multi-use respawn script if you want to respawn at different offsets each time? Just have the offset be a public variable?
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 03, 2022, 03:56:41 PM
The one at 1 second doesn't run though...

But I got it all working just putting it under start for the first one and first timer related one being at 30 ticks (.1f tickrate) which is fine. Just seems like there's a brief lag with the tickrate before it can run commands?

huh, it might be an order of execution thing;
in the original script, in this line:
Quote
InvokeRepeating("MyTimer", 0, tickrate);
that zero means 'run this shit immediately' - you can delay it there, which might stop it missing the first set value...?

Oh, speaking of multiple scripts. How would you write a multi-use respawn script if you want to respawn at different offsets each time? Just have the offset be a public variable?

in terms of splitting up functionality, you can do
Code: [Select]
Vector2 Setspawn(int spawnIndex)
{
     Vector2 spawnPos;
     //whatever you're doing to offset the spawn here, eg if you spawn one unit further to the left on each death
     spawnPos = new Vector2((0-spawnIndex), 0);
}

void DoSpawn(transform spawnPos)
{
     newSpawn = spawnPos + SetSpawn(timesDied);
     instantiate(player, newSpawn, transform.rotation);
}
or whatever.
Or you could just have two floats for spawnX and spawnY, and set them directly? that would probably be even less complicated
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 03, 2022, 04:11:15 PM
Fixed all the timers. Now the game should "hopefully" work on every setup.
Now gotta finish up the art assets.


Btw, so with the animator in Unity, when you put animation on a sprite and you scale the sprite up or down the animation scales as well.

But, when the object dies, if I have a death animation it's not scaled :|  I think this is because the gamemanger script has it setup where the object and its death animation are separate because you put for each object "death effect" where you drag a prefab which is the death animation & sound effect for that thing. Not sure if there's a quick solution to this other than to go back to the animation program and resize the animation loop at the scale you're going to have the sprite in game so the animation matches on death.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 12:00:36 AM
Been sprite & animation making for the last 8 hours. Done with all the sprites/animations I needed. Now just gotta put them on objects and allllmost done. Need to make like one song and some sfx and clean up a few small things. Might make it by the midnight deadline.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 03:11:26 AM
Just turned it in at 11:59pm.

Not super happy.


Most things worked. I never got to the rest of the music or upgrading the game over/title pages or adding any additional script features like a retry button on game over for each of the final boss phases. Or doing any interesting UI movement stuff.


Implementing all the sprites and animations I made today including player/enemy/boss sprites, animations and death animations and even replacing the bullet sprites with more Cave-like bullets and animating some of the environmental effects a bit more took hours.

Worst of all, I spent like 3-5 hours today entirely on the final boss animation and death animation since I wanted it to be the most impressive visual piece of the game. Instead of a small 16x16 I upscale 10x just to get working in my game, it's a big 600 x 500 or something sprite.


For whatever reason Unity fucks up the sprite in animation and makes it look like some 12x12 blurry thumbnail. The sprites in unity after being sliced up look fine and sharp and full size. But when I put them on an object in animator and make an animation it's like a thumbnail and looks like total shit. This really bummed me out since I put so much effort in.

I guess I'll be spending another day troubleshooting this and if I can fix it, I'll spend another day doing the last little music and effects bits I wanted and then I guess I'll share it with y'all. Really was hoping to be done today after like 60 hours crunching over the last 4 days on this.
Title: Re: Do any of you code for your jobs?
Post by: remy on April 04, 2022, 03:14:35 AM
60 hours crunching over 4 days is indeed an authentic game dev experience
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 03:43:17 AM
FIXED IT. There's a bit on sprite compression where it's on normal compression and I changed it to best quality. Problem was the sprite was too large because I made it too awesome :(
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 03:51:24 AM
Oh wow, changing max size really, really changes it up. Like night and day. Gonna go back through all my sprites. Stupid low file size compression fucking everything up. Looks sharp now.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 04:47:22 AM
So the game's in a pretty good place. I mean it's still just a 5 min mediocre first indie game that absolutely does not feel like it shows 100-200 hours of dev time. But then again like 75% of that was learning, learning, learning. Every day I learned like a dozen things that will apply to any future projects.

Hell, today when I was trying to animate the final boss I started breaking it down modularly and drawing and animating each part of it separate and then layering it together. Even just doing simple small animations with layers so you can transform and rotate certain parts without other parts is really helpful.

I wrote up a checklist of all the items left that I'd like to do. Definitely less pressure now that the game is feature complete and working and turned in. Basically can just enjoy polishing it up a little bit more and adding a few things and then will call it good. Definitely calling it good this week so I can move on and start watching some new classes and learning new things.

Will link it later in another day or two.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 04, 2022, 12:58:49 PM
But, when the object dies, if I have a death animation it's not scaled :|  I think this is because the gamemanger script has it setup where the object and its death animation are separate because you put for each object "death effect" where you drag a prefab which is the death animation & sound effect for that thing. Not sure if there's a quick solution to this other than to go back to the animation program and resize the animation loop at the scale you're going to have the sprite in game so the animation matches on death.

Hey, rememeber when you were messing with transform.localscale earlier?
after you spawn it, use transform.localscale to resize it to the new scale!

FIXED IT. There's a bit on sprite compression where it's on normal compression and I changed it to best quality. Problem was the sprite was too large because I made it too awesome :(

You also want to set texture filtering (FILTER MODE) to POINT rather than bilnear / trilinear if its pixel art, so it renders 'as is' rather than trying to smooth it with a lowlevel blur

Will link it later in another day or two.

Do a WebGL build and stick it up on Itch.io!
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 01:42:09 PM
Yeah, been using point and webgl builds. Also fixed matching up the death animation size last night :)

So tired today. Crunch is hard. Goal for next game is better planning and less crunch. Gonna need a few days for my body to recover from this.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 03:47:56 PM
My project got a couple of peer reviews and passed yay!

Some nice comments too.

I did lose a couple points because of no screenshots. I have screenshots on my itchi.io page but yeah looking on view page they don't show. Turns out you have to edit the theme and set sidebar for screenshots or they don't show. Good to know. Just like the Unity extreme compression I have no idea why these are the default settings for things.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 08:56:42 PM
Doing some clever more efficient code stuff in my clean up but there's one thing that conceptually I'm not sure how to do and I think it has to do with my animator.

Basically one thing I didn't like was when you killed the final boss and the death animation started the other enemies on the map (which are invincible bullet spawners) would keep spawning bullets that could kill you while the final boss death animation was playing.

So to solve this I created a new scene and set the idle animation of the boss to the death animation and destroyed the object with a set destroy timer once the animation finished.

Now once the last hit registers it instantly changes to the new scene where the boss is in the same place but the other enemies are gone and then the final boss animation plays and then it transitions to the ending.

This is better, but the transitions are still a bit jarring. Like suddenly the other enemies just vanish and I feel like there should be a short pause upon the final shot landing on the boss before the very short death animation starts and ends. This would require two coding concepts:

#1 - A script on each enemy to search the scene at every update and when the boss uhhh changes sub-state to running death animation to then start running their own death animations? This is actually a bit complicated because it requires not just getting objects and setting them true/false but changing settings within their component scripts. Maybe there's a simpler way to do this?

I mean I could just have the enemies search the scene and when boss is setActive(false) to run their death effect animations but they'd still be shooting bullets while the boss death animation is playing.

*edit* - Ok, interestingly if I put the other enemies as children of the boss they disappear on final boss final hit and the boss death animation plays out. This is good. But I wish I could have the other enemies play their death animations and not just vanish.

#2 - To have a pause before the death animation starts. I feel like I need to learn the animator controller and how to add states and transition between them. I have taking/watched zero classes on the animation controller and all I know is how to make a controller and give it one animation I make and that's it.

A work around is for me to go back and edit the animation to just add a bunch of sitting still frames for a second first and then go into the animation. That way I can play a sound effect on death ARGHGHHH and pause sits for a second, hopefully the other enemies on screen die in #1 above and then the boss plays out the death animation.


In the end this is super nitpicking, but improving transitions and stuff is the kind of polish that goes a long way! Hell, on that note when the final boss appears it would be nice to lean how to do a transition effect so it like wavy lines fizzles into existence. Right now the scene loads and there's an empty space and then it just POPS into existence and starts spewing bullets instantly. For other bosses I have them come down from off-screen but this boss should start in the middle of the screen so either it's there the second the scene loads and instantly firing bullets (I'd need to mess with the timer to pause this) or it pops into existence a few seconds later which I'm ok with and is how it is currently. Just would be nice to learn how to make an effect for bringing it into the scene.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 09:05:32 PM
Just brainstorming but a potential slightly complicated way of doing #1 could be having a script on the non-boss enemies that checks boss HP each update and when boss HP == 0 they run their death effect.

Now that goes back to the thing I don't know how to do which is one object checking a variable in another object's script though.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 09:15:23 PM
Well I figured out the life UI thing pretty quick. And yeah I just stuck it under the health script where currentLives are stored. Added public Text bit and stuck it on the UI and there you go.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 04, 2022, 10:54:02 PM
Ok, got some small cool stuff in. Added a retry button that reloads stages skipping cutscenes and figured out how to make an easy mode version of the final boss stage. Actually pretty easy making multiple difficulty stage variations since you can adjust all kinds of stuff quick (lives, invincibility time, enemy health, enemies on-screen). Will use this knowledge in the future to make multiple difficulty levels for future projects if it makes sense.

As someone that hates dying and sitting through shit again, getting that retry button in was pretty important before I started sharing the project  :lol
That's sort of the best thing about game making is you can make sure to address all the little stuff that pisses you off in games.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 02:02:23 AM
Spent part of tonight redoing my skull enemy. The old animation was just testing some shadowing and the animation is lacking in fun. Ideally I want things in my game to be fun. So I gave my mohawk skull an MGS style death.

Old:
(https://i.imgur.com/ePOmqSv.gif)

(https://i.imgur.com/1GpA9NF.gif)

New:
(https://i.imgur.com/ikQTNsG.gif)

(https://i.imgur.com/QxfdTTI.gif)


This really isn't anything much to do with my game, I'm just enjoying being able to animate things for the first time in my life as someone with no hand drawing talent.
Title: Re: Do any of you code for your jobs?
Post by: daemon on April 05, 2022, 08:54:37 AM
Which software are you using for spritework?

I recommend Aseprite.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 01:16:52 PM
Had a friend test out the game and had some good ideas. One was adding lifebars for bosses to tell you are making progress. I'll look up a guide on that, having something visual besides a number that changes per hit is something I haven't coded yet.

Which software are you using for spritework?

I recommend Aseprite.

Yeah, I'm using Aseprite. It's great! Lots of really good tools. Though I still can't figure out how to paste  a group of animation frames after copying them. I ctrl+c on a group and ctrl drag them to the end of the bar and it only pastes like..two random frames of the batch. So I'm manually copying and pasting and moving one frame at a time. At some point I should go through a tutorial.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 05, 2022, 02:25:47 PM
again there are myriad ways to do anything, but an easy one is if you have a simple object that is "textured" with just one color, like green for a life bar, and have its width set to a calculation based on 100% of the boss's health, and simply reduce its width as life goes down (revealing a UI element behind it that is red to show how much of the bar has depleted)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 02:59:01 PM
again there are myriad ways to do anything, but an easy one is if you have a simple object that is "textured" with just one color, like green for a life bar, and have its width set to a calculation based on 100% of the boss's health, and simply reduce its width as life goes down (revealing a UI element behind it that is red to show how much of the bar has depleted)

Thanks, that's great. My one concern is I don't want an ugly lifebar messing up the visual space, so really depends on how much I can get it to look alright. Otherwise I'll skip lifebars.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 06:35:04 PM
Couple of things:

1. I'm definitely at that point where the thing is pretty much done but I keep going "Well I can make this better" or come up with a new idea and go "aha, I'm gonna spend hours doing this" and sometimes I do it and it makes it worse and I throw it all away, and basically I keep tinkering with the thing and it never actually gets released.

I'm very aware that this is my first baby's first game test game and it's not supposed to be perfect, hell it's not even supposed to be good and if I stick with this I have a very long road ahead of learning and many more projects and I need to move on and start the next class.

So I'm gonna just finish a few more bits (nothing too intensive) and get this out by tomorrow.


Now
2. For a small thing, at lunch I tried putting my enemy movement script on a canvas UI text to have it move off the screen and a new canvas UI text moves up from off screen to replace it. The going down off-screen is fine, but going up is fucked because my movement script is incrementing based off the transform.position of the object in the game, whereas the canvas UI transform position of the object is relative to the local window size canvas. What works on my screen suddenly does not work on the WEBGL embedded version. Not only that but it crashes the WebGL version whoops.

Is there a way to modify my script to make the movement increments like canvasUI.gameobject.transform.y instead of transform.y to move it up or down on the canvas based on its position relative to the canvas (the text is a child of the canvas)?

*edit* google search makes it seem like I should be using rectTransform instead of transform. I'll see it that fixes it. Localscale might fix it too...
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 07:09:33 PM
(https://i.imgur.com/L5w3DKO.jpg)

How do I get that -24 number? I want to set an (if > -24) move upwards.

I'm trying RectTransform and this code just gives me the RectTransform is 0.0, 0.0 no matter where the text object starts on screen and I can only manipulate it relative to that.

Code: [Select]
  void Update()
    {
        RectTransform RT = GetComponent<RectTransform>();

        Debug.Log("RTpositiony = " + RT.position.y);
    }
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 07:44:32 PM
Unity manual says localScale should be the position relative to the parent. And Localposition is relative to screen pixels.

When I use:

Debug.Log("RT " + transform.localPosition.y );

it gives me -235 because the parent is like -211 or something. So in the inspector it says -24. I can't figure out how to get the parents transform.localPosition so I can just do:

Debug.Log("RT " + transform.parent.localPosition.y - transform.localPosition.y ); to get -24?

When I use localScale it gives me 1,1,1 which is still nothing like -24.

I'm very confused.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 08:18:42 PM
finally found it on the example using the unity manual.

m_RectTransform = GetComponent<RectTransform>();
Debug.Log("RT " + m_RectTransform.anchoredPosition);

This gives me, -78, -24.4 in the debug window.

Now just need to figure out how to grab the Y and manipulate it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 05, 2022, 08:36:58 PM
Got it maybe working, using the traditional transform.position movement but using that m_RectTransform.anchoredPosition to find the point at which to stop moving the text. Will need to test it on the embedded version to see if it works on a different screen size.

Code: [Select]

public class Test_MoveSpecial2 : MonoBehaviour
{
    public float EnemyMoveSpeed = 1.0f;
    public bool GoingUp = false;
    public float DestinationY = 0;
    RectTransform m_RectTransform;

    private void Start()
    {
        m_RectTransform = GetComponent<RectTransform>();
     
    }

    void Update()
    {
        Debug.Log("RT " + m_RectTransform.anchoredPosition.y);
        if (GoingUp == true && m_RectTransform.anchoredPosition.y <= DestinationY)
        {
           

        transform.position = new Vector2(transform.position.x, transform.position.y + (1 * EnemyMoveSpeed * Time.deltaTime));
        }
        if (GoingUp == false && m_RectTransform.anchoredPosition.y >= DestinationY)
        {


            transform.position = new Vector2(transform.position.x, transform.position.y + (-1 * EnemyMoveSpeed * Time.deltaTime));
        }
    }
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 06, 2022, 12:29:17 AM
Assuming nothing breaks when I finally build it, game will be released in approximately 30-60 mins!

*edit* had crashes with the WebGL version; compiling what I hoped is the fixed version now. I have issues throughout the whole thing with UI text and getting the right size & position. Need to learn how to get this right for localScale. So best way to play it is in the windowed version, fullscreen is fine but a few spots have kind of small text.

*edit* This time when I tested out the WebGL build (and building these things takes like 10 mins each time) got all the way to the end credits and crashed on loading them.

Basically all my crashes are from all my fucking with the UI text trying to make it move around and change because sometimes it won't be there in the next scene and stuff is scripted to put things in it and I get nullpointer exceptions.

Some of my if/else statements keep failing and I end up in else even though there is no reason why I should be? And I don't 100% know how to use null, like an example of code (not literal code) is

if scene5, put text in textgoherespot + timer; else put other text in textgohere spot.

But sometimes that spot disappears and it gives me a null crash. I tried "if textgoherespot = null" do nothing" but it wouldn't let me use null with a string?

I ended up getting around this by using tags and telling it only to do those things in scene where there is an object with the "player" tag and then untagged the player in scenes that was going to be an issue.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 06, 2022, 03:03:54 AM
https://dkclassdesign.itch.io/the-task

Ok, here it is, I did a run through from start to finish and it worked.

But then I tested dying on the final boss and retrying on easy mode and it got stuck in the ending. So uh, don't do that. I already toned down the final boss and gave 6 lives, I think it's pretty impossible to lose tbh on normal.

*edit* actually did it again and easy mode works through the credits. It has something to do with if you play the game out of order some variables get screwed up and the game progression scene loading can hang. Like pretty sure the cause was because I beat it and then loaded a level and went to the ending again.
Title: Re: Do any of you code for your jobs?
Post by: daemon on April 06, 2022, 05:40:18 AM
(https://i.imgur.com/L5w3DKO.jpg)

How do I get that -24 number? I want to set an (if > -24) move upwards.

I'm trying RectTransform and this code just gives me the RectTransform is 0.0, 0.0 no matter where the text object starts on screen and I can only manipulate it relative to that.

Code: [Select]
  void Update()
    {
        RectTransform RT = GetComponent<RectTransform>();

        Debug.Log("RTpositiony = " + RT.position.y);
    }

Just letting you know, never put things like GetComponent on Update, as it will keep doing a fairly expensive instruction. make the RT get declared on start or awake.

Alternatively, if for some reason you can't do it on start or awake (doubtful scenario, but things can happen), do something like an if (RT==null){RT=Getcomponentblabla}. That way it will only run through the first time, and an if condition would be quite inexpensive, processing wise.

Also check this graph cause it's really useful

https://docs.unity3d.com/Manual/ExecutionOrder.html
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 06, 2022, 08:40:15 AM
screenshot doesn't illustrate this that well but you can shoot right through this specific set of walls for some reason

(https://i.imgur.com/cK6k1IM.png)

I know it doesn't really matter just wanted to point it out, they look like they're individual objects so maybe those 4 don't have some property set that every other wall does?
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 06, 2022, 01:44:44 PM
You have a lot of nice little touches in your game that beginners usually don't have - were they part of the course, or did you add them?
Things like 'leading' the camera with your crosshair rather than the camera following the player, and having particle onhit effects on bullet collisions

#1 - A script on each enemy to search the scene at every update and when the boss uhhh changes sub-state to running death animation to then start running their own death animations? This is actually a bit complicated because it requires not just getting objects and setting them true/false but changing settings within their component scripts. Maybe there's a simpler way to do this?

You'd do this in a similar way that your object pool script worked; if those enemies are non killable before the boss (as I think they are having played it...?) you could do something like
Code: [Select]
public gameobject explosionPrefab; // or a dummy object that plays their death anim then deletes
public gameobject[] minions; // the [] means this is an ARRAY, or basically a list of all the types of gameobject you add here

void BossSpawnCodeBlock() // or whatever
{
     for (int i = 0; i<minions.length; i++) // this will cycle though each member of the Array and run the below code on each one
     {
          instantiate (explosionPrefab, minions[i].transform.position, minions[i].rotation);
          Destroy(minions[i]);
     }
}

which will delete all the objects you've added to the array, and play a one shot explosion / death anim where they were.

If those enemies ARE killable, this won;t work though, as it will break the array, like you did earlier with the bullet pooling by deleting rather than disbaling and repurposing.
You CAN do pretty much the same thing with a LIST though, as long as when you kill a minion you remove it from the list so when it does the FOR loop its only cycling through things that exist

In the end this is super nitpicking, but improving transitions and stuff is the kind of polish that goes a long way! Hell, on that note when the final boss appears it would be nice to lean how to do a transition effect so it like wavy lines fizzles into existence. Right now the scene loads and there's an empty space and then it just POPS into existence and starts spewing bullets instantly. For other bosses I have them come down from off-screen but this boss should start in the middle of the screen so either it's there the second the scene loads and instantly firing bullets (I'd need to mess with the timer to pause this) or it pops into existence a few seconds later which I'm ok with and is how it is currently. Just would be nice to learn how to make an effect for bringing it into the scene.

So what I'd suggest for this rather than making a bespoke animation for it appearing (the 'right' way to do this) would be that you can set the gameobjects material renderer to solid black (and maybe add some transparency) and then fade it in from black ("shadow", again, maybe with some trasparency) to solid coloured / fully opaque. when its material has fully changed to its 'real' colour, you can then allow it to start taking damage - you might wanna kill the player too if they didn't take the hint about the giant fucking shadow monster below them fading into existence right before combat phase starts.

You could also help sell this with some particle animations with 'negative' velocity, so it looks like particles are 'assembling' at the sprite outline to 'create' it (normal particle velocity would have particles moving away from their spawn point, not towards it, and make the spawn object type the sprite edges)

Is there a way to modify my script to make the movement increments like canvasUI.gameobject.transform.y instead of transform.y to move it up or down on the canvas based on its position relative to the canvas (the text is a child of the canvas)?

I'd generally recommend if you wanna do cool UI movements, get yourself a tweening solution and just use that, but in this case you can probably do what you want to do by going to your canvas properties and changing it from ScreenSpace - Overlay to WorldSpace; this will - as it might suggest - make the Canvas option appear in the actual playable gamespace, at the gamespace coords, and take all the same kinds of values any other gameobject in worldspace would
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 06, 2022, 09:30:49 PM
Ok, done with work.

screenshot doesn't illustrate this that well but you can shoot right through this specific set of walls for some reason

(https://i.imgur.com/cK6k1IM.png)

I know it doesn't really matter just wanted to point it out, they look like they're individual objects so maybe those 4 don't have some property set that every other wall does?

Yeah, so level 1's collision is a mess. If I was releasing it to the general public I'd completely redo stage 1, but I left it as is because y'all know this was my first game and stage 1 -> 2 -> 3 learning progression is something you can see since I made the stages in order.

When I did stage 1, I grabbed a wall texture asset from an asset pack I had off a bundle and cut and pasted a square of it into a texture file. Then I made a square object and give it a 2d rigid body square collider and then put the texture on. Then I placed one square title and it was really small, so I placed a couple by hand (didn't think to use transform numbers to line them up or vertex snapping key) and then copy & pasted the group when there were 3-4 at a time and then made a prefab of 3-4 wall tiles and just used dozens of them to build the walls.

This was a terrible, first game design room idea. The bullets are really small and there are seams between certain sets and it's all fucked up.

If I redid the level I would make just make rectangle blank shapes with the Unity editor for the walls and use vertex snapping and the transform to make sure they're all lined up and then I'd throw the wall texture on and tell it to tile the texture.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 06, 2022, 09:46:12 PM
You have a lot of nice little touches in your game that beginners usually don't have - were they part of the course, or did you add them?
Things like 'leading' the camera with your crosshair rather than the camera following the player, and having particle onhit effects on bullet collisions

Thanks, but everything you mentioned came with the base game assets  :lol

Here's an example of someone else's that they did in the class. Their stage 1 is kind of the template we were given and they did a good job making a few levels of it adding more complexity in the level design, challenge and remixing the provided music. The template used particles for enemy bullets but I hated that and didn't want to learn particles at this point to make them better so I switched them to textured bullet objects in mine.

https://grabriel-roby-73.itch.io/2d-shooter

https://crewdipie-playz.itch.io/starship-wars

You can see from these that like the base movement, shooting, camera controls and UI menus are basically the same. Also the win jingle I use in mine is from the assets. I think outside the win jingle all the music is 100% original stuff I made. SFX are mostly template explosions and shots but I did the thump thump thump SFX for the talking scenes.

Quote
#1 - A script on each enemy to search the scene at every update and when the boss uhhh changes sub-state to running death animation to then start running their own death animations? This is actually a bit complicated because it requires not just getting objects and setting them true/false but changing settings within their component scripts. Maybe there's a simpler way to do this?

You'd do this in a similar way that your object pool script worked; if those enemies are non killable before the boss (as I think they are having played it...?) you could do something like
Code: [Select]
public gameobject explosionPrefab; // or a dummy object that plays their death anim then deletes
public gameobject[] minions; // the [] means this is an ARRAY, or basically a list of all the types of gameobject you add here

void BossSpawnCodeBlock() // or whatever
{
     for (int i = 0; i<minions.length; i++) // this will cycle though each member of the Array and run the below code on each one
     {
          instantiate (explosionPrefab, minions[i].transform.position, minions[i].rotation);
          Destroy(minions[i]);
     }
}

which will delete all the objects you've added to the array, and play a one shot explosion / death anim where they were.

If those enemies ARE killable, this won;t work though, as it will break the array, like you did earlier with the bullet pooling by deleting rather than disbaling and repurposing.
You CAN do pretty much the same thing with a LIST though, as long as when you kill a minion you remove it from the list so when it does the FOR loop its only cycling through things that exist


Thanks, that makes sense. The tentacles on the final boss are non-killable yeah.

Quote
In the end this is super nitpicking, but improving transitions and stuff is the kind of polish that goes a long way! Hell, on that note when the final boss appears it would be nice to lean how to do a transition effect so it like wavy lines fizzles into existence. Right now the scene loads and there's an empty space and then it just POPS into existence and starts spewing bullets instantly. For other bosses I have them come down from off-screen but this boss should start in the middle of the screen so either it's there the second the scene loads and instantly firing bullets (I'd need to mess with the timer to pause this) or it pops into existence a few seconds later which I'm ok with and is how it is currently. Just would be nice to learn how to make an effect for bringing it into the scene.

So what I'd suggest for this rather than making a bespoke animation for it appearing (the 'right' way to do this) would be that you can set the gameobjects material renderer to solid black (and maybe add some transparency) and then fade it in from black ("shadow", again, maybe with some trasparency) to solid coloured / fully opaque. when its material has fully changed to its 'real' colour, you can then allow it to start taking damage - you might wanna kill the player too if they didn't take the hint about the giant fucking shadow monster below them fading into existence right before combat phase starts.

You could also help sell this with some particle animations with 'negative' velocity, so it looks like particles are 'assembling' at the sprite outline to 'create' it (normal particle velocity would have particles moving away from their spawn point, not towards it, and make the spawn object type the sprite edges)

Very cool stuff. It's like what Uncle posted about the lifebars changing width. I guess since I haven't done it yet, I just don't know the coding words to tell things like colour and opacity to change in a script. Just need to look that up and learn that.

This weekend when I start on my next game project, first thing I'm going to do is test these effects in a fresh new game (lifebars, enemies phasing into existence, start learning to use particles) and if I get familiar with them in my new game I can go back and spend a few hours incorporating them back into this game.

Quote
Is there a way to modify my script to make the movement increments like canvasUI.gameobject.transform.y instead of transform.y to move it up or down on the canvas based on its position relative to the canvas (the text is a child of the canvas)?

I'd generally recommend if you wanna do cool UI movements, get yourself a tweening solution and just use that, but in this case you can probably do what you want to do by going to your canvas properties and changing it from ScreenSpace - Overlay to WorldSpace; this will - as it might suggest - make the Canvas option appear in the actual playable gamespace, at the gamespace coords, and take all the same kinds of values any other gameobject in worldspace would

Wow, this would have made my life so much easier.

I spent 4-5 fucking hours yesterday all trying to get the score to drop down and the red fear UI text to move up to its place. Even when I got it working like it does, the scale is fucked and if you fullscreen the game it takes like 3-4x the amount of time for the red UI text to get to its spot than if you play it windowed because there are more pixels to traverse to get up there. Originally that scene was shorter and would scene change before the red text got in place in fullscreen so I ended up lengthening it so now in windowed it just sits there for a few seconds doing nothing before the scene change.

Dealing with stuff, especially movement, in the game space is something I'm getting really comfortable at scripting to manipulate quickly, but dealing with UI stuff movement is a nightmare for me at this point so if changing the canvas to worldspace makes the UI text stuff no different from any other object on the screen that would be extremely helpful and timesaving.

Like I don't really get why you can make a square/circle/whatever on the game screen and move and manipulate it around  but you can't just make a blank gameobject and put TEXT on it and have TEXT appear on screen that you can move around the same. Seems stupid to me. I get it does that because text needs to resize based on the window size, but like so do the pixel enemies you have? They're bigger in fullscreen than in windowed? Everything resizes according to window size, so why can't I just move text blocks around :(

Since I like having a lot of text/dialogue in my stuff this is something that will keep coming up.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 06, 2022, 10:43:06 PM
So now that y'all played it, and I'm proud of lots of little bits in it, here's my post-mortem on things specifically that I'd like to fix if I made a Championship Edition remake later on when I have more experience:


Title Screen:
-Sucks, but until I learn how to draw larger art my choices are to go do some photography and edit the photos into something I can use in a title screen/game over screen, learn some vector art skills, or commission artists for a few art pieces I can use for game over/win/title, etc....one of the very few benefits of starting getting into this at 40 instead of as a teen/college kid, is I got some $$ so I don't mind putting a couple hundred bucks into stuff here and there to improve the game.

Intro text:
-Fine

Stage 1:
-As mentioned the collision is a disaster
-The level scale isn't great. Player needs to be smaller or moveable area needs to be bigger. Too tight. Flames/Bats/Player need consistency in sizing (a little hard when original pixel art is all at differing sizes, I should try next game to make all sprites the same pixel size to be more consistent)
-The background tile looks horrible parallax scrolling kind of effect in windowed, looks ok fullscreen. Just need a different background.
-The art up top is awful and super low-res blurry. I tried making a "room" initially with like a wall and a fireplace at the top but it doesn't match with top-down for the rest. Should just ditch it and have wall tiles only and a better wooden floor background.


-If I made a public release remake, I'd make multiple stages in this style of increasingly larger and more complex mazes with more traps than just a flame that goes back and forth. Probably like 3-5 stages and this would be "world 1"

Stage 1->2 transition text:

-THE MOUSE CURSOR HAUNTS THE REST OF THE GAME even though no scenes have mouse aiming after the first scene!! If you start the build after any scene past the first scene there is no cursor in any scene. This upset me greatly and I could not figure out what was causing it or how to turn it off.

Stage 2:
-Is alright, make the 2d planets/rocks and stuff a bit smaller and less blown up pixelated. Have more waves of enemies with a few different enemy types (the skulls actually have like 3 different enemy types that do different types of attacks but I just used the same sprite on all of them).

-I had trouble making this scrolling stage work in terms of enemies either die too quickly or if they have more life by the time you kill one you're behind on the next ones that are scrolling in your face and it gets overwhelming. I think maybe I need to slow down the scroll movement speed for the enemies and spread them further apart and give them more life.

-For the eye boss, I'd try to fill in the sprite with a bit more detail so it's not just an 16x16 sprite blown up so large. I'd also give it a lifebar.


-Like stage 1, if I did a public release I'd make 3-5 stages of different enemies and obstacles to dodge layouts and make it "world 2". I could have it like you pass by 2d earth at the start and as you go through the 3-5 stages you pass by 2d versions of each planet in order they exist in distance from earth so it feels like each stage you're getting further and further away from earth and towards the end of the solar system. For the final stage of it can have like a black hole you go into and then come out of and fight the "EYE OF THE UNIVERSE" boss in darkness in there.


Stage 2->3 transition
-Fine, I kind of want to make my own spookier sound effect for when the eyes open.

Stage 3 intro
-Fix the UI text replacement so it's the same speed both windowed and full-screen
-Would like to make spooky scary music for 10 seconds building to a crescendo at scene change

Stage part 1
-In general with all my scene transitioning I have a bit of a hiccup in the music transitions that I need to work out. I tried putting the new music upon entering a stage on its own timer so it can wait a second or two or three before starting the stage music to transition more smoothly. Worked ok, but still room for improvement.

-Generally I like this stage! Was fun to make. The 3d planet dropping looks pretty ugly, but I spent like 3 hours getting those 3d planets to work and react to 2d bullets and the ship and didn't want to cut them. Also certain planets play a sound when they are falling on you but others don't. But they all have THE SAME AUDIO SOURCE with the same values and it makes no sense. Like the giant sun should sound REALLY LOUD and scary but it has like no sound at all... also stage could use more of a few seconds pause between dropping black holes and then dropping 3d planets. Was just too lazy to retime the motion speed of everything to make it better at that point.

-Speaking of sound I hate that Unity's audio source only has sound volume at 1 or below for audio. Lots of times my audio is too low at 1 and I don't know damn anything about how to throw that audio quickly into another program to increase volume and bring it back. And adjusting all the other audio in the level lower to compensate is too much work. I see this issue in a lot of games/programs. If volume slide is going to start at 1, then it better be able to go to 1.5 or 2. Otherwise end up dropping everything else to try to compensate and it's annoying.

-Stage 3 part 1 -> 2 BEAM SCENE transition
-this was the last stage I made yesterday, had been wanting to put it in and was fun getting it working, scripting in the movement system to change movement based on an internal timer so you go from locked movement to free roam movement at the last second after being told you can move. Also put a timer on the health script for the giant bullet to explode at a certain time so you didn't have to sit and wait for it to slowly leave the screen after dodging it.

-The "here, have more life" dialogue is supposed to be directly under the lives but the scaling fucks it up on Itch in both window & fullscreen. The centered stuff was less of an issue, but could not get this in place.

(https://i.imgur.com/EBTkMsJl.jpg)

-Also I think it's bad at communicating to people that they can move at the last second. It just says I'll help you move and players probably expect something to happen before than can move. I should put a timer ding sound effect maybe turn on a particle effect around the player at that moment to indicate they are now free to move and dodge the giant bullet.

-So because I put the stage transition on a timer, if you die and the game over screen pops up if you sit for a few seconds it'll still transition to the next scene. Whoops. I need to put an && gameOver != SetActive(true) in on that timer to avoid this.

-Also would like to do a scary music here that builds up to the moment the giant bullet is gonna hit.

-Oh, so I didn't have an easily available giant beam/bomb thing to drop and I couldn't use a planet because in the earlier stage planets were all killable and not impending doom scary enough, so I just super-larged a bullet. This is...ok, but not great. But even more so my explosion animation I created for it, while looking fine at smaller sizes looks pretty awful that big lol, would redo the explosion and maybe replace the giant pink bullet with something else.

Stage 3 - mid-stage


-I like this stage a lot. Originally I didn't have the boss in the background and it was just on generic space. The boss in the background does make it too busy, but I think it conveys a good insanity effect of fighting giant space tentacles while a giant cosmic being's twirly eyes are spinning around in the background. This might actually be my favorite stage in the final version. Even the bullet patterns are set up in a way that it's fun weaving in between waves to get shots in. Tentacles need about 2x the health though and maybe health bars if I'm giving health bars to stuff in stage 2 in a later version.

-Death animation for tentacles isn't terrible, but it looks a little less pixely than I'd like (mostly used spray instead of pencil to spray red blood as I shrunk down the tentacle)

Stage 3 - final boss

-Feels like a scene is missing. I think I did a good job on the boss consistency until this point. It's unknown, then  eyes, then you start to see the tentacles come down and sit in place for a stage, then the body/face comes down and sits for the previous fight...but now the boss pops in and it's room sized and you can move around it? I feel like I need a scene where the boss shrinks down or the player ship due to the magic friend gets bigger. I couldn't think of a scene I liked to do this (also haven't tried scaling things during game through scripts), but if I remade the game I'd add this scene in.

-The final boss needs a transition in, but what GreatSage suggested would probably cover this.

-I'm happy with the bullet patterns. They used to be a little tighter and harder to weave between, but even after dozens of times I'd still game over at times so I think this is a game middleground. I can no-hit weaving through the patterns at this point usually. I think if the boss had about 1.5x HP and if you only had 3 lives instead of 6 it would be a really well-balanced boss fight. As is, it's a bit easy but pretty fun and I'm happy that I made a fun boss with some challenge and reward.

-I also like that I got to make the CAVE style pink bullets I wanted. I took them off a non-pink asset I had from a sprite pack that was just a single frame still and I re-colored it by hand pixel by pixel into a shades of pink version and made a 4 frame spinning animation and they look pretty good in game! Also I got the SUPER SLOWDOWN I wanted at one point when instead of using circle collider on the bullets I use polygonal and it make the complex colliders with a ton of vertexes and then with all the bullets being fired on screen it brought the game down to a crawl :D Now I know if I want intentional slowdown just throw lots of vertexes on a 2d collider for bullets.

-Oh, and speaking of assets, the non-original sprites the game were the 2d planets, the 3d planet textures, the 2d asteroids in stage 2 and meteors and black holes in stage 3 part 1, the space background, stage 1 background and the stage 1 wall tiles and top area texture. I think all the rest is my own work, the flames came in an asset pack BUT I'm gonna take credit for them because they came as a 2-frame animation that looked so shit I had to use them with animation turned off so I spent some time and hand animated my own animation frames and now the flames look good so imma take credit for that one.

-Finally, if I did a remake, for this fight I'd change it so you'd dodge bullets for like 10 seconds then the bullet script would stop, then the boss would throw out a Zelda LTTP energy ball that you'd shoot back and the hit animation would be 1-2 tentacles die and are no longer on the boss so you know you're doing damage and making progress (no lifebar for the boss). Then 10 seconds of bullets with 1st tentacle shooter added on, then another energy ball fight, then repeat with 2nd tentacle shooter, etc... If I don't end up using the 3d planets in Stage 3 - first phase, I think it'd be fun if the energy balls were actually the boss throwing planets at you one planet at a time and you shoot them back into the boss and a tentacle explodes. Final one could be the sun and the boss burns up or something.

Final Boss death scene
-I hate it. It's fast and choppy and small and is lacking any sound effects. I'd really like to redo this proper but animating that boss was such a long endeavor because it's a big multi-part sprite with a lot of moving pieces, that smoothing it out would take a while and getting the right SFX too. If I did a remake for a public release I would 100% replace this scene with something more consistent looking.

-Also I think I did it wrong with making the animation in animator combining the eye guy and boss as one flat animation. Would have been better to have a gameobject of the flying eye boss that comes in then have some particle effects beam out from its eyes and then have a separate death animation that looks solid for the boss and the move the flying eye boss off screen. But this is all just a learning experience.

Ending credits:
-Actually this was the final scene I made last night. I was gonna make an additional song and my musician buddy was supposed to make me a short 60 second song, but he didn't get around to it and I was sick of the game and wanted it done so I just used stage 2 music which actually worked fine.

-Making the credit scene was a lot of fun. I like the idea of having the enemies pop in and be jolly as credits appear.

-Still has the text size mis-match between windowed and fullscreen. I mean this is a big fucking difference:

(https://i.imgur.com/XoJenVWl.jpg)

(https://i.imgur.com/ioaq6ypl.jpg)


I think that's most of my thoughts on the process. Was fun! Learned a lot! Have some basic background now for my next game which unfortunately is a 2d platformer and I don't have a lot of interest or interesting ideas for a platformer as it's not one of my favorite genres. But as I take the class and learn what I can do (including learning how to appropriately do tilemaps) I'm sure ideas will pop into my head.

Also if I did do the remake of this one and added in the additional world 1 stages and world 2 stages while doing the few cleanups on world 3 I'd imagine the game length would go from like 5 mins -> 20-30 mins which would be a good size to release on Itch to the public.







Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 07, 2022, 04:48:38 PM
I've been buying like every one of these assets bundles since I started making my game. It's actually overwhelming because I have all these zip files with various sprites and music loops and sfx and tiles. I need to like organize them all into something so I can use them as placeholders or edit them to use in stuff.

https://www.humblebundle.com/software/grand-game-dev-toolbox-software

And like this one comes with a sprite lighting software which I didn't even think about for sprites. I think that's something to save for 10 games down the road to start learning normal maps and lighting and stuff.

One thing that hopefully I'll learn in this 2d platformer class is a lot of these world/town/dungeon tilesets are just like one PNG file with a bunch of blocks and I'm not sure what the correct way to use them is? When I made my walls in stage 1 of my game I just cut and pasted from MS Paint a square from the giant PNG and saved it as a new png and that's my texture. Is there a way you're supposed to auto-slice up these single image tilemap things to get a bunch of different usable tiles?

Also with music I think I'm gonna have to pony up the dough and move on from the free Bosca Ceoil to Abelton Live sooner or later. The biggest frustration I have with Bosca Ceoil for making music is that there is no way to export bars that you make. So if I'm working on a song and I come up with a clever little melody but it doesn't work in the current song, best I can do is screenshot it and try to recreate it each time in future songs to have on my selectable bar list for those songs.

Ideally I'd like a program where there is a single database of every bar I've ever created that continually grows and when I make songs I can just pull them into the song and see if they work for the current track. Apparently this kind of program is called Ableton Live or FL Studio. It's just kind of bogus for game development that these are so expensive when like Asesprite and a lot of other tools are like $20-30 affordable.

The other issue Bosca Ceoil has is there is no undo button which sucks when you're messing around with notes and you fuck up a note and can't remember where it was. You also can't copy & paste within a bar itself which isn't as big of deal.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 07, 2022, 05:10:06 PM
Actually this music bundle on humble I picked up for $25 includes Mixcraft which apparently is sorta comparable to the $400-$500 Abeltons/FL Studio type stuff (but probably not as good). Will try it on the weekend and maybe it'll be enough of what I need for now.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 07, 2022, 08:35:04 PM
I saw that and thought about posting it here!

honestly I pirated fruityloops 20 years ago and that version is probably still as usable as the day I stole it  :doge

a while back I loaded up an old backup hard drive and my virus scanner found an ancient virus buried in a zip of VST plugins that I'm sure I downloaded from kazaa  :lol
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 07, 2022, 09:31:29 PM
a while back I loaded up an old backup hard drive and my virus scanner found an ancient virus buried in a zip of VST plugins that I'm sure I downloaded from kazaa  :lol

 :lol
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 01:22:48 AM
I started on the next class and now that I actually have an idea of what things are in Unity, the initial overview for what topics the class covers was pretty good. It's starting with Tilemaps which is perfect for something I need to learn next, including animating tilemaps and tiles, and then goes into spritework which may cover what I already learned in the aesprite stuff, but then it goes to learning how to use the animator to make multiple animation states and transition between them which would be really helpful for me since for my first game every animation had to be the on-awake/idle animation for the object since I didn't know how to use the animator  :lol

I think they might've also mentioned something about particles. I wanna learn those so I can start my game with some particles surrounding the main character to practice those and I'll give him a lifebar to practice that too.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 08, 2022, 06:44:29 AM
I think that's most of my thoughts on the process. Was fun! Learned a lot! Have some basic background now for my next game which unfortunately is a 2d platformer and I don't have a lot of interest or interesting ideas for a platformer as it's not one of my favorite genres. But as I take the class and learn what I can do (including learning how to appropriately do tilemaps) I'm sure ideas will pop into my head.

If they teach you a good kinematic side scrolling platformer character controller, that's a really solid base for a fucking ton of old skool game genres; turn the 'gravity' off and you got side scrolling beat em ups and even top down zelda style movement, keep the 'gravity' on, and you can do all kinds of gameplay mechanics ranging from pseudo point and click adventure through super meat boy platforming through cuphead style run and guns

One thing that hopefully I'll learn in this 2d platformer class is a lot of these world/town/dungeon tilesets are just like one PNG file with a bunch of blocks and I'm not sure what the correct way to use them is? When I made my walls in stage 1 of my game I just cut and pasted from MS Paint a square from the giant PNG and saved it as a new png and that's my texture. Is there a way you're supposed to auto-slice up these single image tilemap things to get a bunch of different usable tiles?

yea, in unity set it as 'multiple' on import - if you know the per-tile resolution you might wanna set that at the same time
(https://i.imgur.com/KFKQlQ8.png)

then open up the sprite editor, and select out your individual sprites; if they've created a tileset to a specific format / size, you can just manually enter the numbers
(https://i.imgur.com/yFSU090.png)
this tileets 32x32 tiles with no padding, so nice and easy to import
e: actually, I think I dun fucked up and this is actually a 16x16 tileset - oh well, you get the gist

Load up the uhhhhh I think its called 2D tilemap package from unitys package manager, and you can then paint these in as solid blocks, or you can use something like Tiled  (https://www.mapeditor.org/)to map build then import

I'll be honest, I don't think that Humble pack is that good for the price, but if you feel you need to asset-load, you do you :trumps

Ideally I'd like a program where there is a single database of every bar I've ever created that continually grows and when I make songs I can just pull them into the song and see if they work for the current track. Apparently this kind of program is called Ableton Live or FL Studio. It's just kind of bogus for game development that these are so expensive when like Asesprite and a lot of other tools are like $20-30 affordable.

If you can live with a little open source jank;
https://lmms.io/
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 12:31:04 PM
Oh shoot, I didn't think about slicing tile maps like that. I use slicing for the sprite sheets I make in aseprite but they are horizontal strips you slice by count. Didn't think about slicing a full image. Will be very useful I'm sure.

Yeah, I saw lmms recommended elsewhere. Will check that and Mixcraft out on the weekend. Would like to start my new project by making the title theme song, lead character sprite & animation and title screen first this weekend.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 12:55:56 PM
Also, in terms of these asset bundles I'm grabbing, I'm mostly getting them for SFX because searching for free SFX I can use legally is time-consuming and I haven't tried to make my own SFX with my phone recorder yet, so having a large list of stuff I can quickly browse through on my HDD to fit sounds is very, very helpful.

Also 2d background tilemaps too, because while I have fun making character/enemy/object sprites, making background tilemaps seems more like work than fun to me and they are generally generic enough that using some legal asset from a bundle isn't something that'll stick out to players whereas if your enemies look like they are from another game or generic asset pack it will.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 08, 2022, 01:23:47 PM
yeah it's fun to collect bundles and have piles of stuff to look through, but I was also thinking this current humble bundle isn't really top tier, they've had better ones

I prefer the ones that are all assets to throwing in some software or unity plugins with a really niche usage
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 02:39:55 PM
Yeah, these software programs that need their own installers and keys and aren't on steam are stuff that's just gonna sit uninstalled unless I need a specific use for them.

Like I'll install Mixcraft to try it out, but like the Sprite Illuminator software is something I don't need to deal with yet. That Pixelmash software I looked up and it seems like it's an ok companion piece to Aesprite in that you can realtime transform bits like scaling the size through dragging, but reviews also say it's pretty buggy and crash prone and not great.

The Sprite Illimunator reviews are pretty decent, people say it's pretty comparable to Sprite Dlight for that kind of normal mapping stuff.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 02:42:55 PM
Also my favorite thing about this current bundle is it has a bit of Japanese assets. Like one of the SFX/VFX sets

(https://i.imgur.com/8SkYSJ7.jpg)

How else you gonna find your vaccuum slash and aeolian slash sounds quickly?  :lol
Title: Re: Do any of you code for your jobs?
Post by: tiesto on April 08, 2022, 03:00:31 PM
For someone who writes software using C#, VB.NET, and Javascript (accounting/business software), how easy is Unity to pick up and learn?
Any good tutorials to create a simple 16-bit style turn based RPG?

I'm feeling a bit of a creative streak and want to get out an RPG but not sure if I should go the RPG Maker or the Unity route. I feel Unity may be a bit more flexible, especially in the case of a battle system, but RPG Maker would enable me to get off the ground MUCH quicker (I made some RPG Maker 2000 game back in 2002 based on my college friends and it was the talk of my dorm for a good hot minute).
Title: Re: Do any of you code for your jobs?
Post by: Tasty on April 08, 2022, 03:01:41 PM
You should go the GB Studio route. :D

https://www.youtube.com/watch?v=LKISokmluOI
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 03:19:17 PM
For someone who writes software using C#, VB.NET, and Javascript (accounting/business software), how easy is Unity to pick up and learn?
Any good tutorials to create a simple 16-bit style turn based RPG?

I'm feeling a bit of a creative streak and want to get out an RPG but not sure if I should go the RPG Maker or the Unity route. I feel Unity may be a bit more flexible, especially in the case of a battle system, but RPG Maker would enable me to get off the ground MUCH quicker (I made some RPG Maker 2000 game back in 2002 based on my college friends and it was the talk of my dorm for a good hot minute).

No idea. This is definitely a question I have for future genre.

I eventually wanna try making a 2d rpg and not sure if there's advantages in making it in Unity over something like Rpgmaker. Like I would imagine the advantages are being able to do more non-standard things through code scripting, but the disadvantages are probably more time/effort required for standardized things like making towns, world maps, turn based battles, items, equipment, etc...

Whereas if you're doing a 3d rpg or isometric 3d rpg like Infinity Engine stuff Unity would be better I would think.

I also want to make a tactics isometric FFT kind of game, not sure if Rpgmaker can do that stuff. I want to do like a modern setting SMT/FF15 tactic game with cars and stuff since I think Makai Kingdom is the only tactics game I can think of that's had vehicles.

Like another genre I want to take a crack at is Visual Novels and it really seems like a VN engine would make much more sense than making a VN in Unity since all you need for VNs is a way to display background, text and play music and maybe have some choice branching. Whereas doing it in Unity as scenes and text gameobjects for 1,000 lines of dialogue or something seems like it'd be tedious?


The genres I want to try to take a stab at are:

1. Shmup - stabbed

2. 2d platformer - next class project

3. 3d fps - I think this is a bad idea (I really enjoyed making levels for FPS as a kid and think I would still enjoy making levels/campaigns for FPS like Prodeus, but that's because doing that uses a strong core already of good FPS gameplay, making my own FPS gameplay is stupid because it will never be as good as Quake/Doom/Prodeus/Half-life/whatever and if I wanted to make an FPS it would be better to make a total conversion mod in one of those), but it's class project after

4. 3d Platformer - final class project, gonna be lolz but will be fun to learn to work with 3d in an open non-FPS space.

5. Rhythm/Music Game

6. Horror game

7. VN

8. 2d rpg

9. 3d rpg

10. Sports-ish game, like a mecha baseball game or something. I saw on the indiegame website I read someone made a bowling combat game and that seemed like a great concept.

11. Sim game like Game Dev story kind of stuff. I have a concept already for Video Game Reviewer Sim based on real stories I have from days as a game journalist, but I need a lot more game dev experience to do what I wanna do here.


Genre I never plan on attempting:

1. Fighting games - hahahahahahahaha, no, I love fighting games, but the FGC and high-level fighting game intricacy scares me.

2. Puzzle games - I am way too dumb to make good puzzles. At most I will put simple fun puzzles in my other games.

3. RTS games - I can't even win a starcraft map vs the ai

4. Strategy 4x games - Too brainy for me.

5. Racing games - Ehh, I like racing games (arcade & sim) a lot but I know jack shit about car physics so I don't think I'd attempt even a kart racer.

6. Flight games - Same thing.


Maybe genre:

1. MP games - Not an MP gamer but do enjoy a good MP game with friends here and there, if I ever had a good concept maybe I'd try.

2. Board/Card game - Probably not, don't have enough irl experience with them since I didn't play Magic growing up. But I do like Snk v Capcom Card Fighters, so idk maybe someday

3. VR - Would be fun since I like VR, but this would be years down the line when much more experienced to even attempt something without making you throw up.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 03:36:14 PM
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?

I messed around with AGS a bit like 10 years ago but never made anything with it. A lot of my favorite PnC Adventure games are all made in AGS though so it seems perfectly capable.


Also for 2d games in general like 2d rpgs or whatnot, I googled what some of the more well-known games were made in like Undertale or Hotline Miami and a lot were made in GameMaker Studio and googling a bit, there seems to be a pretty heated debate online as to whether there's any point in making 2d games in Unity vs making them in GMS2 or even RPGMaker. I'm coming across a lot of reddit thread posts of people saying Unity is kind of mediocre for 2d stuff and should mostly be used for 3d projects?

The good news is that all these threads I'm reading seem to say if you learn Unity and C#, you can learn GML and GMS in like a week and transfer over for 2d projects to there if you want.

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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 04:05:58 PM
This is interesting researching what indie games are using.

Apparently an alternative to the old golden days of Adventure Game Studio, is making an Adventure game in Unity using Adventure Creator which was made by an AGS heavy user that tried to bring AGS to Unity and improve on its functionality.

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

https://youtu.be/8xcmlkcm7sU

Some impressive games in that trailer.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 04:14:11 PM
Going further, looking at the toolkits available for purchase on the Unity store that are 5 star reviewed with hundreds of reviews or won awards, it sure looks like there's some really helpful stuff for certain genre.

For 3d rpgs:
https://assetstore.unity.com/packages/tools/game-toolkits/rpg-builder-177657

I really like the idea of an engine that you can pay money to buy parts already made by other people and save you time. As an adult I have money more than I have time. So this stuff is right up my alley when I actually start working on bigger than intro prototype concepts.

I wonder if there's a good 2d rpg toolkit that makes Unity more similar to Rpgmaker. Will search around.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 04:34:20 PM
https://assetstore.unity.com/packages/2d/environments/2d-isometric-tile-starter-pack-27944

Good start for FFT/TO Tactics maps

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

Has good reviews for 2d platforming controls


But searching through the store it doesn't seem like there's any good tools for 2d rpgs. ORK Framework seems mostly 3d focused but can do 2d turn-based:

https://assetstore.unity.com/packages/tools/game-toolkits/rpg-editor-ork-framework-3-209685
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 08, 2022, 05:58:27 PM
I think modern RPG Makers like MV are capable of being contorted into doing anything you like in the realm of 2D, they are just intended for RPGs, but people have made all sorts of games using RPG Maker engines

it is really important to be able to "fail faster," get things up and running and working as a prototype, being able to refine it sooner, or learn early on whether it's just not working out as a concept



but it looks like the next upcoming RPG Maker is called Unite and is literally intended to run within Unity  :whoo
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 08, 2022, 07:06:50 PM
but it looks like the next upcoming RPG Maker is called Unite and is literally intended to run within Unity  :whoo

Nice. Solves the issue then.

Also sounds similar to Adventure Creator where it's basically an implementation of AGS in Unity so you get best of both.


By the time I get around to trying to make a 2d jrpg this will probably be out and maybe will end up going with it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 09, 2022, 06:01:09 PM
Animated tiles are fun:

(https://i.imgur.com/qcZdu93.gif)
Title: Re: Do any of you code for your jobs?
Post by: Tasty on April 09, 2022, 06:01:53 PM
Such a pain in the ass tho lol.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 09, 2022, 07:15:24 PM
(https://i.imgur.com/MPkI2tO.jpg)

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.

(https://i.imgur.com/mgmA2Hj.jpg)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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

(https://i.imgur.com/XFvcNQw.jpg)

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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Madrun Badrun 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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.

Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 11, 2022, 07:03:29 PM
another one of these today: https://www.humblebundle.com/software/7000-game-dev-icons-software-rebundle
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Uncle 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
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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 (https://assetstore.unity.com/) 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/
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 12, 2022, 03:51:23 PM
man that looks like it was used to make conduct together

https://www.youtube.com/watch?v=9QQt83vyqLI
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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

https://youtu.be/U2snop-6GVM

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

https://youtu.be/podNefNl958

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

https://youtu.be/b8bAt1i9gfo

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

https://youtu.be/3Rr-tCw5lc0

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

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

https://youtu.be/7HRvPxVgKhM

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

https://youtu.be/09Tgy8IBs90

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

https://youtu.be/IOri5hqBcWc

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

https://youtu.be/T8iTwe9zSaU

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

https://youtu.be/LO3eRIytmfs


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

https://youtu.be/lRxIKDU9z4k

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

https://youtu.be/C3Ldd-5PKCw

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.



Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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 (https://ephtracy.github.io/index.html?page=mv_main) 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 (https://fungusgames.com/), 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);
}
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?





Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 14, 2022, 04:19:39 PM
I think you've got hung up on the idea of child objects...?

(https://i.imgur.com/0wqNJtg.jpeg)

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
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 14, 2022, 06:59:05 PM
Got it!

Thanks.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.

https://youtu.be/kJ5kmkVb6as

https://youtu.be/0I_OZ4qQJfY


https://youtu.be/wNcQqGzfWKE

https://youtu.be/wY1yVmX8GqQ

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

https://youtu.be/iWvfaiiVuDI

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:

https://youtu.be/vXm5VjZA4Ys



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.



Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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

Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.

https://youtu.be/G2PSAMk_D8E

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.
Title: Re: Do any of you code for your jobs?
Post by: archnemesis 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 16, 2022, 01:59:41 PM
(https://i.imgur.com/sw0QU8k.jpg)

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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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:

https://www.youtube.com/watch?v=k20DrVECNfo
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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).
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo 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?

(https://i.imgur.com/Z6FoL1k.jpg)

(https://i.imgur.com/Mu6XrK0.jpg)

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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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  (https://www.blockbench.net/)jacked their style and freewared them  :lol
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven 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:
https://www.youtube.com/watch?v=3sWTzMsmdx8

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?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 04:28:57 AM
Not sure if I wanna touch the platforming corgi engine for this project just because dunno if it'll be compatible with this template. That's more for starting fresh in there.

I feel like this template is a house of cards and I don't want to mess with the internals too much or it'll fall apart and I'm relying on it for player/camera stuff because that saves time.

Maybe I'll see if I can make the corgi engine character controller mesh with this. Or some of those other ones you mentioned. I don't think the controls are too bad after adjustments. And not trying for a real tight platformer since more interested in a puzzle platformer.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 01:55:39 PM
Also, yeah Sage, this is how movement is handled by the scripts currently. Adjusting RB velocity each update based on movement and movement speed. It doesn't work with conveyer belts because they are trying to move the player but the player velocity is being reset each update to 0 if you're not moving. I wonder if I can add an "if collidingonstay with an object with tag "conveyer" don't update player velocity.

Code: [Select]
private void HandleMovementInput()
    {
        Vector2 movementForce = Vector2.zero;
        if (Mathf.Abs(horizontalMovementInput) > 0 && state != PlayerState.Dead)
        {
            movementForce = transform.right * movementSpeed * horizontalMovementInput;
        }
        MovePlayer(movementForce);
    }

private void MovePlayer(Vector2 movementForce)
    {
        if (grounded && !jumping)
        {
            float horizontalVelocity = movementForce.x;
            float verticalVelocity = 0;
            playerRigidbody.velocity = new Vector2(horizontalVelocity, verticalVelocity);
        }
        else
        {
            float horizontalVelocity = movementForce.x;
            float verticalVelocity = playerRigidbody.velocity.y;
            playerRigidbody.velocity = new Vector2(horizontalVelocity, verticalVelocity);
        }
        if (playerRigidbody.velocity.y > 0)
        {
            foreach (string layerName in passThroughLayers)
            {
                Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer(layerName), true);
            }
        }
        else
        {
            foreach (string layerName in passThroughLayers)
            {
                Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer(layerName), false);
            }
        }
    }


Is there a way that I can tell it to ignore all this and just use default rigidbody built in physics when colliding with an object that is tagged "Conveyer belt"?

I read some threads on kinematic physics for characters and Unitys RB and a lot of people talk about using both and their code switches between the two physics system depending on what the player is doing. Like using RB for moving and then you get hit and it switches on hit to a hand tailored kinematic physics for the knockback force. Or switching to kinematic for climbing ladders/robes and stuff.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 02:26:37 PM
So yeah, I tried commenting out this bit

" playerRigidbody.velocity = new Vector2(horizontalVelocity, verticalVelocity);"

and dropping my player on the conveyer belt and now it works with moving my player just like moving crates at various speeds.


Problem is, even if I could write some code that said "when colliding with a conveyer belt tag, turn off that one line", now I can't move my player because I removed the velocity entirely and all I can do is move while jumping.

I feel like there has to be a good solution for this that says when colliding with conveyer tag, don't use that line of code, instead use "______" to move left/right?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 02:46:11 PM
Lol, when people talk about how long Unity takes to boot I never noticed it with these really small projects I'm working on.

Right now I started a new project to import the Corgi 2d/2.5d platforming engine and it's taking a whiiiile to finish startup.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 03:16:51 PM
Wow, this engine within an engine thing is insane.

Like there are so many sample scenes that do a crazy variety of every kind of side scrolling game that exists. It's like it turns Unity into Super Mario Maker. Controls are pretty solid.


For this project there's no reason to use this, any game I made in this Corgi engine wouldn't resemble the base template we're supposed to be modifying at all and the whole assignment is to modify the base template and make a game with it.

But holy hell, after this class is done if I want to try to make some games using pre-made engines, so many possibilities and it's nice having so much done for you already. Like I started designing a prototype for my game and it has water and I'm like "how do I code swimming controls in" whereas this Corgi demo already has swimming in water, ice platforms, ladders, etc....

$30 well spent.

Also if there is stuff like this for every genre to turn Unity into Super Mario Maker of all genres that's crazy and completely changes the idea of game making I had in my head. It does feel like cheating though.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 03:36:34 PM
Actually started looking through the editor, like even the most simple stage is very, very complex in these demos. I started going through the scripts in visual basic and this stuff is like 1-2 years beyond me at this point and way over my head.

Basically if I used it would be just using the prefabs with my own art/music/levels and a few adjustments here and there but otherwise wouldn't be messing with the core engine at all because it's way beyond me right now.

Very fascinating and cool learning experience though!
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 17, 2022, 09:45:33 PM
So, at the end of the day and a lot of excuses and distractions, the truth is I just don't know how to make a fun 2d platformer  :'(


Like you tell me to make a shmup, I just try to make fun & challenging bullet patterns to dodge through with some neat gfx effects, make an adventure game, come up with a story and some dialogue and item based puzzles, horror game, make some spookiness or scares, rpg make a story, some towns/dungeons and a battle system.

But like "place down platforms and dangerous things in a way that is 'fun'" and just...no idea. Same with puzzles. If I make a door that is locked and you have to push a crate on a button, is that fun or is that tedious busywork?


I like the idea behind this class of learning different genre quickly to experiment around, but the class is like "making games should be hard fun" and the first game was, but making games in a genre you don't understand well under a class deadline...just feels like I'm back in school and doing work and getting writer's block and nothing done and taking naps. The class also gives 0 lessons/classes on how to design theory a 2d platformer. It's just generic "watch the making of Uncharted to see how to make characters and story" which doesn't help when designing a Mario level at all.

I still don't have a gameplay loop concept
I still haven't really made a single room
and the game is due in about two weeks.

I can keep watching tutorials and learn how to make more tools and better physics and whatever, but that's just distractions from having no idea how to make fun platforming. Even if I fired up Super Mario Maker 2 I'd have no idea how to make a good level in it.

Doesn't help I only play a sidescrolling platforming game like once every 2-3 years. So yeah I love Celeste/SMB/Hollow Knight/Guacamelee/Cave Story/vvvvv/etc... but those are extremely tight games and the metroidvania ones are BIG games and not the "I'm gonna make this in a weekend as my 2nd game" kind of thing. Not sure what I can get from them.

Plus there's still a lot tech-wise I don't know how to do. I was like "ok, the opening scene will look like this"

(https://i.imgur.com/IuliyxX.png)


And then I'm like here are all the things I don't know how to do to execute that:

Room #2 - Screen shakes
Room #3 - Would want flashing red lights like an alarm, don't know how to do colored lighting
Room #6 - Don't know how to do water motions of something moving in water and not just in a straight waypoint move line, also camera changing tracking to follow robo downstream
Room #7 - Don't know how to do particles to show splash

So yeah, for like the first 20-30 seconds scene it would take me a half-dozen to a dozen hours of learning techniques, which isn't feasible for this.

I need to just make a few simple Mario maker kind of levels that don't require tons of techniques. But just no idea how artistically to design that :| Guess I will keep trying. Also unless I make some fun levels I just don't have the motivation for this project to do my own art/music because it's like what's the point in spending that time on a game I don't even like.

Solution might just be to give up and move to the next class on 3d FPS and come back to trying to do this later after I feel more confident in my design and tech skills.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 18, 2022, 07:43:06 AM
Problem is, even if I could write some code that said "when colliding with a conveyer belt tag, turn off that one line", now I can't move my player because I removed the velocity entirely and all I can do is move while jumping.

I feel like there has to be a good solution for this that says when colliding with conveyer tag, don't use that line of code, instead use "______" to move left/right?

This is just a maths / physics problem though, right?
You don't actually want to turn off your existing movement, you want to resolve two forces interacting with each other (one 'positive' if youre moving with the conveyor, one 'negative' if you're 'swimming upstream').
So basically, think of this as sideways gravity; how is your current movement controller resolving a gravity constant in the negative Y axis?
Because what you wanna do, is resolve 'sideways gravity' in the X axis, which is probably going to be something like
Code: [Select]
if (col.ground =="conveyor") => rb.setvelocity((input.x * moveSpeed)+conveyor.velocity, rb.velocity.y);

Also if there is stuff like this for every genre to turn Unity into Super Mario Maker of all genres that's crazy and completely changes the idea of game making I had in my head. It does feel like cheating though.

I mean, it's not quite that simple, but most of the decent and well mantained Unity code addons basically give you a new API for doing specific stuff - this is why I suggested you try out that dialogue asset you bought instead of doubling down on getting a VN engine, because I kind of suspect it has everything you need to make a VN built in.

The upside is to get something done, you're working like you'd be working at an actual games company where someone else is doing the engine work to enable the designers / scripters to do what they need to do, which saves you a ton of learning / expertise / time - the downside obviously is if you don't understand something or you get weird bugs, its kind of a black box (although most of the top rated unity addons are really conscientious about customer support and have discords and shit to assist you)

So, at the end of the day and a lot of excuses and distractions, the truth is I just don't know how to make a fun 2d platformer  :'(


Like you tell me to make a shmup, I just try to make fun & challenging bullet patterns to dodge through with some neat gfx effects, make an adventure game, come up with a story and some dialogue and item based puzzles, horror game, make some spookiness or scares, rpg make a story, some towns/dungeons and a battle system.

But like "place down platforms and dangerous things in a way that is 'fun'" and just...no idea. Same with puzzles. If I make a door that is locked and you have to push a crate on a button, is that fun or is that tedious busywork?

Okay, so firstly what I'll say is, if you have no particular love for the genre, don't look at the 'genre kings' which are literally exemplars of platforming methodologies; think back to the 16 bit days, when every fucking movie / toy / cartoon tie in was a sidescrolling platformer. Why? Because if you have a decent character controller, moving around in a 2D space is pleasing, and you then just have to tell a visual story (based on the IP) so the player wants to keep playing to see what the next area is going to be.
Chuck in a boss fight every 4 levels, and you're gold. Throw in some collectibles hidden around and you have replayability.
Don't overthink it.

HAVING SAID THAT; you don't even have to make a 'platformer' game - play something like Lost Vikings or Krustys Funhouse; these look and feel like platform games, but they're fucking not.
Look at Zelda 2, or more recently things like Mark Of The Ninja, or Fez.
If you know how to build a satisfying SHMUP, go ahead and build that; you're just adding an additional play constraint of gravity. Hell, thats basically Contra, right?

And then I'm like here are all the things I don't know how to do to execute that:

Room #2 - Screen shakes
Room #3 - Would want flashing red lights like an alarm, don't know how to do colored lighting
Room #6 - Don't know how to do water motions of something moving in water and not just in a straight waypoint move line, also camera changing tracking to follow robo downstream
Room #7 - Don't know how to do particles to show splash

Screenshakes = easy; you already know how to find your camera, just fuck with its transform for a second then reset it (might want to use a Tween library to do this though to get a nice easing)
Flashing lights = also easy; when you add a light, you can literally colour it in the inspector. If you're using the URP there's a nice suite of specific 2D lights built riht into unity too. Otherwise, just drop a spotlight in at a z position so you can aim it at your scene, and colour it red / set its strength / range.
Water = potentially easy, potentially nearly unsolvable and bringing high end gaming rigs to their knees trying to calculate in real time; think about your end goal, not the 'flavour' or how you might think about implementing it 'correctly' - videogames are all smoke and mirrors, so cheap hacky shit that works and approximates an effect is always going to be usable. If what you want is something that 'wobbles' up and down a little bit deterministically as it moves left and right, just do a SIN wave modifier on your Y position, based on your X position.
Particles = also pretty easy, and also fun to play with, but you might find yourself going down a rabbit hole
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 18, 2022, 07:50:19 AM
while setting up a little story is important, focus on what would make a fun game first

a big part of what makes levels fun and interesting is having an enemy on the next platform you have to jump to, so you have to time your jump carefully, or perhaps enemy projectiles flying overhead that you have to dodge as you make your jump

think about level layouts, like, would it be fun if you had to search for 5 things in a level to unlock a door to the next level?  so does the player start in the center and have a spoke-design level with 5 discrete challenges in every direction?  or do you go more linear and make the collectibles obvious along the way?

what if you put in a lot of doors/pipes to small bonus room type areas which eventually lead back to the main level?

a common forgiving level design is platforms along a "ground level" which then ascend into a sky area that loops back over the earlier part, so that if you fall you end up in familiar territory and can climb back up

or you reach a tall wall and have to double back up a short climb to get over it

https://vgmaps.com/Atlas/Genesis/Aladdin-Level1-AgrabahMarket.png

I know these are really basic things but if you just make a level with them you can continuously refine it, and opportunities present themselves, "ooh I could put a powerup here, it's a tricky jump off the beaten path"
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 18, 2022, 07:56:57 AM
you can also get a lot of mileage just out of really fucking drilling deep into what a single mechanic can do, and what kind of challenges it can create in mastering that one mechanic.

VVVVVV is a really good example of this, because you can't even jump; the entire game is just pretty much every permutation the maker could come up with of a 'flip gravity' mechanic.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 18, 2022, 08:18:21 AM
Monster Party is a very weird NES game that's worth looking into, but one of its main conceits is that the (fairly simple) levels have a lot of doors, some rooms are empty, some have bosses in them who say something weird

https://www.vgmaps.com/Atlas/NES/MonsterParty-Round1.png

you could make an entire game out of that concept, a fairly normal platformer but the fun is coming across a door and thinking oh geeze, what's going to be behind THIS one

actually Kid Icarus was similar to that too, though in that case I think it was more figuring out over multiple playthroughs which rooms are traps that you should avoid?  which is less fun

what about a game where every level has 5 doors, but you can only open 3 of them?  so you want to replay it to see what you missed behind the other doors

are you rescuing hostages and the two you couldn't open are because you were "too late" and those people died?

or is it just a matter of you are given 3 keys in each level and you use them up?

do some have permanent powerups that are missable?

maybe you could even cheat and force the player's third room to be a powerup, no matter what?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 18, 2022, 07:56:17 PM
Thanks,

so I made a "real" platforming level with a few things.


You can check it out here:

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

Let me know what you think. There is:

-Test idea level - Most fun because it has a variety of stuff
-Boring level - Totally rote boring simple level
-Level 2 - mediocre-ish challenge platformer level

All three levels are clearable.

That being said I've decided to throw it all in the fire and start from scratch. No template, no Corgi engine, just new project, make my own character movement, camera movement, game manager, UI manager, use my own art assets from the start for tiles/objects/player.

It's a lot more work, and I honestly don't want to do it while working a full time job (that's a lot of this, there are things I can do to make better quality stuff but I don't want to spend the time/effort. Easier to feel worth spending that time/effort for something that's got initial form going and I'm building on it and excited about what I'm making), but the only way I'll get motivated is if I'm making my own thing and not "making levels/gameplay within someone else's thing".

And like you said, it doesn't need to be a pure platformer. Can be whatever I want. Though honestly the more I work with side scrolling tiles the more I hate making side-scrolling and after this project I'm only doing overhead or 3d games going forward. Filing in tile by tile/platform by platform just feels tedious and boring. Prefer just like painting overhead area all green grass and then individually putting in objects/enemies. Just feels like the environment is much easier to draw out in overhead because you don't have to worry about how the player is getting from every single step to the next.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 18, 2022, 09:04:03 PM
Ok, learning stuff from scratch is pretty helpful. It's nice writing your own movement so you know what is going on the whole time and can adjust it. I'm going through some guides that cover the really basic stuff like this and even for things I know how to use I'm learning a lot of tips. Like I didn't know you could erase tilemaps with shift while drawing titles since in Aesprite it's right click. Also not being tied to an inputmanager someone else has written, so you can just type "getkey or getkeydown" is so nice and refreshing for interactions.

I haven't written any camera script stuff, but how hard is a camera controller that just follows a target's transform position? I think the game manager script will be the toughest bit for me to learn how to make, but conceptually I understand it, so maybe not.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 19, 2022, 06:30:18 AM
All three levels are clearable.

That being said I've decided to throw it all in the fire and start from scratch. No template, no Corgi engine, just new project, make my own character movement, camera movement, game manager, UI manager, use my own art assets from the start for tiles/objects/player.

theyre all fine, even if I hate those megaman style vanish / reappear blocks :idont

I think there's a lot ot be said for rawdogging your code from complete scrtach though, especially if youre kinda unsure about the specific of what you just done in a tutorial; if nothing else, trying to recreate from memory is going to reinforce learning a lot better than just assuming you have it down.

I haven't written any camera script stuff, but how hard is a camera controller that just follows a target's transform position? I think the game manager script will be the toughest bit for me to learn how to make, but conceptually I understand it, so maybe not.

yeah, ez-mode cam control is just making your camera a child of your player object, intermediate is making an invisible object that moves to your player (or a relative position, if you wanted camera 'leading' like your top down shooter) that the camera focuses on, probably with a smoothdamp or lerp and probably in lateupdate after movements resolved so it doesnt seem jerky.
galaxy brain camera is some kind of box focus so you can move in a genre dependent / relevant area without camera movement until you really need it.

https://www.gamedeveloper.com/design/scroll-back-the-theory-and-practice-of-cameras-in-side-scrollers

some good stuff in there for ideas on camera moves.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 19, 2022, 07:35:55 PM
Learning so much good code practice going through these tutorials on basic things from scratch. Like how to separate your code so you don't put a ton of stuff in Update but just call methods and put the stuff in that with ///summaries and #region for initial variables to make the script OCD clean to read.

Also learning how and why to make most things private and used [serializefield] instead of public for getting stuff into inspectors but cutting down on bug chances from variables getting messed with outside the script.

This is all stuff the class has basically skipped since it's not really a coding class, but this is so helpful for understanding code and how to write things.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 19, 2022, 09:59:00 PM
Hey GreatSage, I'm trying to put in conveyors now with my new movement and game from scratch but I'm trying to wrap my head around the coding collision to get a component of the item you've collided with.


This is what I want to do:

Code: [Select]
private void OnTriggerStay2D(Collider2D collision)
    {
        if(collision.CompareTag("Conveyor"))
        {
          private SurfaceEffector2D col;
          col = collision.GetComponent<SurfaceEffector2D>();

          rb.velocity = new Vector2 ((dirX * movementSpeed) + col.velocity, rb.velocity.y);
        }
    }

But this doesn't work because the collider isn't actually bringing you the gameObject you've collided with, just a string with its tag. So when you try to pull a GetComponent of the string it's not going to work.

What do I need to do to pull the SurfaceEffector2d off a colliding object so that I can access it's velocity and add it to my velocity?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 19, 2022, 10:17:06 PM
Although the more I google this, the more it seems like conveyer belts for characters in 2d games are something that's just inherently a problematic issue in Unity?

https://forum.unity.com/threads/player-controller-unity-2d-character-script-not-working-with-surface-effector-2d.974505/#post-6336327

Basically the info I'm getting is the only way around this is using "addforce" to move and letting the physics determine velocity instead of player controls. This results in slippery physics characters and not tighter 2d controls.

I've googled for days and there's not a single video/website on how to add a simple mario conveyer belt for a 2d game that the player can ride. It's kind of crazy since conveyers are like really basic platforming tools.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 19, 2022, 10:53:54 PM
I found this code online and it actually works...mostly, it's good enough that I could use it for certain stuff if I want a conveyer belt. Though to be fair I doubt I'm gonna have any belts in my game at this point and this is more just curiosity trying to figure out how to get past a problem.

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

public class testbelt : MonoBehaviour
{
// We will need a list of items on the belt. Generic list collections work best for dynamically sizing arrays imo
public List<GameObject> objsOnBelt;
//you can adjust the speed using the float speed. If you want the belt to push right left use a negative number.
public float speed;
// Use this for initialization
void Start()
{
//Best to initialize the list. I find that objects with scripts added dynamically through code don't always intalize lists
objsOnBelt = new List<GameObject>();
}

// Update is called once per frame
void Update()
{
if (objsOnBelt.Count != 0)
{
//We no longer need a bool we can simple see if the list is empty
for (int i = 0; i < objsOnBelt.Count; i++)
{
Debug.Log("MovingPlayer");
objsOnBelt[i].transform.position += transform.right * (speed * Time.deltaTime);
}
}
}
void OnTriggerEnter2D(Collider2D col)
{
//Enter is good for a player detetion because we just need when the player first enters the collider.
// The player will need a rigidbody2d for this detection to work.
if (col.gameObject.tag == "Player" || col.gameObject.tag == "ConveyorObj")
{
// "Player" is a standard tag in the editor you can change your player's tag in the drop down.
// Create a new tag for objects that can react to the conveyor.
Debug.Log("Player in the coveyor");
// Remeber to always delete uncessary debus before building.
objsOnBelt.Add(col.gameObject);
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.gameObject.tag == "Player" || col.gameObject.tag == "ConveyorObj")
{
// "Player" is a standard tag in the editor you can change your player's tag in the drop down.
Debug.Log("Player left the coveyor");
// Remeber to always delete uncessary debus before building.
objsOnBelt.Remove(col.gameObject);
}
}

It moves the player along the conveyer and if you are jumping against the direction it's pushing you don't jump as far which seem correct, but if you are jumping in the direction it is pushing you don't gain any extra distance/momentum.

Which makes sense because it is just moving your character a frame at a time to the right and not actually adding any velocity. I still wonder if Great Sage's method of adding velocity of an object like a surface effector to the velocity calculating of the player movement would work.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 19, 2022, 11:30:12 PM
I did a test and I think Great Sage's code will work for velocity.

I basically made a public gameobject on playermovement called "put conveyer object here"
then I dropped it in, grabbed it's 2d surface effector in a variable called suf

Then I just used velocity as (dirX+movement speed) + suf.speed, y)

This seems to work correctly. Harder to jump against it, extra momentum when jumping with it.


So I just need to make an if statement that only applies this when collidingonstay on a conveyer tag object. Because right now with my code if the conveyer speed is 5, you just always have that extra 5 velocity even if not on the conveyer and walking on the ground.

Then I need to figure out a way to grab that surface effector 2d of the object I'm colliding with so I don't do the public thing since I can only drop one belt at a time that way.

That should solve it?
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 19, 2022, 11:45:24 PM
I like reading your journey into game-making blog even if you don't usually get a lot of varied feedback :mario
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 12:06:14 AM
Thanks,

I got the "if on conveyor belt, apply the extra speed to velocity" but, I think there is an inherent issue here. This is my movement code

Code: [Select]
private void UpdateMovement()
    {
       
        dirX = Input.GetAxisRaw("Horizontal");

        if (OnConvey)
        {
            rb.velocity = new Vector2((dirX * movementSpeed) + suf.speed, rb.velocity.y);
        }
        else
        {
            rb.velocity = new Vector2(dirX * movementSpeed, rb.velocity.y);
        }
       
        if (Input.GetButtonDown("Jump") && isGrounded())
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpStrength);
        }
    }

Its fine when on the conveyor belt, and even fine the first frame you jump, but once it updates to the take frame of your leap you are not on convey and it rewrites your horizontal velocity back to the default velocity. So you don't feel the extra force against or with you when you jump from a conveyor belt.

Conceptually the only way I think you could get around this would be to either:

A) Lock your player's jump in once you leap on the first frame, so you can't adjust any movement mid-air.

B) Somehow tell it to keep running with the conveyor belt speed added to your velocity for an extra second or two? Though if jumps will be different lengths of time I don't see how you could do this without undershooting or overshooting it. Maybe something convoluted like:

If you are on a conveyer belt & if you hit jump, then run coroutine (effected jump)

coroutine effected jump()
Until you collide with non-conveyer belt ground/object
-Keep using x velocity with conveyer belt included
then return

Which at that point should return back to normal velocity movement?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 12:34:02 AM
Came up with that coRoutine but it's not working and I know why:

Code: [Select]
  if (OnConvey && Input.GetButtonDown("Jump") && isGrounded())
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpStrength);
            StartCoroutine(AffectJump());
        }
        else
        {
            if (Input.GetButtonDown("Jump") && isGrounded())
            {
                rb.velocity = new Vector2(rb.velocity.x, jumpStrength);
            }
        }

Code: [Select]
IEnumerator AffectJump()
    {
        Debug.Log("Is Grounded: " + isGrounded());
        while (!isGrounded())
        {
            Debug.Log("Getting here");
            rb.velocity = new Vector2(rb.velocity.x, jumpStrength);
     
        }
        yield break;
         }

After I jump on a conveyor belt the debug.log still returns "Is grounded = true" so my while loop never runs.

This is because the collider trigger for the ground probably takes a bunch of frames for the jump to initially clear. So yeah when it checks the next frame after starting the jump it thinks it's still colliding with the ground. At least that's my guess.

Not sure what a good way to try to do this is.

*edit* figured out the issue with this one, once in the coroutine or a while loop it never checks isgrounded() again because that's outside the loop/coroutine.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 01:11:09 AM
Spent like the last hour writing various codes attempting to figure out a solution to keep the momentum until contact with a new object but no luck. I think I'll just be happy I have working belts even if they don't affect the jump challenge.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 20, 2022, 10:33:23 AM
learning how and why to make most things private and used [serializefield] instead of public

👍  :lol

Although the more I google this, the more it seems like conveyer belts for characters in 2d games are something that's just inherently a problematic issue in Unity?

https://forum.unity.com/threads/player-controller-unity-2d-character-script-not-working-with-surface-effector-2d.974505/#post-6336327

I mean... the thing here is, if you read between the lines, the Unity dude is trying to tell them as politely as possible that their code fucking sucks, because if you're using physics you shouldn't be directly applying a velocity (although thats what you commonly see on pseudo-physics based character controllers trying to mimic kinematic 'feel').

Its also not exclusive to Unity, anything using a physics 'system' is going to have the same issues when attempting to reconcile physics with not-physics.

I've googled for days and there's not a single video/website on how to add a simple mario conveyer belt for a 2d game that the player can ride. It's kind of crazy since conveyers are like really basic platforming tools.

yeah, I mean, if nothing else, making your own games gives you a hell of a lot more appreciation for what it takes to make games that feel effortless and basic.
Other platforming shit that will probably surprise you with how much more fucking effort it takes than it seems it should include;

Conceptually the only way I think you could get around this would be to either:

A) Lock your player's jump in once you leap on the first frame, so you can't adjust any movement mid-air.

B) Somehow tell it to keep running with the conveyor belt speed added to your velocity for an extra second or two?

Taking it back a step, conceptually what's going on here?
 - You're modifying the players current X velocity via an external system

And what's breaking things?
 - You're directly applying an X velocity (ie effectively zeroing it) on input (which overwrites any modifications)

So an alternative way of doing this would be to not directly apply X-input velocity, but to add X-input velocity after running a check, right?

like
Code: [Select]
player.velocity.X = CheckModifiers(Input.getaxis("Horizontal"));
rb.velocity = Vector2(player.velocity.x, player.velocity.y);

float CheckModifiers(float currentVal)
{
     newval = currentVal;
     //stuff that modifies val
     return(newVal);
}

and if you want a little 'follow through' from being on a conveyor belt, you could think of that as a 'powerup' on 'cooldown', right? So for ~1 sec after jumping, your val is still being modified until the cooldown for that modifier 'wears off', and the 'cooldown' is reset whenever you stand on a conveyor belt, and only starts 'ticking down' when you jump.
You might even want to map cooldown remaining directly to power of modifier too, so you have 'full' power modifier as soon as you jump, after 0.5 secs its only 0.5 power etc

And you're probably thinking "well, that's a lot of fucking legwork just for a conveyor belt", and you'd be right; but what you'll have built is an extensible system that you can 'nicely' modify a players velocity by via coefficients that you can turn on / off and 'cooldown' over time, that you can then use for other stuff, like springboards, 'mud', ice, moonjump power ups etc etc etc that will all work nicely with each other, because they'll all modify X/Y velocities in the same way and can be layered

does that make sense? You seem to have this solution like, 90% figured out by yourself, so I don't wanna be all 'look, just have a fish, bro'
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 20, 2022, 12:04:36 PM
to be fair 90% of coding is googling what you want to do and finding the fish
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 12:23:26 PM
Yeah, I'll take the fish here.

That stuff inside check modifiers is what I spent all night trying to figure out and couldn't get it working. Even using your 1 sec powerup example, I had trouble setting it to continue to add the belt force for 1 sec after jump while on a belt?
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 20, 2022, 01:56:37 PM
Well I dunno if you really need my fish, after you paid $30 for a create-your-own sushi platter  :lol

but id be thinking of this as something like a general buffs+debuffs timer, its just its a 'mixed' buff/debuff where you're buffed walking right but debuffed walking left (or vice versa)

so something like

Code: [Select]

bool hasEffect;
float moveSpeed=10f;
float conveyorTimer;
float conveyorEffect=5f;

void OnCollisionEnter(col other)
{
     if (other.tag.name=="Conveyor") { ConveyorEffect(100); }
}

void OnCollisionStay(col other)
{
     if (other.tag.name=="Conveyor") { ConveyorEffect(100); }
}

void ConveyorEffect(float duration)
{
     if (!hasEffect) { Invoke("EffectsTimer", 0.1f, 0.1f); hasEffect=true; }
     conveyorTimer=duration;
}

void EffectsTimer()
{
     if(!hasEffect) { CancelInvoke(); return; }
     else
     {
           bool endCheck=false;
           // all your effects checks
           if (conveyorTimer>0) { conveyorTimer-=duration; } else { endCheck=true; }
           if (endcheck) { hasEffect=false; }
     }
}

float GetPlayerXVelocity(float baseline)
{
     playerX = Input.Getaxis("Horizontal") * baseline * Time.deltatime; // or whatever
     if (conveyorTimer>0) { playerX += conveyorEffect; }
     return(playerX);
}

void DoMove()
{
     rb.velocity = Vector2(GetPlayerXVelocity(movespeed), rb.velocity.y);
}

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 03:05:14 PM
True, I could fire up the Corgi demo template and look at how their script does stuff for certain objects on the map. Good idea.

So trying to understand your code.

When you collide with the conveyor, the game applies a conveyor effect for 100milliseconds (.1f tick) and as long as you're on the belt it continues to apply that restarting the 100 second count until you exit the collision which is when the 100 millisecond count will actually go down.

The conveyor effect sets the timer as the duration being sent in effect and then invokes a .1 tick rate timer and sets effect as true on character

The timer takes your conveyor time buff duration and then counts it down at a .1 tickrate until it's 0 and then sets endtimer and effect as false.

Player velocity is calculated as normal movement + conveyoreffect as long as the conveyer time is going



Now this clears up an idea I was screwing with for so long last night. That there's no need to tie the conveyor speed buff effect to jumping off the conveyor. I kept trying to make it start upon jump/exiting collision with the belt. By just applying the movement that will continue to apply the force on jump without having to specifically tie it to the jumping command. That's helpful to clear up the logic puzzle I was trying to solve.

So like for the effects check, since different belts may be in the scene at different speeds, how would I get the speed off the conveyor I'm colliding with? That was one of my issues last night and the only "test" get around I had was to make a public gameobject and link a single conveyor belt in as a test so I could grab its speed from getcomponent.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 20, 2022, 03:21:28 PM
yeah, you got the gist of it; note it might not be the best way, but its how I'd initially approach it while keeping it extensible.

And speaking of extensible, if you wanted another kind of conveyor with a different speed / direction, I can just go ahead that as a new case with a new value, like;
Quote
float GetPlayerXVelocity(float baseline)
{
     playerX = Input.Getaxis("Horizontal") * baseline * Time.deltatime; // or whatever
     if (conveyorTimer>0) { playerX += conveyorEffect; }
     if (conveyorTimer2>0) { playerX += conveyorEffect2; }
     return(playerX);
}

(although a better way would be just having a different mgnitude of effect for different conveyors rather than a new 'class' of conveyor if they do the same thing; maybe making the magnitude of effect be attached to the conveyor script, and then deriving it from there on collision contact)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 03:31:24 PM
Ok, just spent like 30 mins integrating this into my player movement existing code base. But it's not getting to the point of effects. Going to debug each step and trying to figure it out.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 20, 2022, 03:35:52 PM
just design the game in such a way that all conveyors are located at y = 50 and then if the player's y is ever 50 set their X velocity to -10

:idont  :whatisthis
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 03:38:12 PM
I guess this is my first time using oncollision instead of ontrigger.

It was giving me a red flag on other.tag.name, so I tried using other.tag which worked for trigger but doesn't work for collision?

 void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log("Test2");
        if (other.tag.name == "Conveyor") { ConveyorEffect(100); }
    }

The bold is giving me:

Collision2D does not have a definition for tag.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 03:41:10 PM
Fixed it

if (other.gameObject.CompareTag("Conveyor")) { ConveyorEffect(100);

But now my player is moving with 5f even when not on the conveyer and on the ground lol, time to figure out what is wrong.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 03:56:32 PM
Nm,
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:04:31 PM
Basically among the few issues I'm having is the timer/effect isn't actually working

Code: [Select]
   void ConveyorEffect(float duration)
    {
        Debug.Log("Getting Here4");
        if (!hasEffect) { Invoke("EffectsTimer", 0.1f); hasEffect = true; }
        conveyorTimer = duration;
    }

    void EffectsTimer()
    {
        if (!hasEffect) { CancelInvoke(); return; }
        else
        {
            Debug.Log("Getting Here5");
            bool endCheck = false;

            // all your effects checks
            if (conveyorTimer > 0) { Debug.Log("Getting Here6"); conveyorTimer -= duration; }
            else { Debug.Log("Getting Here7"); endCheck = true; }
            if (endCheck) { Debug.Log("Getting Here8"); hasEffect = false; }
        }
    }

It's getting to 6, but never hits 7/8 so it never turns endCheck to true.

I can't tell if this is because the timer is only running 1 time and timer is > 0 so it say 100-.1 = 99.9 and then it never runs timer again? I tried changing the timer to a while loop and it just crashed the whole thing.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:08:12 PM
Actually I see the error. It was giving me an issue in compiler on the invoke having .1f, .1f and told me it should only have a string + one float so I changed it and it was happy. I guess it needs both to keep repeating. Just need to figure out the language the compiler will like.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 20, 2022, 04:10:29 PM
Nah, it could just be me misremembering parameters - my code snippets are being written with Simpleforums as my Syntax Hightlighting  :lol

I might have just forgotten / confused Invoke withInvokeRepeating
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:13:19 PM
Yeah that's what I thought but Invoke Repeating is still giving me compiler issues?
This is the timer you gave me in the other project which worked fine:

InvokeRepeating("MyTimer3", 0, tickrate);

But here it tells me this is bad:

InvokeRepeating("EffectsTimer", .1f, .1f);

The error says:
There is no argument given that corresponds to the required formal parameter 'repeatRate' or 'Monobehaviour.InvokeRpeating(string, float, float)'

I get the same error whether it's Invoke or InvokeRepeating.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:15:28 PM
actually changing it to 0 like the other one fixes the error, let me see if it works now.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:16:38 PM
It compiles and runs but still not getting the "getting here 7" meaning the timer is never = or <0 even when off the belt.

Also I put conveyorTimer in update and yeah it goes to 100 when jumping on the belt but never goes down from 100.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 20, 2022, 04:21:55 PM
It compiles and runs but still not getting the "getting here 7" meaning the timer is never = or <0 even when off the belt.

this:
Quote
if (conveyorTimer > 0) { Debug.Log("Getting Here6"); conveyorTimer -= duration; }
should probably be
Code: [Select]
if (conveyorTimer > 0) { conveyorTimer -= 1; Debug.Log("Getting Here6, and timer is: " + conveyorTimer); }
for a) non-fucked up code  :lol (its late and I'm doing this from memory) and b) more info on your debugging - I wouldn't be surprised if conveyortimer was never decreasing because duration was never set, and I dunno why I had that in my OG code in the first place looking back at it  :lol
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:23:48 PM
Fixed it this way which seems to work?

In your code it's set as duration
conveyorTimer = duration;

instead I tried

 if (conveyorTimer > .1) { Debug.Log("Getting Here6");
                conveyorTimer--; }

And it counts down now and gets to 7/8. Let me try adding the movement effect now and see if it works.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:32:12 PM
OK, got it working. Had to set the timer on 10 otherwise would keep moving the player after they land and are walking on the ground. 10 seems to run out before they land.

Here is my player movement code at this point
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    #region Variables
    private Rigidbody2D rb;
    private SpriteRenderer sprite;
    private BoxCollider2D coll;
    private Animator anim;
    private float dirX = 0f;
    bool hasEffect;
    float conveyorTimer;
    float conveyorEffect = 5f;
    float duration;


    [SerializeField] private LayerMask jumpableGround;

    // Gets movement speed & jump strength

    [SerializeField] private float movementSpeed = 7f;
    [SerializeField] private float jumpStrength = 14f;

    public GameObject Convey = null;
    private SurfaceEffector2D suf;

    private enum MovementState { idle, running, jumping, falling }
    private MovementState state = MovementState.idle;
    #endregion


    /// <summary>
    ///  Gets and assigns the rigidbody, animator and sprite to local variables
    /// </summary>
    private void Start()
    {
        Debug.Log("Start");
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
        sprite = GetComponent<SpriteRenderer>();
        coll = GetComponent<BoxCollider2D>();
        if (Convey != null) {
        suf = Convey.GetComponent<SurfaceEffector2D>();
        }

    }

    /// <summary>
    /// Updates Movement & Animation State
    /// </summary>
    private void Update()
    {
        UpdateMovement();
        UpdateAnimationState();
        Debug.Log("Conveyor Time: " + conveyorTimer);
    }

    /// <summary>
    /// Gets horizontal axis movement and applies it with movement speed to be the new x-axis velocity
    /// Gets jump and assigns y-axis velocity based on jump strength while still using existing movement speed from last frame
    /// </summary>
    private void UpdateMovement()
    {
        GetPlayerXVelocity();
        rb.velocity = new Vector2(dirX, rb.velocity.y);

        if (Input.GetButtonDown("Jump") && isGrounded())
        {
           rb.velocity = new Vector2(rb.velocity.x, jumpStrength);
        }
    }

    float GetPlayerXVelocity()
    {
        dirX = Input.GetAxisRaw("Horizontal") * movementSpeed;
        if (conveyorTimer > 0) { dirX += conveyorEffect; }
        return (dirX);
    }

    /// <summary>
    ///  Updates animation based on if running or idle and flips sprite based on horizontal direction
    /// </summary>
    private void UpdateAnimationState()
    {
        MovementState state;

        if (dirX > 0f)
        {
            state = MovementState.running;
            sprite.flipX = false;
        }
        else if (dirX < 0)
        {
            state = MovementState.running;
            sprite.flipX = true;
        }
        else
        {
            state = MovementState.idle; ;
        }

        if (rb.velocity.y > .1f)
        {
            state = MovementState.jumping;
        }
        else if (rb.velocity.y < -.1f)
        {
            state = MovementState.falling;
        }

        anim.SetInteger("State", (int)state);
    }

    /// <summary>
    /// Does Boxcast .1f down and returns true or false if overlapping jumpableGround layer
    /// </summary>
    /// <returns></returns>
    private bool isGrounded()
    {
        return Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, jumpableGround);
    }


    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Conveyer")) { Debug.Log("Starting Conveyer Effect"); ConveyorEffect(10); }
        else conveyorEffect = 0f;
    }

    void OnCollisionStay2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Conveyer")) { ConveyorEffect(10); }
        else conveyorEffect = 0f;
    }
    void ConveyorEffect(float duration)
    {
       
        Debug.Log("Getting Here4");
        if (!hasEffect)
        { InvokeRepeating("EffectsTimer", 0, .1f);
        hasEffect = true;
        }
        conveyorTimer = duration;

    }

    void EffectsTimer()
    {
        if (!hasEffect) { CancelInvoke(); return; }
        else
        {
            Debug.Log("Getting Here5");
            bool endCheck = false;

            // all your effects checks
            if (conveyorTimer > 0) { Debug.Log("Getting Here6");
                conveyorTimer--;
                conveyorEffect = 5;
            }
            else { Debug.Log("Getting Here7"); endCheck = true; }
            if (endCheck) { Debug.Log("Getting Here8"); hasEffect = false; conveyorEffect = 0; }
        }
    }

}


Now, after all this there's still one inherent issue even if I could figure out a way to grab the conveyor belt speeds of each belt and adjust the conveyorEffect off their speed in 2dsurfaceeffector.

When I jump against the belt it's tougher because of the force = good
When I jump with the belt I get extra distance because of the force = good
When I'm on the belt I get pushed in the direction = good
When I'm off the belt I get normal movement = good

But...when I jump against the belt and turn in mid-air towards the belt I go flying that way.

Basically the way this code works would be perfect for a wind stage. Forget the belt thing, just have this extra force always applied and bam you have every wind stage ever in a 2d platformer.

But it's not quite right for jumping from conveyor belts. Not sure if there's a solution to this, at this point I'm just not planning on having belts or if I do they are setup in a way that locks the player from jumping in the first place and just moves the player around along with crates/other objects.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:38:28 PM
Also when you fall right off the conveyor belt to the ground at 10 you still bobble a few steps before stopping. Not sure if there's an easy way to just tell it to stop once it touches ground. I thought my

"void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Conveyer")) { Debug.Log("Starting Conveyer Effect"); ConveyorEffect(7); }
        else {conveyorEffect = 0f;}
    }"

Would do that, but it doesn't.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 04:51:19 PM
whoops
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 05:03:55 PM
I thought I was clever but this doesn't work. It almost works to stop the 2nd issue I mentioned of moving after landing.
Code: [Select]
    void EffectsTimer()
    {
        if (!hasEffect) { CancelInvoke(); return; }
        else
        {
            Debug.Log("Getting Here5");
            bool endCheck = false;
            bool Jumped = false;
            bool Airborne = false;
            bool Landed = false;

            // all your effects checks
            if (conveyorTimer > 0 && !Landed) { Debug.Log("Getting Here6");
                if (rb.velocity.y != 0)
                {
                    Debug.Log("Jumped!");
                    Jumped = true;
                }
                if (Jumped == true && !isGrounded())
                {
                    Debug.Log("Airborne!");
                    Airborne = true;
                    Jumped = false;
                }
                if (isGrounded() && Airborne == true)
                {
                    Debug.Log("Landed!");
                    Landed = true;
                    Airborne = false;
                }
                conveyorEffect = 5;
                conveyorTimer--;
            }
            else { Debug.Log("Getting Here7"); endCheck = true; }
            if (endCheck) { Debug.Log("Getting Here8"); hasEffect = false; conveyorEffect = 0; }
        }
    }

I can get Jumped to debug.log true, airborne to debug.log true, but I can't get landing to connect when I touch ground.

I tried both:

   if (isGrounded() && Airborne == true)
                {
                    Debug.Log("Landed!");
                    Landed = true;
                    Airborne = false;
                }

and in case it was having trouble running IsGrounded I tried

if (Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, jumpableGround) && Airborne == true)

but neither are working to activate landed.

The idea being that once you land on ground it cancels the timer run.

*edit* Also I realized "jumping" is redundant, just need to know when not grounded for airborne and then when grounded for landing which should cover all situations I can think of.

Anyhow, I better get back to work at this point. Will mess with this tonight or just work on my game and leave it alone at this point.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 20, 2022, 08:07:19 PM
Btw, was thinking and similar to the "after airborne if I collide with an object -> cancel momentum timer invoke" idea above,

If you did an "after airborne if getRawInput on horizontal axis and it's in the opposite direction from the direction when I jumped -> cancel momentum timer invoke", that should basically let you control your momentum leap mid-air by pressing back, which seems...ok? And if you're jumping against the momentum you'll just fall down instead of being pushed back with momentum which seems good?

Like I think the only way you could tell it was shakey vs professional is that when you press back to control your mid-air momentum pushed leap forward you'd instantly drop to 0 momentum instead of gradually lessen the momentum by how much you pushed. But that's such a small thing I can live with that.

So basically if I can get both of those timer cancels in, I think it should all work?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 03:54:17 AM
So didn't touch that code stuff further but worked on my first level all night and at about halfway just started throwing placeholder art everywhere and designing it all out and finished it.

It's pretty good! I'm very happy with it and it's a good start. Lots of stuff I can clean up and do with the first stage. It's also pretty lengthy. Not sure how that'll work for stuff like Itch.io play in window games if they're actually more than like a 5 min game.

If I stick with this and do a few levels, maybe throw in a boss or two with lifebars, could see this being more like 15-30 mins. Still gotta figure out what I want to do for stage 2.


Also thematically uh, I still need to figure out what my theme is. The first stage is like sorta Swervy MegamanxMarioxNinja? It's just sort of a weird amalgamation of stuff.

I was thinking of that Monster Party game structure that Uncle suggested for level 2, being a bunch of doors that are all mini-level challenges and the bulk of the middle of the game (maybe have like this long level 1, a middle level that's more like a world with doors going into micro-levels each themed on one thing, and then a final stage with a boss or boss rushes or something). And potentially if I go the door route, the doors could be thematically all over the places so the whole thing would feel like a weird PS1/high on drugs game? It might work, or it just feels like a mess of a ton of different styles with no thematic connection and will be terrible lol

But at least I have a solid start now and can just iterate on it. The worst parts of the night (and worst parts of game making in general) is when I get hung up on something really small and stupid and lose an entire hour trying to figure it out. Like I wanted to have signs that you activate by pressing UP. And I figured I'd just use getinputbutton like I do for jump or getrawverticalaxis and if axis goes > .1f or getinputkey("vertical.up") or ("up") or some fucking thing but after an hour of googling and reading documentation I never figured it out how to just check if they are pressing up on a sign. So now the signs just auto play when you stand in them :|

I think one thing that helped motivate me tonight was I watched a video on adding sound effects and so while I was on the unity free asset store getting sfx the tutorial was using I saw a lo-fi BGM pack and the first track fit the stage really well so put that on and was listening to that the whole time I was making and testing it and it clicked a lot better.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 04:00:18 AM
(https://i.imgur.com/PmKELHal.jpg)

(https://i.imgur.com/rD21lMu.jpg)

Some WIP shots, using placeholder main guy for now and those are placeholder trees until I make some tree tiles

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 04:52:03 AM
Actually was going to bed and came up with a story that ties it all together. Pretty much have the whole story penned out now and a general game plan for the rest of the game. Excited to put it together.

The hardest part is just getting to the point where I have a plan. Once I have a plan it stops being bang your head against a wall aimless wasting time and it becomes a fun passion project to make it happen.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 21, 2022, 07:57:28 AM
When I jump against the belt it's tougher because of the force = good
When I jump with the belt I get extra distance because of the force = good
When I'm on the belt I get pushed in the direction = good
When I'm off the belt I get normal movement = good

But...when I jump against the belt and turn in mid-air towards the belt I go flying that way.

Oh yea, of course, silly me.

Easiest fix would probably be to seperate 'conveyor' effect into 'conveyor left' and 'conveyor right' and add an input check for left/right so going 'with' the flow is additive, and 'against' is subtractive rather than treating it as a generic 'wind boost'.

Other things you might consider - because really, what you're doing here is faking momentum, and momentum doesn't work like wind - is modifying conveyor magnitude by time remaining (so it has 'fall off'); easiest way would be to just use (time remaining / initial time apllied) as a coefficient for a linear drop off, unless you really want to get fancy.

Btw, was thinking and similar to the "after airborne if I collide with an object -> cancel momentum timer invoke" idea above,

If you did an "after airborne if getRawInput on horizontal axis and it's in the opposite direction from the direction when I jumped -> cancel momentum timer invoke", that should basically let you control your momentum leap mid-air by pressing back, which seems...ok? And if you're jumping against the momentum you'll just fall down instead of being pushed back with momentum which seems good?

...and this was gonna be my other suggestion, that you zero out the 'boost' with a 'counter' move in the opposite direction. This is (obviously) unrealistic as fuck, but then so is platformer air control in general.
What it might do though is open up an interesting mechanic where you have to avoid 'overshoots' by using air control momentum damping for precision landing.

For the 'still has some momentum after leaving a conveyor without jumping' thing, presumably your grounded check has an if (floortag=conveyor) { doconveyorstuff(); } check? because you can zero out any conveyor stuff if grounded and not on a conveyor pretty safely I'd think, as that's basically how friction works anyway.

It's pretty good! I'm very happy with it and it's a good start. Lots of stuff I can clean up and do with the first stage. It's also pretty lengthy. Not sure how that'll work for stuff like Itch.io play in window games if they're actually more than like a 5 min game.

Have a look at playerpreferences (which I think work in WebGL builds) and give players a stage select / save stages cleared functionality and they'll be fine I reckon; I mean, shit, that's more accomodating of a users time than a lot of actual commercially released NES titles did  :lol

Like I wanted to have signs that you activate by pressing UP. And I figured I'd just use getinputbutton like I do for jump or getrawverticalaxis and if axis goes > .1f or getinputkey("vertical.up") or ("up") or some fucking thing but after an hour of googling and reading documentation I never figured it out how to just check if they are pressing up on a sign. So now the signs just auto play when you stand in them :|

You could modify my generic trigger script with an extra control check to do this, and then just enable / disable the textbox on trigger enter / exit?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 11:39:04 AM
For that last bit, I mean, after an hour of research, I still couldn't figure out what the "up button" is literally called. My code works with any other button since I can get the "e" key or "jump" button, but under inputmanager there is no up, only "Vertical" positive and I can't figure out the name. "Vertical.positive" or "Vertical > 0" aren't it.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 21, 2022, 12:27:42 PM
it'll be something like
Code: [Select]
if (input.getaxisraw("Vertical") > 0)

I'm pretty sure; might be easier to do a button check anyway though? (IIRC SMW does the infoboxes with jump)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 12:31:06 PM
it'll be something like
Code: [Select]
if (input.getaxisraw("Vertical") > 0)

I tried that one actually haha, it didn't work. Was really buggy.

Quote
I'm pretty sure; might be easier to do a button check anyway though? (IIRC SMW does the infoboxes with jump)

but then you'd have to tell it to not jump when in a sign trigger zone which is workable but idk if it'll feel bad.

The main reason I don't just use E or something for interact button is I want it to be controller friendly.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 12:37:16 PM
Also, now that I'm at a computer.

Quote
For the 'still has some momentum after leaving a conveyor without jumping' thing, presumably your grounded check has an if (floortag=conveyor) { doconveyorstuff(); } check? because you can zero out any conveyor stuff if grounded and not on a conveyor pretty safely I'd think, as that's basically how friction works anyway.

Right now it's on a collision, if collider tag.

You're right that it might be better to switch it to the ground check. Might fix some of this stuff.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 01:22:04 PM
So I switched the conveyor to a layer mask ground but I still can't reach landed = true.

Any idea why?

Code: [Select]
private bool isConveyor()
    {
        return Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, Convey);
        Debug.Log("OnConvey");
    }

Code: [Select]
  private bool isGrounded()
    {
        return Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, jumpableGround);
    }

Code: [Select]
if (isGrounded() && !isConveyor())
        { conveyorEffect = 0; }

        if (isGrounded() && isConveyor())
        { ConveyorEffect(20); }
Code: [Select]
void EffectsTimer()
    {
        if (!hasEffect) { CancelInvoke(); return; }
        else
        {
            Debug.Log("Getting Here5");
            bool endCheck = false;
            bool Airborne = false;
            bool Landed = false;

            // all your effects checks
            if (conveyorTimer > 0 && !Landed)
            {
                Debug.Log("Getting Here6");
                if (!isGrounded())
                {
                    Debug.Log("Airborne!");
                    Airborne = true;
                }
                if (isGrounded() && Airborne && !isConveyor())
                {
                    Debug.Log("Landed!");
                    Landed = true;
                    Airborne = false;
                }
                conveyorEffect = 5;
                conveyorTimer--;
            }
            else
            {
                conveyorTimer = 0;
                conveyorEffect = 0;
                Debug.Log("Getting Here7"); endCheck = true;
            }
       
            if (endCheck) { Debug.Log("Getting Here8"); hasEffect = false; conveyorEffect = 0; }
        }
    }

I mean logically, if I'm getting to "Airborne" debug.log it means I'm not Grounded and Airborne = true, so when I land I should be Grounded = true & Airborne variable still = true and "Landed!" should trigger? but it's not?
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 21, 2022, 01:36:42 PM
(https://i.imgur.com/PmKELHal.jpg)

(https://i.imgur.com/rD21lMu.jpg)

Some WIP shots, using placeholder main guy for now and those are placeholder trees until I make some tree tiles

visually what you did with some of those platforms reminds me of techniques used in certain games like Castlevania 3 to show an under-shadow below blocks that are sticking out into the foreground

(https://i.imgur.com/QPkfu3k.png)

I know that's not the intent since it's not under all of them, just a thought
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 02:09:26 PM
So I got the conveyor belt working finally. I used visual basic's suggestions because for whatever reason it kept greying out the bool Airborne and telling me that

"setting the bool Airborne = true when you've taken to the air is redundant"

And sure enough I checked if Airborne was actually being set as true and it wasn't. I have no fucking idea why.

Code: [Select]
if (!isGrounded())
                {
                    Debug.Log("Airborne!");
                    Airborne = true;
                }

The debug.log would run, but the bool which was created at the start of the timer as private bool Airborne = false; would not be set true. This is weird as fuck. The other bools were fine.


So I rewrote the code in that section without Airborne bool to

Code: [Select]
void EffectsTimer()
    {
        if (!hasEffect) { CancelInvoke(); return; }
        else
        {
           
            bool endCheck = false;
            bool Landed = false;

            if (isGrounded() && !isConveyor())
            {
                Debug.Log("Landed!");
                Landed = true;
       
            }

            if (conveyorTimer > 0 && !Landed)
            {
             
                if (!isGrounded())
                {
                    Debug.Log("Airborne!");
                }

                conveyorEffect = 5;
                conveyorTimer--;
            }
            else
            {
                conveyorTimer = 0;
                conveyorEffect = 0;
                endCheck = true;
            }
       
            if (endCheck) { hasEffect = false; conveyorEffect = 0; }
        }
    }

Now it says landed when you touch ground that isn't a conveyor belt. And it turns off the effect timer. So you get momentum going into your jump but not continuing after you land.

I guess I'll fuck with the left/right to cancel momentum timer next. If I get that then I'm making AN ENTIRE ROOM OF NOTHING BUT CONVEYOR BELT PLATFORMING in order to justify all this time spent on this logic problem.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 02:34:19 PM
Ok, got it. Even fine tuned it so if you let go of holding left when jumping against a belt moving right the 0 input will have you fall straight down instead of at a wind push angle to the right. Whereas if you jump with the momentum to the right and press nothing you'll keep going with the momentum and it'll only cancel on landing.

Will make a variable for beltDirectionRight? and flip the code if it's going left (as well as using that variable to flip the effect momentum).

Between those and a [serializefield] variable for belt speed that basically should do it for conveyor belts.

Though I'm not suuuper thrilled that the belt speed is determined on the player beforehand vs a way to grab a variable of speed off each individual belt with a script that can be set with its own speed & direction. Basically the current way I'll have to use tags for BeltRight, BeltLeft along with the Conveyor layer mask to tell the player movement script which way to go on them and if I want to set multiple speeds for the belts in one room I'd need to tag them BeltLeft2/3/etc... and write in the player script the speed for each tag.

There has to be a way to get something besides a tag/masklayer from the object you collide/trigger with, right?? All I need is some way to call GetComponent of what I'm colliding with and I can put the speed/direction stuff in those belts and pull them with my character on collision.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 03:11:27 PM
also a really minor polish thing that logically I'm trying to figure out as the final touch before I load a room with conveyor belts.

If you are jumping against the belt momentum (i.e. belt is going right and you jump left), if you let go of the controller your character falls flat (ok)

but their sprite still flips the other direction like you pressed back. I.e. your sprite is facing left as you push against the belt, you jump left and it's still facing jump left and you let go and now it's facing jump right as it falls flat. This doesn't happen in the other direction because I'm not cancelling momentum with 0, you actually have to press back to cancel momentum if you're jumping with the belt direction.

Logically, cancelling momentum with 0 but for an extra frame update it sees that as being less than dirX was on the previous frame so it flips the sprite.

Trying to think of a logic solution to this.

Maybe something convoluted in the animation bit like:

IF (special 0 fall from belt jump && if notgrounded && if getrawinput axis horizontal = 0)
then do nothing
Else - update animationstate

which might cover the fall and if you press back it would skip that and update animation and if you touch ground it'll update animation (which still could potentially flip the sprite direction on landing depending on what the dirX it's comparing to is at the landing moment).
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 03:31:55 PM
Going back to the first thing about putting the speed/direction on each belt and grabbing it from the belts on collision. I did some testing and idk why I thought this didn't

void OnCollisionEnter2D(Collision2D other)
    {
    SpriteRenderer srp;

        srp = other.gameObject.GetComponent<SpriteRenderer>();
        srp.flipX = true;

    }

Seems like I can getComponent on collision no issue.

Will make a script I can attach to each belt with direction & speed.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 05:13:59 PM
Alright, finished all the coding side stuff for the conveyor belt.

Grabbing the speed & direction off the surfaceeffector2d when colliding, which also lets me just drop crates or any non-player object on the belt and the surfaceeffort2d takes care of it.

I changed the update() code to this

Code: [Select]
private void Update()
    {
        UpdateMovement();
        if (Input.GetAxisRaw("Horizontal") != 0 || isGrounded())
        { UpdateAnimationState(); }
     
    }

And it fixes the turned animation when letting go of a direction when jumping against a belt force.


Now I need to

1) Make/find a conveyor belt texture

2) Adjust the colliders. When I put a sprite in instead of the blank square I'd been using it messed that all up.

very, very close to finished with this one environmental object.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 06:48:58 PM
Been coding some creative stuff to flesh this out. First time trying to write scripts that call methods from each other. Trying to figure out what I'm doing wrong here?

Code: [Select]
public class Switch : MonoBehaviour
{
    public bool ON = false;

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        { ON = !ON; }
    }

    public bool CheckOn()
     { if (ON == true) { return true; } else return false; }
}

That is a switch for turning belts on/off externally (also making a reverse direction switch after I get this working)

Here is my belt code that is trying to call CheckOn() to see if the switch is pushed on or off at the moment:

Code: [Select]
public class BeltScript : MonoBehaviour
{
    [SerializeField] private bool On;
    [SerializeField] private GameObject OnOffSwitch = null;
    [SerializeField] private GameObject ReverseSwitch = null;

    private Switch OnOff;
    private Animator anim;
    private SurfaceEffector2D suf;
    private SpriteRenderer sprite;
    private float beltSpeed;

    // Start is called before the first frame update
    void Start()
    {
        suf = GetComponent<SurfaceEffector2D>();
        anim = GetComponent<Animator>();
        sprite = GetComponent<SpriteRenderer>();
        OnOff = GetComponent<Switch>();

        beltSpeed = suf.speed;
       
    }

    // Update is called once per frame
    void Update()
    {
       
     
            Debug.Log("On = " + OnOff.CheckOn());
            if (OnOff.CheckOn())
            {
                suf.speed = beltSpeed;
                if (beltSpeed < .1f)
                { sprite.flipX = true; }
                anim.enabled = true;
            }
            if (!OnOff.CheckOn())
            {
                suf.speed = 0;
                anim.enabled = false;

         
            }  }}

I drop the Switch gameobject in inspector into the On/Off gameobject field. It should be grabbing the Switch script component from it. Not sure what I'm missing to call the method.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 07:12:22 PM
Got it!

OnOff = GetComponent<Switch>();

was supposed to be

OnOff = OnOffSwitch.GetComponent<Switch>();


Now I can run stuff in other scripts without collisions or triggers. Cool. Will be helpful when I get around to writing my first GameManager script.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 07:18:46 PM
Quick question,

If I want switches and stuff to only activate when colliding with feet, do I basically make a gameobject and attach it to the player called "feet" with a feet box collider and then tag it feet and use that with these objects like standing on buttons? (and put their collision boxes off the ground a bit so running into it won't trigger with ground feet)

I still have an issue here because the conveyor belt collision is within the playermovement script and set to activate on collision with player. Is there I way I can re-write this in the player_movement code to stay Entercollision w/child 0 or something? Seems like it'd be a pain in the ass.

I was using boxcasting to detect when on conveyer belt with feet with 2 conveyor game objects on top of each other, one with a layer ground, one with a layer conveyor. But by using tag conveyer w/layer ground I don't need the double objects. But I can't boxcast with the tag so I have to base it off collision with the tagged object.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 08:03:05 PM
I think I took care of all that. Have the ground checks separate in feet and reporting back to the body player_movement script.

Basically everything works perfect at this point. Working conveyors, can switch them on/off, can reverse them. Set the speed and direction per belt.

Have a weird glitch where somehow my client gets pulled up the left vertical side into the air upon contact with the surface collider. Despite the surface collider having no effect on anything else.

Pretty sure this is because I don't mess with y.velocity and it's basically on default RB which is what 2d surface effect effects.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 21, 2022, 09:24:38 PM
Man, I think I was just coding logic stuff for like 8-9 hours straight. Brain is broke. Probably need to take a day off this to refresh. I am ready to build out my conveyor belt challenge room next. Everything is good to go. Actually programmed my way out of this. Learned a lot of coding stuff along the way and getting to the point where I'm writing scripts from scratch with no reference and it's mostly going ok for this kind of stuff. Feel like I'm past the intro coding hump and into the beginner level coder stuff.


Only other weird thing I ran into was I had to separate on/off and reversal switches on conveyors because the on/off switch would store the speed of the surface effector and turn it to 0 and then when turning on would replace the speed.

But if I was reversing the speed with a reverse button it would conflict with the stored speed. I'm sure there's a way to logically deal with this but I'm too burnt out at this point so I just made two different scripts with 1 button you can link, either an on/off switch or a reverse/forward script. That should be plenty for a challenge room with preset directions and speeds and the ability to jump on buttons to change them up.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 22, 2022, 01:17:17 AM
Have a weird glitch where somehow my character gets pulled up the left vertical side into the air upon contact with the surface collider. Despite the surface collider having no effect on anything else.

Pretty sure this is because I don't mess with y.velocity and it's basically on default RB which is what 2d surface effect effects.

Fixed this in like 30 seconds by just adding a THIRD box collider on this thing  :lol and having the side edges be further out than the inner surface-effector box collider so you don't touch that except on top.

Basically.

1st box collider is the physical box object collision that does nothing
2nd box collider is the 2d surface effort collision on top that moves non-player objects and sends speed & direction to player movement
3rd box collider is the trigger that goes a bit above that and actually triggers the collision to tell the player it's tag.Conveyor and to apply the special movement script with values sent by the 2nd box collider.

Looks really nice and clean when playing! It's...interesting building these things. Feels like engineering.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 22, 2022, 03:30:32 AM
So I spent the whole night on clean up.

Went through every C# code I wrote in this project and went line by line commenting on them, taking out any redundancies and just making things better if possible. Basically fixed every issue I have through careful cleanup and logic.

Now have a really good prefab for belts, can also use it for wind stages or it's a good base for power-ups (thanks to Great Sage's timer setup code). Have really good stomp switches both for turning things on/off on jumping on them, or in the case of a belt flipping it's direction.

All the collision codes and trigger boxes and everything are nice and polished. Have all the scripts/prefabs organized in folders.

Feels good, like cleaning the house.


Only single thing that is missing is I need to make a sprite for the jumpable button prefab and have it sprite change when you jump on it to a depressed button sprite. For testing this stuff I just put it on an apple sprite as my switch so you jump on the apple lol. Will make a button sprite or find a free asset 2d button soon and then these things are done. My belt sprite and animation is pretty crappy but it does the job and animates showing the direction. Will probably draw a better one during visual art polish stage.

At this point I think the next step will just be designing out the rest of the game with placeholders and then once that's done -> creating art/music for all the placeholders -> polishing things up.

But yeah I'll probably take a day off working on it tomorrow for some refresh and this is a good spot with everything organized and stage 1 to leave off. Will come back on Saturday and spend all weekend trying to make the rest of the game with placeholders.


Oh and for final questions at this point, this is what I've got:

1. I'm being real good at keeping everything private and [SerializeField], but the methods I'm calling in other scripts I'm using public void method(). Is there a better way I should be doing this to keep them private and not introduce bugs?

2. One of the things I haven't tried to do yet since I haven't needed it is write a script of something that keeps track of stuff between stages/deaths. Like your score and lives if you use lives (this game isn't going to use lives so it's just restart scene on death, I like platformers these days with no life counters and just a lot of checkpoints).

Does doing this have something to do with don'tdestroyonload? Because I googled that to stop the stage BGM from starting over on death and I use that and it basically keeps a separate instance going with the music in it that is separate from the scene.

Or do you put all that in the gamemanager and just have the gamemanager not be destroyed on load so it can carry over these things? I feel like this will be helpful to learn for creating inventory systems that carry between scenes/stages. I.e. I want to know if my character picked up a Jetpack in the previous stage and should now be flying around.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 22, 2022, 07:07:19 AM
I'm making AN ENTIRE ROOM OF NOTHING BUT CONVEYOR BELT PLATFORMING in order to justify all this time spent on this logic problem.

 :lol

I'm pretty sure this is the background info on Sonic 1s Marble Zone too

Quick question,

If I want switches and stuff to only activate when colliding with feet, do I basically make a gameobject and attach it to the player called "feet" with a feet box collider and then tag it feet and use that with these objects like standing on buttons? (and put their collision boxes off the ground a bit so running into it won't trigger with ground feet)

So you're probably familiar with the idea of the 'hitbox', let me introduce you to its evil twin the 'hurtbox' - this is usually used in things like fighting games to resolve things like hit priority, but you can also use it to do shit like marios 'jump on head' kills, or touching things only with your feet by jumping on them rather than running into them;

(https://i.imgur.com/MLFw3Aj.png)

Oh and for final questions at this point, this is what I've got:

1. I'm being real good at keeping everything private and [SerializeField], but the methods I'm calling in other scripts I'm using public void method(). Is there a better way I should be doing this to keep them private and not introduce bugs?

Nah, the 'correct' way of doing OOP coding includes encapsulation, so you have a different script 'responsible' for every aspect, but never directly modified by other scripts; ie, if you have a 'health' class, you can access that class to get / set health values from enemy objects, player objects, destructible scenery objects, boss objects, etc but there's only one class that actually determines how health is handled, so if you need to refactor anything theres only one bit of code you need to change, and anything that accesses health via public methods are all still good (in theory).

Like... don't sweat to what extent you're adhering to the 'correct principles' of OOP while you're still just figuring out what shit works, but having private variables and public methods is pretty robust and secure whether thats for enterprise or game dev.

2. One of the things I haven't tried to do yet since I haven't needed it is write a script of something that keeps track of stuff between stages/deaths. Like your score and lives if you use lives (this game isn't going to use lives so it's just restart scene on death, I like platformers these days with no life counters and just a lot of checkpoints).

Does doing this have something to do with don'tdestroyonload? Because I googled that to stop the stage BGM from starting over on death and I use that and it basically keeps a separate instance going with the music in it that is separate from the scene.

Or do you put all that in the gamemanager and just have the gamemanager not be destroyed on load so it can carry over these things? I feel like this will be helpful to learn for creating inventory systems that carry between scenes/stages. I.e. I want to know if my character picked up a Jetpack in the previous stage and should now be flying around.

This is whats called a singleton; people will shit talk it online as being over used, but its overused because its super fucking handy.
That object pooling you had in your first project was probably setup as a singleton too.
It's super common for a GameManager to be setup as a static persistent object for obvious reasons - you're only gonna be running one version of the game at a time, right? - but you can also have singleton classes for stuff like audio playback (for exactly the same reason you already implemented that) or UI stuff, or data management.
Basically, anything that you want to apply across level loads and there will definitely only be one version of is a good candidate for being a singleton.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on April 22, 2022, 07:45:15 AM
I'm making AN ENTIRE ROOM OF NOTHING BUT CONVEYOR BELT PLATFORMING in order to justify all this time spent on this logic problem.

 :lol

I'm pretty sure this is the background info on Sonic 1s Marble Zone too

also this

https://www.youtube.com/watch?v=MP56G41hR7A

"These goddamn gun cameras were a nightmare to debug and you're telling me we only have a half a dozen in the entire game?  Fuck it, I'm adding an extra room."
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 22, 2022, 02:37:53 PM
Damn, I killed a HDD backing up my Unity folder lol


Like this computer I built was built a couple years pre-pandemic so probably about 4 years old now and I brought over a few old SATA drives from my old rig so I have like 4 hard drives on this thing. 1 is totally unused, 1 is backup, 1 is for storage, 1 is main SSD for installed stuff.

I tried copying the unity folder over to the backup one and started hearing some clicking and went to bed. Woke up and it was still clicking non-stop so I reset the computer which crashed and then started it up and...drive is gone lol

Thankfully I don't think anything important was on it as it was just a backup/mirror of my storage drive really in case that ever died. And I still got one totally unused drive so I'll just try backing up my storage drive again to this one instead tonight.

But yeah the Unity folder was like 60,000 files already. Was too intense for my old HDD  :lol
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 22, 2022, 02:47:44 PM
Actually, just looked and my storage drive is a 4TB with 2.5TB used and my remaining empty HDD is only 900GB free. Will need to swap drives if I wanna backup everything again (alternatively probably would just make sense to pick up another 4TB drive and have them mirror each other).
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 03:00:13 AM
Been looking into statics.

For my audiomanager which I want so the music keeps its spot on scene reset on death, for changing BGMs per level/area/scene, would it make the most sense to have my audiomanager gameobject basically loaded with the entire game soundtrack and all the tracks and then I could put a public method on it called "ChangeTrack(track name)"

And then in any other script I can just tell it to ChangeTrack(put track name here) and then it will switch currentBGM private variable in the static to whatever track name is and play it?

I'm not sure where I would put code to call this, maybe a script on an object called [Scene_X_Start_Object] which has a script for that one scene and calls on start to change track and set whatever else for the scene? 
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 04:19:54 AM
I know I have the Dialogue System to try out, but at night sometimes I've just been finding myself watching random youtube videos on doing game things in Unity lately. Just a curiosity thing now that I'm getting the hang of all this and it's neat seeing all the ways real world game effects/systems/interactions are made in Unity.

I thought this video part 1 of 2 was cool in how they basically took Undertale and then showed you how to create a dialogue system that is close to it. The letter by letter (array of characters displayed one at a time) with goofy sounds for each letter and a background & portrait of the character talking is pretty classic and flexible, so if for some reason I can't use the dialogue system I bought I may try this:

https://youtu.be/8eJ_gxkYsyY
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 23, 2022, 07:54:07 AM
But yeah the Unity folder was like 60,000 files already. Was too intense for my old HDD  :lol

Yeah, actually that's another gripe I have with Unity, it literally creates a unique-per-machine 'shadow file' of every fucking file in a project, and also metadata files for every asset file in a project, so you end up with literally thousands of fucking files in a near empty project.
Like, if you're using Github with unity stuff, theres a whole unity specific gitignore template you really really really should use, to stop all the fucking junk files unity generates bloating your repo.

Its almost worth not actually backing up your unity projects as you think you should (ie as entire folder structures), but by exporting your whole project out as a custom asset .unitypackage and backing that up to import into a 'clean' unity project if you ever want to go back to it.

Been looking into statics.

For my audiomanager which I want so the music keeps its spot on scene reset on death, for changing BGMs per level/area/scene, would it make the most sense to have my audiomanager gameobject basically loaded with the entire game soundtrack and all the tracks and then I could put a public method on it called "ChangeTrack(track name)"

And then in any other script I can just tell it to ChangeTrack(put track name here) and then it will switch currentBGM private variable in the static to whatever track name is and play it?

I'm not sure where I would put code to call this, maybe a script on an object called [Scene_X_Start_Object] which has a script for that one scene and calls on start to change track and set whatever else for the scene? 

I'm happy to post mu singleton script if you want it, like I say, they're so fucking useful everyone uses them for something.

In usage terms, just create an empty gameobject in your initially loaded scene (and call it _audiomanager or whatever) and put it at the top of your hierarchy.
You can also have an "_Managers" empty, with children for _GameManager, _AudioManager, _LevelsManager, _ProfileManager, _AchievementsManager etc each with their own singletons controlling that stuff too.

You're right, you absolutely can use it as a 'jukebox'; you can also use it as a master mixer, so if you have any game settings for audio volume you can store them there and route all SFX through it to ensure they're obeyed everywhere (and can do seperate SFX / Music volume controls).

You can also use it to crossfade between tracks (like, if you have a 'general gameplay' track, but also a more uptempo 'times running out' or 'shits going down' track) from contextual calls (like timer less than 1 minute, or unit manager is spawning in boss or whatever).

You can also do a fairly easy ghetto custom soundtracks thing, by making a folder called uhhhhh streamable assets I think it is, and then explicitly pointing to that in your manager and creating an array of any music it finds in there, and players will be able to drag and drop their own MP3s into that folder, and it will scan them all and add them to a playlist.

The letter by letter (array of characters displayed one at a time) with goofy sounds for each letter and a background & portrait of the character talking is pretty classic and flexible, so if for some reason I can't use the dialogue system I bought I may try this:

I'd be willing to bet IRL money the system you bought has a 'typewriter' text effect built in, probably also with an audioclip for the audio effect; hell, I'd suspect it probably has a randomised variance audioclip so you can do animal crossing / banjo kazooie style nonsense sounds that match text
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 01:12:16 PM
Oh! Yeah exporting a package for backup makes a ton of sense. Will do that instead from now on. Hopefully kill less HDDs that way.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 09:26:56 PM
Sometimes I just want to throw everything in the fire. I'm having the worst luck on this games on the weekends when I actually have time to spend on it. Instead of making tons of progress and getting lots of rooms and areas done or art/music or whatever I get hung up on something, end up fucking around in scripts and googling and watching tutorials for 3-5 hours and end up fucking up my existing scripts because I'm trying to mod them to get something to work and then I have to spend hours just fixing my scripts to get things back to how they were. It's depressing when I get so little done and I lose my weekends.


For the last 3 hours I've wasted my entire Saturday afternoon just trying to make a goddamn working fucking checkpoint. Which I already had as a prefab in the class version but it was so entwined with their game manager I figured I'd just write one from scratch here.


First I was like "oh shit, the way this game is setup is using loadscene on death so I can't just save the checkpoint position and respawn there because it'll destroy the checkpoint position", so this is a good time to try to practice and create a singleton/game manager where one of the several variables I can carry over across scenes will be current checkpoint location.

-> Cue 90 mins of trying to make a 10 line static instance with a single Vector 2 position variable work and failing every time and realizing I have no fucking idea what I'm doing and every example of a singleton/game manager is complicated and doing lots of shit and for a start I just want it to hold ONE goddamn variable.

So then I give up and decide ok I'm going to do it this way:

1) If you have a checkpoint it gets registered in the currentCheckTracker and then upon death the scene doesn't reload, you just move transform position to the checkpoint after the death animation plays -> trigger in animation to respawn_at_checkpoint.

2) If you haven't gotten a single checkpoint registered yet, you just do the normal reload scene on death.

In theory this actually works better because if the player collects some pick up items, hits a checkpoint and dies and respawns at the checkpoint, those old pick up items shouldn't respawn. Then again now you can pick up collectibles, die and respawn at checkpoint with those collectibles picked up so you can do suicide runs which isn't great.


Anyhow then I just spent 90 mins on that 1/2 solution and it's not working either because the death animation is all fucked up. The way the tutorial I learned from did death was you do an animation which plays the death animation on death trigger being sent to the animator and then turns off the spriterenderer and then performs trigger restart scene.

So I ditched the spriterenderer turn-off and tried turning the death trigger into a death bool that gets switched to true, plays the death animation and then gets switched to false and you teleport to the respawn checkpoint spot.

But instead I'm getting weird stuff like the animation getting stuck on frame 1 and freezing movement in place. Even if I don't have a checkpoint the animation should play and then trigger reload scene but the character is getting stuck and the scene isn't reloading.

So now my death cycle which was already working is broken and I need to try to fix it and then still try to figure out a way to checkpoint :( And then I can actually make more game. I hate this shit.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 09:58:59 PM
Ok, finally got it working by resetting the death trigger and creating an animation state transition from death to idle called respawn and trigger that.

So now I have checkpoints. Though still have the issue of it doesn't reset the collectibles grabbed since the last checkpoint but Idk how to do that.


I GUESS you could make copies of the level and every checkpoint would async smoothly load the next scene and death would restart the current scene so you'd keep restarting from the latest checkpoint with all the stuff ahead of you reset. But this would also respawn the stuff behind you and you'd have to keep track of which items you picked up already to destroy upon loading the new scene. /sigh, just so much work.

Will leave as is and people can suicide run if they want to get the collectibles.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 10:19:44 PM
Ok, checkpoints still not working. I'm gonna lose the entire day just trying to get checkpoints which were already working in the build I threw out to work here, but I need working checkpoints :(((((((((((((((

Code: [Select]
public class CurrentCheckPointTrack : MonoBehaviour
{
    // Start is called before the first frame update

    [SerializeField] private Checkpoint chk = null;

    public void Start()
    {
        chk = null;
    }
    public void AddCheckpoint(Checkpoint talky)
    {
        chk = talky;
        Debug.Log("new checkpoint spot = " + chk.transform.position.x + chk.transform.position.y);
    }

    public Vector2 GetCheckpoint()
    {
        if (chk != null)
        {   
            return new Vector2(chk.transform.position.x, chk.transform.position.y);
        }
        else
        {
            Debug.Log("No Checkpointset");
            return new Vector2(0, 0);
        }
    }
       
}

So this is nonsense.

If I'm looking at the checkpoint tracker it has a serialized field showing the current checkpoint that you will respawn at. When I pass a new checkpoint the debug log tells me the checkpoint variable chk now equals the position of checkpoint #2

BUT the serializedfield for that same fucking variable chk still says checkpoint #1 and when I die, viola! I respawn at checkpoint #1 even though the debug log is telling me the coordinates for the variable is at checkpoint #2.

What the hell is going on?

I wonder if this might have something to do with prefabs and checkpoint #1 being a prefab but 2+ not being because they are copies or something.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 10:36:44 PM
Maybe I'm overcomplicating this checkpoint setup. I have my tracker keep a private variable of the current checkpoint and new checkpoints add themselves as the current checkpoint and when you die it runs getcheckpoint() from the tracker and gets the checkpoint coordinates and respawns at those coordinates.

I'm looking at how my class template does it and it's way less code. This is my class version:

Tracker
Code: [Select]
public static class CheckpointTracker
{
    // The most recently activated checkpoint
    public static Checkpoint currentCheckpoint = null;
}

That's it.

Checkpoint
Code: [Select]
public class Checkpoint : MonoBehaviour
{

    public Transform respawnLocation;
   public GameObject checkpointActivationEffect;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            if (CheckpointTracker.currentCheckpoint != this && checkpointActivationEffect != null)
            {
                Instantiate(checkpointActivationEffect, transform.position, Quaternion.identity, null);
            }

            // Set current checkpoint to this and set up its animation
            CheckpointTracker.currentCheckpoint = this;
        }
    }
}

So it just checks the static to point to this checkpoint and does a checkpoint activation effect. Then the player respawn gets that position from the static.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 23, 2022, 11:04:13 PM
Ok, I just used theirs and it worked. What a waste of time. I guess I just was getting static stuff wrong initially because I'd never used it before and because instead of just using one basic static variable I jump straight to trying to make a static gamemanager script I could assign multiple things to and when I failed at that I tried a non-static route.

Also in the inspector my [Serializefield] for the currentcheckpoint variable still doesn't actually update in the inspector when I'm using the editor and hit a new checkpoint, but I have a debug log shout out the new spot coordinates and then I test dying and it seems to work fine.

Next challenge will be figuring out how to keep the score across stages because I'm doing things in the latter stages based off total score (i.e. multiple ending branches).
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 12:07:11 AM
Next thing I'm wasting an hour of my life on.

I have a cool little script called "flip sprite" where if you run past a NPC they turn and follow your direction. This works based on collision/triggers as you pass through them.

But if you run past them so they turn from looking left to looking right, but then you die and you respawn at a checkpoint to the left of them they are still looking to the right when you are on the left.

I thought this would be a 5 min fix of just getting players transform position at the start, assigning it to a variable and just having on update for these flippy sprites an if statement looking to see if the player's transform.position.x is > or < then the transform.position of the sprite and to flip accordingly.

But it's not working at all. I don't even know why. Why does nothing simple ever work right. This isn't worth spending hours on :\
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 12:15:56 AM
Ok, fixed it by instead of putting a drag & drop serialized field with the player in it I tried just FINDING the player and it works now. Who the fuck knows why, but I'll take it

I just switched the serializedfield game object player1 and then p1p grabbined from the serializedfield gameobject player1.getcomponent<transform>(); to

p1p = GameObject.FindWithTag("Player").transform;


Maybe it's because I was called getcomponent transform in the first case and the second I'm just assigning the transform? Is the basic transform of an object not a component of that object?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 01:35:10 AM
So I got a few more things taken care of. I think in terms of understanding coding and being able to put my own game together from start to finish with all the whirly gags I like, I just need one more core concept.

I need a top level scene script where I can mess with objects in the scene. Like if I want to turn on a UI element once a counter reaches a certain # or set a pause canvas active if you hit escape.

I'm assuming this is basically the game manager to control the scene + the ability to carry over variables between scenes like score/lives/etc...

I'm trying to find a good youtube video on making a game manager script but haven't found the right one yet. I think when I understand this and how to do static stuff better I'll have everything I need.

This project has been very difficult. My first project I relied too much on the core class template and was more like a total conversion mod of it. Plus by dividing every event into its own scene and not having much/any player interaction because it was a shmup I could just use timers for events and loading scenes. Whereas this is learning how to make a game from start to finish from scratch and interacting constantly with stuff.

At least when I get to my next project I think maybe it'll be a bit easier from that point? Since I'll have all these basics down. Fingers crossed.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 02:23:49 AM
Also regarding statics and stuff I don't really understand, now that I have a pause menu and can go back to the main menu, how do I tell this static to go away.

Code: [Select]
public class Keep_Music_On_Death : MonoBehaviour
{

    static Keep_Music_On_Death instance = null;

    void Awake()
    {
        if (instance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            instance = this;
            GameObject.DontDestroyOnLoad(gameObject);
        }
    }
}

Basically 1 BGM starts in Stage 1 but when you quit to the main menu it keeps playing, same with stage 2. This is pretty bad if I want different music for different scenes which I do.

The only reason I'm even using this thing is so that the music doesn't reload on scene-reload when you die. But I'm held hostage with it because I don't know how to use it since it destroys itself in other scenes.

Tbh now that I have checkpoints I could just put a checkpoint at the player start and then never have to reload the scene during a stage and I can just do music like normal like I did last game with each scene having a level_music gameobject with a source BGM.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 02:52:12 AM
Ok, did some testing without watching/reading tutorials on static and just trial & error-ing. My goal right now is just to have the score carry from stage 1 -> 2 in the scoredisplay.

I sorta did that but I have a few errors. Here is my test code:

Code: [Select]
public class TacosTesting : MonoBehaviour
{
    static TacosTesting instance = null;
    public static int numbertest = 0;

    void Awake()
    {
        if (instance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            instance = this;
            GameObject.DontDestroyOnLoad(gameObject);
        }
    }

    public int ReturnNumber()
    {
        return numbertest;
    }
}


-Now when I try to increase numbertest from another script++, it works
-When I try to send numbertest to the scoredisplay UI text to show the score count, it works
-When I try to call new INT Burrito = TacosTest.ReturnNumber(); it doesn't work. So I don't know how to do methods in a static script from another script.


Also a side thing I've had this whole time is my game kind of hiccups when loading level 2 from level 1's end goal. The tutorial I read had me using Invoke on the sceneload to give 1 second for the level clear sound effect to play, it does and when I load my character is in some weird jump animation and my controls are horizontally locked on the x-axis and sometimes when I jump forward right away it auto resets me to the start of the stage.

I'm pretty sure the jumpyness is all caused by the don't destroyonload stuff.

It's so weird, but I may get around that by putting in a player thing that says at new scene load to go static for 1 second before being able to move. Game just seems to be hiccuping on physics/controls for the first second in a new stage.


Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 03:44:21 AM
Well I've added the ability to hit "esc" or back button if you're not in the main menu screen or ending screen and to load up the pause menu to this TacosTest static script.

Seems to work well. So I got my scene controller and score variable carry-ing gameobject.

I guess I'm slowly turning this tacostest into a game manager?

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

public class TacosTesting : MonoBehaviour
{
    static TacosTesting instance = null;
    public static int numbertest = 0;
    public GameObject PauseScreen;

    void Awake()
    {
     

        if (instance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            instance = this;
            GameObject.DontDestroyOnLoad(gameObject);
        }
    }

    private void Update()
    {
        if (SceneManager.GetActiveScene().buildIndex == 0)
        { numbertest = 0; }
        if (SceneManager.GetActiveScene().buildIndex == 0)
        { Time.timeScale = 1;  PauseScreen.SetActive(false); }

        if (SceneManager.GetActiveScene().buildIndex != 0 && SceneManager.GetActiveScene().buildIndex != 3 && Input.GetButton("Cancel"))
        { Time.timeScale = 0;  PauseScreen.SetActive(true); }
    }

    public int ReturnNumber()
    {
        return numbertest;
    }
}

At this point I have most of the code stuff I wanted to do what i wanted implemented so tomorrow hopefully can focus on designing new stages. Today was just all tools stuff.

Actually simplified this even further by taking the BGM don't destroy on load code and putting it in the tacostest manager (and having one less script/gameobject), taking the pause screen and putting it as a child under the tacostest manager (so I don't need to put a don'tdestroy on it) and did the same with my screenshot app.

Now it looks pretty clean where only a single gameobject (tacostest) is carried over between stages and it has everything nested in it. Definitely feeling like I may rename this to gamemanager by the end of tomorrow as I give it more and more abilities.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 24, 2022, 08:20:46 AM
Ok, fixed it by instead of putting a drag & drop serialized field with the player in it I tried just FINDING the player and it works now. Who the fuck knows why, but I'll take it

I just switched the serializedfield game object player1 and then p1p grabbined from the serializedfield gameobject player1.getcomponent<transform>(); to

p1p = GameObject.FindWithTag("Player").transform;

I'm gonna guess your respawn code is like the 'teleporter' from The Prestige, and you're not actually moving the current player somewhere, you're destroying them and then creating a new copy somewhere else?

Because that'll be why your cached reference doesn't work as a pointer anymore - its actually a completely different hugh jackman.

Findwithtag is actually a kinda terrible way to get pointers, but if it works it works - either using your original pointer reference and disabling it, moving it, reenabling it or grabbing the pointer reference at reinstantition would be better ways of doing this, but - no shade - you're at the point where you're learning to get shit working, so imo don't sweat the 'proper ways' until youre comfortable with ways that work.

Also regarding statics and stuff I don't really understand, now that I have a pause menu and can go back to the main menu, how do I tell this static to go away.

It seems like you're leaning more into singleton use, but yeah, the point is it never goes away, you want to handle whatever it exists for on it.
So if you want a different track per level, you're better off having an audiomanager singleton that has ALL the music on it, and then loads up the next tune when the next levels loaded, rather than having an individual music track object per level (or at worst, if you do have a single object for music per level, they are triggered by your singleton rather than acting independtly of each other).

Doing it this way lets you do cool stuff like cross fade from one track to another while the levels loading and shit.

-When I try to call new INT Burrito = TacosTest.ReturnNumber(); it doesn't work. So I don't know how to do methods in a static script from another script.


So the important bit of your code here that I think you're overlooking is this bit;

Code: [Select]
    static TacosTesting instance = null;
Tacostesting is your class name, the thing that actually holds that code and the variables is a variable of <T> (type) TacosTesting named instance.

So you need to find that - luckily as its static, it should be as easy as
TacosTest.instance.ReturnNumber();
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 01:14:31 PM
Ok, fixed it by instead of putting a drag & drop serialized field with the player in it I tried just FINDING the player and it works now. Who the fuck knows why, but I'll take it

I just switched the serializedfield game object player1 and then p1p grabbined from the serializedfield gameobject player1.getcomponent<transform>(); to

p1p = GameObject.FindWithTag("Player").transform;

I'm gonna guess your respawn code is like the 'teleporter' from The Prestige, and you're not actually moving the current player somewhere, you're destroying them and then creating a new copy somewhere else?

Because that'll be why your cached reference doesn't work as a pointer anymore - its actually a completely different hugh jackman.

Findwithtag is actually a kinda terrible way to get pointers, but if it works it works - either using your original pointer reference and disabling it, moving it, reenabling it or grabbing the pointer reference at reinstantition would be better ways of doing this, but - no shade - you're at the point where you're learning to get shit working, so imo don't sweat the 'proper ways' until youre comfortable with ways that work.

Also regarding statics and stuff I don't really understand, now that I have a pause menu and can go back to the main menu, how do I tell this static to go away.

It seems like you're leaning more into singleton use, but yeah, the point is it never goes away, you want to handle whatever it exists for on it.
So if you want a different track per level, you're better off having an audiomanager singleton that has ALL the music on it, and then loads up the next tune when the next levels loaded, rather than having an individual music track object per level (or at worst, if you do have a single object for music per level, they are triggered by your singleton rather than acting independtly of each other).

Doing it this way lets you do cool stuff like cross fade from one track to another while the levels loading and shit.

-When I try to call new INT Burrito = TacosTest.ReturnNumber(); it doesn't work. So I don't know how to do methods in a static script from another script.


So the important bit of your code here that I think you're overlooking is this bit;

Code: [Select]
    static TacosTesting instance = null;
Tacostesting is your class name, the thing that actually holds that code and the variables is a variable of <T> (type) TacosTesting named instance.

So you need to find that - luckily as its static, it should be as easy as
TacosTest.instance.ReturnNumber();

Nah, my respawn code was just moving the transform position. I'm still using the same code and it works now with the static variable for currentcheckpoint.

I'm not sure why my checkpoint tracker was messed. I also get why find with tag is bad, but there's only going to be one object per scene tagged player (in an SP game) so I think it should be ok here.

Thanks on that singleton bit, I feel like it's way safer to have a private method on that to addtestnumber() and retrievetestnumber() with a private int than having a generic static testnumber int that could easily get messed up. If I can call methods in this I'll switch it to that.

Oh, and for Singletons, can't I just tell it to destroy itself if certain things happen? Like if scene = 3 destory.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 03:44:26 PM
So first thing I'm trying this morning is removing

Code: [Select]
public static int numbertest
in my singleton tacostesting class

and replacing it with:

Code: [Select]

private int numbertest;

 public void UpdateScore()
    {
        numbertest++;
    }

    public int GetScore()
    {
        return instance.numbertest;
    }

Cool this worked, though I had to change the static variable at the top of the class from static instance TacosTesting = null; to public static instance TacosTesting = null for other scripts to be able to call methods in it.

But now that I can do this I think I can do a lot of stuff I want.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 05:23:41 PM
Having a weird bug where I can't use teleports with my movement code.

Like my respawn on death works fine. And that just teleports player.transform.position to currentcheckpoint and switches back to idle animation and static body on death back to dynamic.

But teleport the code is literally just this

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

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (teleportPoint != null)
        {
            collision.gameObject.transform.position = teleportPoint.transform.position;
        }
    }

}

And I throw in a blank gameobject somewhere as the exit point.

And it works and I teleport to the new spot,

but it completely fucks up the player?? the first frame I appear in the new spot is OK, but the second I hit left or right, the player gets locked into the running animation even if I'm idle and even worse the player can't jump anymore.

But doing this same thing on respawn works perfectly fine...

No idea what is causing it, I could change the player's RB to static when teleporting and back to Dynamic after exiting which might fix it but that removes any ability to take motion through teleports so it's not really preferred.

This is the basic movement animation state code on the player. Not sure how teleporting the transform with the teleport code above would mess this up?

Code: [Select]
private void UpdateAnimationState()
    {
        MovementState state;

        if (dirX > 0f)
        {
            state = MovementState.running;
            sprite.flipX = false;
        }
        else if (dirX < 0)
        {
            state = MovementState.running;
            sprite.flipX = true;
        }
        else
        {
            state = MovementState.idle; ;
        }

        if (rb.velocity.y > .1f)
        {
            state = MovementState.jumping;
        }
        else if (rb.velocity.y < -.1f)
        {
            state = MovementState.falling;
        }

        anim.SetInteger("State", (int)state);
    }

Alternatively I may just make separate scenes for teleport triggers (I'm talking about entering doors) instead of teleporting you to different stages within the same level at different spots.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 05:28:13 PM
Well, turning the Rigidbody static while teleporting and back to dynamic fixed it. So something was messing up the physics during the teleport idk why

Code: [Select]
public class Teleporter : MonoBehaviour
{
    public GameObject teleportPoint;
    private Rigidbody2D rb;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (teleportPoint != null)
        {
            rb = collision.GetComponent<Rigidbody2D>();

            rb.bodyType = RigidbodyType2D.Static;
            collision.gameObject.transform.position = teleportPoint.transform.position;
            rb.bodyType = RigidbodyType2D.Dynamic;
        }
    }

}
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 05:40:53 PM
So I figured it out I think, because I'm getting editor errors that the teleport code is trying to get a rigidbody2d component off the wall check object within player and feet object within player.

I think when it was teleporting it maybe only was teleporting the player and not their body part children?? Since the feet do the ground check if the feet didn't come with the player that would explain not being able to jump.

But on dying & respawn it doesn't have this issue? Maybe turning the whole player static and back to dynamic resets this? But then I'm doing that here with the teleporter and it's giving me errors and I don't get those errors when respawning after death.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 05:47:44 PM
Ok, figured it out. Because I had an if/else since I wanted else to cover things like crates going through a teleporter

It was doing 3 collisions on trigger, player object, wallcheck object, feet object.

And would teleport all 3 to the same transform.position which...means the feet would be moved to the center of the player and same with the wall check and the player's body would be all fucked up.


So the solution was to get rid of the else statement and just do "if compareTag("Player") and then do an elseif CompareTag ("Crate") for anything else I want to throw through a teleport.

Also now I can get rid of all that rigidbody changing while teleporting since it wasn't the issue.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 06:30:39 PM
I'm trying to add multiple conveyor belts to my reverse switch so a single switch stomp reverses a bunch of belts instead of just one. First time trying to use arrays and not sure why this isn't working? It says null error that the method calls are "object reference not set to an instance of an object"

and stomping on the switch does nothing

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

/// <summary>
/// Basic switch can jump on if you put a trigger on top
/// If trigger hits feet, switch is switched
/// This trigger flips direction of receiving object (belt in this case) if it has a flip direction method
/// </summary>
public class ReverseSwitch : MonoBehaviour
{
    [SerializeField] private GameObject[] Belt;
    private BasicConScript[] BeltScript;
    private int currentIndex = 0;


    private void Start()
    {
        if (Belt != null)
        {
            while (currentIndex < Belt.Length)
            {
                BeltScript[currentIndex] = Belt[currentIndex].GetComponent<BasicConScript>();
                currentIndex++;
            }
            currentIndex = 0;
        }
    }


    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Feet"))
        {
            while (currentIndex < Belt.Length)
            {
            BeltScript[currentIndex].FlipDirection();
                currentIndex++;
            }
        }
    }

}

And here's how it looks in inspector


(https://i.imgur.com/wUUTLcm.jpg)


logically it seems like it should work?

Belt length = 2
starts at 0

gets component for Belt 0 and puts it in scriptholding object for script0
increases index+1
same for 1 and 1
increases index+1
now index = 2 and the while statement ends.

index reset back to 0

then on jumping on the switch, index is 0,

for each 1/2 it runs the flip() on both their scripts
index+1 each time
then index = 2 and while statement ends and collision trigger is done?

What am I missing?

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 24, 2022, 11:48:57 PM
Making games is a lot of work  :doge

Got a couple more stages done with placeholder assets today. Outside not figuring out arrays (so for now I just stuck 2 button gameobjects on top of each other so you hit both triggers on jumping on the button), everything else worked.

Still have a fuckload to go just to finish the whole game with placeholders before moving into the art phase. At least I'm being good about fixing 98% of issues and bugs now instead of leaving it all to deal with at the end.

Also just opened my PC up and installed the new HDD and am creating it as a mirror now for my storage drive. The case is not designed well for HDD access, but luckily the first accessible drive I pulled was the dead drive.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 25, 2022, 01:57:45 PM
I'm trying to add multiple conveyor belts to my reverse switch so a single switch stomp reverses a bunch of belts instead of just one. First time trying to use arrays and not sure why this isn't working? It says null error that the method calls are "object reference not set to an instance of an object"

What am I missing?

I dunno man, I'm afraid I can't debug this for ya from this info.

what I would say though is it seems a little overcomplicated; couldn't you do something like:

Code: [Select]
for (int i = 0; i < BeltScript.length; i++)
{
     BeltScript[i].FlipDirection();
}

instead?

Making games is a lot of work  :doge

IKR? :lol
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 04:16:08 PM
Wait, do I not need to call getcomponent<>(); on a gameobject to get its script when calling a method within a script on it?

I thought I had to get the script as a variable and call the method from that variable.


Your method sounds good, I'll give that a try next time.


Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 25, 2022, 04:24:28 PM
Wait, do I not need to call getcomponent<>(); on a gameobject to get its script when calling a method within a script on it?

I thought I had to get the script as a variable and call the method from that variable.

if your array was of Type Gameobject, you might have to, but its of Type BasicConScript (which is the class I assume contains that method) so you can pretty much assume an array of component<BasicConScript> definitely has component<BasicConScript>
Title: Re: Do any of you code for your jobs?
Post by: Tasty on April 25, 2022, 06:16:34 PM
Making games is a lot of work  :doge

:P

So worth it tho :lawd
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 06:29:24 PM
Wait, do I not need to call getcomponent<>(); on a gameobject to get its script when calling a method within a script on it?

I thought I had to get the script as a variable and call the method from that variable.

if your array was of Type Gameobject, you might have to, but its of Type BasicConScript (which is the class I assume contains that method) so you can pretty much assume an array of component<BasicConScript> definitely has component<BasicConScript>

I think there might be a typo in there, but I'll mess around with your code tonight and figure it out.

I've just never used arrays/enums before this and I haven't used a list in 22 years. Enums I figured out pretty quick after a few examples used them. Arrays I get in principal but I just need to find the magic words to make them work right and lists are pretty similar but last time I wrote a script with a list was when I was in college so I need to actually try to do those again.

Just haven't run into any real use for lists or even strings outside tags in my projects yet.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 06:34:11 PM
Making games is a lot of work  :doge

:P

So worth it tho :lawd

Yeah, I get excited thinking about game design stuff.

This morning in bed I came up with the scenario design for my 3rd game. I really like it and it's a pretty complete scenario. So now I have games #1-3 scenario-planned.

And for game #4 I have the gameplay concept and story/scenario is not important in this one so I can figure it out at the time.

Games #1-3 are planned as existential horror trilogy, whereas Game #4 is a colorful Katamari-like fun game that if it turns out alright I would probably try to make an IOS/Android build (in addition to PC/Mac) because it'd fit in with that audience.

I think my year 1 goal, which would go through March 2023 since I started at the beginning of March 2022, is to get those 4 games done, which includes fully remaking & expanding the first game. If Games 1-3 turn out ok, might try to package them as a single 3-games-in-1 thing.

If I can pull that off, in year 2 I'll start thinking about games #5/#6 which I'm not even gonna think about yet besides that I want to do a point & click adventure game as game #5 and then an rpg as game #6. Haven't decided on both whether they'd be 2d or 3d. Won't make that decision until I get to them.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 08:48:52 PM
I'm trying to add multiple conveyor belts to my reverse switch so a single switch stomp reverses a bunch of belts instead of just one. First time trying to use arrays and not sure why this isn't working? It says null error that the method calls are "object reference not set to an instance of an object"

What am I missing?

I dunno man, I'm afraid I can't debug this for ya from this info.

what I would say though is it seems a little overcomplicated; couldn't you do something like:

Code: [Select]
for (int i = 0; i < BeltScript.length; i++)
{
     BeltScript[i].FlipDirection();
}

Ok, tried this and it doesn't work either because it's not set to an object.

I have

GameObject = Belt = the conveyor Belts gameobject
GameScript = BeltScript = on the conveyor Belt GameObject as a script, the FlipDirection() is a method within this script

Now, I am using a

Jumpable switch GameObject = ReverseSwitch = the game object you can jump on
ReverseSwitch Script = ReverseSwitch = The script that tells the switch what to do which is when stomped on to tell the targetObject to run FlipDirection


This works fine with a single Belt where I getcomponent Belt's script, then when button is jumped on switch tells belt's script to run flipdirection.

This does not seem to work at all with arrays because it's not finding the object?


I think I need to just run a dummy practice tutorial on how to right a working array. I'm obviously getting some logic wrong on how you do things with arrays.[/code]
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 08:56:39 PM
Ah, I think my issue with arrays is I don't know the correct way to add to an array in runtime.

I'm pretty sure I do need to GetComponent of each Belt and stick their script in an Array index variable and then I pull the script out of that array and tell the script to run flip each time.

I guess I can circumvent this for now just by making the scriptholders a bunch of present variables like Script 0/1/2/3/4 and put first belt's script into 0, 2nd belt's script into 1, etc... for length of the belt. Should work, will test this now until I learn how to add to an array.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 09:02:43 PM
So yeah, this code works fine, using one array-ish.

Code: [Select]
    [SerializeField] private GameObject[] Belt = null;
    private BasicConScript BeltS1;
    private BasicConScript BeltS2;
    private int i = 0;





    private void Start()
    {
            BeltS1 = Belt[i].GetComponent<BasicConScript>();
            i++;
            BeltS2 = Belt[i].GetComponent<BasicConScript>();
            i = 0;


    }


    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Feet"))
        {
            BeltS1.FlipDirection();
            BeltS2.FlipDirection();
        }
    }

But you have to manually adjust the code for however many belts you want to reverse at once each time. What I want to do is basically to take that

BeltS1
BeltS2
...

and turn it into a callable array called

BeltS[]

Google is telling me this is how you add to an array in C#, will try it out

Code: [Select]
private T[] AddElementToArray<T>(T[] array, T element) {
    T[] newArray = new T[array.Length + 1];
    int i;
    for (i = 0; i < array.Length; i++) {
        newArray[i] = array[i];
    }
    newArray[i] = element;
    return newArray;
}
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 25, 2022, 09:13:07 PM
Bam, got it. Reading that code I saw what I was missing and was causing my error.

I was creating a private array to hold the scripts.
Then I was adding to the array.

Problem is that the array was size 0 initially so it had no room to add to the scripts.
I was missing the one line to create space in the array to slot in the scripts.

     BeltS = new BasicConScript[Belt.Length];

fixed it all. Now I can load up multiple conveyor belts to react to a single switch. This is useful for things in general.

Code: [Select]

public class ReverseSwitchArray : MonoBehaviour
{
    [SerializeField] private GameObject[] Belt = null;
    private BasicConScript[] BeltS;





    private void Start()
    {
        BeltS = new BasicConScript[Belt.Length];

            for (int i = 0; i < Belt.Length; i++)
        {
            BeltS[i] = Belt[i].GetComponent<BasicConScript>();
        }


    }


    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Feet"))
        {
            for (int j = 0; j < Belt.Length; j++)
            {
                BeltS[j].FlipDirection();
            }
        }
    }
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 26, 2022, 12:51:08 PM
yeah, arrays are fast + cheap, but also kinda brittle.

If you want a list of things that you can add / remove / sort / resize at runtime, you're better off using, well, a List or a Dictionary
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 26, 2022, 01:27:56 PM
Never heard of a dictionary in coding, will look it up.
Yeah, at some point I should practice making a list. Just like read up an online exercise in C# using lists so I can get the gist of how they work.


So I think the next thing I want to mess with is RNG? Like it seems RNG would be useful for a lot of stuff that you don't have to manually design out. For instance if you have a room shake and debris falling you can set 5 spawn points at the top that drop a debris object and generate an RNG every second between 0-10 and if that number is 1-2 the first spawner goes off, 3-4 the second one, etc...

Like that should work and you have a shaking room that is randomly dropping debris at various spots every second? That way you don't have to like think about the timer design for spawners firing.

Also the conveyor belt array yesterday gave me an idea for a boss fight which includes RNG items being thrown by the boss, so I wanna test that out.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 28, 2022, 04:18:36 AM
I like that I'm at the point where if I can think up something in my head I can program it to happen.
Like I wanted a boss fight where you can see a bunch of conveyors and bombs drop and you have to adjust the conveyors to move the bombs to hurt the boss and not kill you.

So I made a camera adjusting script triggered by an invisible trigger the size of the boss screen that tells the camera to ignore updates and lock at a specific position zoomed out and adjusted upwards so you can see the vertical stage single screen stage of conveyors. Then I made bombs that kill the player (though right now they just kill on collision and I'd like to polish it with a 3 second beep beep and then kill around a certain damage box that isn't the object's collider). Then I made triggers in the areas that hurt the boss that says when X amount of bomb tag objects are stayintrigger then play boss arm fly up and punch head event and then boss has a script that if damaged x 3 to play death animation and die and spawn exit for boss fight.

I'm still cleaning it out and haven't done the art/sound effects/animations for it yet, but was able to take that concept and write a bunch of scripts and make it work in about 30-60 mins. It's just cool being able to take concepts and create them through scripting and objects.

(https://i.imgur.com/zlbQiZd.png)

Basically I took this and am making it happen pretty quick which is cool.

*edit* And then I decide instead of having this at another room on the map that you teleport too, since I want the boss state and bombs to reset on death I change this all to its own scene that reloads on death, which in the process breaks a bunch of the stuff I did and I spend 2 hours fixing it all lolcry
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 28, 2022, 02:03:21 PM
I like that I'm at the point where if I can think up something in my head I can program it to happen.

Yeah, I think thats the interesting stage of coding, where you know 'the lingo' and can look up the manual for the specifics, but get to figure out the approach on handling something
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 28, 2022, 03:49:30 PM
Yeah, it's fun. I'm still going back and forth on the scope. I keep thinking up ideas for new rooms/areas/bosses, but at the same time I don't think the concept/game is good enough to devote so much time to and the time would be better spent moving on to the next game.

Basically I think my original plan of doing a bunch of short 5-10 min prototypes of different genre and then seeing what works and learning the ropes and then coming back to the ones that work and expanding them into full games...is a good idea.

But somewhere along the way the scope and ideas for this 2nd game started getting to this idea that instead of 10 mins, it could be a full, but very short, indie game with 30 min+ runtime, multiple branches & endings, full controller support, etc...where I'd release it for free on stuff.

I still think that's doable, but just as I'm designing things out with placeholders and thinking about how much time it's going to take to fill in the placeholders as well to keep designing and playtesting out the areas, I'm kind hmmmmm, maybe I want to actually finish this and move on in the next few weeks and not still be working on this game for another 2-3 months before I move on.


It doesn't help that I feel way more confident in my 3rd game. Like I've designed it to be incredibly small in scope since it's my first 3d game and will be a lot of learning the ropes. In terms of assets it's super minimal (like the whole game takes place in 1 room) and I feel like I should be able to churn it out in a few weeks no problem. I also think it's more original and more interesting than this 2nd game I'm working on. So I kind of want to get to it.


My current platformer game is ok so far, like it plays decent and has what I think is a good challenge balance and some good game ideas. But at the end of the day, at least at this point it does not have a single original idea in it, so it's just another platformer with a mix of stuff from all good platformers that came before. I think if I had a good creative gameplay concept I'd be more motivated to stick with this. At this point I'm kind of just building the whole game and then if at some point I go "aha!" and come up with a clever gameplay idea I can edit all the levels/bosses to work with it after.

Originally my plan was like Stage 1->Stage 2 -> Stage 3 with 3 different stage 3's depending on branching
Then Stage 2 became Wiley's Castle from MM and like 6 mini-stages + mid-boss
Then the 6 mini-stages became more like small but actual MM stages with their own bosses

But now I'm thinking of cutting Stage 2 down to like 3 micro-stages + mini-boss + escape from Wiley's Castle sequence -> Stage 3 just being a final boss and calling it a 10-15 min short prototype that like my first game I can come back to later and expand if I want.

Right now I have done w/placeholder assets:

Stage 1
Stage 2 castle with doors
Door 1
Door 2
Door 3
Mini-Boss

Was going to make Door 1/2/3/Mini-boss all a single door stage, but yeah I think for now I'll just have them as separate stuff and basically the entirety of stage 2. Will design an escape sequence and then a transition to stage 3 and then do that + final boss at this point I think.

Ideally by the end of this weekend I'd like the game to be playable from start to finish with placeholder assets, so next week I can spend doing the art/music phase and then the week after polishing it and releasing it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 28, 2022, 04:04:27 PM
Oh, is there any easy way to record gameplay and then play it back as a cutscene?

Like if I want when the player steps through a trigger the camera zooms in a bit and the player loses control and the main character walks forward and then the ground breaks apart under them and they fall.

The long way would be to like remove control of the player and then tell the player object in script to like transform.right until this point and play running animation while doing so and then on the spot have the ground play breaking animation -> remove ground and rigidbody physics on the player will make them fall and you can transition to a black screen after a few seconds of falling.

The short way would just be if I could record me walking forward and standing on a spot and then take away the player's control of the MC and then play that bit?

This seems like it would be especially useful for FPS cutscenes where you can just record moving and looking and doing something and then play it as a cutscene at spots.

Google is showing me stuff like this, probably will explain it:

https://www.youtube.com/watch?v=Y5RDtN1jM6A&t=204s


Another question I have for Unity/C#, when do InvokeRepeating, is the time based on something that will be the same across hardware? Or will it be one of those things where at 120fps it'll fire off the invoke method more often than someone playing it at 30fps in the same amount of time? I'm using InvokeRepeating on my spawner to spawn bombs for my conveyor belt boss. Wondering if this is problematic and I should tie it to a time.deltatime thing instead?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 28, 2022, 04:59:46 PM
So I watched a few videos on making cutscenes in 2d/3d and it makes sense, but I'm not seeing anything that lets you just record gameplay?

Like say you're making an FPS, and you want your cutscene to be the player walks to the wall and jumps twice. Now you can use timeline or whatever and move the player to the wall and make them jump twice,

but there has to be a way to just hit record and the gameplay starts with you in control of the player and you walk over to the wall and jump twice and then hit exit record and now you have your cutscene?
Title: Re: Do any of you code for your jobs?
Post by: Tasty on April 28, 2022, 05:23:43 PM
Maybe FRAPs plus a custom camera?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 28, 2022, 05:27:58 PM
Seems like Unity Recorder lets you record gameplay but it just makes it a video file, so you can save the video and play it on trigger but that seems stupid to me for in-game stuff idk.

Guess I'll just do it using animator and timeline when I get to it. For my 3d game I do want to do FPS animations where it takes the control away from the player and looks in a certain direction.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 28, 2022, 06:51:30 PM
Also one of the many lessons I'm learning from this project is for now if I just want to make prototypes all of kinds of genre for practice and then dive in heavy on a bigger project later, that from the start to keep the scope of each of these projects really small.

Game #3 idea I have is good for that.
Game #4 idea all I have is some gameplay loop ideas so can keep it small

Better to be focused initially on a small project you can keep the passion flame going and knock out in a few weeks/month vs losing your way and losing interest.

For example for a 2d platformer, I think a good prototype size idea would've been make a gameplay concept even if it's been done before like "button 2 lets you zero dash once per jump aka move in a direction a few units while invincible", and then just make like 5-10 single room platformer puzzles with a set still camera that increase the complexity using that. Then an ending screen. Maybe throw in a couple of brief couple line dialogue cutscenes every few stages.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on April 29, 2022, 06:47:54 AM
Oh, is there any easy way to record gameplay and then play it back as a cutscene?

I mean... this is kind of a bigger topic than you might realise.
If you want to do a traditional 'in engine' style cutscene, you're basically writing non-interactive code to simulate how gameplay actually works (and yeah, you probably want to use Timeline to handle sequence of events, and probably Cinemachine as well to handle precision camera placement / focus / moves) and that's basically going to involve you faking gameplay through animations / placements / translations etc.

Because when you think about it, when you take away the systemic / mechanical aspects of a videogame, you are basically just watching a series of animations.

This is probably the closest to 'hit record and playback' you're likely to get, especially as the unity animator pretty much works like that for any given component, except you're controlling those values through the inspector rather than via input scripts (so if you want to move something 5 units north at 1 unit/second, then rotate 90 left, you can create a new anim, hit record, then make a keyframe at 5 seconds, drag their Z transform to +5, then drag their Y rotation to -90)

If you want to do actual player gameplay repetition (like Super Meatboys Replays, or driving game ghost cars) you're going to want to basically create a class that pretty much records player inputs at timestamps, and then when finished does a stochastic playback of replicating the players gameplay by replicating their inputs (and its going to go wrong if you have non-deterministic gameplay, or randomness involved, and if you're trying to track more than just player input is going to get exponentially more complicate with every new thing you try and track)

Another question I have for Unity/C#, when do InvokeRepeating, is the time based on something that will be the same across hardware? Or will it be one of those things where at 120fps it'll fire off the invoke method more often than someone playing it at 30fps in the same amount of time? I'm using InvokeRepeating on my spawner to spawn bombs for my conveyor belt boss. Wondering if this is problematic and I should tie it to a time.deltatime thing instead?

I think both invoke delay (and the coroutine alternative yield for new n seconds) are both internally using Time anyway, which is both a sufficiently big enough number as its baseline (seconds) that any drift between different spec machines isn't going to be that big a deal, and also something ultimately measured via Operating System hardware (as I believe it gets its values from system clock).
I mean, basically any real machine differences is probably going to fall into the realm of 'imperceptible to humans' so I wouldn't sweat it too much.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on April 30, 2022, 10:31:19 PM
Finally googled some stuff on game dev creative block and viola there's a lot of very helpful tips out there because this is not a unique thing.

Best advice I found was get off social media and make a small shitty game in a day or two based on one idea whether it's good or bad, because you can't get good at stuff unless you make some sucky things first and just getting something done is motivating. Gonna try that out to get motivated again.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 01, 2022, 07:50:35 AM
Finally googled some stuff on game dev creative block and viola there's a lot of very helpful tips out there because this is not a unique thing.

Best advice I found was get off social media and make a small shitty game in a day or two based on one idea whether it's good or bad, because you can't get good at stuff unless you make some sucky things first and just getting something done is motivating. Gonna try that out to get motivated again.

Yeah, gamejams are fun (and if you wanna do one just go to itch, they have like, 50 a fucking week lol) but I always lose focus on personal projects and either end up just noodling or abandoning them
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 02:41:14 PM
Finally googled some stuff on game dev creative block and viola there's a lot of very helpful tips out there because this is not a unique thing.

Best advice I found was get off social media and make a small shitty game in a day or two based on one idea whether it's good or bad, because you can't get good at stuff unless you make some sucky things first and just getting something done is motivating. Gonna try that out to get motivated again.

Yeah, gamejams are fun (and if you wanna do one just go to itch, they have like, 50 a fucking week lol) but I always lose focus on personal projects and either end up just noodling or abandoning them

Yeah, I looked and there were A LOT of game jams hahaha, didn't realize they were so prevalent. Before covid, we used to have local game jams like once a month or two here at an esports center. Always wanted to go but never did.

Working on a game jam game today  :hyper

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 06:11:28 PM
I need some help. I've been stuck an hour on trying to figure out how to right a code to move little AI NPC around in random directions.

Basically just want:

Every3secondspickadirection()
KEEPMOVINGINTHATDIRECTION()

I don't get why this is so hard :(

I can do the random number direction thing, but I'm just having problems moving the NPC forward for a few seconds in a direction that's been selected??

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 06:29:52 PM
This stuff is so soul destroying when it halts your entire project. fuck. I was making good progress on my gamejam thing, I guess I'll just use some google code without understanding it. 90 mins on this now and I wanted to make this whole game in one afternoon.

This is my code. It sort of works but the NPC can only move in 4 directions and really shitty and I have tried a ton of oncollision ideas to get the NPC to move away from the wall but nothing seems to work. My NPCs constantly end up running into a wall and just get stuck on the walls.

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

public class NPC_Movement : MonoBehaviour
{
    [SerializeField] private float MoveSpeed;
    private Rigidbody2D rb;
    private int Direction;


    // Start is called before the first frame update
    void Start()
    {

        rb = GetComponent<Rigidbody2D>();
        InvokeRepeating("WaitandTurn", 0.1f, 3f);
    }

    // Update is called once per frame
    void Update()
    {
        Movement();
    }

    private void DecideDirection()
    {
        Direction = Random.Range(0, 3);
        Debug.Log("Direction Code =" + Direction);
    }

    private void WaitandTurn()
    {
        DecideDirection();
    }

    private void Movement()
    {

        if (Direction == 0)
        {
            rb.velocity = new Vector2(0, MoveSpeed);
        }
        else if (Direction == 1)
        {
            rb.velocity = new Vector2(0, -MoveSpeed);
        }
        else if (Direction == 2)
        {
            rb.velocity = new Vector2(MoveSpeed, 0);
        }
        else if (Direction == 3)
        {
            rb.velocity = new Vector2(-MoveSpeed, 0);
        }

    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("Collision!");
     
    }


}
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 06:37:38 PM
Found this code online, seems to work a bit better maybe, pretty similar results. Still gets stuck on walls.

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
/// <summary>
/// This makes an object move randomly in a set of directions, with some random time delay in between each decision
/// </summary>
public class Wanderer : MonoBehaviour
 
{
    internal Transform thisTransform;
    public Animator animator;
 
    // The movement speed of the object
    public float moveSpeed = 0.2f;
 
    // A minimum and maximum time delay for taking a decision, choosing a direction to move in
    public Vector2 decisionTime = new Vector2(1, 4);
    internal float decisionTimeCount = 0;
 
    // The possible directions that the object can move int, right, left, up, down, and zero for staying in place. I added zero twice to give a bigger chance if it happening than other directions
    internal Vector3[] moveDirections = new Vector3[] { Vector3.right, Vector3.left, Vector3.up, Vector3.down, Vector3.zero, Vector3.zero };
    internal int currentMoveDirection;
 
    // Use this for initialization
    void Start()
    {
         // Cache the transform for quicker access
        thisTransform = this.transform;
        // Set a random time delay for taking a decision ( changing direction,or standing in place for a while )
        decisionTimeCount = Random.Range(decisionTime.x, decisionTime.y);
 
        // Choose a movement direction, or stay in place
        ChooseMoveDirection();
    }
 
    // Update is called once per frame
    void Update()
    {
        // Move the object in the chosen direction at the set speed
        Vector3 direction = moveDirections[currentMoveDirection];
        float xDir = direction.x;
        float yDir = direction.y;
 
        thisTransform.position += direction * Time.deltaTime * moveSpeed;
 
        if (animator)
        {
            animator.SetFloat("MoveX", xDir);
            animator.SetFloat("MoveY", yDir);
        }
 
        if (decisionTimeCount > 0) decisionTimeCount -= Time.deltaTime;
        else
        {
            // Choose a random time delay for taking a decision ( changing direction, or standing in place for a while )
            decisionTimeCount = Random.Range(decisionTime.x, decisionTime.y);
 
            // Choose a movement direction, or stay in place
            ChooseMoveDirection();
        }
    }
 
    void ChooseMoveDirection()
    {
        // Choose whether to move sideways or up/down
        currentMoveDirection = Mathf.FloorToInt(Random.Range(0, moveDirections.Length));
     
 
    }
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 07:06:31 PM
Since my game takes place in a single 640x480 screen with a collision border around the edges, I wonder if it'd be easier to just use MoveTowards and have X/Y be an RNG position on the map that changes every few seconds and on collision change that position.

Anyhow if this doesn't work I'm gonna move on and make the rest of the game and come back to this. I only have like 2 coding mechanics in this game. One is to fill a top-down street with a bunch of stick figure people that spawn & move around at random and another is interactions with them.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 07:24:06 PM
Ok, I think this sorta works for what I need and keeping it simple:

Code: [Select]
public class Movetowards : MonoBehaviour
{
    [SerializeField] private float MoveSpeed = 1;
    private float DirX = 1;
    private float DirY = 1;
    private Vector2 TACO;

    private void OnEnable()
    {
        InvokeRepeating("PickSpot", 0, 3f);
    }

    void Update()
    {
        transform.position = Vector2.MoveTowards(transform.position, TACO, Time.deltaTime * MoveSpeed);
        Debug.Log("Position Heading to: " + TACO);
    }

    public void PickSpot()
    {
        TACO = new Vector2(Random.Range(-2.8f, 3.2f), Random.Range(-1.7f, 2.76f));
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        TACO = new Vector2(Random.Range(-2.8f, 3.2f), Random.Range(-1.7f, 2.76f));
    }
}/code]
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 07:48:40 PM
You know what, I'm having an incredibly difficult time moving objects that I don't control. Makes me feel like I need to go back to square 0. This game jam thing was supposed to be motivating but instead it's incredibly depressing. Makes me want to give up on making games.

Like I can't even get a freaking square car to move to the right (x-axis) What am I doing wrong??

Why doesn't this work?

Code: [Select]
private void Update()
    {
       if (DRIVE)
        {
            transform.position = new Vector2(transform.position.x * MoveSpeed * Time.deltaTime, transform.position.y);
        }
    }

The car just teleports from like -2 to 0 and then sits. I also tried Vector.MoveRIGHT and it does the same thing.

I'm going to cheat and just use MOVETOWARDS for every fucking thing in this game because I don't understand basic fucking movement. I'll just tell it to move towards the coordinates on the right side of the screen. THE END.

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 09:56:44 PM
Man, I think I give up on coding.

Gonna decide whether I want to put out an ad to hire a programmer or just can game making in general and move to a different hobby.


My goal was to make a simple ass one screen game for a game jam that ends tonight. I figured I could make the whole thing from start to finish in about 4-5 hour and it'd be refreshing to make something in a one day kind of jam experience.

The first hour or two went well. I draw out the sprites, the animations, the background.

Then I started coding and made the background and screen clamps and player movement. All good.

Then everything started going wrong. The NPC movement code took forever.

Then I made a car and couldn't figure out how to move it.

Then I tried using particles for the first time and hit a bunch of visual glitches trying to use them in an overhead 2d game. They'd constantly be partially obscured by 2d objects for no reason. And they'd be sorted in the layer ahead of everything else.

Then I tried to make a death sound effect. Something that is VERY SIMPLE and I literally just used the same code from my current platformer that says "[SERIALIZED] PRIVATE AUDIOSOURCE AS" and later "AS.PLAY();" and put the audio source on the gameobject and put it in the slot. And it doesn't fucking play. Been wasting 15 mins trying to get that to work and am giving up.

No sound effects, jacked up particle effects, whole thing is a mess and fucking sucks and doesn't work right. Been a super shitty day.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 10:46:57 PM
Nothing works  :maf

Gave up on having sound effects and just tried making my game over screen. I wanted the final score tally to show on the game over screen so I put it on my game manager with don't destroy on load.

Now for some reason I can't figure out at all the "RESTART GAME" button on my game over screen doesn't work when the game manager object exists. If I uncheck the game manager so it just goes to the game over screen I can loop infinitely from the game screen -> game over and back using the restart button on the game over screen.

But if the game manager is in play, the restart button won't work. ??????????

There is nothing going on in my code that should do this?

Here is my game manager code
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class UITracker : MonoBehaviour
{
    public static UITracker instance = null;
    private int Score;
    [SerializeField] private GameObject StartUI = null;
    [SerializeField] private GameObject EndUI = null;
    [SerializeField] private Text Deaths = null;
    [SerializeField] private Text EndDeaths = null;


        void Awake()
        {
        if (instance != null)
            {
                Destroy(gameObject);
            }
            else
            {
                instance = this;
                GameObject.DontDestroyOnLoad(gameObject);
            }
        }
    private void Start()
    {
        if (SceneManager.GetActiveScene().buildIndex == 0)
        {
            Score = 0;
        }
    }

    private void Update()
    {
   

        if (SceneManager.GetActiveScene().buildIndex != 1)
        {
            StartUI.SetActive(true);
            EndUI.SetActive(false);
            Deaths.text = "Score = " + Score;
        }

        if (SceneManager.GetActiveScene().buildIndex == 1)
        {
            StartUI.SetActive(false);
            EndUI.SetActive(true);
            EndDeaths.text = "Score:" + Score;
        }

    }

    public void AddScore()
    {
        Score++;
    }

    public int GetScore()
    {
        return Score;
    }
}



You know, if a single thing, just one fucking thing I wanted to do actually worked off the bat and didn't make me spend hours trying to figure out why it's not working I'd feel a lot better about this.

Because right now I have a game with no sound effects that once you die you can't leave the game over screen without hard quitting. I also only have 1 stage and 1 interactable object because I wasted all this time. So basically I got nothing I can turn in for the game jam.
Title: Re: Do any of you code for your jobs?
Post by: Madrun Badrun on May 01, 2022, 10:48:17 PM
Honestly, man, don't give up.  Learning to code just takes time.  There will be frustration but figuring out problems like these is also very rewarding, as seen by all the things you have overcome in the thread so far. 
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 10:54:02 PM
I think I figured out the problem with my last thing. I think the game over text score canvas it was setting active on the game over screen was covering up the restart level button so you couldn't actually click it? This is what I've figured out from disabling things one at a time in the game manager trying to see what is causing the restart level button not working.

*edit* ok that fixed it. Still have no idea why my sound effects don't play on enemy death.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 01, 2022, 10:54:09 PM
Honestly, man, don't give up.  Learning to code just takes time.  There will be frustration but figuring out problems like these is also very rewarding, as seen by all the things you have overcome in the thread so far.

Thanks,
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 01:51:32 AM
Took a 3 hour break on a date, was kind of stressing because I was in a such a frustrated mood from all this that it would ruin the date, but actually went well and felt a lot better after.

Not sure if I'm gonna try to finish up this game jam game. I guess it's due on Tuesday, so there's one more day. I have most of the code working so theoretically I could finish it out. I guess it'll depend on if I can get sfx working tonight before bed.

I am trying to do a bangai-o/lemmings kind of thing with massive NPC explosions and sfx and I got glitchy working particle effect explosions but without all the cascading sfx it's kind of :(((((((

I'm gonna try putting the SFX on the object hitting the NPCs to play on collision instead of the NPCs playing the sfx when they explode and die and see if that maybe works instead.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 06:13:03 AM
Ended up sticking with it and finishing it out.

It's just 1 stage and it's pretty crappy! Probably took me like 12 hours in one day because of all the troubles I ran into. Was hoping I could make game jam stuff like this in 3-5 hours from scratch. Life goals I guess. Also had to spend an hour fixing bugs I found every time I built it for upload. Why does every canvas default to constant pixel size instead of scaling with screen size arghh. Kept finding text that wasn't scaling and had to rebuild.

I could easily make a few more simple stages (I like the levers and think could make some stages out of them) before uploading it to the newbie game jam. Also I just used whatever sfx I had around. Didn't use things I wanted like cheering and crying sounds for the ending.

I guess it's cool I learned how to use particles and get some nice crunchy noises/effects?

Oh and the game jam constraints were 1) minimalism, 2) you are alone, 3) you are the villain, 4) everything kills you
I sorta got those to a degree. Getting all four perfect seems ridiculously hard in concept.

Here it is:
https://dkclassdesign.itch.io/entropy-chans-tea-time-adventure-beta
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 02, 2022, 07:02:31 AM
(https://i.imgur.com/PJjeNgK.gif)

I need some help. I've been stuck an hour on trying to figure out how to right a code to move little AI NPC around in random directions.

So I'm guessing you're not using any kind of pathfinding?

Probably the simplest way of doing this would be what a Roomba does; pick a random direction to start moving in, raycast in that direction, when you encounter something ahead of you, rotate until the raycast says the way is clear, rinse and repeat.
I mean, it's basic, but if you maintain the same rotation direction each time, and rotate in right angles, it will be able to solve a maze

:idont

Nothing works  :maf

It looks like you solved it, but if you have a game manager, you might be best off routing things through your gamemanager?

You have your score values there, but you can also solve your SFX and button action issues with something like;
Code: [Select]
public void DoSFX(audioclip fx) // call this from any other script by sending it an audioclip; this wouldn't have 3D spatial properties, but youre making a 2d game right?
{
     myAudioSource.PlayOneShot(fx); // myaudiosource would be a cached audiosource component reference
}

public void RestartGame() // assign this to your restart button
{
     scenemanager.loadscene(currentscene()); // or whatever the command is
}

// public void MainMenu() // can do another version to take them back to menu screen, or can do a next level button, or whatever you want; again, reference this via your UI buttons
Title: Re: Do any of you code for your jobs?
Post by: Uncle on May 02, 2022, 08:10:12 AM
I think a lot of game jams are intended for people with like at least 1 more year of experience than you, people who have already tried implementing their first/second/third particle systems etc., or run into the problems you had already like with sound effects and figured out how to efficiently circumvent them

this isn't meant as an insult at all, you just need a little more experience, game jams aren't necessarily entry-level, in fact they often stress experienced creators
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 02:32:17 PM
I hear you. Some of this stuff was just wacky though and yeah the time pressure doesn't help. Like things that should be normally working don't and I have no idea why  ??? that stuff is frustrating.


Quote
It looks like you solved it, but if you have a game manager, you might be best off routing things through your gamemanager?

You have your score values there, but you can also solve your SFX and button action issues with something like;

Yeah, I could have the gamemanager play a death sound every time since I'm already adding to gamemanager scorecount each death and could just have the sfx play there.

The button issue was literally just the UI canvas text covering the button. Like the text didn't cover it, but the text rect was double the size with a lot of blank space and the blank space covered the UI button. I guess I could also fix this by making the UI button the child of the text so it sits on top.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 02, 2022, 03:04:27 PM
The button issue was literally just the UI canvas text covering the button. Like the text didn't cover it, but the text rect was double the size with a lot of blank space and the blank space covered the UI button. I guess I could also fix this by making the UI button the child of the text so it sits on top.

There's a couple of easier fixes; the generic one, is anything you don't want to block raycasts, put it on the Ignore Raycasts physics layer.

The UI specific one, which is common enough it has its own dedicated fix, is on any UI element, there's a raycast target checkbox on the image component - just uncheck that
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 03:21:47 PM
This is a list of every issue I ran into and either solved or still don't know how to do it or what is wrong:

Problem #1 - Moving things forward
I don't know how to move an object "forward", this is a major problem that is going to continually haunt me in projects so I better learn this. Normally I would just use move in x direction * movement speed * time.deltatime each update call. But when you're not playing a side scrolling game where you are only moving right or a shmup where you are only moving down, it gets more complicated.

How do you even quantify an abstract of "the direction you are moving in" when it could be left/right/down/up or any 360 degree direction?

Solved? - No.
Workaround? - Sorta. I know how to use Vector2.MoveTowards to set waypoints and have things move to them. I also similarly know how to direct set the coordinates for objects to move to such as in my shmup where I say "move down until Y axis ____ and then move left & right between X axis __ and X axis ___. But this is pretty limiting and doesn't cover all the movement situations I'll need. For example what Sage is saying about raycasting. I've never done a raycast before, I assume it's similar to a boxcast which I've done in my platformer by boxcasting "down", but with a raycast how would I know what direction to even cast the ray? Forward ahead of you could be any 360 direction.

I tried transform.position = but that just teleports things and I tried Vector3.Moveright and that didn't work for moving my car from the left side of the screen to the right on the X-axis.

I definitely need some help on figuring out how to just make a blank scene and drop an object and then make a script that says move from the left side of the screen to the right. You would think putting "transform.position = new vector2(transform.position.x+1, y) * movement speed * time.DeltaTime would do it, but I swear that didn't work for my car.

Problem #2 - Multiple Movements

I wanted my UFO's to circle instead of just moving forward, or at least move in a square. I tried putting in 4 waypoints and having a waypoint counter to tell which waypoint it was at and when it reaches that waypoint to increase the counter and then the next if counter == kicks in and it moves to the next one. For some reason it would just move to the first waypoint and stop.  I'm sure I could fix this with some debugging.

Solved? No. But can fix this on my own with time debugging.
Workaround? Nah, I just gave up and had it move in a straight line to one waypoint.

Problem #3 - NPC random movement

This mostly ties into #1, I think if I could figure out how to tell an object to pick a direction and move forward in that direction I'd be ok. The turning and changing directions is the easier part.

Solved? Sorta.
Workaround? Yeah, honestly if you check out the game the NPC random movement looks pretty ok. I think my solution of using MoveTowards and just setting the waypoints as RNG that changes every 3 seconds to a different spot on the map, and changes on collision with anything works pretty well. It does just congregate most NPCs in the middle of the screen though as the RNG waypoints tend to draw NPCs towards the center of the screen.

Problem #4 - NPC Spawning with screen border collision

So here's the thing. I don't like how NPCs just magically appear in the middle of the screen when they spawn. Especially since they can RNG spawn ON YOU and instantly kill you with no warning.

Ideally I'd have liked to have some spots outside the map where the NPCs funnel in from and then spread out from there. The problem is that if the screen border is a collision that keeps the NPCs from wandering off the screen, it would also prevent them from entering the screen. So I'd need like a one way door to let NPCs in, and I have zero idea how to do that.

Even if I knew how to do that, I'm not sure how I'd make the NPCs initially come in and then spread. I think a solution would be to set their initial waypoint as the center of the stage arena for the first 5-10 secs after spawn and then start RNGing the next waypoint every 3-4 seconds. That would probably work.

Solved? - No. Maybe if I could make one way doors and had some time.
Workaround - Nah, just left them teleporting in.

Problem #5 - NPCs spawning on you and instantly killing you

I tried to work around this in multiple ways and wasted some real time on this issue to make the game more fair. I tried turning off the NPCs collider for the first 3 seconds after spawn to give some invuln time of hitting the player if they spawned too close to the player. The problem being that this also meant you couldn't kill NPCs with objects for the first 3 seconds which was incredibly unsatisfying when you opened a street fault line and half the NPCs take no damage and just float over it.

Solved - Nope, good luck player! All's fair in RNG.
Workaround? - Nah, not really sure how to do this. You need a collider to be able to trigger/collide and NPCs need to hit stuff to die but not the player. Maybe some complicated code where the player death on collision isn't coded on the player script but on the NPC script reaching over to the player and then can make it if colliding tag is the player and time since spawn is less than 3 seconds, do nothing, else send DIE() to the player. That's a little complicated and with time I could probably do it but feels like it'd be a lot of work.

Problem #6 - Particles

My particles were fucked.

Solved - Yes. Turns out somehow when I added a particle system to the scene it attached to a car object, meanwhile I was working with a different particle system and the two were causing interaction problems. I never knew there was one on the car because the sorting layer had its particles hidden behind the scene. Only when looking at the car object did I see it and removing it fixed the particles.

Problem #7 - SFX

My SFX were iffy if I tried to play them.

The way I would do SFX is I would put the SFX as an audio source on the object and then in the object's script it would say

Code: [Select]
[SerializeField] AudioSource SoundEffect
then in the code on collision would say

Code: [Select]
private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            DRIVE = true;
            SoundEffect.Play();
        }
    }

Then I would drag the audiosource on the object into the public field for sound effect. And this worked for my car and UFOs.

But for my NPCs I was spawning, I did this exact same thing to play SFX on collision before they died. I even put a waitforseconds coroutine in to give a few seconds before they were destroyed in case it was destroying them before the SFX could play. It never worked. When I put the SFX on the car to play on collisions with non-player it would play.

The NPC prefabs included the audio source on the NPC as well as it slotted into the serializefield for sound effect, these NPC prefabs were spawned. I...still don't know why the SFX wouldn't play.

Solved? No.
Workaround Yes. I ended up putting the death sound effect on the bloodspurt particle effect game object. When NPCs are hit they instantiate the deatheffect gameobject which is the bloodspurt particle so the SFX plays on awake. I just wish I knew why the NPCs won't play their own SFX.

This is the code on the NPCs.

Code: [Select]
[SerializeField] private AudioSource ADD
And

Code: [Select]
private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("NPCKILLER"))
        {
            ADD.Play();
            Explode();
            StartCoroutine("Death");
            Destroy(this.gameObject);
        }
        else
            Newwaypoint = new Vector2(Random.Range(-2.8f, 3.2f), Random.Range(-1.7f, 2.76f));
    }

Problem #8 - UI stuff with carrying over score between stage and game over screen and implementing it into the text on the game over screen.

Solved - Uh, sorta.

Workaround - Yes, I basically ended up carrying the game over screen's UI panel & text with the gameManager as setactive(false) on the stage screen and it becomes setactive(true) on the game over screen.

I'm pretty sure I could get around this with better coding, where the game over screen UI text has a script that calls a method on the gamemanager instance to get the score int and then display the text + score int. I just needed to organize my game manager better from the start. Ended up carrying a lot of random stuff on it between the stage and the game over screen.

Problem #9 - Button thing.

Solved? - Yes. Explained above. Fixed once I figured it out.

Problem #10 - Built it wrong!

I was speedrunning this project so I didn't organize my assets at all or even put my build order scenes in the right order and the main menu was scene 3. Learned the hard way after building it that game always starts on Scene 0! Always put your main menu on Scene 0 lol

Solved? - Yes, I knew this but forgot. Good reminder.

Problem #11 - Not using the SFX I wanted

I was lazy and under time crunch and didn't want to start searching for free use SFX for the exact sounds I wanted (I wanted a cheering SE on happy win screen and a sulking sad SE on sad win screen and I wanted NPC death effect to be screams). So I just used whatever I had from like 30 SFX from one pack I had.

Solved? - Sorta. The SFX I ended up using were semi-decent. Can fix this if I just spent some time finding the right SFX or even making my own like making a few screams and pitch modding them on my phone.

Overall

I think that was it. I definitely could've done things better and smoother. The plan originally was to have multiple levels with different objects like the Statue of Liberty which starts walking and crushes people and wrecking balls and open manholes and stuff. With NPCs spawning in increased amounts over time and maybe having a timer to make it more a certain death over time try to get as many kills as you can thing.

The two major issues that screwed up the development of this game concept were making NPCs wander and not get stuck crowded up on the wall borders and the SFX playing on NPC death. If not for those, probably could've made this pretty smooth in 4-5 hours and had time to add a few more stages and some more polish.

If I can figure out the basic "how to move things in a direction" I think I'd feel more confident about trying another small shot project like this and doing it better. Maybe keep trying one screen small games over and over until I can make one smoothly in a few hours to get me back feeling confident about coding and not awful about it.

The button issue was literally just the UI canvas text covering the button. Like the text didn't cover it, but the text rect was double the size with a lot of blank space and the blank space covered the UI button. I guess I could also fix this by making the UI button the child of the text so it sits on top.

There's a couple of easier fixes; the generic one, is anything you don't want to block raycasts, put it on the Ignore Raycasts physics layer.

The UI specific one, which is common enough it has its own dedicated fix, is on any UI element, there's a raycast target checkbox on the image component - just uncheck that

Time for me to look up what a raycast is!
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 02, 2022, 03:55:53 PM
Problem #1 - Moving things forward
How do you even quantify an abstract of "the direction you are moving in" when it could be left/right/down/up or any 360 degree direction?

There's a bunch of premade constants for Vector3 relative positions;
eg Vector3.up = {0,1,0} = 'up'
Vector3.left = {-1,0,0} = 'left'
Vector3.forward = {0,0,1} = 'into the screen'
etc

so you should be able to slap transform.position += vector3.forward * time.deltatime * speed; onto a 'bullet' and it 'just works'

Quote
Problem #2 - Multiple Movements
yeah, waypoints would be the solution; you can also check distance from waypoint, then switch up your waypoint to the next one when youre 'close enough' (your gametype would determine when that is, and how smooth you want that transition to be)

Quote
Problem #3 - NPC random movement
as above; absolute random x/y/z works, but so does having an array of 'valid' waypoints, then randoming array.length (which will 'cluster' based on your placements, not your random results)

Quote
Problem #4 - NPC Spawning with screen border collision
So there's a command called uhhhh getsphererandom or something, which will return a random point on a sphere surface (theres a circle version for 2D too I think) so if you multiply that up so your sphere / circle is bigger thn your playspace, you can spawn things 'off camera' nicely, then waypoint them into the 'scene' - a good way to get a valid 'target' point is just set them to the player position when it spawns (because the players probably moved by the time they get onscreen).
You can also only turn on any 'stay in bounds' checks only when they actually enter bounds.

Quote
Problem #5 - NPCs spawning on you and instantly killing you
As above, spawning 'offscreen' is super fair.
Alternatively, have a 'prespawn' animation / VFX / whatever at their spawnpoint before they actually do is also pretty fair.

Quote
Problem #6 - Particles
particles are super fun to play with, watch some tuts!

Quote
Problem #7 - SFX
yeah, I can't help but feel your NPCs were being destroyed along with their audiosource component, especially as moving it to your spawned VFX solved it.
IMO putting your clip on your VFX is a nicer solution anyway, as you can clean them both up simultaneously (and also an explosion VFX + SFX prefab is super reusable)

Quote
Problem #8 - UI stuff
I think when we were talking about singletons, I have 'UI manager' as a super common usage case for singletons; this kind of thing is why!

Quote
Problem #10 - Built it wrong!

I was speedrunning this project so I didn't organize my assets at all or even put my build order scenes in the right order and the main menu was scene 3. Learned the hard way after building it that game always starts on Scene 0! Always put your main menu on Scene 0 lol

Yeah, the list of levels is a zero-indexed array of ints.
You can reorder them in the build properties though, you just need to drag and drop to reorder!


Quote
Time for me to look up what a raycast is!
Its basically a 'laser' that returns info on whatever it hits.

Any 'mouse' commands built into Unity, are actually shooting a 'laser' (raycast) from the camera to the mouse pointer, then doing stuff based on what it hits; so if you put a sprite on top of soemthing you want to mouseover, the sprite can actually block it.
Likewise, sometimes you want to manually block a raycast, eg if you have a UI button that clicking on it also shoots a bullet into the world in an FPS UI interaction
Title: Re: Do any of you code for your jobs?
Post by: Nintex on May 02, 2022, 04:16:22 PM
Congratulations you shipped a game :rejoice

It's pretty fun to play actually and quite intuitive, no tutorial needed.
Kinda like a reverse Castle Defender type of game as opposed to say Pac-Man.
The level music is also catchy and I dig the atari/retro aesthetic.

Considering you've never made a game before in your life this is pretty impressive.
My first game was literally 2 boxes that collided and some crazy ass trippin' seizure shit in Unity.  :doge
Game 3 was way too ambitious but somehow worked. You could scan 3D models with a infared light and those would pop up in a Banjo-like adventure game.
You would have to model shit with clay, for example a chess set was missing a piece so the horse piece asked you to create a new tower piece.

Game 4 was the best gameplay wise and much more streamlined like your game. It was made in Unreal and the laser gun was modded to resemble a super soaker.
You had to shoot the smokers back to the designated smoking areas of the university. It took about 3 months to build and we had 4 people on the team.

Cutting features is part of any software development. You can never create everything you come up with in the time you have.
The key is to retain the things that make the game fun, fake the things that make the game more interesting and cut the things that people don't notice.
Remember, I don't know what your original vision for the game is or was so I can't really tell if Statue Stomping is cut or not.

I always quote Gandalf when new developers I work with complain about running out of time or not having enough time and wanting to spend more time.
"So do I",  "and so do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given us."
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 04:47:46 PM
Problem #1 - Moving things forward
How do you even quantify an abstract of "the direction you are moving in" when it could be left/right/down/up or any 360 degree direction?

There's a bunch of premade constants for Vector3 relative positions;
eg Vector3.up = {0,1,0} = 'up'
Vector3.left = {-1,0,0} = 'left'
Vector3.forward = {0,0,1} = 'into the screen'
etc

so you should be able to slap transform.position += vector3.forward * time.deltatime * speed; onto a 'bullet' and it 'just works'


Yeah, I feel like in update transform.position = vector2.right * time.deltatime * speed for my car should work? I was having issues with it. Idk.

For randomizing, I wanted to do just A. "pick a direction between 0-360 rotation" -> B. "move in that direction for 5 seconds" -> repeat. C. On collision take current direction you're moving in and flip it to the opposite with a *-1.

I can do A, I can't do B without setting a waypoint (do you need to always set targets for movement unless you're doing Vector2/3 -> up/down/left/right? and I couldn't figure out C because I can't figure out B.


Quote
Problem #4 - NPC Spawning with screen border collision
So there's a command called uhhhh getsphererandom or something, which will return a random point on a sphere surface (theres a circle version for 2D too I think) so if you multiply that up so your sphere / circle is bigger thn your playspace, you can spawn things 'off camera' nicely, then waypoint them into the 'scene' - a good way to get a valid 'target' point is just set them to the player position when it spawns (because the players probably moved by the time they get onscreen).
You can also only turn on any 'stay in bounds' checks only when they actually enter bounds.


Sorry, I don't understand that at all  :'(

But yeah, turning off colliders for the first 5 seconds or until in screen bounds and then turning them back on probably is the easiest. And setting the player position on spawn for the first waypoint makes the game more fun because you can't camp spots. I may try this tonight before I upload the game to the jam.

Quote
Problem #5 - NPCs spawning on you and instantly killing you
As above, spawning 'offscreen' is super fair.
Alternatively, have a 'prespawn' animation / VFX / whatever at their spawnpoint before they actually do is also pretty fair.

Good idea about the pre-spawn animation the spawner can instantiate. Don't think it would be helpful here (too busy/chaotic), but in the future could find it useful.

Quote
Problem #7 - SFX
yeah, I can't help but feel your NPCs were being destroyed along with their audiosource component, especially as moving it to your spawned VFX solved it.
IMO putting your clip on your VFX is a nicer solution anyway, as you can clean them both up simultaneously (and also an explosion VFX + SFX prefab is super reusable)

Yeah, idk. Just little things I don't understand annoying me and my OCD fixation trying to make everything work.

Quote
Time for me to look up what a raycast is!
Its basically a 'laser' that returns info on whatever it hits.

Any 'mouse' commands built into Unity, are actually shooting a 'laser' (raycast) from the camera to the mouse pointer, then doing stuff based on what it hits; so if you put a sprite on top of soemthing you want to mouseover, the sprite can actually block it.
Likewise, sometimes you want to manually block a raycast, eg if you have a UI button that clicking on it also shoots a bullet into the world in an FPS UI interaction

Thanks, that's a helpful start. I'm assuming Boxcasting is the same? 

My question goes back to your suggestion to raycast & turn for NPC movement. How do you know what direction to raycast the laser out since you won't know what direction the NPC is heading at any time?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 04:57:08 PM
Congratulations you shipped a game :rejoice

It's pretty fun to play actually and quite intuitive, no tutorial needed.
Kinda like a reverse Castle Defender type of game as opposed to say Pac-Man.
The level music is also catchy and I dig the atari/retro aesthetic.

Considering you've never made a game before in your life this is pretty impressive.

Thanks, actually my 2nd released game. I think you were off the forum when I released my first one. For the music in this current little project I used some rejected pieces that I made for my 2nd game and trashed because they didn't fit and I didn't think they were good haha. But good enough for one shot stuff like this. Didn't write any music yesterday while making this.

My first game took about 100 hours development over 2 weeks. I still need to reuppload it with scaling for canvas as this version uses constant pixel size for UI text and doesn't look right at full screen.

https://dkclassdesign.itch.io/the-task

I'm also like midway through a bigger 2d platformer thing for the last few weeks with about 5 mins of stages done, but it's kind of stalled and I've lost confidence in the concept which is why I'm starting to do these one shot tiny games to find some motivation again. It's the 2nd reboot of this project though the first was just conceptual and no coding was done outside making a character sprite. The 2nd time was using pre-set assets to make a few bad platformer stages and the 3rd time was this game I'd been making. Will either get motivated to finish it or more likely will reboot it a 3rd time and start over again.

Quote
My first game was literally 2 boxes that collided and some crazy ass trippin' seizure shit in Unity.  :doge

haha, trippy stuff is great to make. Much easier to not have to worry about grounded logic when designing.

Quote
Game 3 was way too ambitious but somehow worked. You could scan 3D models with a infared light and those would pop up in a Banjo-like adventure game.
You would have to model shit with clay, for example a chess set was missing a piece so the horse piece asked you to create a new tower piece.

 :doge

That sounds really complex? Uhhhhh, how did you translate whatever data came in from an infared light into 3d space? That seems like year 2/3/4+ kind of big brain coding.

Quote
Game 4 was the best gameplay wise and much more streamlined like your game. It was made in Unreal and the laser gun was modded to resemble a super soaker.
You had to shoot the smokers back to the designated smoking areas of the university. It took about 3 months to build and we had 4 people on the team.

Sounds good, FPS?

Quote
Cutting features is part of any software development. You can never create everything you come up with in the time you have.
The key is to retain the things that make the game fun, fake the things that make the game more interesting and cut the things that people don't notice.
Remember, I don't know what your original vision for the game is or was so I can't really tell if Statue Stomping is cut or not.

I always quote Gandalf when new developers I work with complain about running out of time or not having enough time and wanting to spend more time.
"So do I",  "and so do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given us."

Ya.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 06:06:59 PM
Thought up an idea at lunch for improving it. What's fun is triggering switches to cause things that mass explode NPCs.

So instead of having cars/ufos on the map that are one time things, I could revise it so it's just a bunch of switches around the map and they cause cars to drive across with a screech noise and ufos to fly across with ufo noise, etc...

(how do you have things ignore one collidor but work with another? My stage border is a tilemap with a collider map, I'd like to have these objects ignore that and just fly across from outside the stage but still collide with NPCs). I feel like you can do this with a sorting layer maybe? Otherwise I can make these objects triggers so they pass through colliders and kill NPC on trigger which should work just as well.

And the switches have cooldown periods so when you exit them they're still pressed down but after like 5 waitforseconds they pop back up and become collidable again to instantiate the objects.

So the gameplay becomes running around the map trying to avoid anything touching you while you hit switches to cause things to clear NPCs away and give you openings.


I'll try to implement that tonight after work & also try to implement the NPC spawning outside the stage and swarming in towards the player. If I can get it working and replace some of the SFX and still have an hour or so before I gotta turn in I'll try to do one more stage. I was thinking a 2nd stage where it's two half sides with a river in the center and two bridges that connect on the N/S would be a fun challenge. Because the bridges can get full of NPCs and then you're stuck navigating half a stage and have to wait for switch cooldowns to run to fire off objects to clear the bridges so you can cross to the other side and use the switches on that side.

Anyhow that's a whole lotta stuff for a few hours so will depend on how smoothly things go or not /shrug



Also I kind of like the idea for now, as my platformer project is on hold, of doing 2-3 day dev games. Where day 1 is I make a tiny game from start to finish, then day 2 I sleep on it and try to figure out what works, what doesn't and then day 2/3 I revise it to focus on the fun parts and cut down on the not fun parts and then call it a day.

Do this enough times and it should give me a lot of practice which will help me get back to my main (probably dead) project. I have an idea for a new 2d platformer to replace the project but I want to up my skills a bit before attempting it, so will stick to these kinds of tiny games for a few weeks.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 02, 2022, 10:52:03 PM
It's actually...coming together pretty ok tonight?

Like idk if it's more fun than last night's build but it's actually pretty balanced now. Npcs come in from all 4 sides through the outer walls, you see little icons near switches of what the switches do and they have different cooldowns with the quake being the longest cooldown. Easy at first but then you can start getting overwhelmed.

Now I need to decide whether to focus on improving the sfx or making stage 2. I think Stage 2 gets priority so gonna try to make that for the next hour, then maybe swap some sfx and upload it and call it a day. Since the stage are basically survival stages I'm not going to make stage 1 -> 2 link but rather have both be playable from the main menu and the death menu will let you return to main menu.

Also as an extra cherry on top thing I'd like to save high scores since it's now a survival wave arcade game but I've never messed with that (player preferences, right?) and I'm not sure if I can figure it out in 30 mins or so.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 03, 2022, 02:22:14 AM
So everything went well until I went on a 3 hour tanget (time I really, really didn't have) to try to make a particle beam that sweeps 360 degrees and triggers everything it touches which in their own script explode on triggerEnter2d.

I couldn't solve it.

I could get colliders working with the particles but it would knock the particles around and wouldn't work great. So I'm giving up and finishing this without it.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 03, 2022, 04:35:52 AM
Eh, I finished it and submitted it to the Jam.

https://dkclassdesign.itch.io/entropy-chans-tea-time-adventure-beta

You can guess what I spent 3-4 hours on in Stage 2 just trying to get right. Overall I think I'll give myself a pat on the back for making that work. Even got the particles & their colliders working.


One thing that is super annoying is all the UI stuff looks wrong in the Itch build and even when I do a windows build compared to playing it in the editor. It's really frustrating spending all this time on the UI and having it be off in the final product. Don't like that the editor play mode isn't 100% representative.

Also I spent some good time on an excellent screen shake in stage 2 and it looks awesome in the editor in play mode. The Itch WebGL version...doesn't screen shake. Something about camera/UI is messed up in the transition so the script that shakes the camera around doesn't work...

I'll try to record a clip tomorrow to show the screen shake in the editor.


I'm pretty tired. Was up too late on this yesterday and second night in a row it's 1:30am+ and I realized I never even ate dinner. Glad I only spent two days on this, way too draining. But had some fun.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 03, 2022, 01:59:30 PM
Yeah, I feel like in update transform.position = vector2.right * time.deltatime * speed for my car should work? I was having issues with it. Idk.


just to check  youre doing +=, not just = right?

Thanks, that's a helpful start. I'm assuming Boxcasting is the same? 

My question goes back to your suggestion to raycast & turn for NPC movement. How do you know what direction to raycast the laser out since you won't know what direction the NPC is heading at any time?


yeah, a boxcast is 'firng' a box object instead of a thin line (so can do shit like calculate if somethng the same size as that box or smaller can fit through a gap for example.
although you dont see the code for it when you use a mouseover command, you define the movement of the ray / box in 3D space by providing the start point and end point and the direction to move / distance to check

Also as an extra cherry on top thing I'd like to save high scores since it's now a survival wave arcade game but I've never messed with that (player preferences, right?) and I'm not sure if I can figure it out in 30 mins or so.

I guess you got this working ok, as its pretty easy if you're only saving an int?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 03, 2022, 02:47:08 PM
Yeah, I feel like in update transform.position = vector2.right * time.deltatime * speed for my car should work? I was having issues with it. Idk.


just to check  youre doing +=, not just = right?

Uhhhhh....no  :lol 
That might explain it.

Quote
Thanks, that's a helpful start. I'm assuming Boxcasting is the same? 

My question goes back to your suggestion to raycast & turn for NPC movement. How do you know what direction to raycast the laser out since you won't know what direction the NPC is heading at any time?


yeah, a boxcast is 'firng' a box object instead of a thin line (so can do shit like calculate if somethng the same size as that box or smaller can fit through a gap for example.
although you dont see the code for it when you use a mouseover command, you define the movement of the ray / box in 3D space by providing the start point and end point and the direction to move / distance to check

Still confused on this. Because it's going to be a random spawned NPC heading in a random direction so there is no way to know which direction it is moving in at any time unless I'm missing something? I guess you just raycast 360 around the character and change direction if there's something (which is similar to what I did with using oncolliderenter).

Quote
Also as an extra cherry on top thing I'd like to save high scores since it's now a survival wave arcade game but I've never messed with that (player preferences, right?) and I'm not sure if I can figure it out in 30 mins or so.

I guess you got this working ok, as its pretty easy if you're only saving an int?

Nah, I had to cut this and give up on fixing the scaling UI issues because of the jam submission deadline and that I was tired af.

Before my next game I'm going to figure out how to save HS and fix the scaling UI issues between editor versions and build versions so I don't run into this at the last minute for the 3rd time when I'm out of time and can't fix it.

Ideally I think it's probably good to try to finish a day early so the last day can be spent trying to debug and fix all the build version headaches.

I still have no idea if it's possible to get screen shake working in the WebGL build.

This is the screen shake code I found online that I used. It works perfect in game playing in the editor. But it just doesn't do anything on the uploaded web version. It's really straight forward code and I wrote a version of it myself before finding this one that looked a little better. It just moves the camera a bit for 3 frames and returns. I'm guessing embedded web things don't let you move the camera transform or something? I haven't tried building a windows playable version to see if the screen shake works there.

Whenever I build a windows playable exe it always defaults to full screen only? I made this game in 640x480 resolution. I wish I knew how to make the exe run in a 640x480 window on boot.

Code: [Select]
public class ScreenShake : MonoBehaviour
{
    public static ScreenShake instance;
    Vector3 startPos;

    void Awake()
    {
        instance = this;
    }

    void Start()
    {
        startPos = transform.position;
    }

    IEnumerator Shake()
    {
        for (int i = 0; i < 3; i++)
        {
            transform.position = new Vector3(startPos.x + Random.Range(-0.1f, 0.1f), startPos.y + Random.Range(-0.1f, 0.1f), transform.position.z);
            yield return new WaitForSeconds(0.05f);
        }
        transform.position = startPos;
    }

    public void ShakeMe()
    {
        StartCoroutine(Shake());
    }

}
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 03, 2022, 08:44:52 PM
So I just started looking into build settings and for the windows build setting the resolution at windowed 800x600 fixes all the UI matching up with my build version play mode.

BUT, the screen shake still doesn't work. Like it'll jitter a second and then ten seconds later another jitter for a second instead of like a 10 second straight screen shake which is what happens when played in the build mode. Now that I'm done with work I'll see if I can record some clips showing the screen shake.

*edit*
Ok, yeah setting the resolution on 800x600 even fixes the UI in the Itch.io embed build. Honestly outside the missing screen shake everything looks working ("though camera positioning is slightly off so it's tough to see NPCs coming through the lower border on stage 2. Camera needs pulled back a bit.

https://dkclassdesign.itch.io/testingitchui

Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 03, 2022, 09:23:43 PM
So I've started to figure out why my screen shake doesn't work. When I tried to get a clip in Unity recorder, there was no shake but then I messed with the settings and changing the FPS from "constant" to "variable" brought back the screen shake.

Though it's weird that in the constant setting there's still a minor brief shake on start.


Spoilers for Stage 2 secret guy but here's two vids showing the difference:
spoiler (click to show/hide)

Shaking proper:
https://www.youtube.com/watch?v=lwLbGRumYfk

Release builds people can play with no shake:
https://www.youtube.com/watch?v=q1LqyRBe2Nk
[close]

I wonder if there's a way to change my release build framerate?
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 04, 2022, 02:50:04 AM
Been playing other people's games in the game jam and giving feedback. This is cool. I've never done a game jam before and everyone playing each other's games and commenting on them has a nice community feel. I think I'll try to do more of these.

Although I guess a lot of the community is on a discord and I'm still an old foggie who doesn't understand discord so oh well there.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 04, 2022, 12:21:08 PM
Figured out my screen shake issue but need help.

The issue isn't coming from the screen shake, that's why it still shakes for 3 frames on the constant framerate release build. The problem is the timer I'm using to keep calling that 3 frame screen shake. On variable framerate this lasts for like 15-20 seconds, on constant framerate this code lasts for like 1 second?

Did I screw up my timer to be constant across builds?

Quote
[SerializeField] private float GodzillaShake = 20f;
    private float elapsedTime = 0f;

 if (elapsedTime < GodzillaShake)
            {
                ScreenShake.instance.ShakeMe();
                elapsedTime += Time.deltaTime;

            }
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 04, 2022, 02:26:02 PM
Still confused on this. Because it's going to be a random spawned NPC heading in a random direction so there is no way to know which direction it is moving in at any time unless I'm missing something? I guess you just raycast 360 around the character and change direction if there's something (which is similar to what I did with using oncolliderenter).


Yeah, this is a vector maths thing; somethings facing direction (as a Vector3) is always target transform.position - current transform.position.
Also, if you're doing 'rotate towards a direction then move in that direction' type movement (rather than, like, a UFO sliding in any way it wants), transform.forward / vector3.forward will be the direction the things facing; knowing both of these makes it pretty easy to figure where somethings heading and check if anythings in the way


Been playing other people's games in the game jam and giving feedback. This is cool. I've never done a game jam before and everyone playing each other's games and commenting on them has a nice community feel. I think I'll try to do more of these.

yeah, for the most part the indie dev community are super welcoming and helpful; be a little wary of some dunning-kruger going on where someones watched some brackeys videos and browsed some stackexchanges (or whatever) and are confident telling you you're a shit coder because you use a singleton and singletons are bad (or whatever) but can't actually explain why.

Figured out my screen shake issue but need help.

The issue isn't coming from the screen shake, that's why it still shakes for 3 frames on the constant framerate release build. The problem is the timer I'm using to keep calling that 3 frame screen shake. On variable framerate this lasts for like 15-20 seconds, on constant framerate this code lasts for like 1 second?


I probably wouldn't do it that way... do you actually want a 3 frame screen shake?
Something like a screenshake, I probably wouldn't go below a tenth of a second or so, and thats still probably too subtle to pick up on without a big magnitude move?

TBH, for something like a camshake, I'd just grab one of the free tweening solutions off the asset store so I could use an easing equation (or if I REALLY had to write my own, I'd do something like:
Code: [Select]
public AnimationCurve easingCurve;
public WrapMode curveMode;
public float time = 0.1f;
Vector3 currentPos = transform.localPosition;
public Vector3 shakeMagnitude;

IEnumerator CamShakeThing()
{
     float i = 0;
     float rate = 1 / time;
     while (i < 1)
     {
          i += rate * Time.deltaTime;
          transform.localPosition = Vector3.Lerp(shakeMagnitude, currentPos , easingCurve.Evaluate(i));
          yield return 0;
     }
}

so I can draw in the 'bounciness' of the movement manually)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 04, 2022, 05:00:01 PM
I mean my screen shake in question looks pretty great in motion.

Your solution is good, especially the easing drop off curve. Though not sure if it gets around my issue which seems to stem not from the shake but from my timer in a separate script that calls the shake. So like I may have the same issue calling the shake you wrote.

I feel like I'm doing the timer wrong?

I should debug.log elapsed time to show so I can watch how it increases because something is fucking up if it's only running for a second yet it's ending up > 20f.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 04, 2022, 05:09:36 PM
Fwiw, there is a fake workaround where instead of calling SHAKE SCRIPT over and over each update for X amount of time on my timer in another script that is busted.

I can just make the variable in the shake script public for the length and set the length of a single call there.


Buuuut, for coding learning sake for future projects I'm gonna debug what is wrong with the timer I'm using in the other script that is giving me to completely different results in a constant vs variable framerate.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 04, 2022, 06:43:45 PM
Ok, this is an interesting discovery.

The elapsed time counter was fine in both constant/variable.


So I just did the backup of having the (for i = 0; i < 3; i++) be public with i = 0, i < timer, i++).
I changed the screen shake to wait .5f per call.

On constant framerate, where normally it would shake a second and then nothing, I kept increasing timer until it matches the Godzilla spawn length.

turns out it matches it exactly at 30
Godzilla spawn length is 15f using Invoke timer
WaitforSeconds at the end of each shake call is .5f

That...matches up. So it takes 30 calls of the FOR loop that moves the camera every 1/2 second to last exactly 15 seconds.

So the constant framerate version is the correct one?

But if I use variable framerate at 30 calls of shake the shake far outlasts the 15f spawn. So there's something really f'd up about the variable framerate which unfortunately is the framerate that the editor play mode plays at. Means the timings in the play mode of the Unity editor can be way off.

So basically still not really sure what is going on, but setting it this way at least fixed it for the release build. Now UI is fixed, Screen Shake is fixed. Time to learn how to save player high scores ints with player prefs.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 04, 2022, 07:47:28 PM
Saving high scores to playerprefs was pretty easy. Was worried about getting null kind of errors the first time I call the preferences when they don't exist before setting them but it just puts them as 0 with no error, so that's good.

UI = fixed
Screenshake = fixed
High Scores = implemented
Slight camera framing adjustments and glitches = fixed

Game is pretty much done for what it is. After the game jam is over and I can technically update the game page I'll update it with this new build. Some good lessons here going forward to get this stuff right initially.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 05, 2022, 03:33:17 PM
Another thing that's cool about joining a game jam with people who are around similar levels of experience is playing other games you run across cool things they do and you're like "I wanna learn how they do that"

Like NES Metroid/Megaman/CV style room transitions where the screen pauses and then scrolls to the new room and unpauses. Read up on it somewhat last night, sounds like there's various ways to implement room transitions with maybe the easiest to code being a timescale stop, camera LERP slide to the new room, timescale start. This game has a good example of smooth room transitions that I really liked:

https://dangohz.itch.io/i-think-i-am-lost

I found this link among the stuff I read last night about how games uses various camera styles to track:

https://www.gamedeveloper.com/design/scroll-back-the-theory-and-practice-of-cameras-in-side-scrollers

Extremely in-depth, long but informative. I like the idea for platformers of using Super Mario style re-position camera vertically each time you touch the ground from a jump. Also the way Super Mario 1 handles the camera tracking of Mario with a little leeway left/right is genius, would be fun to try to replicate that.

There's also this tool that does a lot of the camera scripting for you in 2d games and a lot of people recommend it. Maybe when it's on-sale, not feeling like paying $40 for a camera script I can write myself for the level of games I'm doing atm.

http://www.procamera2d.com/

A few really good games in the jam are fully mouse controlled. I haven't tried making anything with mouse controls yet outside menus. Adds a whole another possibility. Was very impressed by this Wariowario microgames take using mouse/touch controls:

https://hidey-hermit.itch.io/to-do-list

This is the best game I've tried in the Jam so far. Feels like a real game you'd see sold on Steam for a couple of bucks if it was longer. Pretty clever Fez/Echochrome kind of 2d/3d swap puzzle design:

https://igorfm.itch.io/stramb


Also one of the feedback items I got was to add a volume slider in my games, I looked it up and saw it takes all of 5 mins to add a slider in Unity UI and then one piece of code to script it to the overall audio listener of the camera. Will implement this next and in future projects. Feedback like this is really helpful for figuring out what basics to include in games going forward.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 05, 2022, 03:43:31 PM
I found this link among the stuff I read last night about how games uses various camera styles to track:

https://www.gamedeveloper.com/design/scroll-back-the-theory-and-practice-of-cameras-in-side-scrollers

Extremely in-depth, long but informative. I like the idea for platformers of using Super Mario style re-position camera vertically each time you touch the ground from a jump. Also the way Super Mario 1 handles the camera tracking of Mario with a little leeway left/right is genius, would be fun to try to replicate that.

I haven't written any camera script stuff, but how hard is a camera controller that just follows a target's transform position? I think the game manager script will be the toughest bit for me to learn how to make, but conceptually I understand it, so maybe not.

yeah, ez-mode cam control is just making your camera a child of your player object, intermediate is making an invisible object that moves to your player (or a relative position, if you wanted camera 'leading' like your top down shooter) that the camera focuses on, probably with a smoothdamp or lerp and probably in lateupdate after movements resolved so it doesnt seem jerky.
galaxy brain camera is some kind of box focus so you can move in a genre dependent / relevant area without camera movement until you really need it.

https://www.gamedeveloper.com/design/scroll-back-the-theory-and-practice-of-cameras-in-side-scrollers

some good stuff in there for ideas on camera moves.

 :rage
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 05, 2022, 03:52:16 PM
 :lol

I remember reading that post because the advice of putting the camera as a child, but I guess I didn't click the link!
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 05, 2022, 03:54:51 PM
You're right though, it is a really good article with a lot of research to back it up.
Title: Re: Do any of you code for your jobs?
Post by: Akala on May 05, 2022, 04:02:55 PM
good job doing all this in like a month Bebpo.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 05, 2022, 04:44:44 PM
Btw, I was thinking, for hit impact effects can you just use timescale? Like on collision with big sword strike to enemy -> turn timescale from 1.0 -> .7, wait for seconds (1), turn timescale from .7 -> 1.0? That way you hit the enemy with a big hit that kills them and game slowdowns for a second as the enemy explodes and particles fly and then resumes back to normal speed?

If that works then that seems like a really easy way to add some nice impact to things. Even like giant boss stomps you slow down timescale slightly on landing with a couple frame camera shake.

Also this would help me fake massive slowdown on like shmups if there's a lot going on and each thing was slowing down the timescale briefly.

good job doing all this in like a month Bebpo.

It's been like 2 months and a few days, but thanks. Yeah I feel like I've come a long way already. Excited to see where I'm at in one year. Goal is to try to stick with this for at least that long and make as much as I can in that time period and then re-evaluate.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 05, 2022, 04:52:52 PM
Btw, I was thinking, for hit impact effects can you just use timescale? Like on collision with big sword strike to enemy -> turn timescale from 1.0 -> .7, wait for seconds (1), turn timescale from .7 -> 1.0? That way you hit the enemy with a big hit that kills them and game slowdowns for a second as the enemy explodes and particles fly and then resumes back to normal speed?

Zelda style? Yeah, you can totally do that.
If you create your own Time function thats based on... timesincestartup? I think it is? you can have stuff moving at regular speed while everything else is in bullet time too... did we discuss this before? I have a feeling of deja vu talking to you about running realtime shit while the rest of the games timescale is in bullet time...
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 05, 2022, 07:12:03 PM
Btw, I was thinking, for hit impact effects can you just use timescale? Like on collision with big sword strike to enemy -> turn timescale from 1.0 -> .7, wait for seconds (1), turn timescale from .7 -> 1.0? That way you hit the enemy with a big hit that kills them and game slowdowns for a second as the enemy explodes and particles fly and then resumes back to normal speed?

Zelda style? Yeah, you can totally do that.
If you create your own Time function thats based on... timesincestartup? I think it is? you can have stuff moving at regular speed while everything else is in bullet time too... did we discuss this before? I have a feeling of deja vu talking to you about running realtime shit while the rest of the games timescale is in bullet time...

Maybe, I haven't actually messed with this stuff yet outside setting timescale to 0 for making a pause menu (which I could then still turn my sprite left & right while the game was paused  :lol)

Creating your own time function sounds hard af though and I can't think of a ton of situations where you'd only want other stuff to slow down but not your character. Even bullet time like Max Payne and stuff you slowdown as well. Just not sure if this is something I'll need anytime soon.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 06, 2022, 07:57:47 AM
its pretty easy, you just make two methods to replace time.deltatime calls, one that returns time.deltatime (which will scale) and the other that returns realtime.deltatime (which ignore scaling).

I've used it twice..? I think, one was when they introduced the new UI system all of the things like sliders were using time.deltatime so if you made a timescale=o pause button, all your UI interactions fucking broke  :lol

The other was in an RTS type game where I wanted you to be able to pause the game, but still move the camera around manually, and still using deltatime to smooth its movement out
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 06, 2022, 04:18:08 PM
its pretty easy, you just make two methods to replace time.deltatime calls, one that returns time.deltatime (which will scale) and the other that returns realtime.deltatime (which ignore scaling).

I've used it twice..? I think, one was when they introduced the new UI system all of the things like sliders were using time.deltatime so if you made a timescale=o pause button, all your UI interactions fucking broke  :lol

The other was in an RTS type game where I wanted you to be able to pause the game, but still move the camera around manually, and still using deltatime to smooth its movement out

Interesting uses. So when you timescale 0 you can’t move the camera around for your RTS example? Could you write an if statement in your camera saying if paused ignore timescale or something?

And UI sliders don’t work on timescale 0? That’s…good to know. I was planning on putting my volume control slider on my pause menu.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 12, 2022, 10:48:47 PM
Gonna get back to this soon. Had major surgery and been dealing with recovery this week so lost all interest in coding and game making. Gonna try to get motivated and back to it this weekend with something small.

Feels like with coding can develop an aversion when you haven't been doing it for a week or two. Like coding player movement all over again just feels like "ugh, work"

Btw, for my next small game I wanna have the movement just be jetpack bursts. I'm thinking this may be a situation to just use the RB 2d physics and addforce for movement since floaty is ok? I've never tried using addforce before. Basically I want to be controlling a character with a jetpack as they leap off a cliff and you can move them left/right as they are falling and hit space to give a jetpack boost burst back up in whichever direction you're falling. Addforce RB physics would make sense for this, right? Then I want to code a fuel meter that decreases when you boost and when out of boost you can't boost anymore and just fall left/right until you hit the bottom. That part should be fairly simple I think. Though I haven't tried making lifebars/bars yet but earlier in the thread the suggestion about tying the meter/percent to opacity sounds good.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on May 13, 2022, 01:32:23 AM
Jetpacks are fun.

Wanna design a small game together bebps? :thinking

I'm thinking small GB size.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on May 13, 2022, 02:38:11 AM
Jetpacks are fun.

Wanna design a small game together bebps? :thinking

I'm thinking small GB size.

Would love to! As long as you're thinking like finish it in a couple of weeks kind of thing, or at least a prototype with everything done outside needing more stages that can piecemeal add on. Not ready yet to commit to larger projects. Why don't you DM some ideas you're thinking of?

I'd enjoy making some small with other people, but I don't want to work with strangers and none of my friends are artists or programmers any more. I have one musician friend but he's retired, and the only artists I know are ex-gfs and I'm not hitting them up for art. So I don't really have anyone to work with.

I should probably look and see if they've restarted doing live game jams because would be fun to go and work with a team for a day.
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on May 13, 2022, 08:09:15 AM
Interesting uses. So when you timescale 0 you can’t move the camera around for your RTS example? Could you write an if statement in your camera saying if paused ignore timescale or something?

And UI sliders don’t work on timescale 0? That’s…good to know. I was planning on putting my volume control slider on my pause menu.

Nah, that was an old bug they fixed, UIs work fine now, but you can imagine you get pretty panicky when shit that works suddenly doesn't  :lol

Basically, anything that you use Time.deltatime on to smooth, if you go to timescale.0 means it returns a zero, so a
Code: [Select]
camera.transform.position += target.position * movespeed * time.deltatimetype call is going to always return 0, because you're now making time.delatime always return 0, and anything times 0 is always 0

Gonna get back to this soon. Had major surgery and been dealing with recovery this week so lost all interest in coding and game making. Gonna try to get motivated and back to it this weekend with something small.

Feels like with coding can develop an aversion when you haven't been doing it for a week or two. Like coding player movement all over again just feels like "ugh, work"

Sucks dude, glad you're feeling better.
If I take time off from coding, its not even a motivation thing, I legit forget actual coding and get back and look at stuff and go "what the fuck is a boolean?  ???"  :lol

For health bars / timer bars, easiest way to do them is to use the slider component from the UI, but just remove the handlebar, and send it currentvalue / maxvalue as the distance between 0 and 1 for the slider.

the only artists I know are ex-gfs and I'm not hitting them up for art. So I don't really have anyone to work with.

"You up?"
"Whyyyyy.....? ♥"
"I need a 9-slice chatbox pattern for a thing I'm playing around with"
"Hello?"
"THIS NUMBER HAS BLOCKED YOU"
Title: Re: Do any of you code for your jobs?
Post by: Tasty on May 13, 2022, 10:10:52 PM
Jetpacks are fun.

Wanna design a small game together bebps? :thinking

I'm thinking small GB size.

Would love to! As long as you're thinking like finish it in a couple of weeks kind of thing, or at least a prototype with everything done outside needing more stages that can piecemeal add on. Not ready yet to commit to larger projects. Why don't you DM some ideas you're thinking of?

I'd enjoy making some small with other people, but I don't want to work with strangers and none of my friends are artists or programmers any more. I have one musician friend but he's retired, and the only artists I know are ex-gfs and I'm not hitting them up for art. So I don't really have anyone to work with.

I should probably look and see if they've restarted doing live game jams because would be fun to go and work with a team for a day.

Hmm yeah a game jam would be cool, might be good to have some focus.

On the other hand would be cool to go wild and original.

I won't be able to commit for a few weeks, I'll give this some deep thought and get back to you... just don't let me forget. :P
Title: A few PM's later...
Post by: Tasty on June 02, 2022, 08:54:20 PM
In the grand tradition of announcing indie projects way before they should be,

Bebpo × Tasty 2D RPG Project (2023)

😎
Title: Re: Do any of you code for your jobs?
Post by: Uncle on June 03, 2022, 01:04:46 PM
are you going to be making the whole engine or use a version of RPG Maker? those are surprisingly full-featured and don't have to feel like RPG Maker games, you can customize nearly everything and even use scripting to make entirely different genres in that engine
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 03, 2022, 11:05:02 PM
are you going to be making the whole engine or use a version of RPG Maker? those are surprisingly full-featured and don't have to feel like RPG Maker games, you can customize nearly everything and even use scripting to make entirely different genres in that engine

It's a bit too early to say at the moment, but I'll check it out (it's been about... oh god... 15 years since I last looked at RPG Maker, outside Omori. It's early and it honestly hasn't been decided yet, but based on our combined backgrounds it'll either be using Unity, JavaScript, or GB Studio. The idea is to intentionally limit ourselves so we can actually ship something, and using a tool like RPG Maker could speed things along.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on June 04, 2022, 01:07:49 PM
it would take time to learn how to use RPG Maker effectively, but it would take a lot less time than developing your own full engine and debugging it at every turn  :P

but I know sometimes the desire is to completely "own" the project and have it be all your own work every step of the way
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 04, 2022, 03:45:51 PM
I know this is a cliche for indie / budding game devs to say, but getting a basic 2D engine up and running isn't really that hard anymore, even doing it with just programming. Libraries have gotten really good, and after you get past the basics then it's a lot more freeing to be able to go in and change whatever you want for the mechanics you want, instead of working within say RPG Maker's limitations. For something SNES level, the scale probably tips in RPG Maker's favor. But we're likely targeting the Gameboy or similar hardware (design-wise if not platform-wise).

The biggest pain in the ass, to my mind, isn't the engine, or the writing, or the design, or the sprites, or the music, or the scripting. It's the related tools you need to build, like the level editor. But pulling in a a library that uses a standardized level format could probably solve that pretty easily, I suppose.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on June 04, 2022, 04:08:16 PM
just remember the two main rules of game design:

- you have to put a bridge in there somewhere, and there has to be a secret under the bridge

- you have to put a waterfall in there somewhere, and there has to be a secret behind the waterfall
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 04, 2022, 04:49:25 PM
Absolutely. :rash
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 04, 2022, 04:53:46 PM
Also fwiw in the past I developed most of my unreleased projects using Game Maker (v4-7), Construct 2 and 3, and an obscure now-10-year old-abandonware HTML5 engine called "Akihabara JS."

I did release at least one thing using Construct 3 tho... (http://www.thebore.com/forum/index.php?topic=37206.msg2386057#msg2386057)
Title: Re: Do any of you code for your jobs?
Post by: Madrun Badrun on June 12, 2022, 09:02:05 AM
This thread has made me start looking into game dev for fun.  It seems like it is super easy to actually get into with tools these days compared to a decade ago. 
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on June 12, 2022, 09:07:56 AM
It's never been easier, there's never been more resources available for people who want to, and the tools have never been better or cheaper (there is pretty much an extremely high quality freeware version of anything you might choose to use)
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on June 12, 2022, 08:01:47 PM
This thread has made me start looking into game dev for fun.  It seems like it is super easy to actually get into with tools these days compared to a decade ago.

That's definitely my experience so far.

If you're interested, give it a shot! We get enough devs here we can have our own Bore jam going.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on June 12, 2022, 08:08:18 PM
you hadn't posted in this thread for a while bebpo

are you guys trying to be cagey about what you're working on like a real game company?  :P
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on June 12, 2022, 08:22:40 PM
Nah, I've been on a coding/design break. Will be getting back to it. Just taking care of other life stuff first.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 12, 2022, 09:34:36 PM
are you guys trying to be cagey about what you're working on like a real game company?  :P

Maybe Square, but unintentionally.  :shh
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 12, 2022, 09:39:38 PM
This thread has made me start looking into game dev for fun.  It seems like it is super easy to actually get into with tools these days compared to a decade ago. 

It's never been easier, there's never been more resources available for people who want to, and the tools have never been better or cheaper (there is pretty much an extremely high quality freeware version of anything you might choose to use)

I remember being turned onto Game Maker via Game Pro in like 2003. Things have seriously, seeeeeriously come a long ways.
Title: Re: Do any of you code for your jobs?
Post by: Uncle on June 12, 2022, 09:49:46 PM
game maker was so shitty back then  :lol

at the time it was barely graduated from (IIRC) having been a teaching tool a teacher made to teach a class about game creation?

the only way to include background music was to have it in midi format, and whatever engine they were using to play it caused the entire game to freeze for a few frames whenever the music looped  :doge
Title: Re: Do any of you code for your jobs?
Post by: Tasty on June 12, 2022, 09:56:43 PM
game maker was so shitty back then  :lol

at the time it was barely graduated from (IIRC) having been a teaching tool a teacher made to teach a class about game creation?

the only way to include background music was to have it in midi format, and whatever engine they were using to play it caused the entire game to freeze for a few frames whenever the music looped  :doge

100% right. The version I got was like 5, and v1-3 were the college versions. There was no scripting. I think it was nearly impossible to make a decent platformer, it seemed more tuned to top-down shooters and maybe RPGs. Still, I was totally captivated by that and later, "Dark Basic."

Man now I want to dig out my old Game Maker EXEs even though I don't have a way to play them myself. :lol
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on June 13, 2022, 03:59:48 AM
If any of y'all get the game making bug and want unity help, freeware tools or free assets let me know; I'd like to think I'm more useful than "Let's show you how to make a thing, do this, do this, do this, now you know, don't forget to like and subscribe (and don't add anything to this prototype because its made in a fucked up way)"
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on June 13, 2022, 04:46:54 PM
Yeah, you've been super helpful Sage!
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on July 11, 2022, 08:04:31 PM
So I tried getting back to coding today. Always figured a quick way to ease into it was to just make a volume slider for my Entropy-Chan game jam game. Should be a 5-15 min thing.

Since my game doesn't have a pause menu and there's not a great place on the map to put a volume slider I thought I'd add a pause menu first. But uhhhhh, I've completely forgotten everything I learned about coding in Unity having been away from it for two months  :cry

Like I found my gamemanager prefab and added a new canvas called PauseScreen and added a panel and a Resume button. Then I referenced my pause screen in my other projects and copied the code:

Quote
[SerializeField] GameObject pauseMenu;

   public void Resume1()
    {
        pauseMenu.SetActive(false);
    }

Like I'll get to the part that makes the pause menu appear in the first place and time scale stops the game next since that is a bit more complex having to grab a key command. The first thing I want to do is just have the pause menu active from the start and test the resume button to make sure it unpauses the game aka sets the pause screen false.

So I go into my Resume button and add the Resume script, turn PauseScreen into a prefab and add it in the serialized field. Put the script into the On Click() and have it call Resume.Resume1 on click.

But...it doesn't work (hitting the button does nothing and I can't remove the pause screen) and this feels like fuck I need to start from scratch and redo all the tutorials from scratch again to remember how to do this stuff properly :|

I looked at my other game with a pause screen and ...it's set up exactly the same way with the pause screen canvas as a prefab which goes into the serializedfield slot on the resume button and uses the resume.resume1 command to just setActive(false).

Any idea what I fucked up? I want to get a working pause menu that just has a resume button and below it a volume slider. I'll learn how to code the volume slider bit next if I can just figure out how to unpause and then pause all over again.

(https://i.imgur.com/oGKVkp9.jpg)
Title: Re: Do any of you code for your jobs?
Post by: chronovore on July 11, 2022, 10:38:10 PM
All I can say is: I hear you.

I started Blender tutorials and stepped away for a couple months. I'm as puzzled as a newborn child.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on July 11, 2022, 11:23:32 PM
All I can say is: I hear you.

I started Blender tutorials and stepped away for a couple months. I'm as puzzled as a newborn child.

Yeah, did not expect to forget this stuff so fast. Hoping it'll come back to me once I get some stuff going again.

May just need to run a couple of short early tutorials to get the gears in my brain clicking again.
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on July 12, 2022, 07:20:54 PM
So trying it today, it turns out I had nothing wrong. It was just bugged and it worked fine today  :mindblown


Made the pause menu with placeholders and it worked. Added a volume slider and spent way too much time trying to figure out how to adjust the AudioListener since like everyone result on google was about changing individual audiosources or audiomixer but I just wanted an overall volume control.

Turns out audiolistener is default static so you don't make [privateSerialized] private AudioListener Audio like I was trying.
Instead my entire code for my audio volume slider is literally:

Code: [Select]
public class VolumeSlider : MonoBehaviour
{
    public void Volume(float vol)
    {
        AudioListener.volume = vol;
    }
 
}

(https://i.imgur.com/v3WYFHNl.jpg)

Anyhow, it worked. I can hit the placeholder pause button in the upper right corner and it'll pause the game and bring up the pause screen and can adjust the overall volume and unpause. Since it's attached to the gamemanager static, it works in both stages.

Very, very, very slowly starting to refresh on how to do things.

Should probably clean up the pause screen visually. I couldn't remember how to make an image that said Volume so I just made a button that says Volume and does nothing on click for placeholder lazyiness.

And I should probably try to make a new stage for the game to remember how to make things. Honestly it feels like it's harder going back to an old project and adding things vs like just starting on an all new project fresh. Because with the former you have to remember how to do things whereas with the latter you can just start with a blank slate and do things one at a time looking up how to do each thing.

But yeah, overall this really sucks how much I've already forgotten. I'm like uhhh how do I make a top part of a script correctly to make a variable? How do I get getcomponent?  :gloomy

I guess if I can pull myself back into this I need to make sure I never take more than like a week or two off without doing some coding, just to keep it in the brain.



Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on July 13, 2022, 08:45:38 AM
But uhhhhh, I've completely forgotten everything I learned about coding in Unity having been away from it for two months  :cry

IKR?

It's more common than you think;
If I take time off from coding, its not even a motivation thing, I legit forget actual coding and get back and look at stuff and go "what the fuck is a boolean?  ???"  :lol

this is why we leave ourselves comments if it starts getting even remotely tricksy  :lol

Made the pause menu with placeholders and it worked. Added a volume slider and spent way too much time trying to figure out how to adjust the AudioListener since like everyone result on google was about changing individual audiosources or audiomixer but I just wanted an overall volume control.

Yeah, prebuilt UI components like sliders / text inputs / fill bars are nice and easy to use.

For a volume control, I have a couple of suggestions beyond just setting via slider;

also worth seperating music and sfx volumes out too, and letting people set them individually
Title: Re: Do any of you code for your jobs?
Post by: Tasty on July 16, 2022, 10:55:41 PM
Sooooo I got the bug and I got more ideas and I'm gonna proceed on my little RPG project on my own, with the hope to collab with Bebpo in the future. My skills will only be sharper after doing this project, even if I don't finish it I think. :)

Should I start my own thread? Or just post stuff here, either way is cool. Thanks for the inspiration bebps. :D
Title: Re: Do any of you code for your jobs?
Post by: Uncle on July 16, 2022, 11:08:25 PM
what kind of game are you thinking?

an RPG where your main character is a low level mage who languished in his studies and just became an enchanted hot dog vendor, he conjures up hot dogs and sells them on the street corner, and everyone likes his hot dogs and he doesn't really have much ambition

but then his condiment supplier is interrupted due to a war and tariffs and sanctions so he is forced to buy black market condiments, which have been sabotaged by an agent on the other side of the war who knows the royalty have a penchant for hot dogs

so his latest batch of hot dogs transform people into actual dogs, and he gets blamed for it and is forced to flee the city, and this is the impetus for his adventure, to uncover who has framed him and restore his good name

and you attack by flinging enchanted hot dogs at your enemies which are augmented by various spell effects

 :thinking
Title: Re: Do any of you code for your jobs?
Post by: Tasty on July 16, 2022, 11:27:07 PM
what kind of game are you thinking?

an RPG where your main character is a low level mage who languished in his studies and just became an enchanted hot dog vendor, he conjures up hot dogs and sells them on the street corner, and everyone likes his hot dogs and he doesn't really have much ambition

but then his condiment supplier is interrupted due to a war and tariffs and sanctions so he is forced to buy black market condiments, which have been sabotaged by an agent on the other side of the war who knows the royalty have a penchant for hot dogs

so his latest batch of hot dogs transform people into actual dogs, and he gets blamed for it and is forced to flee the city, and this is the impetus for his adventure, to uncover who has framed him and restore his good name

and you attack by flinging enchanted hot dogs at your enemies which are augmented by various spell effects

 :thinking

I don't have much at the moment but I'm diving into the battle system since I have that pretty fleshed out, and I think it's about as offbeat as your ideas. :P

It combines a turn-based system and first-person view with a cooldown timer and randomized menu items. I think my influences are Tetris and WarioWare.

I don't play a lot of JRPGs so there could be prior art, but I'm doing this in GB Studio (https://www.gbstudio.dev/) with the intention of writing it to actual physical cartridges and giving them to friends. :)
Title: Re: Do any of you code for your jobs?
Post by: Tasty on July 16, 2022, 11:28:51 PM
I do think the story will involve robots... and maybe a dog.

Maybe a robot dog. :thinking
Title: Re: Do any of you code for your jobs?
Post by: Uncle on July 17, 2022, 01:40:30 AM
first person RPG like wizardry GB?

https://www.youtube.com/watch?v=1hlJr_3Dh9s
Title: Re: Do any of you code for your jobs?
Post by: Tasty on July 17, 2022, 06:58:58 PM
first person RPG like wizardry GB?

https://www.youtube.com/watch?v=1hlJr_3Dh9s

Yup, except I haven't played that while I have played Earthbound Beginnings and Omori. :P
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on August 04, 2022, 05:22:12 PM
I started learning html for a work thing. I've never looked into it before.
I'm like what's a .css file? What's a </div>? etc...

Spent an hour reading some online starter tutorials and crapped out an empty page with an image, link, background and wrote a .css style file to put hover text over the image. Was kinda fun. Don't really need to learn anything beyond like very basic stuff like this for what I'm doing for this client. I'm not writing code, I just need to be able to read some basic stuff like where the img sources are in a website and the alt text.

But wouldn't mind spending a couple of weeks actually learning how this stuff works just to have that knowledge since I work with a lot of websites at work.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on August 04, 2022, 10:22:38 PM
I started learning html for a work thing. I've never looked into it before.
I'm like what's a .css file? What's a </div>? etc...

(https://c.tenor.com/s_H4VZA5CTIAAAAC/house-doctor.gif)
Title: Re: Do any of you code for your jobs?
Post by: Tasty on August 04, 2022, 10:24:09 PM
HTML is super easy.

Some people say CSS is hard but it's actually pretty easy.

JavaScript is just awesome. 8)
Title: Re: Do any of you code for your jobs?
Post by: Nintex on August 05, 2022, 01:25:13 PM
Vertically align your div in another div
WITHOUT FLEX BOX CHEATING  :bolo

Custom style your checkbox
without Javascript :bolo

Fix the Firefox font aliasing

No seriously, fix it.
Title: Re: Do any of you code for your jobs?
Post by: Tasty on August 05, 2022, 07:41:00 PM
Vertically align your div in another div
WITHOUT FLEX BOX CHEATING  :bolo

display: table-cell;
vertical-align: middle;

You can also use the CSS units vw and vh to vertically align a div you already know the height of.

I think. :thinking Grid Layout is the new hotness now anyways, flexbox is "old" (aka popularized 2011-2014).

Custom style your checkbox
without Javascript :bolo

Will try when I get home. CSS shadow parts, or even combining background with CSS shapes, could work...

Fix the Firefox font aliasing

No seriously, fix it.

Use Linux. :trollface
Title: Re: Do any of you code for your jobs?
Post by: Nintex on August 05, 2022, 07:43:42 PM
That's a good v-align hack you could also do top: 50%; and transform:translateY(-50%);


For Firefox

Code: [Select]
-moz-osx-font-smoothing: grayscale;
Code: [Select]
@-moz-document url-prefix() {
  body {
    font-weight: lighter !important;
  }
}

why font-rendering is forever broken in Firefox :idont
Title: Re: Do any of you code for your jobs?
Post by: therealdeal on August 07, 2022, 05:54:40 PM
Yeah I prefer grid to flex box but let’s be real for what I do it’s mostly “throw bootstrap at it”
Title: Re: Do any of you code for your jobs?
Post by: GreatSageEqualOfHeaven on September 08, 2022, 01:40:21 PM
Bumping for a couple of Good Deals on Humble if Bepbos got that itch again

https://www.humblebundle.com/software/unity-art-software

https://www.humblebundle.com/software/unity-tools-software
Title: Re: Do any of you code for your jobs?
Post by: Bebpo on September 08, 2022, 02:37:43 PM
Yeah it’s tempting. Some of the ones I looked at on the store are in those.

But I definitely regret the ~$300 I dropped during the Unity sale on tons of stuff I’ll probably never end up using even if I get back to making things. At my level of skill I just like hands on making all the stuff so I know how it works.