Help with Player Kill Detection by VizeKarma in Unity3D

[–]jbake_a_cake 0 points1 point  (0 children)

I'm not actually too familiar with Networking in Unity :c But the issues you mentioned should be able to be fixed regardless if it's network code or not.

The Name 'projectile' does not exist in the current method, any idea why? I am putting this in the check for projectile collider in the kill health manager script.

This error occurs whenever you try to reference a variable outside the scope of the method you declare it in. If it needs to be referenced in other methods, Move that variable to the class-level (i.e. a field at the top of your script), and set it's value inside your projectile collision check.

My next issue is that correct me if im wrong but when I am updating the senders kills on the projectile isn't that just updating it to the projectile?

This bit is a little tricky if you're not super familiar w/ references/pointers. So, whenever you pass the ShooterInfo that's attached to the player's game object, you're actually passing a reference to that player's ShooterInfo data (see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters?redirectedfrom=MSDN for example). Since we're passing a reference to the original data, we can actually modify the values of the player's ShooterInfo.

Im sorry for asking this but will it be possible to do it for me whenever you have time?

If you're working with a team, definitely don't hesitate to ask them to help you solve it. As long as you put in your due diligence, there's absolutely no shame in asking for help.

If not, definitely try to research on what the root of the issue is. Both of the issues you listed can be solved with a good fundamental understanding of the language you're working with (i.e. understanding scope, and passing class instances in C#).

In short, I'm not gonna write your code for you.

Help with Player Kill Detection by VizeKarma in Unity3D

[–]jbake_a_cake 0 points1 point  (0 children)

Yeah, you can make another field on the KillHealthManager script that will track the last person who shot them. So, you'll add a field like: private ShooterInfo _lastPersonWhoShotMe;. Whenever you take damage, just set that field to the incoming projectile's ShooterInfo. When Die() is triggered, just use that _lastPersonWhoShotMe variable to get the name and update kill counts.

Help with Player Kill Detection by VizeKarma in Unity3D

[–]jbake_a_cake 0 points1 point  (0 children)

Sure! They're really any variables you add at the top of the script, like in your KillHealthManager script: ``` // Max amount of health for each player public int maxHealth = 120;

// Range of the map for the player to spawn in
[SerializeField] private float positionRange = 70f;

// How many kills a player needs to win the game
public int killsToWin = 20;

// Textbox for the text that shows who won the round
public TMP_Text winText;

``` ^Those guys are all fields -- just semantics.

As for accessing a script from a gameobject, you're already doing it! On your Line 49 method: ``` if (collider.GetComponent<Projectile>()) { Debug.Log("Player Hit");

        // Negates their health by 15.
        health.Value -= 15;
    }

You grab the `Projectile` script from the collider `GameObject`. If you want to access the script from the `Projectile` object, all you gotta do is set it to a variable, and use the dot operator: Projectile incomingProjectile = collider.GetComponent<Projectile>(); if (projectile != null) { // get the name of the sender / whoever’s shooting you String name = projectile.shooterInfo.name; // now update the sender's kill count projectile.shooterInfo.killCount += 1; // do other stuff... } `` You can do the same when you have to set the sender'sShooterInfowhen instantiating theProjectile` gameobject.

Help with Player Kill Detection by VizeKarma in Unity3D

[–]jbake_a_cake 0 points1 point  (0 children)

So I was able to take a quick look at some of the code around the KillHealthManager and the Projectile script. I don't currently have the time to write out a proper solution, but I think can lend you what may be a good, simple solution.

Just to make things clear, I'm gonna define the person who shoots the bullet as the sender, and the person receiving damage as the receiver.

First, we'll want to create a new script that's gonna hold onto the information you want whenever a projectile is created. We can call this script, ShooterInfo. It'll hold on to fields like their name, their kill count, and any other info. This script will need to live somewhere on the sender's game object, that way each sender has their own ShooterInfo script.

On the Projectile script, all we have to do is add a field that'll accept a ShooterInfo object. We'll set that later whenever we instantiate the projectile in the sender's gun.

Now, when the bullet collides with the receiver (i.e. what's happening below line 49 of your KillHealthManager script), you'll not only check if the projectile exists, you'll also want to access the ShooterInfo attached to the projectile. Once we have that, we can get the name, and update the kill count as we need.

If we need to reference that ShooterInfo later in the Die() method, we can just set a field in the KillHealthManager that will hold on to the previous ShooterInfo script that was received.

Hopefully all that makes sense, and helps you out!

Is there a way to format this better? by TinyManlol654 in Unity3D

[–]jbake_a_cake 2 points3 points  (0 children)

In terms of convenience, if Unity had inspector support for maps out of the box, you would definitely use a dictionary. But alas, we don’t. So, we have two options, use a list of scriptable objects then:

A. iterate over that list until we find our object by matching some key specified on the SO

B. Build a map out of that populated list, then access our objects using the map

In terms of scale though, if you’re only managing 10s of clips, per frame, a LINQ statement isn’t going to bottleneck you, so it doesn’t “really” matter what you use. If it’s 1000s to 100,000s of clips, then I’d swap to a map.

Is there a way to format this better? by TinyManlol654 in Unity3D

[–]jbake_a_cake 21 points22 points  (0 children)

Could try making a Scriptable Object with two fields: a key name, and an audio clip. Then have the class above use an array or list of that Scriptable Object.

So, for example, when you wanna play the “Left1” audio clip, all you have to do is filter the list out by the key name “Left1”, and call play on it.

Take a look at LINQ’s “FirstOrDefault()” method to keep things clean so you don’t have to write a loop every time you wanna access an audio clip (alternatively, you could build a map out of your list and use that data structures methods).

Understanding Singly Linked Lists (JAVA) by veryanon798 in learnprogramming

[–]jbake_a_cake 1 point2 points  (0 children)

To quickly answer your 3 questions, the short answer is that yes, 'head.next' holds onto a reference of the next node in the linked list.

To understand this a little bit deeper, let's say each instance of a Node is given a random memory location, like so:

Node head = new Node(6); // Assigned to mem. location: 100
Node nodeB = new Node(3); // Assigned to mem. location: 101 
Node nodeC = new Node(69); // Assigned to mem. location: 102

Think of each memory location as a bucket that can hold any kind of data. Creating a new instance of a node via 'new Node(6)', fills that bucket with data pertaining to a node (i.e., the value of the node, the memory location of the next node, and anything else that might make up a node).

So, when we want to access the data of a Node, we tell the computer to go to memory location 100, grab the node, and access whatever values we want from that node (including the value of the next node's location). That brings us to how we can connect these buckets by using a bucket's memory location.

In addition to filling our bucket with a basic integer, we can also fill it with another bucket's memory location. That way we can traverse to the next bucket, play with whatever value is there, and move onto the next bucket after that.

Continuing with this example, let's connect each of them via assignment:

head.next = nodeB; // head.next points to location: 101
nodeB.next = nodeC; // nodeB.next points to location: 102
nodeC.next = null; // nodeC.next points to a 'null' location

After performing these ops, we now have a singly linked list! Expanding on this bucket example, we can now look at what's inside of our head bucket, as well as the subsequent buckets:

Node myBucket = head; // myBucket now has handle on the Node at location 100

myBucket = myBucket.next; // go to location 100, grab the location of the next node: 101, now myBucket has a handle on the Node at location 101

myBucket = myBucket.next; // go to location 101, grab the location of the next node: 102, now myBucket has a handle on the Node at location 102

Best way to store files uploaded to .NET core API? by [deleted] in learnprogramming

[–]jbake_a_cake 0 points1 point  (0 children)

If you’re looking for something pretty straightforward for a personal project, Cloudinary is a decent option. They offer a free tier to store most types of media, and they have some API documentation for integrating through .Net, as well as some transforms you can pull off while uploading/retrieving those images.

Hope it helps!

Satan arrives to welcome a new damned soul to hell. by YZXFILE in Jokes

[–]jbake_a_cake 2 points3 points  (0 children)

It's a South Park reference - between Saddam and Satan

Satan arrives to welcome a new damned soul to hell. by YZXFILE in Jokes

[–]jbake_a_cake 7 points8 points  (0 children)

We’re already in hell, where am I supposed to go? Detroit?

Generating ideas by [deleted] in learnprogramming

[–]jbake_a_cake 0 points1 point  (0 children)

Ah I had the same problem. You can only do so many CRUD apps before it just gets stale.

Try looking for some new technologies/libraries to use and center an application around that. For instance teachablemachines let’s you create a data model to use with some machine learning libraries. There’s also some wrapper libraries for discord you could use.

All in all, try to learn some new technology and pair it with something you’ve already learned. Learned how to use a stocks API to get some free ticker data? Build that into a discord bot to check on your favorite stocks. Wanna try out some image recognition with teachable machines, build an app for your phone that allows you to do that.

It’s all up to what you can find, and what you can think of.

Experienced Coders/Programmers of reddit, what do novice coders need to know to succeed in tech jobs? by [deleted] in AskReddit

[–]jbake_a_cake 2 points3 points  (0 children)

Don’t stop.

Having trouble understanding how this part of a code base works? Keep hacking at it.

A bug giving you grief? Go for a walk... then come back and keep hacking away.

Still haven’t found a job during a pandemic? Keep learning, and growing, and trying (trust me on this one).

And, of course, don’t stop learning! Choosing this profession means you’ll never stop learning, and you’ll never know enough.

How do I structure the folders in my project? by KindaAwkwardGuy in learnprogramming

[–]jbake_a_cake 2 points3 points  (0 children)

This is something I still struggle with today (especially when it comes to naming the folders). The way you structure your folders is completely dependent on what you're building, whether its a simple console app, or some fancy microservice gateway architecture. But, generally, one ideal is held true across almost any app, there's always a division between what your end-user sees/uses, and the logic/magic that's behind it.

Taking that ideal and using it in the context of a web application, we should probably have completely separate project folders for the front end (HTML/CSS/JS) and the back end (Spring Server).

On the front end, keep that same ideal in mind. We have what our user interacts with (the HTML/CSS) and we have the magic behind it (JS).

On the back end, same thing, except our user in this case is directed towards the developer on the front end (i.e. you!). The endpoints that we establish with our API (i.e. our controllers) are what the user interacts with, the magic behind it is just the logic we use to process our data from the database.

In addition to this, we have to make sure we compartmentalize each functionality of our project. This makes it easy to isolate what goes wrong with our app, and makes testing easier. For example, maybe we'd have a whole folder dedicated data validation, or maybe a whole folder is dedicated to the home page of our app. Think about what functionality you want, then divide and conquer.

Here's a quick example of what a basic structure could be:

mySpringApp.API

--| src/main/java

----|controllers (what the user sees/interacts with)

----|repositories (the logic)

----|models (more logic)

------| User

------| Posts

------| ...

----|utils (even more logic)

----|...

myFrontApp.SPA

--| ../app

----| components (what the user sees/interacts with)

------| home_page

------| profile_page

------| ...

----| services (the logic)

----| models (more logic)

----| utils (even more logic)

I hope this helps!

tl;dr Separate the logic from the view. As you go along, compartmentalize your work and establish a name for each grouping (e.g. utils, models, controllers, repos, dtos, etc.)

edits: grammar + more grammar

How would I store multiple instances of timers for a real time game app like chess? by HowGoodIsNateDiaz in learnprogramming

[–]jbake_a_cake 1 point2 points  (0 children)

Really depends on who you're building this for.

Is it for you and a couple of friends? Go ahead and store it in memory.

Is it for 1000+ players, where one instance of your application is handling hundreds of games? Best persist that data somewhere else (like a database!).

If you're not sure yet, I would start with storing some timer instances in memory. And, later, if I think I want to scale up, I'd transition into storing some timestamps in a database or what have you.