#💻┃code-beginner
1 messages · Page 453 of 1
not denying that
yeah I agree on that one
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
ROBLOX TAKES 70%???????
Does roblox really take 70?
lets try not to jinx us now
The fact that kids are working on roblox games means that it technically consitutes exploitative child labor, 70%, jesus.
effectively yes because their robux conversion rate is terrible + they charge a developer fee
70% before taxes, need to factor in VAT, Income tax, business tax
roblox automatically does it for you
if roblox is a calculator..
unity is spaceX's flight controller..
and roblox still pays you a better cut than vtuber agencies 😄
I agree
I love unity way more
https://www.youtube.com/watch?v=_gXlauRB1EQ&pp=ygUScm9ibG94IGNoaWxkIGxhYm9y
And the follow up:
https://www.youtube.com/watch?v=vTMF6xEiAaY&pp=ygUScm9ibG94IGNoaWxkIGxhYm9y
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...
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...
i wish you luck in ur game-dev endeavours
Thank you! This looks like a morbidly fascinating watch. I've literally never touched the Roblox sphere.
And yes, it's 70% revenue. Not even 70% profit
roblox argues it comes with server hosting, publishing and outreach though + you get access to an underage audience who throws their robux at anything they see
third point being evil but money is money
their parents money*
ftfy
Steam does all that and they take 30%
Yeah I am planning to release games on steam If I become good enough
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
what do they even do with all that money??
yeah I got marketing
microsoft owns roblox
True, does roblox really handle google/social media marketing and all for your game?
actually If you pay yes
people search "tycoon" on roblox and click what they see
haha so true
doing that on steam won't net you as good of a result
The same thing every capitalist pig does with their money -- buy senators and US Supreme Court Justices, mostly
i am people
well my plan is social media on the marketing side
btw ms edge actually gives free robux if you earn enough coins
https://www.youtube.com/watch?v=Z4mqcR7wBcw
https://www.youtube.com/watch?v=UwjbLFImXOg&t=1s
heres some resources i watched a while ago that helps you get an idea of whats involved
my current game is on alpha testing on play store
will think about marketing another time
I am currently just trying to learn the basics of c# and unity
until you make it to steam, you can upload your games to itch.io for free
steam takes $100 from you for each game you upload, until you make $1000
https://www.youtube.com/watch?v=_cCGBMmMOFw&list=PLFt_AvWsXl0fnA91TcmkRyhhixX9CO3Lw&ab_channel=SebastianLague heres a solid crash course/introduction
i remember my first ever unity game....
it was a brackey's cube game clone
holy thankss
Idk what that is but I'll definetly check it out
poor mans steam
its a website where you can upload games, basically indie version of steam
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...
tyy
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 👍
btw it wasnt until i recently watched this video out of curiosity that i learned how to make visual studio use the unity thing lol
goes to show how you can always learn
itch.io is a site that lets you upload your games for free and even lets people follow you there. great for indie devs; people actively look for indie games on that site to play so its a great way to boost your popularity
can also monetise your content there
youll find lots of silly games there, though be careful about running random .exe files on your computer
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
to expand on this, game jams are a period of time where you make a game based off a given theme and submit it
like, imagine trying to have a steam game jam
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
a huge jam is also coming next week
you dont need to be professional expert coder to join a jam, just have fun
GMTK game jam 2024
once I uploaded my game as a webgl build, some of my relatives who were testing it asked why it was laggy for them and I had to teach them how to turn on hardware accel
idk why it was disabled for them by default
but no I can just do float instead of private float
cause its private by default
ohh
i think they meant manually typing the word private
that makes sense
yeah yeah
tbh idk why you would do that
some companies have it standard
Coding standards matter a lot when you have a codebase past a certain size
also do you know about [SerializeField] ?
no its like I just spawned in learning controls :/
anything in square brackets are called Macros, unity things
what are macros
you can put [SerializeField] before declaring a private variable and that variable would show up in the inspector.
its probably the thing i type the most in unity ever lol
its kinda like an indicator
[SerializeField]'s are good when you dont want a variable to be public but you still want to see it in the inspector
uhm why don't you use public instead?
with public other scripts can detect it
sometimes you dont want other scripts influencing that variable
well but why would you even use it then
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
oh like someone cheating?
in order to assign and change the value in the inspector instead of manually typing it in the script
in this example other rooms need to check if the room is unlocked but no one really needs Spawn Position
i mean you could set everything to public
to prevent cheaters?
interesting
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
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
just put a indicator number in front of it?
but this is more of people who you're working with next time
Idk sounds useless but maybe I'll get to use it later on
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
thats what I thought at first, now that I'm working with other programmers a lot I am thankful for it
so to prevent glitches?
and bugs yes
theres a lot more to this, i just explained 1 thing
well time shows it I guess?
makes sense
its a good idea to only have a variable public if other scripts need to interact with said variable
referring to this example. since spawnPosition is private and unlocked is public, I can do room.unlocked = true but not room.spawnPosition = ...
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.
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
dont be discouraged by this barrage information
theres lots to learn in both programming and unity
its generally better practice to make methods / properties
it took me a very long time before the unity workflow clicked for me
wdym
instead of making the field public, you interact with the private one through a public method.
or properties ie (get; private set;)
oh so like instead of
scriptName.boolName = true;
you can do
scriptName.functionName();
and have
functionName()
{
boolName = true;
}
?
private int _someField;
public int SomeField
{
get
{
return _someField;
}
private set
{
_someField = value;
}
}
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.
Other things can be dome during get and set which makes properties particularly powerful
Hard to tell without code
Show the call stack that occurs when pressing the offending button
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
these are important practices to adopt once you head out into the working world, especially when maintaining big codebases
idk how get and set work lol im a bruteforcer
fair you can just use functions
just look up properties
depends on what your companies want you to do
they are essentially..just "fancy" methods
i game dev for a hobby
Depends yeah, and if you are using certain libraries (Mirror networking comes to mind) you can't really use properties for everything
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)
they're clean tbh and dictionary getters/setters are a big help in my current project
yes props are awesome, I have many usecases. Also I use MAUI / Blazor so props are core to binding
do you run the first part in Update()?
if so, you are setting it inactive every single frame that youre not pressing X
thats intended
you hold x to view it
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
trying to wrap my head around the workflow for it rn
ive been raw htmlcss user my whole life and dont even know what server side rendering is
not even bootstrap
server side rendering is so the client never downloads the executable/dlls
your code is never seen
I think so
that is very neat
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
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)
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
yeah! good point there
they have one on blazor specifically to do that SSR first then its client side
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!
do it! it really simplifies front-end combined with backend, ala NEXT
if you need/love doing web and know c# its a no brainer
There are many but remember every game has different styles of movement so it really depends
The built in CharacterController is very popular - there's also a lot other solutions on the asset store
It's settled then! I love Next 😁. But I don't especially love JS backends as it turns out
yeah coding backend with JS seems like a nightmare. Typescript seems ok but
Luckly the only time i deal with JS is if i want C#/JS interop. So you can easily jam in any javascript library your heart desires 😄
render modes explained (sorry for getting a bit offtopic 😛 best of luck in your journey)
https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0
what about Input GetAxis("Vertical")? does it automatically get a vector3 of the Vertical directions you are looking?
or horizontal
doesn't really matter
GetAxis does not return a Vector
no I checked this out but doesn't make sense with the tutorial I am watching
which tutorial, which part doesnt make sense?
reference more than one tutorial
well
where do you see V3 th
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
this does
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
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
plus this was a bad tutorial I had to figure some things out myself
no shite
its okay is not your fault, they just kinda left it there cause its got views
no what doesn't make sense to me is that how is that giving us a move direction?
like you're constructing a vector3, how does that make you move?
because generally you apply vector math to move
Was it stupid for me to make my own character controller
Transform.forward should return direction an object is facing right
https://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html
take a look at velocity of a rigidbody. it is described as a vector3 for example
yes
local rotation forward
depends what you're going for
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
well whats done is done
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 ?
only if parent or thing triggering into it has rigidbody
local rotation forward is synoynmous with transform.forward right?
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
should be afaik
ok ty
a 1 or -1
depending on what you press
it says it in the manual..
I sent it to you
call it and debug log the values
oh
or is that getaxisraw
awesome , you want me to DM a link ?
yeah for sure, lemmie get you one
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
hold up I have my DMs locked, I will msg you see if itworks
yeah mb, you getting spammed or smth?
unsolicited help requests lol
WAIT WHAT IT IS A BUILT IN FUNCTION THAT DETECTS WASD KEYS?
iirc getaxis horizontal/vertical
lemme check
no like I am doing this rn
Or whatever - it's just configured for directional keys/wasd by default
yeah this
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
Technically it detects whatever inputs you've specified as "Horizontal" and "Vertical" in the input manager
the only thing that makes it WASD is because unity created Horizontal and Vertical axis that correspond to it
(in the Input class)
it's just that those values are WASD by default
you can multiply that value by your move speed and then add these two values (make sure you NORMALIZE) to get a movement direction
where is the Input manager
ops
Project Settings
but what about
also btw unity got a new input system a few years ago
how do I fix the character moving faster when holding both buttons?
normalize
what does it exactly do
send me the movement code, the part where you put the two axes into a direction
lemme visualize
you normalize the v3
how do I get the rotation of a child game object with respect to global axis?
it gives a max magnitude of 1
It creates a vector with the same direction but with a magnitude of 1
its litteraly like clamping
Yeah, within the range 1,1
Did you normalize it
I'll
square is not normalized direction, circle is normalized direction.
red and yellow are x and y, green is diagonal
normalize dir
yh Ik this
yeah but the variable
like thats how you assign a vector3 variable, right?
new Vector3 is in fact how you create a new vector3 yes
thanks
you can do dir.Normalize()
or
dir = new Vector3(a,0,b).normalized
im trying to get the direction the cameraHolder is looking in but I suck
whats the problem ?
transform.forward isnt working
CameraHolder.forward?
why not?
idk
well whats happening instead?
where is the code where you apply the movement?
let me put a few debug.logs in to test rq
wait
Debug.DrawRay(startpos, mything.transform.forward * length, Color.red, 2)
no why is it at godspeed?
did u multiply it by time.deltaTime
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?
AD/LeftArrow RightArrow keys
It gets a value between -1 and 1 based on what keys you have assigned to horizontal
by default, it'd be A/D
An "axis" in that context is just a pair of inputs which can evaluate to values in the range -1 to 1
neither, it gets the value of the Horizontal input axis defined in the input manager settings
show code?
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
then you are using a method of moving the object that expects a world space direction rather than a local space direction or you are not actually rotating the object being moved
you need Time.deltaTime to fix speed thing btw
ty
This object is indeed moving forward when you hit W. What direction is the object facing?
I fixed it and I have genuinly no idea what I changed
thanks tho
lets see the player and where you put the camera in scene in Local Pivot view mode
I already was in
local
Okay, now show the arrows on the object in the scene
Okay, so, hitting W should move this thing in the direction of the blue arrow
which one is Body and Which one is Player btw
(script wise, which one is linked to what)
yes, but allways
empty is player, capsule is body
which one has character controller
empty
ok
Okay, what direction is the blue arrow on that one
hello i have this error message only with my instancied gameObject but i dont understand what is the problem.
are you sure youre in local, dont crop screenshots next time
yeah
What direction does it actually move when you press W?
Which "arrow" does it follow?
make sure read/write is toggled on for your texture
wait I need to see
oh my bad
I turn it on the local side but it is the same on the global side
are you sure its not the model
normals are part of mesh not texture
where does i change this pls ?
playerbody.transform should effect the global side no?
Import settings on the file. Click on it in the assets folder. There should be a checkbox
it effects local side
which doesn't make any sense
CharacterController.Move will move the object in that object's direction. W will move that object in the direction of its blue arrow
when i export from blender ?
in unity
yeah thats what I am trying to say, the blue arrow changes direction in the local side but not on the global side
What do you mean "on the global side"
global pivot
that doesnt help
Global and Pivot are two opposite things
maybe record a video 😅
thank you 🙂
that's the world
should I move it in local direction?
you are
I don't think so it moves like its facing the global direction
the object is rotating properly, you're just applying dirrection from your inputs directly
wait I am gonna try something
Hang on, I can't actually find decent documentation as to whether Move is local or global
i recall this examples moves a third person character and its consistent regardless of facing direction
I need to go
i just do transform.forward * vertInput + transform.right * horizInput
but you can probably do Transform direction? or is it inverseTransform ?
What's a nice way to pass an argument to a prefab when I'm instancing it from a script?
Call a function on it after instantiating it
Okay, thanks
Not possible at the same time as instantiation?
if a class inherits from another that has a Start method, does the code in Start run on the object with the child class?
The only thing that'll run between the two is Awake. Don't put things in awake that depend on this initialization code
I tryed it but it doesn´t run but I wanted to check if it is normal
*and OnEnable
Great, thanks
well something else is wrong cause it should run
it inherits MB
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
does Resource define its own Start method?
Yes
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
Oh, I might be overriding the method, how can I call the base Start?
while preserving the start of the child class
either don't override it at all, or use base.Start()
if you are actually overriding it, then i already gave you the line of code you need, it is literally just base.Start()
if it needs to perform any actions in its own Start method then it must be overridden. do not hide the base Start method, it will need to be virtual in the base class and overridden in the derived class
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?
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
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Sure, but depending on what precisely needs to be done and the overall class structure, it may be cleaner to separate out whatever is happening in start into discrete functions, inherit the relevant ones and call those directly. base.Start() is perfectly okay of course, but it can get a bit messy down the line (especially if the base class isn't 'finished')
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
Wow this is new! thanks a lot
It isnt working
It still only calls the start of "Resource"
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
show your current code
are you allowed to extend a monobehavior? Ive never done it
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
Yeah, I forgot to remove it
be more specific, because typically when someone says they want to "extend" a class that means they want to inherit from it (in fact, some languages even use that to denote inheritance like Java)
Got it working, thanks a lot, something clicked for me
im just looking at the example Pingu gave
extend a class that inherits from
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)
yea ik that
just to be clear, the gameobject is not being deactivated or destroyed after you instantiate it, right?
then i am confused on what your quesiton pertains to
No, it isnt
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
the same way you do any other object that inherits MonoBehaviour
because it is inheriting MonoBehaviour
oh I thought it added the entire script
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
so Pingu has the option to add Item or Resource Item as a component rn
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
can you show your entire console window when you expect that Start log to be printed?
this is not the entire window
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?
yes
show the code that instantiates the object and make sure that code is actually running
the Start code?
how is the object instantiated? or is it already in the scene?
it is already in the scene
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
you've screenshot two separate objects where only the prefab (which is not the object in the scene) has that component on it
the prefab you've shown a screenshot of does not, it has a SpriteRenderer and a ResourceItem
I mean, it very demonstrably does not
your OverworldItem component contains a reference to a prefab with the ResourceItem, but that item does not exist in the scene
That's not a prefab, and also that's not the thing that has the Start code you want to run
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);
}```
Oh, that is confusing
what can I do?
if you want Start to run then the object must be instantiated
Not really. Only objects that exist run Start. You don't have any objects that exist that log what you want, so it doesn't log
no because there is no active ResourceItem object in the scene
then why is it a component
Well, the "Press E to take" seems to be working, so the OnMouseEnter stuff works. Try logging something inside the if condition to see if the that code is running.
What object in the scene has the ResourceItem component on it
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?
and resources too
you can have classes that are neither MonoBehaviours nor ScriptableObjects
this is the problem I had this afternoon
so I should turn Resource into a non-heritating class?
it really depends. i don't have the time to walk you through refactoring all of this so maybe if you describe exactly what you are trying to achieve instead of the problem you are trying to solve someone can help you
This seems like a completely different problem to "I want to run Start on a child class of a MonoBehaviour." I don't know how one problem led to the other
regarding the durability issue, you need to treat the SO as a blueprint for a tool/weapon and not as the tool/weapon itself
yeah thats the thing, I imagined that the tool/weapon should be a class then
and that is what lead me here
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
Yes, that makes sense. You would want a class that represents the real thing in the game
the SO is a database
you read from the database, and make a thing
exactly, this is why I refactored all of my code
so now every single object has a database but also a Class
you're tossing around a lot of terms here that don't really mean what you're using them to say
With what i have now, my Items have SO´s and classes that contain that data
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
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
that is what I have no?
ScriptableObject is itself a class, which your SO class inherits. The individual items are objects of your SO derived class
Yeah but I don't know why you've got Start functions on objects that are never components
When do you expect Start to run
In the Start function, the Item Class gets its data from the SO (ItemData)
Okay, what calls Start on the Item instance?
what?
Is there a newer version of his Item class posted? The one I pulled up is a mono
What do you mean what
I'm asking you what calls Start on the object
His item class is a component, start should work fine?
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
Only if it exists in the scene anywhere
Which it doesn't
So I'm asking what they're expecting to call Start
Obviously an object needs to exist to have an instance method called, really not sure what you're getting at
float topClamp = 90f;
float bottomClamp = 90f;```
?????
The problem is that Item doesnt get the variables of its SO
It's called "asking leading questions" to try to get them to realize that Start needs to be called by something
Your second problem is you need to get rid of this, it's wrong
So, when should it be
wait what do you mean
At Start
they are both the same number.
Okay, and what calls Start
the guy in the tutorial had it so i put it too
Bad tutorial
💀
#unity #fps #tutorial
In this series, we are going to create a first-person shooter game in unity.
We will learn how to develop all the different features that are common in FPS games.
From basic movement to shooting modes, impact effects, animating the weapon models, ammo management, enemy ai, and more.
Full FPS Playlist:
https://www.youtube...
this is what i was using
Yeah just another bad tutorial
alr
they all based it off Brackey's FPS tutorial which was wrong too
you don't wnat deltaTime there
The program itself at the beggining of the scene
alr tnx man
Okay, so the object is in the scene when it begins?
Yes
good thing i was not too into the tutorial before you told me
Please show a screenshot of this object in the scene
Okay, so you're trying to call the Start function of OVERWORLD Item then ?
No, the Start on Item which is the class ResourceItem inherits from
Okay so please show me a screenshot of an instance of Item in a scene
But I dont want it to be directly on the scene
Then what is calling Start
I want the Start at “Item” to run once the Overworld item is in the scene
So, where are you calling Start?
Since it doesn't exist in the scene, the scene isn't going to call Start
So, where are you calling it?
Oh okay
Now Im getting it
I am using “Item” as a receiver of the database
But it makes no sense
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.
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?
What is the actual object that needs durability
A weapon object?
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
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);
}
}
}
As Weapon SO’s but how can I “materialize” them?
That's not something I am physically capable of answering. This is something you have to decide
How do you want to represent an object that exists
Maybe a “Weapon Object” which has an “actual durability” int
what are you trying to do ?
your zoom is probably wrong
But my Inventory system is programmed to store SO’s how can I store “Material” things
Kind of like this
#💻┃code-beginner message
make it so i can move the camera and drag it around
million dollar question
So it would be a separate process to all the objects?
treat SOs like templates , not the actual object
What would be the difference between the objects that aren't represented by either item or currentDurability
Why would you need a different InventoryItem class
Just change which ItemData it holds
i dont even see Time.deltaTime on that zooming, its probably doing it very fast
hard to say just by this alone, can you record video maybe? idk what "flickers " means here
Okay, I think I get it
But I dont want all of the objects to have Actual durability
Okay, so they'd have a different class
A class represents a "shape" of an object
That could inherit from a common class
If an object has an ItemData and a currentDurability then it's one of these
so when moving or also scrolling ?
no just moving
Okay, thanks!, Ill keep you informed
are you following some type of tutorial?
could also be the z value messing with the calculation
no i just pulled it from one random website and then modified it slightly
can you link it
I find it helpful to have examples, so here's a quick mockup of how I'd approach your issue. There's a billion ways to solve it, and inheritance is certainly not the most flexible, but probably the simplest. https://gdl.space/areqaxabey.cs edit: oops, forgot to cache the result of the name func in the implementations, kind of pointless without
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;
}
}
}
#854851968446365696 please
Have all your information ready then just post it as a single message
oh okay sorry
What debugging steps have you taken?
right so - keep debugging
find out why it's becoming false
when you don't expect it to
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
if this is a string, is this "" or null
It's an empty string.
Unity's serializer doesn't support null for reference types
May be easier tyo use Debug.Log for this becasue you won't be able to do input stuff while using the debugger
if I put [System.NonSerialized] and have public string currentEffect;, will it then be considered null?
yes
cool thanks
#854851968446365696
this is a coding channel. dont ping users in on your discussions if they arent involved
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
that should just be happening automatically, unless your not using the input as a float or something?
Depends on how your code is but the simple answer is "decelerate when there's no input" as you said
wouldn't having separate deceleration/acceleration for example when strafing feel much better, atleast what's what i'd imagine which is why i'm trying to implement it
because otherwise the character, whenever input it'll always use acceleration to calculate it's velocity
and i'm using the magnitude of the joystick to determine wether to move or not
I don't really know what you mean by that to be honest. But acceleration and deceleration are the same thing
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
my bad,
and yes but the issue is that if you for example move the joystick from left to right because i set the target velocity magnitude in relation to the joystick magnitude
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
just sounds like a few if statements in the code.
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.
all that ☝️
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);
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.
Incredibly vague question. At the most basic level you just make one script and multiple prefabs or prefab variants with different values set and different renderer and colliders
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
each prefab with a dif script.
Not sure what you mean by this
why would the script be different?
Do they have different behavior?
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
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
Let's say they all have hitpoints and stuff, but they move differently. You can use one hitpoint script which they all use and different movement scripts.
Understood
if i have a script with a public variable can a change it with a different script?
Thank you.
💯
ok thanks
yourScript.publicVariable = 10f;
I can have 2 scripts in one object, or that is not good practice?
thats called composition.. and is 1 of many different design structures
In real games you will have many scripts on one object
Ok. Thank you.
my player object has like 15 different scripts 🫣
hahahah
one day I will get there
hopefully
look into SOLID principles
ok thank you
On this article I’ll try to explain five design principles involved in object oriented programming that aim to have a more understandable…
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
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.
for example.. Your PlayerMovement doesn't need to know about the players health
its just setting urself up for spaghetti code..
are SOLID principles different for Unity?
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
hmmmm ok. Well my game is super simple.. but I will keep that in mind for future ones.. my mind is already having trouble to wrap around 1 script imagine to think about many interaction with each other.. it will just make things now more dif for me. Bur I will read the link u provided.. thank you
instead of scrolling thru 1 big master class.. that has the player health somewhere in here
makes sense
yea, you just gotta use ur judgment.. theres nothing wrong w/ 1 script handling multiple things..
is ultimately up to you.. what works best for you..
Interfaces are important to a game or you can avoid using them?
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)
they get more important the more you develop
i wouldn't worry about them first thing tho
https://www.youtube.com/watch?v=_cCGBMmMOFw&list=PLFt_AvWsXl0fnA91TcmkRyhhixX9CO3Lw heres a playlist that helped me alot when i first started
Wow.. a single script just to control that few amount of lines.. I would never have thought of that.. My player script.. last game I did.. simples super simple game.. I had like 700 lines hahahaand it was just 1 script.. I might think about doing that way also.. really would be easier.. that is amazing to know thank you a lot
Thank you !!! I will watch it all
oh it happens on the other end of the spectrum
I am focusing in 2d games now as it seems to be more simple to create for beginners
heres my player movement script... she's a thicc gurl
Amazing organization
it wasn't always that way 😅
I imagine hahahaha
but good luck mate 🍀
Thank you. I posted a small game I did here in this discord dont remember what was the channel.. cant find now.
use something like http://www.itch.io and start a portfolio of sorts
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
#1180170818983051344 is the newer version of that
if it was much older.. there was a channel that wasn't set up w/ post/threads and that probably got archived
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
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
yea, dont be.. just start small. and get bigger each time
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
"Im learning Unity, going to make a Multiplayer Minecraft Clone!"
hahahaha
hey now, that's how I'm learning lol, well not multi player, but it's a good exercize to learn
Speaking about 2D and 3D.. in unity.. coding for both is that different.. or for a beginner surely is better to start with 2D?
The main difference is that 2d and 3d use separate physics engines. Everything else is the same . . .
hmm.. so 3D you have more stuff to know I guess.. prob 2D will be better for beginners.
Oh and importing and using 2d/3d assets will be different . . .
Nope, as I said, it's the same. 2d still exists within the 3d space. A few physics methods are different and you need to use the correct colliders . . .
understood. thank you.
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.
Why the two velocity assignments for each enemy type?
The second one achieves nothing
MoveDirection was already normalized
Why do you need different methods or variables here? Looks like you can just use one method here since the code is all the same
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?
Not good
ok
Just have one method to move. Each prefab will just have their own speed value...
The methods are almost the same from what I see. You could just reuse the speed variable, and suddenly it is the exact same
buit do I say in 1 method that enemy circle has speed 2 and enemy square have speed 3 ?
Just change the speed variable in the inspector for each prefab
One method, one variable, you change it in the inspector for each enemy.
ahh ok ,true. Making it as a serialized variable correct?
makes sense
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
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
I would just call the method move btw
Thank you.
syntax highlighting
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Huh yeah, I see it is not mentioned in #854851968446365696
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
you want to control each one differently in code ?
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
just because it's in the inspector doesn't mean you can't change it in code
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
_baseSpeed
_currentSpeed
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
```
like this one??
I tried but it is not working sent a SS
Because your attempt 1 had the ticks on the same line as words
And attempt 2 used apostraphes it looked like
ah ok
What is this for? But no, never ever use gameobject names in logic
use TryGetComponent and get the component directly, there is no need for tags/gameobject names
//code here
But what you are trying to show is not really important
The context is missing
What method is that code INSIDE?
I guess I need to try more here. Will come back later with questions about it if needed. Thank you guys.
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?
yes list of list is fine
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?
ohh lol ok
😅
I am still thinking here how I will do it, before starting.. otherwise It will be a mess
Ok
They need to be the same types
You could have a dictionary with lists of different types as values
hmm never heard about this.. will check it out. Thank you.
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?
The thing that damages the player should have the code yes
I had the feeling that this will make it easier in the future. Thanks bro
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
Does anybody know how to fix those?
Unity bug, restart Unity
that is extremely unlikely, why do you think so?
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
how is the w key supposed to know which direction you are looking?
nothing about GetAxisRaw knows about what object you are calling it on, or what direction it is facing.
I sent a video
irelevant
idk what I am doing wrong
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);
}
}```
so what there says which direction the character is facing?
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?
no, that is telling you which way to move, not which way you are facing
no I don't get it, can someone help?
Input only tells you what buttons are pressed. If you press up, it would always return the same value regardless of where your character is facing.
Direction in game on the other hand would be changing depending on your camera/character rotation.
Hey guys,
How can I change the start time on a state from animator via code ?
I want to change the start time on current or specific animator state
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.
Hello friends, how can I get the user country in unity WebGL?
one possible way https://api.iplocation.net/
https://api.iplocation.net/?ip=8.8.8.8. I see, but we need to pass ip inorder to get information as json
yes, you can get the IPAddrewss from the browser via JavaScript
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
okey, thank you
what happens if u
while(!input.getkey(somekey))
If somekey is not pressed your editor might crash, unless you break the loop somewhere inside the while block
just skip out on the while and put it in update
in an if
tryna make the script which doesnt derive from monobehaviour wait for input
From where do you call the methods on that script?
From monobehaviours? Then call it from Update
i tried
- making an entire new ienumerator
- using a bool to break out of the while block
using update is outta the question
i wouldve done it if i can
the
You need to call a method from the non-MonoBehaviour class inside of Update on a MonoBehaviour script . . .
while loop is inside of another ienumerator
coroutines are attached to gameobjects, I'm pretty sure, so it shouldn't matter if you just call it in an update
this isnt compatible with the setup i went for
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
i HAVE
it still freezes
show code
What setup? What do you mean? You need to check input from Update or receive it from an event using the new input system . . .
IEnumerator WaitForInput(KeyCode key)
{
bool breakpleasedontfreeze = false;
while (!breakpleasedontfreeze)
{
if (Input.GetKeyDown(key)) breakpleasedontfreeze = true;
}
yield return null;
}
this freezes
wait
now
its right
it is very not right
indeed
first of all, in this case, the yield return null is never ran
yea
you should have kept it inside the while loop
like in your original message
that's the first thing
second thing
Your yield is outside of the loop . . .
both end of freezing
Why aren't you using Update? You never explain . . .
show codeeee I need to see how it's ran
i am
how are you calling the function
one ec
You know you can respond in complete sentences, right?
#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;
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
that sure is a way to approach this....
try
yield return WaitForInput(KeyCode.Mouse0);
instead of just
mono.StartCoroutine(WaitForInput(KeyCode.Mouse0));
just realised i could simplify it xD
ok
till unity starts
anyway i can improve on it?
tryna make a spellcaster system
Also I know we're not supposed to comment on formatting on this server but pretty please 1 command per line -_-
discord broke the formatting
EYYY IT DOESNT FREEZE
ok so now why
That's why I sent the bot. Paste your code to a site, save it, and send us the link. It's much easier to read and look at the code . . .
didnt know it existed
you have to wait for the coroutine to be finished, in windup
the way you called it didn't really make the function wait
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
Why do you have GameObject? as a nullable parameter type? It's already a reference type (meaning it can be null) . . .
OCD
How, that doesn't make sense? It's already a nullable type . . .
yes exactly, and it's fine to keep it in that separate coroutine it doesnt' matter much if you call it correctly
OCD = over caring disease
im the type of guy to fiddle around with a table until its perfectly in place
not really(i dont go that far, i think)
but you asked about improving your code
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
spells in the game are really damn variable
ive thought of creating a baseclass for primary-type of spells like hitscan or projectile classification
but they are so damn different from each other
i thought making seperate script and hardcoding each spell was the only way
ye
liek i cant think of a way to make a baseclass that is being derived by two spells that
- does a ground slam
- shoots smth
you can make each spell a separate class but still derive from a generic Spell class that has things like windup or instantiating a gameobject with all the spell components on it or something
and you can make it pretty clean with virtual/abstract methods
no need to get into coroutine hell for this
oh i do have a basespell class
that has like variables like manacost,name,desc etc etc
your code will hang forever, until that input is pressed
that's an example of an issue
with your setup
ill time out the player, after 5 seconds the spell deactivates or smth
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)
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
my baseclass is scriptable object 😭
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
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
wait idont get you..
you can just make multiple instances of the scriptableobject and add different stats to them, assign one to player and another to enemies
ye thats the plan
player folder = player spells/skills
entities have set moves
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
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?
ohhh this is for how im gonna have to handle differnet entities have different spell stats?
yes
and this way you can also handle all the waiting and windup and everything, inside GenericSpell
and you won't have to have this weird mess of coroutines
is this what the tutorial told you to write?
please for the love of whatever is holy, find a better tutorial
yes lol, i know its bad but im just trying to understand it, how is it that every floot that spawns is slightly higher then the previous one?
to answer your question however, no, there is no line of code that changes the position. It's probably done elsewhere
They access the last spawned object to find a child Transform called "EndPosition" and use its position to spawn the next GameObject . . .
this is such a bad bad way to do this 😭
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?
yes but how is it that the spawning floors are higher then the previous ones? because of the prefabs positioned differently?
here, a good, modern tutorial: https://www.youtube.com/watch?v=XtQMytORBmM
For sure, this is fucking terrible. for loops exist . . .
like a trigger collider?
the point is that it just moves through objects but still checks for what its colliding twith
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
aighty i think i get it, ill try to implement it and see
you need to set the collider to trigger
Thanks
i am very stupid, i literally learned that in the very first unity tutorial but it just whooshed over my head
yes thank u
thanks
I just explained. When a GameObject is spawned, it has a Transform named "EndPosition". The next spawned GameObject finds that transform (from the previously spawned GameObject) to use for its position. It finds the end position of the current GameObject to place the new one . . .
Use a trigger collider . . .
but how is the next gameobject higher and further away then the previous one then? theres no line of code that tells the spawner to spawn it higher or further away from the previous? is this because of the prefabs thatvare positioned differently?
i have allready exposed my ignorance and stupidity
yes i understand this, that is why this guy his code is so bad (;
Because it spawns from the position of the "EndPosition" GameObject . . .
yes but that would spawn gameobjects on the x-axis, in this case they are also spawning on a higher y-axis and i dont know how he does this?
Because of the position of the "EndPosition" GameObject . . .
but the endposition is not higher up, its just on the far right side of the gameobject and not higher up
The code just uses the position, that's the only thing I can go off of (reference) . . .
if you showed us what your scene looks like we might be able to fix this issue
aaah now i know, i think i saw it the wrong way, indeed i think the position is higher wait i'll show u
all the code does is get the endpositions Position