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

0 Members and 1 Guest are viewing this topic.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #360 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


Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #361 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??


Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #362 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!");
     
    }


}

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #363 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));
     
 
    }

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #364 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #365 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]

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #366 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.


Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #367 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #368 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.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #369 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. 

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #370 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.
« Last Edit: May 01, 2022, 10:58:51 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #371 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,

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #372 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #373 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
« Last Edit: May 02, 2022, 06:26:51 AM by Bebpo »

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #374 on: May 02, 2022, 07:02:31 AM »


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

Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #375 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
Uncle

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #376 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.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #377 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

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #378 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!

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #379 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

Nintex

  • Finish the Fight
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #380 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."
🤴

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #381 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?

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #382 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #383 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #384 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #385 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #386 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.
« Last Edit: May 03, 2022, 05:29:40 AM by Bebpo »

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #387 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?

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #388 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());
    }

}

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #389 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

« Last Edit: May 03, 2022, 09:00:48 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #390 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:


Release builds people can play with no shake:

[close]

I wonder if there's a way to change my release build framerate?
« Last Edit: May 03, 2022, 09:39:26 PM by Bebpo »

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #391 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #392 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;

            }

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #393 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)

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #394 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #395 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #396 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #397 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #398 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.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #399 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

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #400 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!

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #401 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.

Akala

  • Easy Victor
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #402 on: May 05, 2022, 04:02:55 PM »
good job doing all this in like a month Bebpo.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #403 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.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #404 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...

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #405 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.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #406 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

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #407 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #408 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.

Tasty

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #409 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.

Bebpo

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #410 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.

GreatSageEqualOfHeaven

  • Dumbass Monkey
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #411 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"

Tasty

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #412 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

Tasty

  • Senior Member
A few PM's later...
« Reply #413 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)

😎

Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #414 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
Uncle

Tasty

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #415 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.

Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #416 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
Uncle

Tasty

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #417 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.

Uncle

  • Have You Ever
  • Senior Member
Re: Do any of you code for your jobs?
« Reply #418 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
Uncle

Tasty

  • Senior Member
Re: Do any of you code for your jobs?
« Reply #419 on: June 04, 2022, 04:49:25 PM »
Absolutely. :rash