#💻┃code-beginner

1 messages · Page 453 of 1

eager spindle
#

roblox needs you to deal with a lot of online services, saving player variables and constraints such as no orthographic perspective

#

people have made crazy things

rocky canyon
#

not denying that

steel hull
eager spindle
#

and arguably indie studios on roblox have a much wider reach

#

6yo kids love throwing robux at pet sim games

#

nonetheless game engines let you do way more and let you make your own shaders

#

and don't take 70% of your revenue

worthy tundra
#

ROBLOX TAKES 70%???????

half egret
#

Does roblox really take 70?

rocky canyon
half egret
#

The fact that kids are working on roblox games means that it technically consitutes exploitative child labor, 70%, jesus.

eager spindle
eager spindle
#

roblox automatically does it for you

rocky canyon
#

if roblox is a calculator..
unity is spaceX's flight controller..

eager spindle
#

and roblox still pays you a better cut than vtuber agencies 😄

steel hull
#

I love unity way more

polar acorn
# half egret The fact that kids are working on roblox games means that it technically consitu...

With Roblox Corporation now being valued at more than $45 billion, we ask whether the kids making the vast majority of its content are being taken advantage of?

Support us on Patreon: https://www.patreon.com/PeopleMakeGames

Written and presented by Quintin Smith:
https://twitter.com/Quinns108

Design and art direction by Anni Sayers:
https://t...

▶ Play video

Following our last video on Roblox, players and creators began getting in touch with their own stories to share. Here are some of those stories.

Support us on Patreon: https://www.patreon.com/PeopleMakeGames

Original video: https://www.youtube.com/watch?v=_gXlauRB1EQ&

Our response to Ecoscratcher's blog: https://www.youtube.com/watch?v=My9U41...

▶ Play video
rocky canyon
half egret
polar acorn
eager spindle
#

third point being evil but money is money

half egret
#

Steam does all that and they take 30%

steel hull
eager spindle
#

steam doesnt handle making your game popular tbf you need to do marketing on your own side

#

on roblox you can copy the most popular trend and not need to make social media

worthy tundra
eager spindle
half egret
#

True, does roblox really handle google/social media marketing and all for your game?

eager spindle
eager spindle
#

doing that on steam won't net you as good of a result

polar acorn
steel hull
eager spindle
rocky canyon
eager spindle
#

my current game is on alpha testing on play store

#

will think about marketing another time

steel hull
#

I am currently just trying to learn the basics of c# and unity

worthy tundra
eager spindle
#

steam takes $100 from you for each game you upload, until you make $1000

worthy tundra
#

i remember my first ever unity game....
it was a brackey's cube game clone

steel hull
rocky canyon
#

poor mans steam

worthy tundra
finite dew
# steel hull holy thankss

I love SebastianLague, but do mind the series is 8 years old, here's a newer one by GMTK https://www.youtube.com/watch?v=XtQMytORBmM

🔴 Get bonus content by supporting Game Maker’s Toolkit - https://gamemakerstoolkit.com/support/ 🔴

Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then gi...

▶ Play video
rocky canyon
#

doesn't really matter.. 8 years is nothing.. all the fundamentals are the exact same

#

but im not gonna complain about GMTK, he's solid too 👍

worthy tundra
#

goes to show how you can always learn

eager spindle
#

can also monetise your content there

#

youll find lots of silly games there, though be careful about running random .exe files on your computer

worthy tundra
#

itch.io is also THE place for game jams

rocky canyon
#

facts, to expose ur game the fastest and easiest way is to upload them as webGL

#

ive never stopped and thought whether or not i should open a WebGL build

eager spindle
#

to expand on this, game jams are a period of time where you make a game based off a given theme and submit it

worthy tundra
#

like, imagine trying to have a steam game jam

eager spindle
#

e.g. you got 5 days to make a retro arcade game

#

at the end you can find everyone else who participated in the jam

#

some of them have prizes too

#

the one I plan to participate in has 5 gaming chairs as a prize

worthy tundra
eager spindle
#

you dont need to be professional expert coder to join a jam, just have fun

worthy tundra
eager spindle
#

idk why it was disabled for them by default

steel hull
#

yo

#

isn't private just useless

eager spindle
#

not really

#

its good practice to hide things others don't need

steel hull
#

but no I can just do float instead of private float

eager spindle
steel hull
#

ohh

worthy tundra
steel hull
#

that makes sense

worthy tundra
eager spindle
#

some companies have it standard

half egret
#

Coding standards matter a lot when you have a codebase past a certain size

worthy tundra
steel hull
eager spindle
#

anything in square brackets are called Macros, unity things

steel hull
#

what are macros

worthy tundra
eager spindle
#

its kinda like an indicator

steep rose
#

[SerializeField]'s are good when you dont want a variable to be public but you still want to see it in the inspector

steel hull
steep rose
#

with public other scripts can detect it

worthy tundra
steel hull
#

well but why would you even use it then

eager spindle
#

when you add a script to a gameobject you can add a field to set your variable.

[SerializeField] Vector3 spawnPosition;
public bool unlocked

both let me show them in editor

steel hull
worthy tundra
eager spindle
#

i mean you could set everything to public

steel hull
#

to prevent cheaters?

eager spindle
#

its for other people reading your code

steel hull
#

interesting

steep rose
#

lets say you have 2 variables with the same name. you dont want to put them public or else 2 scripts would be affecting those variables which you dont want, so [SerializeField] is there to allow you to see them in the inspector without causing problems

eager spindle
#

imagine you have a variable that you dont want other coders to change, you can hide it with private

#

cause if other people change it stuff will break

#

this doesnt apply to cheaters/hackers ofc they can do anything they want

steel hull
eager spindle
#

but this is more of people who you're working with next time

steel hull
#

Idk sounds useless but maybe I'll get to use it later on

worthy tundra
# steel hull oh like someone cheating?

like, if a script has a public variable, every script that has a reference to that script can change that variable.

for example:

script 1:
public float varName;

script 2:

private script1 scriptName;

script 2 can influence varName, and sometimes you dont want it to do that

eager spindle
#

thats what I thought at first, now that I'm working with other programmers a lot I am thankful for it

worthy tundra
steep rose
steel hull
worthy tundra
#

its a good idea to only have a variable public if other scripts need to interact with said variable

eager spindle
#

so no one can touch the spawn position of the room

#

another fun fact: the opposite of SerializeField is HideInInspector.

[HideInInspector] public bool unlocked;
``` makes it so it won't appear in the editor.
dense plume
#

The purpose of making fields private is to eliminate any possibility of external modification. Unity only serializes public fields by default, so you must explicitly serialize private fields in order for them to be modified in the inspector, which is actually editing an instance object of your script.

#

"Serialize" means to make something into a string of bytes, basically text. This makes it possible for Unity to "expose" it via the inspector. FYI, not everything is "serializable" out of the box. Dictionaries and hash tables are not, for instance

eager spindle
#

dont be discouraged by this barrage information

#

theres lots to learn in both programming and unity

rich adder
eager spindle
#

it took me a very long time before the unity workflow clicked for me

rich adder
# worthy tundra wdym

instead of making the field public, you interact with the private one through a public method.

#

or properties ie (get; private set;)

worthy tundra
dense plume
#
private int _someField;

public int SomeField
{
    get
    {
        return _someField;
    }
    private set
    {
        _someField = value;
    }    
}
eager spindle
# rich adder its generally better practice to make methods / properties

to expand on this, rather than just letting other programmers directly modify variables you can

int money;
public int GetMoney() {
  return money;
}
public bool Purchase(int cost) {
  if(money >= cost) {
    money -= cost;
    return true;
  }
  return false;
}

Not only does this ensure that users interact with your systems in the way you want it to, it could even save programmers many lines of codes.

dense plume
#

Other things can be dome during get and set which makes properties particularly powerful

humble snow
#

why is the export missing objects

dense plume
#

Show the call stack that occurs when pressing the offending button

eager spindle
#

this is more of a c# thing but you can even

float _health;
public float health {
  get {
    return _health;
  }
  set {
    _health = value;
    if(value < 0) Die();
  }
}
#

so you can health -=5 and itll do everything in the setter

eager spindle
worthy tundra
#

idk how get and set work lol im a bruteforcer

eager spindle
rich adder
eager spindle
#

depends on what your companies want you to do

rich adder
#

they are essentially..just "fancy" methods

worthy tundra
dense plume
#

Depends yeah, and if you are using certain libraries (Mirror networking comes to mind) you can't really use properties for everything

humble snow
#
if (Input.GetKey(KeyCode.X)) { collectCanvas.SetActive(true); }
else { collectCanvas.SetActive(false); }

thats for the transparency mask

toggleGroup.SetActive(!toggleGroup.activeSelf);
rulesCanvas.SetActive(!rulesCanvas.activeSelf);
if (toggleGroup.activeSelf) { foreach (GameObject player in players) { player.SetActive(true); } }

thats for the book (this is on button press not update btw)

eager spindle
rich adder
#

yes props are awesome, I have many usecases. Also I use MAUI / Blazor so props are core to binding

worthy tundra
humble snow
#

you hold x to view it

eager spindle
#

rn I serialize a dictionary as part of my savesystem but I need a bit more internal work before getting a key, so rather than doing Savesystem.variables.SetString(key, value) I can just SaveSystem.variables[key] = value

#

super clean

eager spindle
#

ive been raw htmlcss user my whole life and dont even know what server side rendering is

#

not even bootstrap

rich adder
#

your code is never seen

eager spindle
#

even the htmlcss?

#

does it still have accesibility built in?

rich adder
#

I think so

eager spindle
#

that is very neat

humble snow
#

also ive seen a lot of problems about materials being off but the first transparency mask in the build works and the two transparency masks use the same material

#

so that isnt the problem

rich adder
#

im not 100&% on the css/html part. But in a nutshell SSR is for keeping your code *more secure (making calls to db etc)

#

most of it compiled to webassembly in blazor at least

#

so you dont want someone just peeking your code there (say if you have a algo for signing files etc)

raw token
#

SSR also improves the time to first render, which helps SEO and UX and such. And then for interactive stuff you can hydrate data and interactivity after the markup loads, which is super awesome 👀

#SSR4pres

rich adder
#

yeah! good point there

#

they have one on blazor specifically to do that SSR first then its client side

raw token
#

I've heard great things about blazor, but C# was always out of my wheelhouse at the time. I might have to finally check it out if I find the time!

steel hull
#

is there an already built in system for character controlling?

#

movement

rich adder
wintry quarry
raw token
raw token
rich adder
steel hull
#

what about Input GetAxis("Vertical")? does it automatically get a vector3 of the Vertical directions you are looking?

#

or horizontal

#

doesn't really matter

steel hull
rich adder
mint remnant
#

reference more than one tutorial

steel hull
rich adder
#

brackys 😛

#

shocker

steel hull
#

well

rich adder
#

where do you see V3 th

mint remnant
#

Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;

rich adder
#

well yes that makes perfect sense

#

V3 needs 3 floats

rich adder
#

GetAxis returns floats, so they are constructing a v3 with 2 floats (3 but 2 are returned by get axis)

#

also this the worse part of this tutorial

#

you NEVER multiply your mouse input by deltaTime

#

it is already framerate independent

steel hull
#

no I am talking about the movement

#

not the mouse rotation

rich adder
#

I get it, I already told you . They are not returning a v3 from GetAxis

#

they are constructing a new v3 based on those floats

steel hull
rich adder
#

no shite
its okay is not your fault, they just kinda left it there cause its got views

steel hull
#

like you're constructing a vector3, how does that make you move?

rich adder
crisp token
#

Was it stupid for me to make my own character controller

crisp token
#

Transform.forward should return direction an object is facing right

rich adder
rich adder
#

local rotation forward

rich adder
#

and what yours will need that other controllers dont provide

#

if you're quickly prototyping so much esaier to use premade ones like CC starter ones or KCC and modify them

#

but yes if you want more control, you would build your own

crisp token
#

well whats done is done

round mirage
#

i have put a box collider in an empty who is a child of my gameObject and i have use OnTriggerEnter but it dont work . we cant use OntriggerEnter with ChildObject ?

rich adder
crisp token
steep rose
#

nav remember when i asked you if you wanted to test my movement package out before release, its very early but you can if you want

steel hull
#

what does the getaxis horizontal return

#

exactly

steep rose
#

depending on what you press

rich adder
#

I sent it to you

steel hull
#

oh

#

wait

mint remnant
steel hull
#

oh

steep rose
rich adder
steep rose
summer stump
# steel hull exactly

If you press A it will go from 0 to -1 over a couple frames, and whn you let go, it will return to 0 over a few frames

#

GetAxisRaw will snap directly from 0 to -1

rich adder
steep rose
rich adder
steel hull
#

WAIT WHAT IT IS A BUILT IN FUNCTION THAT DETECTS WASD KEYS?

worthy tundra
#

lemme check

steel hull
#

no like I am doing this rn

raw token
#

Or whatever - it's just configured for directional keys/wasd by default

steel hull
worthy tundra
steel hull
#

It returns a value between -1 and 1

#

depending on which key I press

#

a is 1 if I press w and -1 if I press s

polar acorn
rich adder
# steel hull

the only thing that makes it WASD is because unity created Horizontal and Vertical axis that correspond to it
(in the Input class)

polar acorn
#

it's just that those values are WASD by default

worthy tundra
rich adder
#

ops

slender nymph
polar acorn
steel hull
#

but what about

worthy tundra
steel hull
#

how do I fix the character moving faster when holding both buttons?

steel hull
#

what does it exactly do

worthy tundra
worthy tundra
rich adder
crisp token
#

how do I get the rotation of a child game object with respect to global axis?

rich adder
steel hull
#

I get it

polar acorn
steel hull
#

its litteraly like clamping

raw token
#

Yeah, within the range 1,1

steel hull
#

alrightt thanks

#

this is right, no?

polar acorn
#

Did you normalize it

steel hull
#

I'll

worthy tundra
worthy tundra
steel hull
#

yeah but the variable

#

like thats how you assign a vector3 variable, right?

polar acorn
#

new Vector3 is in fact how you create a new vector3 yes

steel hull
#

thanks

rich adder
# steel hull

you can do dir.Normalize()
or
dir = new Vector3(a,0,b).normalized

crisp token
#

im trying to get the direction the cameraHolder is looking in but I suck

steel hull
#

wtf

#

now I am moving at godspeed and camera is the only thing that is moving

crisp token
worthy tundra
rich adder
crisp token
#

idk

rich adder
#

well whats happening instead?

worthy tundra
crisp token
#

let me put a few debug.logs in to test rq

steel hull
#

wait

rich adder
steel hull
#

no why is it at godspeed?

rich adder
steel hull
#

wait

#

I got more things to take care of

#

what does Input.getaxis horizontal get the axis of? the main camera? the object that it is assigned?

polar acorn
#

by default, it'd be A/D

raw token
#

An "axis" in that context is just a pair of inputs which can evaluate to values in the range -1 to 1

slender nymph
steel hull
#

well I can't turn around

#

when I do w makes me go backwards

rich adder
#

show code?

steel hull
naive swan
#

sup fam! im a newbie but got much interest in game dev, would love a few tips regarding a difficult journey i want to embark haha

#

thanks fam

slender nymph
rich adder
polar acorn
# steel hull

This object is indeed moving forward when you hit W. What direction is the object facing?

steel hull
#

playerbody is set to the Player

#

empty object

crisp token
#

thanks tho

rich adder
# steel hull

lets see the player and where you put the camera in scene in Local Pivot view mode

steel hull
#

Idk what the local pivot view is

#

thats all

rich adder
polar acorn
steel hull
polar acorn
# steel hull

Okay, so, hitting W should move this thing in the direction of the blue arrow

rich adder
# steel hull

which one is Body and Which one is Player btw
(script wise, which one is linked to what)

steel hull
rich adder
steel hull
rich adder
#

ok

polar acorn
steel hull
#

all same

#

all of them are the same

round mirage
#

hello i have this error message only with my instancied gameObject but i dont understand what is the problem.

rich adder
steel hull
#

yeah

polar acorn
#

What direction does it actually move when you press W?

steel hull
polar acorn
#

Which "arrow" does it follow?

steel hull
mint remnant
steel hull
#

oh my bad

#

I turn it on the local side but it is the same on the global side

rich adder
steel hull
#

but wait

#

no it looks true

rich adder
#

normals are part of mesh not texture

round mirage
steel hull
#

playerbody.transform should effect the global side no?

polar acorn
steel hull
#

which doesn't make any sense

polar acorn
polar acorn
steel hull
polar acorn
steel hull
#

global pivot

rich adder
#

that doesnt help

polar acorn
#

Global and Pivot are two opposite things

steel hull
rich adder
#

maybe record a video 😅

polar acorn
#

That doesn't change

round mirage
polar acorn
#

that's the world

steel hull
#

should I move it in local direction?

polar acorn
steel hull
#

I don't think so it moves like its facing the global direction

rich adder
#

the object is rotating properly, you're just applying dirrection from your inputs directly

steel hull
#

wait I am gonna try something

polar acorn
#

Hang on, I can't actually find decent documentation as to whether Move is local or global

rich adder
#

i recall this examples moves a third person character and its consistent regardless of facing direction

steel hull
#

I need to go

rich adder
#

i just do transform.forward * vertInput + transform.right * horizInput

#

but you can probably do Transform direction? or is it inverseTransform ?

drowsy flare
#

What's a nice way to pass an argument to a prefab when I'm instancing it from a script?

polar acorn
drowsy flare
#

Not possible at the same time as instantiation?

ionic zephyr
#

if a class inherits from another that has a Start method, does the code in Start run on the object with the child class?

polar acorn
ionic zephyr
#

I tryed it but it doesn´t run but I wanted to check if it is normal

rich adder
#

it inherits MB

ionic zephyr
#

So if I have the Item object and I have Resource which Inherits from Item, I have a Start function in Item but it doesn´t run whenever a Resource Object is instantiated

slender nymph
#

does Resource define its own Start method?

ionic zephyr
#

Yes

slender nymph
#

is it a separate Start method or is it actually overriding the one from Item? if the former, then it is working exactly as expected because the two methods are unrelated and Start is only called once on an object and there's nothing in place that will propagate the call to its base class(es), if the latter then you need to make sure you are also calling base.Start() in the overridden Start

ionic zephyr
#

Oh, I might be overriding the method, how can I call the base Start?

#

while preserving the start of the child class

steel stirrup
#

either don't override it at all, or use base.Start()

slender nymph
#

if you are actually overriding it, then i already gave you the line of code you need, it is literally just base.Start()

slender nymph
ionic zephyr
#

Is it okay to override it? In my case the Resource needs to call the Start Method to run some code that the other child classe of Item don´t, what is the best method to do this?

slender nymph
#

the real question is, are you actually overriding it or are you actually hiding it. those are two different things and overriding is what you should be doing

#

if you are unsure then show the code

ionic zephyr
#

!code

eternal falconBOT
steel stirrup
ionic zephyr
slender nymph
#

those are two unrelated Start methods. make Start protected and virtual on the Item class and actually override it in the ResourceItem class and call base.Start() there

ionic zephyr
#

It isnt working

ionic zephyr
crisp token
#

I was having a bit of a lag spike every time a Debug.LogWarning was called, is there anyway to make that not happen? I commented out the warning statement and it didnt lag anymore

slender nymph
ionic zephyr
crisp token
#

are you allowed to extend a monobehavior? Ive never done it

slender nymph
# ionic zephyr https://gdl.space/ejubefotot.cs

Before we get further into troubleshooting, I do have one question about this, why is there a CreateAssetMenu attribute on Item? it's a MonoBehaviour, which means it is a component that should be added to a gameobject, not a ScriptableObject

ionic zephyr
#

Yeah, I forgot to remove it

slender nymph
drowsy flare
crisp token
#

extend a class that inherits from

slender nymph
#

what Pingu has is just plain inheritance. You do know that you can inherit from a class that inherits from other classes, right? in fact every class you inherit from isn't even the base class (with the exception of inheriting System.Object which you don't even need to directly do anyway)

crisp token
#

yea ik that

slender nymph
slender nymph
crisp token
#

but i thought the whole point of a monobehavior is to add it as a component, so how do you add the ResourceItem class as a component

slender nymph
#

the same way you do any other object that inherits MonoBehaviour

#

because it is inheriting MonoBehaviour

crisp token
#

oh I thought it added the entire script

slender nymph
#

in fact, it isn't even MonoBehaviour that makes something a component, it's the even more base class Component which Behaviour inherits and then MonoBehaviour inherits Behaviour

crisp token
#

so Pingu has the option to add Item or Resource Item as a component rn

slender nymph
#

yes because they are two different classes that both inherit from MonoBehaviour. it's just that ResourceItem also happens to inherit from Item so an instance of ResourceItem is not only an instance of a MonoBehaviour, it is also an instance of Item

slender nymph
#

this is not the entire window

ionic zephyr
slender nymph
#

even this is still cutting off the important part on the right where it shows what types of logs are hidden. but also just to be clear, this is during Play mode, right?

slender nymph
#

show the code that instantiates the object and make sure that code is actually running

ionic zephyr
#

the Start code?

slender nymph
#

how is the object instantiated? or is it already in the scene?

ionic zephyr
slender nymph
#

then screenshot your entire unity editor window during play mode with that object selected in the hierarchy so it appears in the inspector and make sure the console is also visible

ionic zephyr
slender nymph
#

you've screenshot two separate objects where only the prefab (which is not the object in the scene) has that component on it

ionic zephyr
#

The prefab has an Overworld object component

#

which contains the Resource script

slender nymph
#

the prefab you've shown a screenshot of does not, it has a SpriteRenderer and a ResourceItem

polar acorn
slender nymph
polar acorn
# ionic zephyr

That's not a prefab, and also that's not the thing that has the Start code you want to run

round mirage
#

hello i have made a program that when i am near enough of the gameObject and i look this gameObject i can take but if i look this gameObject before i am near enough i cant take it . Someone can help me 🙂 ?

    {
      if (!gameManager.Echap)
      {
        if (distanceFromPlayer < 5f)
        {
            Near = true;
        }
        else
        {
            Near = false;
        }
        distanceFromPlayer = Vector3.Distance(gameObject.transform.position, Player.transform.position);
        if (Input.GetKeyDown(KeyCode.E) && CanTake)
        {
          transform.position = new Vector3(0f, 1000f, 0f);
          outline.enabled = false;
          PickUptxt.enabled = false;
          if (gameObject.CompareTag("Pepper"))
          {
            invSave.pepperAmount += amoutOfItem;
          }
          else if (gameObject.CompareTag("Glass Bottle"))
          {
            invSave.GlassAmount += amoutOfItem;
          }
          else if (gameObject.CompareTag("Sunflower"))
          {
            invSave.sunflowerAmount += amoutOfItem;
          }
          StartCoroutine(InvMessage());
        }
      }
    }
    void OnMouseEnter()
    { 
      
        if (Near && !gameManager.Echap)
        {
         outline.enabled = true;
         PickUptxt.enabled = true;
         CanTake = true;
         PickUptxt.text = "Press E To Take " + gameObject.tag;
        }
    }
    void OnMouseExit()
    {
        outline.enabled = false;
        PickUptxt.enabled = false;
        CanTake = false;
    }
    IEnumerator InvMessage()
    {
        AddInvtxt.enabled = true;
        AddInvtxt.text = "+ " + amoutOfItem + " " + gameObject.tag ;
        yield return new WaitForSeconds(2.5f);
        AddInvtxt.enabled = false;
        Destroy(gameObject);
    }```
ionic zephyr
#

what can I do?

slender nymph
#

if you want Start to run then the object must be instantiated

polar acorn
ionic zephyr
#

but the resoureceItem inherits from it

#

doesn´t that count?

slender nymph
#

no because there is no active ResourceItem object in the scene

ionic zephyr
#

but resource Item only stores data

#

I dont want it to be on the overworld

slender nymph
#

then why is it a component

polar acorn
polar acorn
ionic zephyr
# slender nymph then why is it a component

Because I had a problem with my tools and weapons. All of my tools and weapons are SO´s which have different stats, however one of them is Durability. I want to know how to remove the object from my inventory whenever it breaks. The problem is that when I reduce de Durability counter with each hit, I am reducing the SO stat so I am facing the problem that I might have to create a new class of tool that has a durability float and add that specific class into a different List on the Inventory Manager, is there another way to solve this?

slender nymph
#

you can have classes that are neither MonoBehaviours nor ScriptableObjects

ionic zephyr
#

so I should turn Resource into a non-heritating class?

slender nymph
polar acorn
steel stirrup
ionic zephyr
#

and that is what lead me here

steel stirrup
#

so instead of the SO representing the tool, what you want to do instead is have a tool/weapon/usable whatever class that has mutable fields within it

#

the SO should generally be treated as immutable at runtime

polar acorn
#

the SO is a database

#

you read from the database, and make a thing

ionic zephyr
#

so now every single object has a database but also a Class

steel stirrup
#

you're tossing around a lot of terms here that don't really mean what you're using them to say

ionic zephyr
polar acorn
#

Example:

public class ItemData : ScriptableObject
{
  public int maxDurability;
}

And also:

public class InventoryItem : MonoBehaviour
{
  public ItemData item;
  public int currentDurability;
}
#

That's it

#

that's all that's needed

fiery moss
#

speaking of databases, i never touched a single line of code in my life, yet i want to make some sort of 'game' where you can interact with a computer, and get to enter the database of some secret organization, i'm gonna first consult guides that already exist first and come here if i need help

ionic zephyr
steel stirrup
polar acorn
#

When do you expect Start to run

ionic zephyr
#

In the Start function, the Item Class gets its data from the SO (ItemData)

polar acorn
ionic zephyr
steel stirrup
#

Is there a newer version of his Item class posted? The one I pulled up is a mono

ionic zephyr
#

Start calls at the beggining

polar acorn
#

I'm asking you what calls Start on the object

steel stirrup
#

His item class is a component, start should work fine?

silk fossil
#
using System.Collections.Generic;
using UnityEngine;

public class CameraMovement : MonoBehaviour
{

    public float mouseSensitivity = 400f;

    float topClamp = 90f;
    float bottomClamp = 90f;

    float xRotation = 0f;
    float yRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked; //lock cursor middle screen
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; 
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;  //mouse inputs;

        xRotation -= mouseY; //rotate aroud x axis, up and down

        //clamp rotation
        xRotation = Mathf.Clamp(xRotation, topClamp, bottomClamp);

        yRotation += mouseX; //rotate around y axis

        //apply rotation to transform
        transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);

        
    }
}

Why is this camera movement script not working, when I start the game, it is just the character staring out the ground, and it cant look up

polar acorn
#

Which it doesn't

#

So I'm asking what they're expecting to call Start

steel stirrup
#

Obviously an object needs to exist to have an instance method called, really not sure what you're getting at

wintry quarry
ionic zephyr
polar acorn
wintry quarry
polar acorn
silk fossil
ionic zephyr
wintry quarry
polar acorn
silk fossil
wintry quarry
silk fossil
#

💀

wintry quarry
#

many tutorials make this mistake

#

get rid of it

silk fossil
#

this is what i was using

wintry quarry
#

Yeah just another bad tutorial

silk fossil
#

alr

wintry quarry
#

they all based it off Brackey's FPS tutorial which was wrong too

#

you don't wnat deltaTime there

ionic zephyr
silk fossil
#

alr tnx man

polar acorn
ionic zephyr
#

Yes

silk fossil
#

good thing i was not too into the tutorial before you told me

polar acorn
ionic zephyr
#

The overworld item containst this

polar acorn
# ionic zephyr

Okay, so you're trying to call the Start function of OVERWORLD Item then ?

ionic zephyr
polar acorn
ionic zephyr
#

But I dont want it to be directly on the scene

polar acorn
ionic zephyr
#

I want the Start at “Item” to run once the Overworld item is in the scene

polar acorn
#

Since it doesn't exist in the scene, the scene isn't going to call Start

#

So, where are you calling it?

ionic zephyr
#

Oh okay

#

Now Im getting it

#

I am using “Item” as a receiver of the database

#

But it makes no sense

polar acorn
#

Right now, you have no Item in the scene. So, you have an object that can be the real-world implementation of your SO, but it doesn't exist.

ionic zephyr
#

So the structure could be that the overworld item gets the data but the abstract items “in Inventory for example” remain as SOs

#

But what about the weapons and the durability, what should I do?

polar acorn
ionic zephyr
#

A weapon object?

polar acorn
#

Sure, whatever thing in the game represents this specific weapon

#

Suppose you have The Axe of Despair and The Sword of A Thousand Truths. The axe has 10 durability, the sword has 20. How would you represent those two objects in your game

ivory flare
#

help my script cause the screen to bug out and like flicker

#

public class CameraMovement : MonoBehaviour
{
    private Vector3 dragOrigin;
    private bool isDragging = false;
    public float zoomSpeed = 1f;

    void Update()
    {
        HandleDrag();
        HandleZoom();
    }

    void HandleDrag()
    {
        if (Input.GetMouseButtonDown(0)) 
        {
            isDragging = true;
            dragOrigin = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }

        if (Input.GetMouseButton(0)) 
        {
            if (isDragging)
            {
                Vector3 dragPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Vector3 move = dragPosition - dragOrigin;
                transform.position -= move; 
                dragOrigin = dragPosition;
            }
        }

        if (Input.GetMouseButtonUp(0)) 
        {
            isDragging = false;
        }
    }

    void HandleZoom()
    {
        float scrollInput = Input.GetAxis("Mouse ScrollWheel");
        if (scrollInput != 0)
        {
            Camera.main.orthographicSize -= scrollInput * zoomSpeed; 
            Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, 1f, 20f); 
        }
    }
}
ionic zephyr
polar acorn
#

How do you want to represent an object that exists

ionic zephyr
rich adder
#

your zoom is probably wrong

ionic zephyr
#

But my Inventory system is programmed to store SO’s how can I store “Material” things

ivory flare
rich adder
ionic zephyr
rich adder
#

treat SOs like templates , not the actual object

polar acorn
#

Why would you need a different InventoryItem class

#

Just change which ItemData it holds

rich adder
ionic zephyr
#

Okay, I think I get it

ionic zephyr
polar acorn
#

A class represents a "shape" of an object

ionic zephyr
#

That could inherit from a common class

polar acorn
#

If an object has an ItemData and a currentDurability then it's one of these

rich adder
ivory flare
ionic zephyr
rich adder
#

could also be the z value messing with the calculation

ivory flare
steel stirrup
proud spoke
#

Hi can anyone help me figure my what the problem?

#

so im making the ladder system

#

it kinda works you can go up and down
the problem is once you get down you cant go up you have to re-enter the trigger

here is the code

using System.Security;
using UnityEngine;

public class LadderClimbing : MonoBehaviour
{
    private bool isLadder;
    private bool isClimbing;

    private float vertical;

    private float climbingSpeed = 2f;

    private Rigidbody2D rb;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        vertical = Input.GetAxis("Vertical");

        if (isLadder && Mathf.Abs(vertical) > 0f)
        {
            isClimbing = true;
        }
    }

    private void FixedUpdate()
    {
        if (isClimbing)
        {
            rb.gravityScale = 0f;
            rb.velocity = new Vector2(rb.velocity.x, vertical * climbingSpeed);
        }

        if (!isClimbing)
        {
            rb.gravityScale = 1;
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Ladder"))
        {
            isLadder = true;
        }   
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Ladder"))
        {
            isLadder = false;
            isClimbing = false; 
        }
    }
}
eternal needle
#

Have all your information ready then just post it as a single message

proud spoke
#

oh okay sorry

wintry quarry
proud spoke
#

here is the issue i think

#

isClimbing is false

wintry quarry
#

right so - keep debugging

#

find out why it's becoming false

#

when you don't expect it to

proud spoke
#

but im trying to multiply it speed and vertical but vertical is 0

#

it should be false

#

because im no climbing

#

the issue is i cant start climbing once im down

autumn lintel
#

if this is a string, is this "" or null

wintry quarry
#

Unity's serializer doesn't support null for reference types

wintry quarry
# proud spoke

May be easier tyo use Debug.Log for this becasue you won't be able to do input stuff while using the debugger

autumn lintel
autumn lintel
eternal needle
#

#854851968446365696
this is a coding channel. dont ping users in on your discussions if they arent involved

eternal steeple
#

hi (3D), i'm using joystick for movement, i'm trying to add inertia and i'm wondering what's the best way to detect when you should de-accelerate as currently my player will only de-accelerate when there's no input on the joystick

deft grail
wintry quarry
eternal steeple
eternal steeple
wintry quarry
#

They're just "change in velocity"

#

If you're asking how to make it so it decelerates at a different rate than it accelerates, you would just use a different rate when the target velocity magnitude is lower than the current velocity magnitude

eternal steeple
wintry quarry
eternal steeple
# wintry quarry What's the issue with that exactly? I'm not sure I understand

sorry if i'm explaining it poorly 😅
basically i want 2 different acceleration rates,

i just don't know how to do if i for example am strafing, when i flip the movement joystick from one side to another one quickly then i want it to have a faster acceleration rate until' it reaches 0 speed on that axis and it'll switch to another rate,
it's basically detecting if your joystick moved from negative value to positive value or the other way around on a specific axis
not sure if this would be the best way hence i asked if anyone knew a good way to determine this

wintry quarry
#

looking at the current velocity and the target velocity

#

what side of 0 those are on

#

etc

#

Draw up a comprehensive set of circumstances and what the result should be

#

there's probably only 4-8 possibilities

#

cover all the cases with if/else statements

#

and you're good.

rocky canyon
#

all that ☝️

eternal steeple
#

thanks 😄

rocky canyon
#

basically lol..

#

could probably implement Mathf.Sign to differentiate between inputs in teh same direction or inputs in the opposite direction

#

or possibly even simpler than that.. if its only on 1 axis.. isSwitchingDirection = (input > 0 && currentVelocity < 0) || (input < 0 && currentVelocity > 0);

solemn fractal
#

Hey guys.. I always have this doubt.. if I want to create a game where I will have different types of enemies.. just to make it simple to visualize.. lets imagine the enemies types are like.. an enemy is a circle.. the other is a square.. the other is a triangle.. etc.. all of them.. they have damage, HP and maybe an hability. The have dif shapes and sizes.. is there a best way to create the system or ways? like scriptable objects and others? Any advises on which system you would use? Also I have a question about it related to classes. Should I have 1 class to control enemy Hps, damage and other to control their behavior? I am just a good newbie here. thank you.

wintry quarry
solemn fractal
#

So making one prefab .. each prefab with a dif script.. should that not be a problem? I would love to do that way for me would be way more simpler..

#

I know its vague. but I am newbie. cant elaborate better the question i think

#

I already did a small game using scriptable object but I didnt like the system

wintry quarry
#

why would the script be different?

#

Do they have different behavior?

mint remnant
#

Since you are a newbie, the best thing to do is probably start out with basic prototypes instead of a more lofty end goal of a game

rocky canyon
#

depends on what ur scripts are in charge of..
say u just want a simple enemy with a health variable..
you can have a script called Enemy.cs that has a health variable.. and u can make 10 different prefabs (all using that same script)
where each instance.. has its own version of Enemy and its own health value

wintry quarry
royal linden
#

if i have a script with a public variable can a change it with a different script?

solemn fractal
#

Thank you.

royal linden
rocky canyon
#

yourScript.publicVariable = 10f;

solemn fractal
#

I can have 2 scripts in one object, or that is not good practice?

rocky canyon
#

thats called composition.. and is 1 of many different design structures

wintry quarry
solemn fractal
#

Ok. Thank you.

rocky canyon
#

my player object has like 15 different scripts 🫣

solemn fractal
#

one day I will get there

#

hopefully

rocky canyon
solemn fractal
#

ok thank you

rocky canyon
#

the having multiple scripts is actually better than having 1 big chunky script..

#

Single Responsibility being that a class should only care/handle 1 thing or 1 aspect of things

solemn fractal
#

hmmm, ok, i was always afraid that having a bunch os scripts and prefabs ni a game would be bad for processing.. but it seems its a normal thing.

rocky canyon
#

for example.. Your PlayerMovement doesn't need to know about the players health

#

its just setting urself up for spaghetti code..

mint remnant
#

are SOLID principles different for Unity?

rocky canyon
#

if ur healthbar isn't working.. u should know to go to the script that handles ur healthbar.. and be able to find/solve the issue quickly

solemn fractal
rocky canyon
#

instead of scrolling thru 1 big master class.. that has the player health somewhere in here

rocky canyon
#

is ultimately up to you.. what works best for you..

solemn fractal
#

Interfaces are important to a game or you can avoid using them?

rocky canyon
#
public class PlayerHealth : MonoBehaviour
{
    public int health = 100;

    void Start()
    {
        health = 100;
    }

    void Update()
    {
        if(health <= 0)
        {
            Debug.Log("PlayerIsDead");
        }
    }
}``` heres my health script for example
#

when i want to change the players health.. i just grab the <PlayerHealth> script from the player.. and just change its health variable.. (enemies usually do that) when they make contact (collide with the player for example)

rocky canyon
#

i wouldn't worry about them first thing tho

solemn fractal
solemn fractal
rocky canyon
solemn fractal
#

I am focusing in 2d games now as it seems to be more simple to create for beginners

rocky canyon
#

heres my player movement script... she's a thicc gurl

solemn fractal
#

Amazing organization

rocky canyon
solemn fractal
#

I imagine hahahaha

solemn fractal
#

Thank you. I posted a small game I did here in this discord dont remember what was the channel.. cant find now.

rocky canyon
solemn fractal
#

yeah the game is there, but I posted here in the discord .. there is a channel here to post your gams I just dont remember which one i created the post

rocky canyon
rocky canyon
#

if it was much older.. there was a channel that wasn't set up w/ post/threads and that probably got archived

solemn fractal
#

there it is.. took me 3 months to make this simple game hahaha

#

but it was 8 months ago.. i stopped and I am just coming back now to unity so .. learning all again

rocky canyon
#

atleast you finished something! 👍

#

some people never make it that far

solemn fractal
#

I want to get money with games one day even if that takes me 10 years.

#

I am not in a rush

#

lets see 😛 thank you for the help

rocky canyon
#

yea, dont be.. just start small. and get bigger each time

solemn fractal
#

yeah.. that is the secret.. people try to already start with the dream game and that is why they stop it and never try again

rocky canyon
#

"Im learning Unity, going to make a Multiplayer Minecraft Clone!"

solemn fractal
#

hahahaha

mint remnant
solemn fractal
#

Speaking about 2D and 3D.. in unity.. coding for both is that different.. or for a beginner surely is better to start with 2D?

cosmic dagger
solemn fractal
#

hmm.. so 3D you have more stuff to know I guess.. prob 2D will be better for beginners.

cosmic dagger
#

Oh and importing and using 2d/3d assets will be different . . .

cosmic dagger
solemn fractal
#

understood. thank you.

solemn fractal
#

Hey guys.. I have this small code here. Its my enemyMovement, Each enemy will have a dif speed movement. Do I have a simpler way to do that, or its ok to do like that? ```public class EnemyMovement : MonoBehaviour{

private float _circleEnemyMovementSpeed = 2;
private float _squareEnemyMovementSpeed = 3;
private Rigidbody2D _rb;

[SerializeField] private Player _player;

void Start(){

    _player = GetComponent<Player>();   
    
}


void Update(){
    
}

 private void CircleEnemeyMovementSpeed(){

    Vector3 MoveDirection = (_player.transform.position - transform.position).normalized;
    _rb.velocity = MoveDirection * _circleEnemyMovementSpeed;

    _rb.velocity = _rb.velocity.normalized * _circleEnemyMovementSpeed;

}

private void SquareEnemeyMovementSpeed(){

    Vector3 MoveDirection = (_player.transform.position - transform.position).normalized;
    _rb.velocity = MoveDirection * _squareEnemyMovementSpeed;

    _rb.velocity = _rb.velocity.normalized * _squareEnemyMovementSpeed;

}

}```

#

Each enemy with a method for its speed.

summer stump
#

Why the two velocity assignments for each enemy type?

#

The second one achieves nothing
MoveDirection was already normalized

eternal needle
solemn fractal
#

I dont know that is why I am asking 😛 i am a complete noob here. as they are dif enemies,. every prefab enemy dif I have will get this script.. to control their dif speed.. but I dont know the best way to do it.. so creating 1 method for each enemy is not good or wroong?

summer stump
#

Not good

solemn fractal
#

ok

summer stump
#

Just have one method to move. Each prefab will just have their own speed value...

eternal needle
solemn fractal
#

buit do I say in 1 method that enemy circle has speed 2 and enemy square have speed 3 ?

summer stump
#

One method, one variable, you change it in the inspector for each enemy.

solemn fractal
#

ahh ok ,true. Making it as a serialized variable correct?

#

makes sense

#

Thank you.

summer stump
# solemn fractal Thank you.
public class EnemyMovement : MonoBehaviour{
    [SerializeField] private float _speed;
    private Rigidbody2D _rb;

    [SerializeField] private Player _player;

    void Start(){

        _player = GetComponent<Player>();   
        
    }


    void Update(){
        
    }

    private void MovementSpeed(){

        Vector3 MoveDirection = (_player.transform.position - transform.position).normalized;
        _rb.velocity = MoveDirection * _speed;
    }
}
#

Also remove the second useless assignment to velocity

solemn fractal
#

Yeah. Thank you.. and how did u post here the code with colors? I tried to find it on pined or read-me and could not find

summer stump
#

I would just call the method move btw

solemn fractal
#

Thank you.

rocky canyon
#

syntax highlighting

ivory bobcat
#

!code

eternal falconBOT
summer stump
solemn fractal
#

But if I change it on the inspector.. and in the game I have factor that might change the enemy velocity, for a specific enemy.. wouldnt that be a prob? Because in the code I dont have a control for each enemy.. and have it only on the inspector

rich adder
solemn fractal
#

I dont know, I mean. in the game i have dif enemies.. dif prefabs for each one.. they will have a fixed starting movement speed. But in the game I might have things that could change the velocity of just 1 enemy and not other.. having control over the movement speed only in the spector and not in the code could be a prob? That is what I am thinking now

mint remnant
#

just because it's in the inspector doesn't mean you can't change it in code

rich adder
#

so reference that specific enemy in the code when you need to and change it

#

make a public method to modify speed

#

enemyMovement.SetMoveSpeed(4f)

#

or whatever

summer stump
#

Oh, maybe I misunderstood

#

So you want ALL enemies of type X to get a speed boost at certain points

#

Same thing you used earlier for code formatting. Just a cs after
They still have to be on their own lines

```cs
//code inside
```

solemn fractal
#

like this one??

solemn fractal
summer stump
solemn fractal
#

ah ok

summer stump
summer stump
#

The cs has to be on the same line as the ticks

#

Just copy paste this:

rich adder
#

use TryGetComponent and get the component directly, there is no need for tags/gameobject names

summer stump
#
//code here
#

But what you are trying to show is not really important

#

The context is missing

#

What method is that code INSIDE?

solemn fractal
#

I guess I need to try more here. Will come back later with questions about it if needed. Thank you guys.

solemn fractal
#

Hey guys.. is it useful or good practice to use List of lists? Example. Instead of having 1 variable for each list of enemy that are spawning, I can have 1 variable of a list of lists to control all spawned enemies list. What is your advise?

rich adder
#

yes list of list is fine

solemn fractal
#

Great. Will try that. Thank you.

#

But can I have a list of dif types inside a list of lists? or they all need to be from the same type?

#

Something like that:

#

I guess not right?

rich adder
#

omg dont do this

#

are you making a class for each enemy?

#

two three four etc.

solemn fractal
#

No, it was just a question to understand how it works

#

😛

rich adder
#

ohh lol ok

solemn fractal
#

😅

#

I am still thinking here how I will do it, before starting.. otherwise It will be a mess

rich adder
#

how you wrote it is fine

#

exept dont make a class EnemyOne two etc

#

lol

solemn fractal
#

Ok

summer stump
solemn fractal
drowsy flare
#

I've made a game where a enemy objects attack player objects with their weapon object.

I did the hit detection in the player controller class. But I'm starting to think that maybe it should be in the enemy weapon class, and call a method in the player controller to reduce hp?

What is good measure here?

eternal needle
drowsy flare
languid spire
#

yes, if the player can be damaged by multiple weapons it only needs one simple TakeDamage method which can be called by all weapons and they say how much damage is caused

rough hill
#

Does anybody know how to fix those?

languid spire
steel hull
#

hello

#

uhm I have an issue

#

where visual studio code uninstalled itself

languid spire
steel hull
#

I don't know I reinstalled but

#

this is damn weird

#

one more thing

#

input.getaxisraw allways outputs 1 when I am pressing w

#

no matter the direction I am looking

#

getaxisraw horizontal and vertical

languid spire
#

how is the w key supposed to know which direction you are looking?

eternal needle
languid spire
#

irelevant

steel hull
#

idk what I am doing wrong

languid spire
#

you know the direction, the keyboard does not

steel hull
# languid spire you know the direction, the keyboard does not
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterMovement : MonoBehaviour
{
    float a;
    float b;
    Vector3 dir;
    public float speed = 0.01f;
    public CharacterController newController;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        a = Input.GetAxisRaw("Horizontal");
        b = Input.GetAxisRaw("Vertical");
        dir = new Vector3(a, 0, b).normalized;
        newController.Move(dir * speed);
        Debug.Log(a);
        Debug.Log(b);
    }
}```
languid spire
#

so what there says which direction the character is facing?

steel hull
#

shouldn't the getaxisraw say that? like if the input of the direction is a little bit rotated shouldn't it like when I press w give me both x and z vectors?

languid spire
#

no, that is telling you which way to move, not which way you are facing

steel hull
#

interesting

#

It seems I have misunderstood the function let me check

steel hull
#

no I don't get it, can someone help?

teal viper
#

Direction in game on the other hand would be changing depending on your camera/character rotation.

polar kraken
#

Hey guys,
How can I change the start time on a state from animator via code ?

polar kraken
#

There is Transition Offset on transitions but how can I modify it from code ?

#

Also there is Motion Time which by modifying that I can't achieve what I want and actually I don't understand what it is exactly.

fickle wagon
#

Hello friends, how can I get the user country in unity WebGL?

fickle wagon
languid spire
ivory bobcat
#

You might not get any response because this is the beginner coding channel. Instead you should copy the message, delete this message here and repost your message in the non coding channel #💻┃unity-talk

nova shore
#

what happens if u
while(!input.getkey(somekey))

finite dew
#

just skip out on the while and put it in update

#

in an if

nova shore
finite dew
#

From monobehaviours? Then call it from Update

nova shore
#

i tried

  1. making an entire new ienumerator
  2. using a bool to break out of the while block
nova shore
#

the

cosmic dagger
nova shore
#

while loop is inside of another ienumerator

finite dew
#

coroutines are attached to gameobjects, I'm pretty sure, so it shouldn't matter if you just call it in an update

nova shore
finite dew
#

but if you're inside an ienumerator then inside the while loop just write yield return null; and it will wait a frame before continuing

nova shore
#

i HAVE
it still freezes

finite dew
#

show code

nova shore
#

time to ctrl + z hundred times

#

one sec

cosmic dagger
nova shore
# finite dew show code
 IEnumerator WaitForInput(KeyCode key)
 {
     bool breakpleasedontfreeze = false;
     while (!breakpleasedontfreeze) 
     {
         if (Input.GetKeyDown(key)) breakpleasedontfreeze = true; 
    
     }
 yield return null;
 }

this freezes

#

wait

#

now

#

its right

finite dew
#

it is very not right

nova shore
#

indeed

finite dew
#

first of all, in this case, the yield return null is never ran

nova shore
#

yea

finite dew
#

you should have kept it inside the while loop

#

like in your original message

#

that's the first thing

#

second thing

cosmic dagger
#

Your yield is outside of the loop . . .

nova shore
finite dew
#

the while loop is never broken

#

oh no wait it is

#

-_-

cosmic dagger
#

Why aren't you using Update? You never explain . . .

finite dew
#

how do you run this function?

#

can you show me?

#

what code is running this function

nova shore
#

a spell

#

first its a wind up

finite dew
#

show codeeee I need to see how it's ran

nova shore
#

i am

finite dew
#

how are you calling the function

nova shore
#

one ec

cosmic dagger
#

You know you can respond in complete sentences, right?

nova shore
#
#nullable enable
    public override void Activate(MonoBehaviour monobehaviour, GameObject Player, GameObject? Target, Vector3? MousePos)
    {
        monobehaviour.StartCoroutine(WindUp(Player,monobehaviour));
        Debug.Log("A");
        
        
    }

    IEnumerator WindUp(GameObject Player,MonoBehaviour mono)
    {
        int Capacity = 0;
        List<GameObject> balls = new List<GameObject>();
        while (Capacity <= MaxCapacity)
        {
            Instantiate(Ball, Player.transform.position + new Vector3(r.Next(-offset, offset), r.Next(-offset / 2, offset), r.Next(-offset, offset)), Quaternion.identity, Player.transform);
            balls.Add(Ball);
            Capacity++; Debug.Log("Basdasd");
            yield return new WaitForSeconds(0.3f);
            
        }
        
        mono.StartCoroutine(WaitForInput(KeyCode.Mouse0));
        Launch(balls);
    }

    void Launch(List<GameObject> balls)
    {
        Debug.LogWarning("Mf");
        for (int i = 0; i < balls.Count; ++i)
        {
            balls[i].GetComponent<Rigidbody>().velocity = Camera.main.ScreenToWorldPoint(Input.mousePosition).normalized * Speed;
        }
    }

    IEnumerator WaitForInput(KeyCode key)
    {
        bool breakpleasedontfreeze = false;
        while (!breakpleasedontfreeze) 
        {
            if (Input.GetKeyDown(key)) breakpleasedontfreeze = true; 
        yield return null;
        }
    }

this activate fn is called in a another script that

 void Update()
 {
     for(int i = 0; i < SlotKeys.Length; i++)
     {
         if (Input.GetKeyDown(SlotKeys[i]))
         {
             StartCoroutine(newThread(i));
         }
     }
 }

 IEnumerator newThread(int i)
 {
     hum.SpellSlots[i].spell.Activate(this,gameObject, null, null);
     yield return null;
 }
eternal falconBOT
finite dew
nova shore
#

also

nova shore
nova shore
#

till unity starts
anyway i can improve on it?
tryna make a spellcaster system

finite dew
#

Also I know we're not supposed to comment on formatting on this server but pretty please 1 command per line -_-

nova shore
#

EYYY IT DOESNT FREEZE

ok so now why

cosmic dagger
finite dew
#

you have to wait for the coroutine to be finished, in windup
the way you called it didn't really make the function wait

nova shore
#

ooooo

#

so its similar to waitforseconds
instead of just calling an entire new coroutine i can just directly do it in the reutnr

#

damn
and is it healthy to create this many coroutines

cosmic dagger
cosmic dagger
finite dew
nova shore
#

not really(i dont go that far, i think)

finite dew
#

the way I like to make spellcaster-like systems is via abstract classes

#

not whatever you got going on, that's probably the less flexible and more work-intensive approach overall

#

do you know what abstract classes are? or how inheritance works in general

nova shore
nova shore
#

liek i cant think of a way to make a baseclass that is being derived by two spells that

  1. does a ground slam
  2. shoots smth
finite dew
#

no need to get into coroutine hell for this

nova shore
#

that has like variables like manacost,name,desc etc etc

finite dew
#

your code will hang forever, until that input is pressed

#

that's an example of an issue

#

with your setup

nova shore
#

and tbh if he intends to hold onto charging the spell forever, might as well be dead xD(thats the game look im goin for)

finite dew
#

my point is that this weird passing a gameobject and a monobehaviour setup you got going on would be better done by having a base class that does those things in Update(), without a need for coroutines

#

and I mean you can make it work

#

with coroutines

nova shore
#

ive tried making base class as mono
that was easy af
the cooldown and all that bs was easy to handle
but i didnt know how i can make it so that the

#

player and enemies spell stats would differ

finite dew
# nova shore my baseclass is scriptable object 😭

you can in that scriptable object put a gameobject prefab that will be spawned on top of the player for example, and will handle all the spell effects and everything
and you will have a separate class for the effects and one class for the scriptableobject with just spell data

nova shore
#

wait idont get you..

finite dew
nova shore
#

player folder = player spells/skills
entities have set moves

nova shore
finite dew
# nova shore this feels like smth i should understand but i dont

you have a class SpellStats : ScriptableObject
you have stats in there like damage cooldown and things
you also have a reference to a prefab there
and when you wanna cast a spell, you spawn the prefab
and on the prefab there's a script that's called SpecificSpellType : GenericSpell with a reference to the scriptable object with its stats
and when you spawn the prefab, you pass the scriptable object into the SpecificSpellType script for the stats

#

this way you can have however many scriptableobjects with different stats for the same spell, and you can have 1 spell class that will just cast the spell according to the stats

#

and you make all the things happen from within the SpecificSpellType class, like all the VFX and raycasts for damage or whatever it is you need

umbral rock
#

So im following a tutorial on how to make an endless runner but i dont understand the code, he is spawning new floors the whole time but they are slightly higher every time then the previous floor that spawned, how? is this because he positioned the prefab higher and this has nothing to do with the code? or is there a line of code somewhere that tells the next floor to be spawned slightly higher?

nova shore
finite dew
finite dew
#

please for the love of whatever is holy, find a better tutorial

umbral rock
finite dew
cosmic dagger
finite dew
winter tinsel
#

curiosity made me come here, is there a way to make a gameobject, like a cube, have collision but be a ghost, so that it phases through objects, yet still checks for what it collides with?

umbral rock
cosmic dagger
winter tinsel
#

so if it comes into contact with another cube that has a collider, it goes through it but it still prints that its colliding with it

#

or it stays inside of it ig

nova shore
finite dew
nova shore
#

Thanks

winter tinsel
winter tinsel
#

thanks

cosmic dagger
umbral rock
winter tinsel
umbral rock
cosmic dagger
umbral rock
cosmic dagger
umbral rock
#

but the endposition is not higher up, its just on the far right side of the gameobject and not higher up

cosmic dagger
steep rose
umbral rock
#

aaah now i know, i think i saw it the wrong way, indeed i think the position is higher wait i'll show u

steep rose
#

all the code does is get the endpositions Position