#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 448 of 1

teal viper
#

It's about size, not length

cedar bone
#

yeah im aware

teal viper
#

You can compress or make lower res video longer

willow scroll
#

51.2MB. You won't be able to send it even with Nitro

cedar bone
#

any tools to compress?

willow scroll
#

Your dimensions are 3360x2100

teal viper
#

Yeah, the main issue is the crazy resolution

#

if you record with OBS, you can control the video resolution

willow scroll
cedar bone
#

thank u!

crisp token
#

sorry, I don't understand what saving the value has to do with

willow scroll
#
public class Animal { }

public class Dog : Animal
{
    public int noIdea;
}
#

In this case, you can create a Animal as a Dog:

Animal animal = new Dog();
#

This is an Animal now, but you can freely convert back to a Dog and its values will be saved:

if (animal is Dog dog)
    // ...
median halo
#

RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, 1.0f, grNd); anything wrong with this? it isnt working

willow scroll
#

Maybe, a better example would be with a constructor

public class Dog : Animal
{
    public int noIdea;

    public Dog(int noIdea)
    {
        this.noIdea = noIdea;
    }
}
crisp token
#

I understand downcasting and upcasting for the most part

willow scroll
#
if (animal is Dog dog)
    dog.noIdea // the chosen value
willow scroll
#

Everything can be casted to object

#

And its actual type will be derived from it

crisp token
#

so when I assign the object into the object list, which holds certain enum types, the object being assigned is automatically casted to the enum Type if possible?

willow scroll
#

Everything can be explicitly casted to object by either using (YourType)@object or @object as YourType

crisp token
willow scroll
crisp token
#

lmao no no, thats not what i mean

teal viper
crisp token
#

What i think ChatGPT said is because the Enum.Parse method goes like this: Enum.Parse(Enum Type, string, bool), it takes the Enum Type you put in and uses that

#

but it returns an object because Enum is a special class or something

teal viper
#

To be fair, I don't understand what the question is either. It feels like the conversation is going in meaningless circles.

crisp token
#

once i can test this thing out, and if it works, ill ask the question again

#

no use trying to solve an equation with two unknowns

teal viper
crisp token
#

im trying to understand the api but its going over my head

teal viper
#

What part of it?

topaz mortar
#

Not sure if coding question, but doesn't seem to belong anywhere else either.
How do I make my bunnies go up/down a little bit, so they don't all overlap exactly?

crisp token
topaz mortar
#

Would it be a bad idea to just disable gravity for monsters? I don't think I will ever use it in my game

#

Or can you disable gravity for the entire game somehow?

vernal bone
#

or spawn them at random height, if it's not critical for your gameplay

topaz mortar
#

but then gravity just pulls them down again (I disabled gravity and did it like that)

vernal bone
#

why gravity will pull them down if it is disabled?

topaz mortar
#

no it works now, just not sure if disabling gravity like that is a good idea

vernal bone
#

don't see why not tbf, but i'm not that proficient in unity for now.

#

you can look into charactercontroller i guess, but i never touched that

severe forge
#

Could anyone guide me as to what could be happening here? When I create a host after the first time, I'm getting duplicate connection calls of my own client.

#

I'm using relay to create a host

topaz mortar
#

Why is this not hitting? The Transform y is set to -3.2
When I set it to -3.4 it does hit

RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, range, layerMask);
Debug.DrawRay(startPosition, direction * range, Color.red);```
#

ew my raycast doesn't use startPosition oopsie

warm raptor
#

Why would it be laggy ?!

meager gust
#

you'll also be generating loads of garbage that needs to be cleaned up

warm raptor
warm raptor
cedar bone
eternal needle
cedar bone
#

but yeah ur right

#

mb

warm raptor
meager gust
#

what do you mean parsing manually?

#

can you show me an example

warm raptor
eternal needle
meager gust
#

yeah... thats really bad.
again, you don't want to use strings when serializing real time data for video games.

warm raptor
# meager gust can you show me an example
int Index3 = queuedMessage.IndexOf('X');
                            int Index4 = queuedMessage.IndexOf('Y');
                            int Index5 = queuedMessage.IndexOf('Z');
                            int Index6 = queuedMessage.IndexOf('!');
                            int Index7 = queuedMessage.IndexOf('R');
                            int Index8 = queuedMessage.IndexOf("IsAiming");
                            int Index9 = queuedMessage.IndexOf("IsWalking");
                            int Index10 = queuedMessage.IndexOf("IsRunning");
                            int Index11 = queuedMessage.IndexOf("IsHigh");
                            int Index12 = queuedMessage.IndexOf("IsReloading");
                            int Index13 = queuedMessage.IndexOf("H?");
                            int Index14 = queuedMessage.IndexOf("T?");
                            

                            coordX = queuedMessage.Substring(Index3 + 1, Index4 - Index3 - 1);
                            coordY = queuedMessage.Substring(Index4 + 1, Index5 - Index4 - 1);
                            coordZ = queuedMessage.Substring(Index5 + 1, Index6 - Index5 - 1);
                            rotY = queuedMessage.Substring(Index6 + 1, Index7 - Index6 - 1);
                            IsAiming = queuedMessage.Substring(Index8+8,1);
                            IsWalking = queuedMessage.Substring(Index9+9,1);
                            IsRunning = queuedMessage.Substring(Index10+9,1);
                            IsHigh = queuedMessage.Substring(Index11+6,1);
                            IsReloading = queuedMessage.Substring(Index12+11,1);
                            LivingState = queuedMessage.Substring(Index13+2,1);
                            CurrentTeam = queuedMessage.Substring(Index14+2,1);
meager gust
#

you're causing future you a lot of issues that you're going to need to clean up in the future. this also will not scale at all as player count increases

#

at the very least just serialize raw binary data. like pointer cast your values into a byte* and memcpy that into your buffer or something

teal viper
meager gust
#

ideally you'll want something automated, so you're not doing all of this by hand and creating human error...

#

you'll generally not want to create any heap garbage at all for network messages

cedar bone
#

Perlin noise go brrr

warm raptor
#

I'm sry but I don't really understand what you mean ( because m'y english is not the best) , because with my Websocket I'm obliged to send my messages in the form of a string

meager gust
#

you can't send a byte array?

warm raptor
#

like just 0 and 1 ?

meager gust
#

no

#

you should probably do some research into this if you're dead set on writing your own network code...

#

or just use one of the pre-exising network libraries like mirror

teal viper
#

Your networking api should probably at the very least be able to send it as char arrays, which is basically the same as a byte array

warm raptor
eternal needle
#

so you see now why literally everyone has told you what you're doing wont work? and that we arent waiting to be proven wrong

meager gust
#

I can assure you that using mirror is much simpler than writing your own netcode API

#

a middle schooler could figure out mirror

teal viper
#

Yeah, I'd avoid implementing your own solution if you don't even know what bytes are

warm raptor
meager gust
#

if thats how you want to do it, then nobodies going to stop you. I'm just warning you that it's a waste of time for anything remotely serious

teal viper
#

Well, if it works good enough for you, then what is the question?

warm raptor
meager gust
#

your performance will tank. I guarantee it.

teal viper
#

Which basically leaves less budget for other features in your game.

meager gust
#

among other things, your method also doesn't factor in interpolation. so you'll need to be sending packets at the monitor's refresh rate for it to appear smooth

#

it also uses TCP which uses head of line blocking... which will cause visual jitter and freezing when packet loss occurs as packet transmission will completely halt until all of the missing packets are resent and ACK'd

#

unfortunately multiplayer isn't as simple as just sending data back and forth.

warm raptor
warm raptor
meager gust
#

if you truly want to learn netcode, those links will give you an introduction
you're missing a lot of basic pre-requisites though, like understanding what a byte array is... you need a lot of work in other areas

#

or just use mirror like a sane person.

teal viper
#

I'm sure you've been told not to start with a multiplayer project when you first started learning gamedev or unity and you probably ignored these warnings.

warm raptor
# teal viper I'm sure you've been told not to start with a multiplayer project when you first...

you're right, everyone advised me against making a multiplayer by myself, but I know insinde of me that if I'd never made one, I'd never have continued developing video games, so even if my project is far from perfect and the most optimized, it's still allowed me to learn a gigantic amount of information, it's very far from being my first programming project, but it's the one that's really going to allow me to say that I'm into programming.

#

that's said I'm gonna learn what's a byte array, thx for your help !

meager gust
#

like dlich said: if your way works, you can keep doing it that way

#

my comments are merely suggestions.

warm raptor
warm raptor
eternal needle
# warm raptor your right, but finding out if I can improve my code can only be a good thing.

imo, if you dont have a concrete plan for the game so far then you should heavily reconsider this whole sunk cost. A concrete plan meaning stuff like how many players you want to support, the actual gameplay planned out, and really just the overall architecture. You're gonna either have to rewrite this system or settle for what you have with the issues that were pointed out above.
I even tried first making a multiplayer game. i rewrote systems so many times, which all was useless because i realized a new feature would require changes. I chose to abandon it to make a singleplayer game and i have around 9 years experience in CS.

meager gust
#

yes, the whole string parsing stuff is just a fraction of the issue here.
manually serializing the data will slow production down to a crawl, especially when you start wanting to change things and now you're wondering why your data is coming in corrupted (because of human error ๐Ÿ˜‰ )

eternal needle
#

It could even be a nice project just for friends to see, but remember that projects have to end eventually. If you aim to upload the game to steam, and it has any lag issues, everyone is refunding it.

warm raptor
meager gust
#

you just tag it with an attribute, and it does everything automatically. synchronizing the state should be as simple as possible during actual game development. you shouldn't be trying to write a netcode framework and a game at the same time. if that makes sense. you should be building your game on top of an already existing netcode platform either created by you or someone else.

lunar lark
#

anyone here to help me?

#

Im having trouble w something

#

!cs

eternal falconBOT
fickle plume
#

@lunar lark You've been pointed to #854851968446365696 already on how to ask a question properly. And don't spam bot commands randomly.

lunar lark
meager gust
#

lol

#

wrong answer

fickle plume
#

@lunar lark Help with what. You didn't ask any question yet.

lunar lark
#

So I've made an ingame saving system like the one in hollowknight but Im having trouble with something. My enemies despawn when you enter and that's alright until you want to get out the save point, I want the enemies to respawn after exiting the save point but it doesnt. Sorry for bad englsh.

CLASS1 Enemic:

public void PlayerEnterAltar()
{
Enemic[] enemies = FindObjectsOfType<Enemic>();
foreach (Enemic enemy in enemies)
{
enemy.MortSLS = false;
enemy.IsDead = false;
enemy.CurrentMoveSpeed = enemy.moveSpeed; // Guarda la velocitat actual
enemy.moveSpeed = 0f;
enemy.gameObject.SetActive(false);
}
}

public void PlayerExitAltar ()
{
Debug.Log("Enemics tornen a apareixer");
Enemic[] enemies = FindObjectsOfType<Enemic>();
foreach (Enemic enemy in enemies)
{
Debug.Log("Enemics tornen a apareixer");
enemy.gameObject.SetActive(true);
enemy.MortSLS = false;
enemy.currentHealth = enemy.maxHealth;
enemy.moveSpeed = enemy.CurrentMoveSpeed;
}
}

CLASS 2 Player (where PlayerExitAltar and PlayerEnterAltar are called FILE)

fickle plume
lunar lark
#

Why all these rules

warm raptor
meager gust
lunar lark
#

womp womp

meager gust
fickle plume
#

!mute 731473620949532704 1d I guess try again next time properly instead of wasting people's time.

eternal falconBOT
#

dynoSuccess martiiic was muted.

warm raptor
# meager gust I'm not talking about p2p, but that's okay. you can do it however you like ๐Ÿ™‚

Oh I might miss understand but what I wanted to Say is that I'm still young and I might not make game my whole life so I think that it's better to learn how to make networking from scratch instead of using things that already exist because it would allow me to use this knowledge other where than juste in Unity game, and I think that this is the kind of things that might help me find a job later

eager spindle
#

in the real world you build a REST API as your server backend so you can get information from the server.
E.g. for those apps that track stock markets you can then send a GET request getting the latest financial data

warm raptor
teal viper
#

When you have proper understanding of the underlying systems, you can implement your own.

warm raptor
#

and I will have time to improve, this is only my 2 project with my homemade networking

teal viper
#

I don't see why having a server prevents you from using a library

eager spindle
#

you did not need to buy a vps but wtv

#

you can test on your own pc or use AWS free tier

teal viper
#

you would need a server regardless of whether you use a library or not

warm raptor
teal viper
#

No..?

#

They're frameworks for networking. Most of them support a wide range of networking styles, including p2p and server based.

#

It's just that some of the companies that provide them also happen to provide hosting services.

#

That just shows how little effort you put into researching the topic

warm raptor
teal viper
#

That's why you research first. To not get lost

#

And yes, it's a very complex topic, which is why no one recommends you start with it as a beginner

tender wharf
#

Any clue on why the signal isn't running GameController.StartRace()?

half egret
#

You need to emit the signal in the timeline

#

Oh hrm

#

Is "CinematicEnd" an inbuilt signal or one you made?

tender wharf
#

I made it

half egret
#

You need a signal emitter track IIRC in the timeline

#

And then move it to the end of the timeline

tender wharf
#

yeah, I've got you

warm raptor
# teal viper And yes, it's a very complex topic, which is why no one recommends you start wit...

I don't know why, instead of helping me, people just keep telling me that I won't make it on my own... Anyway, it doesn't matter, I've always been alone and I've always managed on my own, so with enough hard work, I'll eventually get there. I know they say there's no point in reinventing the wheel, but honestly, maybe what I'm doing is garbage, unoptimized, ugly, and burns your eyes when you look at my code. But I know that doing things by myself is the only thing that motivates me. I know you think I'm stupid and that I should refer to existing libraries, but I know that's not what I enjoy. If we want to have a good game in the end, the most important thing is to have enjoyed the work we've done. I have my own way of working that people often don't like because they think it's not clean enough or professional enough, sure, but unlike others, I see my projects through to the end and refine and rework them until they're good. My network might not be perfect, but at least I can connect players to different games based on the ID they enter, make sure they can move around and others can see the animations they make, ensure the character can shoot and everyone can see the shots, allow players to switch teams and everyone to access the list of different teams, and let players shoot and kill other players while my server detects who killed whom. I've also made 90% of the models myself, including the characters and their animations. I might be a lousy beginner, but at least I have a functional project that's making progress!

teal viper
warm raptor
timber comet
tender wharf
#

sure it works for you but how do you expect them to work with this

teal viper
ionic zephyr
#

How can I make a system in which objects receive more or less damage depending on the weapon/tool you are holding? is it with Enums???

vital tangle
#

Hello

teal viper
ionic zephyr
vital tangle
#

I wrote this class in C++

it uses invoked System class from C# to call the binary reader and writer

I am going to do a native call to the methods from my unity C# code

here is the source code

#
#include <string.h>
#include <msclr\marshal_cppstd.h>
#include "VM.h"

using namespace msclr::interop;

VM::VM(System::IO::BinaryWriter^ writer, System::IO::BinaryReader^ reader)
{
    VM::reader = reader;

    VM::writer = writer;
};

void VM::Shift_Half_Unsigned_Address_F()
{
    System::UInt16 EF = VM::reader->ReadUInt16() * 32;

    System::UInt16 EB = VM::reader->ReadUInt16() * 30;

    VM::writer->Write(EB);
    VM::writer->Write(EF);
};

void VM::Shift_Half_Unsigned_Address_B() 
{
    System::UInt16 EF = VM::reader->ReadUInt16() / 30;

    System::UInt16 EB = VM::reader->ReadUInt16() / 32;

    VM::writer->Write(EB);
    VM::writer->Write(EF);
};```
#

my question is how to create the bindings for it?

teal viper
ionic zephyr
vital tangle
teal viper
vital tangle
#

i just dont know if it will work or not

teal viper
#

Well, there's a 100% sure way to tell: try it and see.

vital tangle
ember gate
#

when doing a platformer and creating the world with a tilemap what for example if I wanna make some moving platforms but the platform itself may consist of more than one sprite how can I make it so the code can fit to most type of platforms?

deft grail
ember gate
deep yew
#

I'm trying ot unfreeze these caps but they keep falling off due to rigidbody.
Is there a way to freeze the rigidbody until a button is pressed?

deft grail
deft grail
deep yew
deft grail
deep yew
tender wharf
#

if its in the ui there must be a way to do it programatically

ember gate
#

oh ok and like when positioning it is there a way to position it without moving it freely and move for example some pixels in a direction everytime I move it in the editor?

deft grail
deep yew
#

Couldn't find any in the rigidbody doc

tender wharf
half egret
#

For position specifically

ember gate
#

is there a way of seeing the trajectory of on which the platform is moving from point A to point B

#

should that be done with raytracing or something like that?

ionic zephyr
#

Should the weapon that my character carries be a ChildObjectof the player?

deep yew
deft grail
deep yew
deft grail
ionic zephyr
# deft grail yeah

and should it have its own component to choose what weapon it is using each time?

deft grail
ionic zephyr
#

Okay, that makes sense

#

thanks

deep yew
ionic zephyr
#

Attacking with weapons should be done with triggers? or is it better to do with OverlapCircle

ionic zephyr
#

area?

#

or all

deft grail
ionic zephyr
warm raptor
# meager gust you can't send a byte array?

I just looked up what a char array is, and I don't understand how it would be more efficient than a string. In both cases, I would need to retrieve the information I need using indices, and anyway, I don't need to be able to modify the messages I receive or send. Can you explain, because I don't really understand the usefulness of a char array.

burnt vapor
#

You don't send stuff as strings then

#

The reason why JSON is bad is because you bloat up your packets way more than what they need to be and this is horrible when you send inputs and stuff to the server for example. It also requires serialization/deserialization

#

Alternatively make your own packet class that reads/writes from a buffer. It's not a lot of work

#

I never heard something requiring strings specifically so I doubt that's needed here either

warm raptor
teal viper
half egret
#

Weird that a char is 2 bytes in C#, I've done networking in C using chars. I wonder what that extra byte is used for... can't possibly be a null terminator. I'll have to look at the docs

languid spire
half egret
#

ah.. right

#

thanks!

ionic zephyr
#

How can I mantain cohesion with my attack component and make sure that I can access the same method "Attack" but it has different effects, for example, I want my enemies to attack with their own attack stat, but I want my player to attack depending on the weapon it has?????????

hot palm
#

!code

eternal falconBOT
hot palm
#

So over the years I've learnt some stuff what to do and not to do, as well as the fact you should always keep your code organized.
I have created this script, which I copy and paste into new scripts and edit only the stuff I need, so that everything is organized the same.
What do you think about this and how did I do?

burnt vapor
#

Sending data to clients etc

#

There are different patterns depending on how you are communicating, but if it's networking where a game needs to continuously send data, then you should use sockets and a system that sends/retrieves byte arrays basically.

#

JSON is still valid if the data you send is not continuous and might have a large/dynamic size.

warm raptor
burnt vapor
warm raptor
burnt vapor
#

It's slow and bloaty

#

You also have no control over the actual size, so you can't specify single bit data since everything needs enough bits to fit in a whole character, which is a waste of space

teal viper
#

It's not just about sending(although it's definitely better to send less data than more without need), but also about processing that data on the sending and receiving ends.
At the moment you have issues with all of these things.

ionic zephyr
#

How can I mantain cohesion with my attack component and make sure that I can access the same method "Attack" but it has different effects, for example, I want my enemies to attack with their own attack stat, but I want my player to attack depending on the weapon it has? Basically what I need is something that makes the player or any entity attack but in different ways

burnt vapor
#

It also depends a lot on encoding but regartless you are wasting time converting the string into usable data, which is the worst part of it

#

Something that is negligible at the start but very noticeable once your game ramps up on the data is sends/retrieves

#

The socket class and its derived classes also don't allow strings in general, only byte arrays ๐Ÿ˜›

willow scroll
# hot palm So over the years I've learnt some stuff what to do and not to do, as well as th...

I first thought it was a class, which you derive from to expand your other class' functionalities, but it does not seem this way.
I understand what you are trying to achive, but I do think it's pretty useless. If I created a script in Unity, and this was its code by default, I would simply remove everything inside of its scope, the same way I do it with Unity's default Start and Update methods on new script creation, along with its descriptions

hot palm
willow scroll
warm raptor
burnt vapor
#

They are a bunch of numbers

#

I don't see why you would be using a string here, why are you so fixated on using it?
Another point, using a string will cause culture issues if you use characters of varying culture.

hot palm
warm raptor
warm raptor
# burnt vapor They are a bunch of numbers

ok , so let's assume that I'm now using a char array instead of a string, how could I get the information I need from the char array ? because now I'm just parsing my string

burnt vapor
#

So how are you sending data over the newtwork to begin with? Surely you'd have to use a byte array in general?

#

I don't think sockets accept char arrays since they are still different

burnt vapor
#

Please give an example of data currently being send in your game. What is that exactly?

willow scroll
# hot palm Can I replace the default script stuff?

Yes.

C:\Program Files\Unity\Hub\Editor\2021.3.27f1\Editor\Data\Resources\ScriptTemplates

Go to this location and add the suitable code to this file:

81-C# Script-NewBehaviourScript.cs.txt

Note that the location can differ on your device and Unity's version. See more here

burnt vapor
#

I have no idea what is happening in that code

#

Does it generate a string full of key-value pairs?

#

Is it just sending a lot of booleans?

willow scroll
#

So remove the functionality from your Awake method

warm raptor
hot palm
#

Ohh okay, I thought my singletons were a bit weird

willow scroll
#

I also feel like you don't need all those comments, because you should definitely know what they mean yourself

burnt vapor
#

In the browser?

hot palm
warm raptor
hot palm
willow scroll
hot palm
#

Yep

hot palm
burnt vapor
#

I would honestly just use a plain Socket class if I were you

#

Only drawback is risk of dropping packets
Either way the Websocket also allows byte arrays, so you can continue using that

ionic zephyr
#

How can I mantain cohesion with my attack component and make sure that I can access the same method "Attack" but it has different effects, for example, I want my enemies to attack with their own attack stat, but I want my player to attack depending on the weapon it has? Basically what I need is something that makes the player or any entity attack but in different ways, please help

willow scroll
burnt vapor
#

So @warm raptor what is the actual data being send in that code now? Is it a bunch of boolean and float values?

hot palm
willow scroll
willow scroll
hot palm
eternal falconBOT
warm raptor
burnt vapor
burnt vapor
#

Here's the thing, you don't have to send over whole keys if what you send is always the same order

#

So you now send over a string and integer, when a single bit is enough

#

This is why it becomes messy once your game grows

warm raptor
burnt vapor
#

Not to mention you are still parsing it for no reason

#

A byte array has everything in its place

#

Your floats take 4 bytes instead of how many bytes would be required for the floats currently

#

FYI a single character is 2 bytes

brave compass
burnt vapor
#

Absolute waste of space and it will slow down everything if you do it everywhere

warm raptor
burnt vapor
willow scroll
burnt vapor
#

A float is normally 4 bytes, and now you convert it to a string and make every single character 2 bytes

#

A float doesn't span a list of characters, it's numbers. But your code doesn't know that

#

So, a byte array just stores the 4 bytes that defines your float, and you send that over

teal viper
burnt vapor
#

You're just adding extra work for the same result

teal viper
# warm raptor yes it's this one

Ok, well then you can look at their source code:

  1. They have a send method that takes a byte array.
  2. The method that takes a string, actually converts it to a byte array for you.
#

You're just doing double work with using a string

ionic zephyr
#

Is it better to attack with triggers if the hitbox is going to vary or with OverlapCircle??

warm raptor
burnt vapor
#

Assuming your byte array first writes a float and then a boolean, the float starts at index 0 and the boolean at index 4

teal viper
#

You can use a binary reader/writer like Fused suggested, to parse the byte array.

warm raptor
burnt vapor
#

Yes, everything is bytes under the hood

#

This might be confusing, but this is a packet class I wrote and maintained for a while. Here's purely the parts for writing/reading a float https://gdl.space/lowiceriqu.cs

#

Whole point is that is uses BitConverter for reading and writing bytes from and to the correct type

#

The code around it ensures it's written/read correctly by getting the correct spot from the array, and some other validation stuff (like making sure the length doesn't exceed 255 since that's the max number a byte allows)

fervent abyss
#
for (int i = 0; i < allowedApps.Length; i++)
        {spawnedApps[i].GetComponentInChildren<SystemUIButton>().onButtonClicked.AddListener(delegate
            {
      ComputerManager.instance.OpenApp(allowedApps[i]);
            });
        }

im trying to add listener to an Unity Event with parameters... but it just gives me "IndexOutOfRangeException" on allowedApps[i]?

burnt vapor
teal viper
burnt vapor
#

Then debug your code and see where it fails. This is the only assumption that can be made from this code

fervent abyss
teal viper
burnt vapor
#

That's still assuming. Actually validate it by logging the length of spawnedApps and allowedApps before this code runs

warm raptor
willow scroll
burnt vapor
#

I suggest you try making something similar

burnt vapor
#

It's kind of hard to make a proper byte array of data without one, but the BitReader thing also works

teal viper
burnt vapor
warm raptor
burnt vapor
burnt vapor
#

Honestly if you're a beginner I'm not sure if you should be doing this to begin with

warm raptor
burnt vapor
#

Isn't it easier to make a very simple console application that sends some data around first?

teal viper
warm raptor
teal viper
#

I think it's not an issue of translation, but of learning some programming basics

night raptor
#

in finland we call bytes syllables, no idea why

languid spire
teal viper
#

Also, I'd say that English is very important for programmers. It is not my native language either, but I read docs and have my environment configured to be in English.

warm raptor
burnt vapor
#

You can still do that with byte arrays

#

However, you should understand that byte arrays assume that the data your send is always in order and of the same size. I assume your editing retains the order and types

#

It's weird to do this though

warm raptor
burnt vapor
#

It's expected you send bytes over under a specific key, and depending on this key the client knows what the data in the byte array represends

#

For example, key player position indicates the byte array might be three floats representing a Vector3

warm raptor
#

but that mean that I have to send way more message to the server

ionic zephyr
#

Should my attack component be in th echild object of th e player or in the player?????????

warm raptor
#

because now I'm sending one huge message for all the different values

warm raptor
summer stump
#

There is no definite answer

fervent abyss
#

what skeletonappears

burnt vapor
#

Right

languid spire
burnt vapor
#

I missed the part where you made a delegate

#

Consider just making a method that opens the app and pass the app by reference instead of using an index into the array

#

That way you would not have this issue to begin with

teal viper
#

Also, proper debugging would reveal that a long time ago

#

That would imply you didn't actually debug log in the correct places.

#

Or the correct variables

deep yew
#

I never gotten this error but it decided to give it to me now

#

It didn't show up as an error when I added it ages ao

slender nymph
teal viper
deep yew
#

Class system

teal viper
deep yew
#

The other one.

teal viper
deep yew
#

Man I have no clue that's why I'm talkin' in beginners chat

#

Never had this error

slender nymph
deep yew
#

Alright, thanks both of u

#

now it works

warm raptor
teal viper
#

We've been saying several times that what you need is a byte array.

#

Not a chat array.

burnt vapor
#

Indeed, just look into setting up a byte array and then reading from that again

languid spire
teal viper
#

As for the keys, if you really want to use them, you should probably replace them with an int or enum.

teal viper
languid spire
#

I'm not getting into this ridiculous discussion, just answering the last post

teal viper
#

Anyways, the main issue is all that string parsing you're doing.

#

Which is why a byte array would be better. It would be much faster with a binary reader/write instead of parsing the strings

warm raptor
teal viper
#

And finding substrings.

#

Which is exactly what everyone was talking about from the very start.

warm raptor
teal viper
teal viper
#

You would be telling your script the value when you have it after retrieving it with a binary reader.

warm raptor
teal viper
#

No. You don't use strings. Or substrings. Period.

#

The whole conversation so far was that you don't use strings.

teal viper
#

Anyways, I'm off to sleep. Good luck.

warm raptor
amber snow
#

can anyone help me with my shader graph?

rocky canyon
#

in a coding channel?

amber snow
#

no not here, i just joined this discord and wasnt sure if i even posted my question in the right channel, and because i saw this one was more active, i thought i might just ask, whats the worst they can say?

rocky canyon
warm raptor
#

so if I receive a bytes array like that :

[88, 49, 50, 89, 51, 90, 50]

wich reprensent this message :

"X12Y3Z2"

how can i get the value for the X Y and Z coordinate ?

ripe shard
#

i mean, just parse the string

#

or marshal it to/from a struct with floats/ints in the first place

slender nymph
#

you should look into how to serialize your data properly instead of making seemingly random guesses at how it works

warm raptor
slender nymph
#

i am aware of that, but you are still doing exactly what you were also told not to and still thinking of your data as strings

#

learn how to serialize your data and encode it as binary, then you just deserialize it into the data you need. you don't need this middleman string manipulation

warm raptor
ripe shard
# warm raptor why you are now talking about binary, I'm so lost ๐Ÿ˜ญ

iirc you were told a lot about basic issues when approaching netcode naively without any foundational knowledge of how networking works. Maybe you would benefit from looking at a foundational intro into networking. It doesn't even have to be game related, but you should at least understand how bits go from one app/pc to another app/pc --> maybe start by looking at https://en.wikipedia.org/wiki/OSI_model and https://en.wikipedia.org/wiki/Marshalling_(computer_science)

The Open Systems Interconnection (OSI) model is a reference model from the International Organization for Standardization (ISO) that "provides a common basis for the coordination of standards development for the purpose of systems interconnection." In the OSI reference model, the communications between systems are split into seven different abst...

In computer science, marshalling or marshaling (US spelling) is the process of transforming the memory representation of an object into a data format suitable for storage or transmission, especially between different runtimes. It is typically used when data must be moved between different parts of a computer program or from one program to anothe...

warm pine
#

help psl

slender nymph
warm pine
#

im not sure how

warm pine
#

i dont have access to packet manager in safe mode

slender nymph
#

then next time, instead of completely ignoring that suggestion ask how

rocky canyon
rocky canyon
slender nymph
warm pine
#

ill go back to unity talk then

slender nymph
#

jsut fucking install the package if you haven't already

#

nobody is saying to go back to that channel to continue ignoring the suggestion. we are saying to actually follow the suggestion you were provided before anything else

slender nymph
#

exit safe mode? you were literally told to do that when you went back to unity-talk too

warm pine
#

to exit safe mode i need to eliminate the error, or unity crashes

to eliminate the error i need to exit safe mode

can you see why I am lost here now?

rocky canyon
#

if its crashing.. you'll probably need to clean it up enough in safe-mode that it doesn't crash

#

//comment out broken code.. or get rid of hte script until u fix it

slender nymph
rocky canyon
#

^ yea, im suspicious as well

warm pine
#

Ive fixed the error in the script and its loading now, Ill let you know how it goes

slender nymph
#

then i imagine something else is wrong with your project as well

warm pine
#

perhaps

languid spire
warm pine
#

it could be because of the missing namespace, or as boxfriend said, something else is wrong

languid spire
#

forget could be. look at the damn logs and know

warm pine
#

idk how to interpret them sorry

languid spire
#

wrong logs, you are not even in the correct folder

warm pine
#

idek what a magic number si

#

!logs

eternal falconBOT
#
๐Ÿ“ Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

slender nymph
#

assuming the error caused it is like breaking your arm then on your way to the doctor you stub your toe and tell the doctor that stubbing your toe is causing your arm pain

warm pine
#

is this the right log?

slender nymph
#

well i certainly won't be downloading the file to find out

languid spire
#

it might be if you posted it using a paste site

warm pine
#

alright sorry

willow whale
#

simple one for you

#

isPoisonBubble is set to true and yet it went down the false route

slender nymph
warm pine
#

all paste sites say i have too many characters, is there a solution?

slender nymph
#

read the logs yourself or only share the relevant part(s)

warm pine
slender nymph
#

that does not seem relevant to the crash

languid spire
#

I'm guessing that is the log from the copied project not the original

slender nymph
#

clear the logs, then cause the crash again and read the logs again. also i thought you said you'd fixed that error? if you had, obviously any logs related to the error would be old and no longer relevant

eternal falconBOT
#
๐Ÿ“ Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

warm pine
#

how can i get the logs of a releavent project?

#

nvm

slender nymph
warm pine
#

yh thanks

vast vessel
warm pine
wintry quarry
vast vessel
#

youre right im getting a NRE

wintry quarry
#

yeah so one of the memories in the list is null probably, or an NRE in the event listener

lethal elbow
#

May need some help trying to get my projectile to instantiate in a horizontal start. It seems to spawn in standing position even though it's zeroed out in the prefab

if (Input.GetButtonDown("Fire1"))
        {
            GameObject Arrow = Instantiate(projectile, arrowSpawnPoint.transform.position, arrowSpawnPoint.transform.rotation);
            Arrow.GetComponent<Rigidbody>().AddForce(transform.forward * launchVelocity, ForceMode.Force);


        }  

wintry quarry
#

so presumably whatever arrowSpawnPoint is, it's oriented improperly.

#

or perhaps the mesh of your prefab is oriented improperly

#

the fix is to fix whichever of those is wrong

lethal elbow
#

Generally it's shooting_origin but I was trying something out

wintry quarry
#

If you look at your prefab, you should make sure the "forward" is actually correct on it

lethal elbow
#

Ah to be honest, it's not actually a prefab. Let me check that out

wintry quarry
#

not global

#

also you should proably use a real prefab ๐Ÿ˜‰

lethal elbow
#

Okay it's local, and everything looks zeroed out

#

No luck still

wintry quarry
#

where's the prefab

#

isn't this your "shooting arm"?

#

Where's the projectile itself?

wintry quarry
lethal elbow
#

Ah, second image of my original post

wintry quarry
#

the blue arrow is pointing sideways

#

the arrow is not oriented properly

#

blue arrow = forward direction

#

yellow is "up"

#

red is "right"

#

orient your projectile prefab accordingly

lethal elbow
#

Can I do this through prefab mode?

wintry quarry
#

of course

lethal elbow
#

So the aim is to get it to face the z-axis from the prefab or the compass in the topright?

wintry quarry
#

when the root object of the prefab is selected

#

aligning it with the compass in the top right just means that your prefab root is also zeroed out, which is good practice as well

#

the simplest way to fix this is to move the collider and the renderer to a child object

#

rotate that child as needed

lethal elbow
#

So I double up on the renderer and collider? Because the object disapears if I remove it from the prefab

wintry quarry
#

no you do not double up

#

move them down to the child

wintry quarry
lethal elbow
#

You want me to move those two into the child I made?

wintry quarry
#

instead of:

Arrow (Projectile script, Renderer, MeshFilter, COllider, Rigidbody)

Do this:

Arrow (Projectile Script, Rigidbody)
  Visuals (Renderer, MeshFilter, Collider)```
#

yes

lethal elbow
#

well it's not an object after that happens

wintry quarry
#

i have no idea what that sentence means

lethal elbow
#

Here it is in the child

wintry quarry
#

you didn't move the mesh filter

queen adder
#

why is this only showing out of bounds when the object is already half way out of the camera view Vector2 viewPos = cam.WorldToViewportPoint(transform.position); float verticalInput = Input.GetAxis("Vertical"); transform.Translate(Vector3.up * verticalInput * _speed * Time.deltaTime); if (viewPos.y >= 0f && viewPos.y <= 1) { Debug.Log("In bounds"); } else { Debug.Log("out bounds"); }

wintry quarry
#

presumably the center of object is where transform.position is

#

so it will happen when the center leaves the screen

queen adder
#

when the top of the object goes out of bounds it prints out of bounds

#

but like you said it triggers in the center

wintry quarry
#

yes, that's where the position of the object is

#

the center

queen adder
#

so how can I get the top of it

wintry quarry
#

Two approaches I can think of:

  • Make empty child objects at the extremities (very top/very bottom) of the object, and check the positions of those for your bounds check
  • Put colliders at the edge of the screen and use physics to detect it.
wintry quarry
#

Or:

  • Mathematically calculate where the top/bottom of your object are and use those calculated positions in the check
queen adder
ancient rampart
#

how should I handle yamldata when importing through unitywebhandler? having some issues going from the uri to yaml data to give to yamldotnet

lethal elbow
wintry quarry
rocky canyon
#
  • Main Object (0,0,0)
    • Graphics
#

its pretty simple.. adjust ur child objects the way u want.. ur main root object can stay str8.. can stay scaled to 1:1:1

wintry quarry
#

also using negative scale is not usually the best idea

lethal elbow
#

Well the object looks much fatter now and rotating just the child doesn't make it alligned

rocky canyon
lethal elbow
#

Il delete the object and just remake it, it's only a cylinder prefab

rocky canyon
#

your previous image looks correct.. (just needs scaled down).. u can see the gizmo in the top right.. showing the Z axis is facing to the left.. so ur capsule is lined up w/ that

lethal elbow
#

Doesn't spawn right still ๐Ÿ˜ฆ

#

Parent is facing the right way but not the child

wintry quarry
#

the root of the prefab is what matters

lethal elbow
#

Ah so that is setup correctly then

rocky canyon
#

ya, bro. the child can point anyway u want it too..

#

the root is what matters..

#

(what would hold a rigidbody) (what would have its direction rotated/modified) (what would be used for orientation)

#
  • Root
  • Graphics
#

thats why we use this type of setup

lethal elbow
#

So this is a code issue then?

rocky canyon
#

whats wrong w/ it?

#

if u want it facing the other direction.. u just use the rotation part of the Instantiation method to orient it how u want

lethal elbow
#

still spawns upright

rocky canyon
#

show it after it spawns

#

instead of hte prefab view

#

and yes, its probably code related if its spawning w/ a rotation

lethal elbow
#

spawns facing up

rocky canyon
#

is it hitting anything that would cause it to rotate weirdly?

#

try spawning it by itself..

#
// Instantiate a prefab at the position and rotation of the current transform
Instantiate(prefab, transform.position, transform.rotation);```
```cs
// Instantiate a prefab at the position of the current transform with no rotation
Instantiate(prefab, transform.position, Quaternion.identity);```
#

when u drag the prefab into the scene hiearchy manually.. (that would be exactly how it looks if u spawn it in using code w/o rotation)

wintry quarry
#

yeah make sure it's not colliding with anything as it spawns

lethal elbow
#

il respond in 30 mins, just had to hop out

rocky canyon
#

and when u share screenshots.. select the objects in question.. and make sure not to clip anything out.. (the more we can see the better chance u have at receiving help)..

final sluice
#

is pathway down ?

languid spire
final sluice
#

ooops sorry

timid quartz
#

I really like using Scriptable Objects for data, I like being able to edit their values right in the inspector. however, they can't be serialized, which makes me wonder if there's a good alternative out there besides using them? right now my workflow is to use a scriptable object to represent one instance of a part of the game - for example, a scriptable object per monster I want to be able to create.

wintry quarry
lethal elbow
# rocky canyon

This is what happens and this is the code I have

   if (Input.GetButtonDown("Fire1"))
        {
            GameObject Arrow = Instantiate(projectile, transform.position, transform.rotation);
            Arrow.GetComponent<Rigidbody>().AddForce(transform.forward * launchVelocity, ForceMode.Force);


        }  
timid quartz
#

I'm not using any 3rd party tools, this is Unity just getting mad when I add System.Serializable to anything inheriting from ScriptableObject

#

I am very happy to be proven wrong, if you want I can copy-paste my save and load flow

#

oh wow! this looks like it might solve my problem!

#

thank you for the thousandth time Praetor Blue, I feel like every time I come here you're always here to save my butt

ripe shard
timid quartz
#

I am using binaryformatter which doesn't work with scriptable object, but looking at the docs for JsonUtility it looks like switching to the new flow might work for me

ripe shard
#

did you not see the big yellow warning in the docs?

timid quartz
#

nope!

#

happy to make the swap, looking at json stuff now ๐Ÿ™‚

ripe shard
timid quartz
#

taking a look!

ripe shard
#

With it you can mark up exactly which fields/properties you want to serialize.

timid quartz
#

thank you! ๐Ÿ™‚

sleek gazelle
ripe shard
#

you may also find that you don't need ScriptableObjects at all to serialize your data to disk.

timid quartz
#

I like using them because I like being able to drag and drop them around and edit their values right in unity

ripe shard
#

which is much simpler because with SOs you need to .Populate an existing object which is often not supported by serialization libraries (though Json.NET supports it)

#

with a plain struct or class you can just have the serializer create a new instance without any unity object lifecylce issues

strong wren
#

I'm not sure if Json.NET necessarily ends up in all default projects. Add com.unity.nuget.newtonsoft-json by name in package manager if you don't have it.

lethal elbow
#

Ignore that, it's always facing up no matter the direction

ripe shard
strong wren
#

Pretty sure Unity has converters for most of the common types.

lethal elbow
slender nymph
meager gust
#

as other people said: it's byte, not char. bytes are literally just raw memory on a computer.

#
public void Serialize() {
  write(variable1); // int32
  write(variable2); // short16
}

public void Deserialize() {
  variable1 = readInt(myByteArray);
  variable2 = readShort(myByteArray);
}

we don't need to parse anything, because we already know that an integer will always be 4 bytes, a short will always be 2 bytes, etc. we can just increment the position after every read/write.

sleek gazelle
warm raptor
meager gust
#

no

#

you load them all into a byte array

#

the byte array is your message

#

that was very incomplete psuedocode

warm raptor
#

I must be dumb but I still dont understand how it work

obsidian kite
#

if anyone could help id be grateful

meager gust
#

@warm raptorhttps://learn.microsoft.com/en-us/dotnet/api/system.io.binarywriter?view=net-8.0

#

look at the example. see how familiar that looks to my example?

lethal elbow
ionic zephyr
#

How can I make a system in which I drag a slotยดs item image and drop it in other slot and that second slot gains the first slot information??

#

Iยดm using these interfaces for now but I donยดt really know how to detect that the place I am dropping the image is a slot for example

rigid ridge
#

So i made this simple dash but how do i make it that i only can dash once and not again until i touch the ground again

meager gust
#

@warm raptor
the whole underlying basis is that memory is stored in bytes. you understand?

every integer (32 bits) will always be 4 bytes in computer memory.
every float (32 bits) will always be 4 bytes in computer memory.
every short (16 bits) will always be 2 bytes in computer memory.

It's just very easy to convert the values to bytes.
bytes are how data gets sent over the internet.
when you send a string over your websocket, it breaks it down into a byte array before truly sending it.

warm raptor
slender nymph
#

the max is about 2 billion for a signed int yes.

#

this is basic information that you should absolutely already know before attempting to do any sort of networking

warm raptor
slender nymph
#

well there are other data types you could use for that. which is, again, fundamental information you should have before attempting to do what you are attempting to do

warm raptor
#

also I just see that the web socket I use send the data in binairy, should I go to
e.RawData
instead of
e.Data
?

meager gust
ionic zephyr
#

how can I get a component from the object I am dropping my slot image on??

#

I want to add the slotData of the Slot image into another slot in which I drop this image

slender nymph
wintry quarry
ionic zephyr
warm raptor
slender nymph
meager gust
#

physics engines use 32 bit computations. at least physx does.

wintry quarry
#

could be

#

I always have to re-figure out how to do drag/drop

slender nymph
#

could just raycastall from the event system at the position the object is dropped

ionic zephyr
#

My idea is to drop the slot image onto another slot which receives the first slot data and adds it to it

warm raptor
slender nymph
#

start by googling it

ionic zephyr
#

with PhysicsRayCaster2D?

wintry quarry
#

definitely not physics

slender nymph
ionic zephyr
#

!code

eternal falconBOT
ionic zephyr
#

Im getting NullReference, I guess the raycast isnt hitting the slot object

wintry quarry
#

or you don't have an Event System in your scene

ionic zephyr
#

I do have it

slender nymph
#

time to print out the individual objects (or set a breakpoint and look at them) to find out which is null

ionic zephyr
#

oh, I think I found the mistake

#

Fixed, nevermind

#

thanks a lot!

twilit iris
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ParalaxScript : MonoBehaviour
{

    private float length, startpos;
    public GameObject cam;
    public float parralax;
    // Start is called before the first frame update
    void Start()
    {
        startpos = transform.position.x;
        length = GetComponent<SpriteRenderer>().bounds.size.x;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float temp = (cam.transform.position.x * (1 - parralax));
        float dist = (cam.transform.position.x * parralax);

        transform.position = new Vector3 (startpos + dist, transform.position.y, transform.position.z)*Time.deltaTime;

        if (temp < startpos + length)
        {
            startpos += length*2;
        }
        else if (temp > startpos - length) { 
            startpos -= length*2;
        }
    }
}```
I tried to make paralax effect but somehow it always out of bound and always moving at same speed
#

why my camera position different than my background position? even though it placed perfectly on the same place

slender nymph
#

why are you multiplying a position by deltaTime

twilit iris
twilit iris
slender nymph
#

it makes absolutely no sense to multiply a position by deltaTime

rose canopy
#

so, im having a problem that i have never had before in my years using unity, i THINK it might be a memory leak, but honestly i have no idea and ive never dealt with a memory leak before, but when i start up my project which btw is a practically empty project right now, it runs great, 200fps in play mode, but then as soon as i change something in the scene for example changing a value of my move script, add/remove any script, add/remove a mesh, ANYTHING, my frames instantly are reduced to a constant 50/60fps when already in playmode or when clicking play the next time until i reload the scene or restart unity. No fucking clue whats going on here any help is appreciated

twilit iris
#

nope still broken

queen adder
#

is this the palce to talk about camera

ripe shard
queen adder
#

Yea but can i talk about camera is there a way to make it stay one Z position at all times

frosty hound
#

Sure, when you move the camera's position, set its z position to what you want.

queen adder
#

okay thanks

eager wolf
#

I'm trying to write code to make it so that when 2 objects collide, they merge into 1. But instead both disappear because the code is running at the same time on both objects.
Not sure how to avoid that.

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.GetComponent<ItemPickUp>() != null && quantityToPickup < ItemData.MaxStackSize) //if it's another item and this current item has capacity to merge
        {
            var itemOnFloor = other.GetComponent<ItemPickUp>();

            if (itemOnFloor.ItemData == ItemData) //if both items are the same
            {
                int availableToMerge = ItemData.MaxStackSize - quantityToPickup; //finds amount that it can add to stack

                if (itemOnFloor.quantityToPickup < availableToMerge)
                {
                    itemOnFloor.quantityToPickup = 0;
                    quantityToPickup += itemOnFloor.quantityToPickup;
                    quantityText.text = quantityToPickup.ToString();
                }
                else if (itemOnFloor.quantityToPickup >= availableToMerge)
                {
                    itemOnFloor.quantityToPickup -= availableToMerge;
                    quantityToPickup += availableToMerge;
                    itemOnFloor.quantityText.text = quantityToPickup.ToString();
                    quantityText.text = quantityToPickup.ToString();
                }

                if (itemOnFloor.quantityToPickup == 0) //if the other item is full consumed then destroy it
                {
                    Destroy(itemOnFloor.gameObject);
                }
            }
        }
    }
wintry quarry
eager wolf
#

Yeah... but how? ๐Ÿ˜…

wintry quarry
#

a cheeky way is something like this:

if (gameObject.GetInstanceID() > other.gameObject.GetInstanceID()) return;```
warm raptor
#

ok thx

#

so you think I could rewrite all my text in my leader bord each update ?

wintry quarry
#

probably better to just do it when something actually changes

#

!code

eternal falconBOT
wintry quarry
#

Surround code with three backquotes. Not quotation marks.

keen rampart
#

oh ok

wintry quarry
#

but also - for a whoile file like that, just use a paste site

keen rampart
#

oh ok

crisp prism
#

how do you see what people added to the project in unity version control

keen rampart
#

im really confused

rocky canyon
#

it sets the sprites parent to the scripts gameobject.. tracks it.. and uses velocity to squash and stretch the local transform of the child object (the sprite)

rigid kite
#
void Movement()
    {
        float speedX = Input.GetAxisRaw("Horizontal");
        float activeSpeed;
        if (Input.GetKey(runKey))
        {
            activeSpeed = runSpeed;
        }
        else
        {
            activeSpeed = walkSpeed;
        }
        rb.velocity = new Vector2(speedX * activeSpeed, rb.velocity.y);
    }

Hello guys. I am making a 2D game with Rigidbody movement. How i can make my Player move with rb.AddForce without being slippery?

wintry quarry
#

Objects have momentum, that's how physics works

#

If you want no momentum at all you can just set velocity back down to zero whenever you want.

#

otherwise, you can control how fast to slow down by applying braking forces

rigid kite
#

how i can add breaking forces

wintry quarry
#

With AddForce

rigid kite
#

But like to what direction

wintry quarry
#

and it's braking* not breaking

wintry quarry
rigid kite
#

you know its begginer bro

#

if i could do it i wouldn't ask it to this server

wintry quarry
#

I don't know what you're trying to say, but I'm explaining how to do what you want to do

rigid kite
#

ok bro ty

strong wren
#

how can i turn a gameobject into a prefab without breaking the Variables?

#

my prefab looks like this

wintry quarry
strong wren
#

well the component prefab

wintry quarry
#

so if you have any references to scene objects, they won't persist in the prefab

strong wren
wintry quarry
#

depends what you mean by "work"

#

depending on what that S is, it's not going to actually do anything

#

since it's a prefab and not in the scene

strong wren
#

yeah but once it is in the scene

wintry quarry
#

prefabs are things that live in your project folder

#

that would be a different object than the prefab

#

it would be an instantiated copy of the prefab

#

your prefab cannot refer to objects in the scene.

#

regardless of if they are copies of a prefab or not

strong wren
#

soo what can i do to make the enemy into a prefab with the same components?

wintry quarry
#

it has the same components

#

what you need to fix is how you get references to those things

#

you can't use inspector drag and drop for this

strong wren
#

i fixed the S, ST, and SP since they are trying to access a script but the PlayerBody is a gameobject and even if i still turn it into a prefab it wont work

wintry quarry
strong wren
#

it works i made it so they work now

wintry quarry
#

You either use something like the singleton pattern or have the script that spawns these things pass the reference they need to them after spawning it

strong wren
#

i just need the PlayerBody To be set

wintry quarry
#

you'll see

strong wren
#

again i dont think i explained myself correctly but that is irelevant now

wintry quarry
#

Singleton.

#

Assuming they are actually singletons

strong wren
#

hopefully they are

wintry quarry
#

SOmething lIke "shop" or "stats" doesn't seem very singleton

strong wren
wintry quarry
#

obviously

strong wren
#

yeah

wintry quarry
#

singleton means "there's exactly one of them in the world"

strong wren
#

the playergoto is now the issue im facing

#

oh

#

then it should work? the playergoto is in the world

wintry quarry
#

and there's some code pattern to take advantage of that for easy references

wintry quarry
strong wren
#

poop

#

i mean i can probably make it so the ememy goes to the player differently

#

like instead of going to a specific gameobject it checks for a gameobject with a specific tag in it then it goes it?

wintry quarry
#

This is a very solved problem with very well known solutions

#

yes, that's one of the solutions

strong wren
#

woudlnt i be using raycasts for that then?

wintry quarry
#

Huh? Raycasts?

strong wren
#

idk last time i watched a tut on raycasts it said smth about info of a gameobjec

#

ima read the link first

wintry quarry
#

You're conflating and confusing things

#

you can get a reference from a raycast sure

#

if you happen to have been making a raycast in some known direction

#

but it doesn't sound like you're doing that.

#

That would be for like some kind of searching behavior

ancient rampart
#

I have successfully gotten my yaml to parse, now I need to figure out how to make it accessible to other scripts, how can I go about making this var visible to a different script?

eternal needle
#

but that seems to be a local variable, it needs to be declared outside a method

ancient rampart
#

here's the context of the line, and yeah adding public in front of it just breaks everything lol

#

also been a long day of trying to get this to work hahaha, not entirely understanding what you mean by declaring outside a method

#

just like at the top of the script?

eternal needle
ancient rampart
#

honestly just never heard someone use the term method before with this stuff, but fair

teal viper
#

Then you haven't learned C# at all. Because it's one of the most used words in it's context.

ancient rampart
#

good thing I'm in the beginner chat ๐Ÿ˜‰

#

anyways ima dip, but thanks

teal viper
neon meteor
#

hey i was wondering if i could get some help with some code?

#

i'll just post it here. any help would be greatly appreciated.
i just need a simple walk script where i can move around with wasd, jump with the space bar and look around with my mouse.

lastly, i need to make a separate cube that when the player touches, they get sent back to the starting point (they die essentially.) thank you in advance.

subtle hound
#

i had a problem with this where it grabs the prefab's transform instead of my object in the scene

#

how can i grab the in scene objects transform here?

#

been tinkering and bugtesting this all day ๐Ÿ˜…

teal viper
subtle hound
#

no

#

the line above debug log

#

tile newtile = (tile)boardmanager etc

#

thank you

#

right above the commented code

teal viper
#

If you're absolutely sure it returns the prefab transform, then the issue is in the GetTile method. You'll need to debug that.

#

You can pass an object as a second parameter to the debug log. This would highlight the object when you select the log message. Can be useful for confirming what it actually references.

subtle hound
#

very helpful info for debug

#

appreciate the help

strong wren
#

i have no clue what ive done

#

and now there is kind of a saving mechanic in my game

#

i made the enemies into prefabs then made it so instead of the enemy going to a specific gameobject it searches for a gameobject with a specific tag then goes to it and now my money is being saved

#

i mean i aint complaining

#

i mean i know how to fix it

subtle hound
#

does that mean its the prefab reference not the object in my scene

#

i would assume so?

#

im in the game display i dont know if maybe my settings arent right to see this outline

teal viper
subtle hound
#

sec

#

yep it highlights the prefab

#

guess i have to debug gettile

rocky canyon
subtle hound
#

but when i google it says i just need to instantiate it first ๐Ÿ˜…

#

so i feel likke i did that

#

any intuition here?

strong wren
#

i mean its neat

#

i know how to fix it

teal viper
subtle hound
#

nope

#

just a tilebase method

strong wren
bold plover
#

Yeah what the hell.

teal viper
eternal falconBOT
strong wren
#

nvm i found the issue that also quite breaks the code

bold plover
#

Hastebin is awesome.

#

Always use it if you can.

rocky canyon
#

it only works half the time

subtle hound
strong wren
#

my money is stored on a gameobiect but now instead of storing it on a gameobject it stores in it the prefab

#

and it seems like its updating but it isnt

subtle hound
#

what do you mean !code?

eternal falconBOT
subtle hound
#

the whole file?

teal viper
subtle hound
#

mhm ok

teal viper
subtle hound
#

sryy ๐Ÿ™‚ bad discord ettiquette

bold plover
#

Yeah, snippets very rarely are enough to go off of. Things like that are your friend since you likely have tons of interlinked code making reference to one another.

#

I need to get more into that habit myself too so don't feel too bad.

rocky canyon
# strong wren my money is stored on a gameobiect but now instead of storing it on a gameobject...

still use the gameobject like u did before.. if ur prefab needs a reference to it and its in teh scene
store the reference on the thing thats spawning the prefab.. then u could just set it..

like ur example had S for spawner..
public Spawner spawnerReference; // <-- on the script that spawns the prefab
then: when u instantiate it..

ChildFollow newChildFollow = instantiate(childfollowprefab);
newChildFollow.S = spawnerReference;``` tha'd be the easiest way i can think of
strong wren
rocky canyon
#

but you could also use a singleton.. and have 1 gamemanager type class that holds all the important references from the get go..

#

you need something important... just access that..

strong wren
#

like i need it to be refrenced

#

i tried using singletons but im having a hard time with them

subtle hound
#

dont expect u to go through a bunch of work just posting in case u wanted to help xp

#

not all my files but everyything associated with the problem im sure

#

some comments may be outdated

rocky canyon
# strong wren i tried using singletons but im having a hard time with them

they're pretty simple once you start using them. ```cs
public class MyScript : MonoBehaviour
{
public static MyScript Instance { get; private set; }

[SerializeField]
private ScriptA scriptA;
[SerializeField]
private ScriptB scriptB;

private void Awake()
{
// If there is an instance, and it's not me, delete myself.

  if (Instance != null && Instance != this) 
  { 
      Destroy(this); 
  } 
  else 
  { 
      Instance = this; 
  } 

}
}``` to access Script A from anywhere: MyScript.Instance.scriptA;

teal viper
subtle hound
#

Ah!

#

how can i fix this

#

abandon tilebase mostly?

teal viper
teal viper
subtle hound
#

anything is fine i just thought tilebase would be easy because i have a grid based rpg game

#

i use tile for the floors and walls etc

teal viper
#

Thing about the Tilemap system is that it only stores the barebones instance data required for rendering. And it stores it internally.

subtle hound
#

i want something with good storage like i dont want to do a big matrix of all the tiles

#

i feel like thats bad for scalability of my game

#

i want to have a larger board

subtle hound
#

right sry

teal viper
#

Well, you'd need to use a 3d array or a dictionary. There's no going around it, since unity doesn't do it for you

subtle hound
#

ok

#

so it doesnt raise danger flags doing a 3d array alright

#

as long as i manage it properly?

bold plover
#

Error on line 23 of Player.cs which is CS0120. Trying to fix it by declaring line 7 in PlayerStateMachine.cs as static causes CS0176. I'm trying to pass acceleration and top speed values for specific states into the main player's script. I keep reading documentation but it's not clicking on how to fix it. Any help appreciated as I feel pretty hard stuck.

Player.cs: https://hastebin.com/share/ibovigezec.csharp
PlayerState.cs: https://hastebin.com/share/dicuyemayi.csharp
PlayerStateMachine.cs: https://hastebin.com/share/netosuwete.csharp
PlayerDashState.cs: https://hastebin.com/share/ipawanuvac.csharp

subtle hound
#

i was relying on my instincts mostly that sounded inefficient at first

teal viper
#

Yes. Obviously if you have huge/infinite world, you'd need some kind of streaming system or something.

wintry quarry
#

sharing your actual error message would be a million times better

subtle hound
#

could you give me better terminology for what a streaming system is so i can google ? it just comes up with "streaming services" haha

#

or a brief explanation would be very helpful

rocky canyon
#

tack Unity to the end ๐Ÿ˜‰

wintry quarry
teal viper
subtle hound
#

great ty for all ur help i think my solo journey starts here

bold plover
#

And holy crap thank you.

#

โค๏ธ

wintry quarry
#

you shouldn't need a copy of it on this script and on the state

#

it will lead to you having to constantly synchronize it

bold plover
#

Yeah I'm confronting that the tutorial I'm following might actually have been terrible the entire time.

#

yeeeeep

wintry quarry
#

You should just read it from the state whenever you need it

bold plover
#

๐Ÿ™ƒ

wintry quarry
#

you could make a property to make that easy

bold plover
#

Like why have it if I am duplicating the code anyway lmao.

rocky canyon
wintry quarry
#
private float currentGroundAcceleration => StateMachine.CurrentState.groundAcceleration;```
bold plover
#

There's so much bad coding advice online.

wintry quarry
#

but the biggest issue is that, you can't take anything as a hard and fast "this is always the best way" rule

subtle hound
bold plover
#

real

wintry quarry
#

there are different ways to do almost everything and each is good in different scenarios

bold plover
#

Yeah if you do it right the first time you don't have to add more spaghetti to "fix" it.

rocky canyon
#

you'll be a better person b/c of it

wintry quarry
rocky canyon
#

unless, ur just a God of hindsight ๐Ÿ‘‡

wintry quarry
#

foresight!

rocky canyon
#

that ^

bold plover
#

Well, that is cathartic to hear anyway. Makes me feel like I didn't waste as much time. And it could be argued that it teaches me how to fix it in the future as needed.

rocky canyon
#

absolutely

#

only worthless if u got no worth out of it.. lol (and u came here for 2nd opinions.. sooo.. ๐Ÿ‘ )

rocky canyon
strong wren
#

dayum

#

i expected it to be harder

rocky canyon
#

singletons are ๐Ÿช„

#

thats why they're typically used for GameManagers, CameraManagers, and whatnot

strong wren
#

it isnt u just rename 1 thing to the name of the script ur using then in the script where ur accesing the other script instead of doing S.Money++

you do
Shop.Instance.Money++;

#

i mean in my case

bold plover
#

Yeah, my biggest hurdle has been adjusting things after they've become larger and dependent on one another.

rocky canyon
#

they can stick around.. and hold important data/ call important (GLOBAL WIDE) type of functions

rocky canyon
strong wren
#

im more slow then others and videos make it eaiser for me to understand

loud owl
#

IDK if its begginer or not but im trying to learn MLagents and i want to make a 2d flappy bird ai

#

I get the basics of rewardingรผ actลŸฤฑbs and observation

#

How can i let the ai know what to do in flappy bird logically?

#

like its a weird question but in a 3d movement game

#

i can teach ai to toucha coin for example

#

but i cant imagine what to do in flappy bird

#

get the birds location and the pipes empty parts location maybe? but i cant get it normally because its prefabs as far as i know

#

I watched a few yt videos and people are using rays but just wanted to ask what to do

#

sorry for yapping a lot

loud owl
#

Yea, I saw that code monkey guy but its a really hard to understand tutorial for beginners

#

he is just skipping parts and not explaining enough atleast for me

rocky canyon
#

CodeMonkey has a 2d version

loud owl
#

yea yea in that part

#

Can I use Unity ML-Agents to teach an AI to play Flappy Bird and beat my high score?
๐Ÿ“ฆ Unity Machine Learning Playlist: https://www.youtube.com/playlist?list=PLzDRvYVwl53vehwiN_odYJkPBzcqFw110
๐ŸŒ Get my Complete Courses! โœ… https://unitycodemonkey.com/courses
๐Ÿ‘ Learn to make awesome games step-by-step from start to finish.
โœ… Get the Project files ...

โ–ถ Play video
#

this one

rocky canyon
#

mmhm im just searching around.. as well b/c idk

loud owl
#

I got the link

#

dw

#

Tysm imma read them

rocky canyon
#

np

modest sky
#

why is this server so wholesome

summer stump
#

You haven't been here long enough