#💻┃code-beginner
1 messages · Page 818 of 1
i added the componenet i needed to and it hsould work according to them
why do you have 3 box colliders
they had a green box appear but mine wouldnt do that
its just how that came i didnt make it
you probably have gizmos turned off and/or you're not looking at scene view
but since you skipped that step, that' probably why it's not working
how do i check if gizmos is on
I mean, each enemy gonna do that about each frame and there gonna be dozens
Trying in your usecase is only way to really know. I would just assume it isn't too much of a difference. Pretty sure the physics queries do a broad and narrow phase kind of steps eliminating most of the possible collision pairs regardless of the shape
top right scene view
with the gizmos button - top right of scene view
so with 16ms per frame you could have 16000000 1ns actions per frame
don't worry about perf at this stage. focus on what makes sense
consider the unit behind the clock speed of your processor
that's in the billions
just wait till we get to picoseconds B)
ive gotta be blind
it looks like you've disabled all of your scene view overlays
this is just how its come installed
press the ~ key in scene view and Turn on "View options", and most of the other ones
there are even non alloc versions, now making a buffer...
I have all these overlays on by default
elite thats a bigg difference
I recommend similar
does "Connecting" a project from the hub check it out from the unity version control system? I'm confused by this interface. I'd simply like to work on the same project on multiple devices
no
thanks so much ill give that a go now
that's what I was afraid of
Toggle Gizmos
If you do add from disk, it doesn't do anything with version control.
If you do add from repository, yes it gets connected with version control.
this third section
What menu is that 🤔
it appears when you press on the project name field in the create project menu
er, "new project" menu
Ok so yeah that creates a project connected to the unity cloud project but that won't create a VCS repository
Are you trying to pull an existing VCS repo?
Or are you trying to create one?
as I have said, I'm trying to pull from an existing one
huzzah has been vanquished thanks so much guys
In Unity hub go to:
Projects -> Add -> Add from repository
ahhh, thank you
I have only ever done WebGL builds of my current project. If i build and then deploy to my website, then I open the link on a macbook laptop in chrome, everything works as expected. But if I open the same URL on chrome on a windows laptop, one single feature does not work! There is a floating platform that moves back and forth and once hit, it plays a sound and dissapears along with teleporting the player. On the windows machien the platform does not dissapear (it does lose its ability to interact with the player). Also the sounds do not play but the user is teleported. Any ideas?
Is there anything in the log?
Why I don't see colliders of the terrain when I turn on physics debugger?
Can't seem to find a way atm, are you having issues with collisions certain areas?
I wanted to see if the collision is working, I have no issues now. Just asking
could anyone show me an example of ParticleSystem.Particle.GetCurrentColor in use? I'm trying to fetch the current color of a particle to get its alpha as it changes over lifetime but it keeps returning (0,0,0,0)
I have a particle system paused mid playback, with a single white particle going from 255 to 0 alpha, and I'm calling the method outside runtime, with an editor button. just trying to grab the color and put into that variable to show it on inspector and see if it works.
code is literally just:
you appear to be reading the color of an uninitialized Particle struct here
You never actually read the particles from the particle system. Wouldn't you need to use this? https://docs.unity3d.com/6000.3/Documentation/ScriptReference/ParticleSystem.GetParticles.html
you just made an array of empty particles of the appropriate size, but never initialized them
but ParticleSystem.GetParticles returns an int
I assumed it was just used for the size
ah right
Returns
int The number of particles written to the input particle array (the number of particles currently alive).
lemme try again
Is the area in the background the terrain? Did you convert from a mesh?
it worked. just had to initialize the array first with only the int from maxParticles, then pass it to GetParticles so it does its thing
thanks
Yes, it's a generated terrain, which I make in a job, then I generate the mesh, then I create a collider
So it does have a terraincollider ...?
no, it has a mesh collider
Oh, my bad. I misunderstood. If this is the desired effect you'll want to make sure 'Collision Geometry' is selected.
And you'll want to be in scene view.
Man, I'm just wrong in every way today.
Hmm, I checked collision geometry, but I still don't see any lines
wait isn't the physics debugger for PhysX?
Looks like you're maybe using Unity Physics for DOTS?
hey guys, I figured a couple things out but could use some help.
So I have a orb im trying to right click hold and drag only on the x and y axis.
Its 3D first person, the orb doesnt have rigidbody, the script to drag the orb is on a weapon on the player.
The problem is when I drag on the X axis it bounces left and right really fast but is smooth dragging on the Y axis(I dont want it to move on the z axis).
Its not the raycast or a problem with the Y axis from testing. Ill leave the script if anyone would like to test
https://pastecode.dev/s/dy1tl7h5
heres another without smoothdamp
https://pastecode.dev/s/s4nvyu6a
More testing, On cam orthographic its all smooth, but im using perspective and the x axis is bouncing left and right.
Wdym by 'bounces'? Like attempts to move but then recenters to horizontal center of screen?
show a video
okay one sec
my record is randomly not working for the first time lol the timing is so bad
You using OBS?
no nvidia replay. I think I found a work around. ima start using obs after this
it compressed so it could send.
also resending script incase
https://pastecode.dev/s/9sr83oba
Hello, I am currently dealing with an issue with particle effects, I have this 1920x1080 render texture that is supposed to only show the particles so that I can layer them on top of my cards which are always culled to be on top. I am having issues however with this render texture displaying because for some reason it displays nothing when mapped to a raw image. Please could I get some help. Thanks for reading.
Also, right after posting this I realized that the values were wonky on the Rect Transform, those are fixed now.
so you know there is a good solution to draw particles in ugui https://github.com/mob-sakai/ParticleEffectForUGUI
I'll look into it however I doubt that I will use it. Thanks for the suggestion though!
i was able to send the clip
It will be better than needing a large extra texture to draw particles too.
Anyway you can check the render debugger to see if it draws the particles properly but the preview suggests it is
Was playing around with the script.
You're creating a new plane each frame that you're holding the object. So I tried just using the plane created when you first grab it.
No jitters on my end
so id remove this from the dragobject()
Plane plane = new Plane(Vector3.forward, currentObject.transform.position);
and add this on top
private Plane DragePlane;
and just use that?
Almost, thats like 77% of what I did.
During the drag, where it's following your cursor you won't need to continually create planes like you had been, each time the function was called.
I'll send you the updated script, lmk if it works
okay thank you
https://pastebin.com/L0a4nNXM - don't forget to fix the class name at the top tho
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
In the end I Just made the emission small enough to completely fit in the size of the card, put the emitter in front of the card and the gave it the same layer as the card. The render texture that puts cards in front picks up both of them and puts it in front. Thanks for the help, I will certainly use the tips and tool provided in another project, I just need to finish this by Friday and I don't have the time to learn a new tool at the moment. Thanks for the future help!
definitely is smoother thank you. do you mind me askin the more smoothtime the more delay I noticed. Is there anyway to have both no delay and smooth or is there no real setup for that in my case
when I have the smoothtime at 0 the sphere goes crazy
I'd probably recommend .lerp
SmoothDamp is more of a fade in/fade out kind of curve, whereas lerp is linear.
And yea the more with smoothtime, you're effectively telling it how long it must take to reach it's destination.
Or if you wanna do smoothtime, set it to it's lowest 0.0001 and see if you like it
the orb goes crazy lol ima try the lerp
Third idea, `smoothTime of 0.015' & replace
currentObject.transform.position = newPosition;
with
if ((currentObject.transform.position - targetPosition).magnitude > 0.03f)
currentObject.transform.position = newPosition;
Anything to do with networking is not a beginner issue.
oh shoot I dont have that channel added sorry!
this is on those changes
uhhhhh mine aint working like that 
Did you make that change at the bottom of the drag function
An improvement would be to get the component anyway and check if its null or not
tags are pretty useless when a component does the job better
Just noticed I forgot to remove my debuglog and now your console is getting spammed. my bad, it's at the bottom of update.
lol its okay
i have tried with layers and same thing
they didnt mention layers
Well we use layers for other things like physics and controlling what a camera can see for example
I think they're saying instead if comparetag, use getcomponent.
But yea, this jittering is still occurring.
if (finishHit.collider.TryGetComponent(out OrbDragGoal))
isDragging = false;
currentObject = null;
return;
you can just use a component check as a tag check and ignore tags altogether
components are basicially just tags with more potential information and usage
Indeedy
{ }
truing
Welp, go back to the previous version, idk why when we switched to lerp & magnitude it went back to going haywrie.
okay I switched to getcomponent and did a debug to make sure it worked
im still testing with lerp and damp my brain is baffled
it also seem to be the further I am the worse it gets
how are you using lerp?
many people abuse lerp when better options exist such as Vector3.MoveTowards()
Vector3 newPosition = Vector3.Lerp(
currentObject.transform.position,
targetPosition,
speed * Time.deltaTime
);
Yea you want to use MoveTowards to keep going towards some goal
got you
its still movin left and right dragging down
I'm replacing some of my Singletons with Static Classes because its basically the same and skips Instantiation and its potential issues.
Lemme know if this is actually super bad for X or Y reason that I wouldn't know unless I read some obscure forum post about it.
a static class is appropriate if you have no interest in Unity lifecycle functions, like Start, Update, or OnDestroy
👍 This is for managers that register items and do some operations so I think I'm good
Config Manager that loads from say json? perfect use of a static manager
And handling coroutines
Async solves that!
augh, can't run Coroutines on static, but its just a short rewrite anyways
coroutines are executed by a specific unity object
UniTask or Awaitable fully replace coroutines and can do more
But can they run coroutines
Unitask can
I personally avoid coroutines so its no bother to me but UniTask has great features relating to coroutines
Awaitable is meh and half baked but functional
Was there some problem with static fields not getting restarted to their default values after scene loading? Or was it just a thing with the fast playmode editor options?
I'm just using the coroutine for detecting a "pause" and waiting for that variable to turn false, easy 2 min fix.
Without domain reload this happens yes. They also remain post play
you would need code that uses editor events to reset them
Or logic that doesn’t require them to be reset
We’re gonna get an attribute for that soon iirc
Yeah, definitely worth knowing when considering between singleton and static class, when that's not an issue either, definitely go for a static class
the runtime init on load ones would work already for this
No as in an attribute you put on the fields
Anyway soon ™️we will get super fast reloading yay
Oh that sounds cool
Ya it’s how core clr workflow will work for reducing enter times
well some of it anyway
Just easier way to do the workflow people are already doing with reloads disabled and their own management
I'm starting to get interested in that core clr stuff that I have been hearing a lot but never looked much into 🙂
Ill be honest it doesnt sound great, how can sbox have incredible hot reload speed but unity cant do the same?
Comes out this year so not much wait
s&box's hot reload is a miracle tbh
Its virtually instant in a lot of cases
It was born entirely out of facepunch's frusturation with unity domain reload and compile times
Yea its amazing so I expect unity to do the same or better. Surely they can afford a few smart devs to make it?
Im expecting Unity to start considering s&box as an actual competitor,
which is going to be beneficial for everyone in the long run
s&box still has some great qol stuff unity could use, hot reload was one of them
Can it do non pc platforms?
right now it cant do any platforms to be fair
its stuck within their own game ecosystem kinda like roblox
the biggest issue is licensing and valve, but they are still figuring things out
is that released yet?
Its been out for a couple of years now yes
I miss the early days when it was basically s2 with c# shoved in there
quick question. whats the best practice now—async/await or coroutines?
or different cases for each
thing just looks like unity with imgui* plastered on it
yeah well those two are a pretty big deal and I doubt valve would budge with licensing lol
better to see godot at the competition as you can crank out stylized games pretty easy and toss em on steam
async is usually preferable esp for Internet calls but also depends, you might need coroutine for Unity specific compatibility
they have awaitable that kinda mashes some functions from coroutines like await unity time
Godot is still far behind in a lot of things
its nice, and i like that its open source
it is, but let's be serious. If you're looking for realistic lighting you're probably using unreal
Not at all
godot and roblox are way closer competitors ye
Godot's weakest is the pipeline and rendering that's for sure, but if you're not trying to create anything too artsy then it works fine. Mobile games come to mind and other minimal artistical games have been produced with it.
Unity is the jack of all trades. It does everything pretty easily, but since it has to support so much stuff the development is so split.
SRP split trying to encourge higher quality games, yeah. Even DOTS id say took away from the general URP/Gameobject workflow
they are doing away with the pipleline split
which is good
dots is an alternative really, its also the less popular option so i honestly wouldnt say its "splitting" anything
I would been honestly fine if they did abandon gameobjects and forced dots lol
homie
Well, I'll let you know right now. DOTS have the better character controllers, it has the better networking solution
So many modules that are just generally better than what you get with game objects
They hired the dude who made the kinematic character controller
If they remove gameeobjects and force DOTS, it will basically kill Unity's market presence for beginners
i think you severely underestimate the value of the gameobject workflow to people
also can dots use the canvas based ui stuff?
I'm not saying the workflow is bad. I'm just talking about how the split with these modules have moved so much high quality work around
Unity loves to have multiples solutions to one problem
Why are you saying that like its a bad thing
having more choice and variety in how you approach problems is a good thing
I'm pretty sure more people would be happy if they developed UGUI more out instead of developing UIToolkit
Imo they are better off just abandoning UGUI and getting UIToolkit perfected
I agree
what makes you say that
S&box also has an entirely Razor based ui similliar to the uitoolkit and its a major plus for the engine
who would have thought that a markup language is good for designing UI
everybody
UGUI needs to be redone completely. The whole resizing of elements isn't intuitive and flexbox support is half-arsed
UGUI being redone completely is UIToolkit(?)
Yeah, but going back to my argument of multiple solutions to one problem.
Just give me a modern imgui instead, I despise retained modes 😔 (can PanGui release soon)
I dont see UGUI ever getting depreciated, but its almost certainly rearing end of life time support
that's just the reality of being an engine that is used for such diverse and long lasting projects
They actually did threaten to remove it in a previous talk, but everyone complained and they actually had quite a few updates in the previous release
you said people would prefer they update UGUI rather than develop uitoolkit, i don't really get that
UGUI is just easier to jump into which is why I was saying more devs would be happy to use it over dealing with html/css garbo
i mean if ui toolkit was further developed it could be easier to jump into
i'm learning ui toolkit and i'm not doing any of the html and css shit
Yeah that is true. The GUI itself for it does provide some help, but you end up copy/pasting templates after getting frustrated at times
My biggest gripe with it is the extra boilerplate when connecting properties to unity's editor
hi guys, am i able to give an ml agent a timeout when going over the line in a 2v2 game?
I have these 4 enums and was wondering how I could have it so that if you select the same option as another enum, the other one is set to None
( so like, if I set _attribute2 to Damage, but _attribute1 is already Damage, _attribute1 gets set to None
What part of this problem are you struggling with
how to do that in general ( i know how to do it in runtime, but this is for the inspector )
Probably want to just use OnValidate if you don't want to deal with Editor library tools
I would think a bitwise enum would be fine too
unity has support for those to display
wasthat?
multiselect enum basically
even if it diddnt, odin inspector SWEEEP GRAHHHH
oh hell yeah
is there a way to limit how many are selected?
ah, actually you'd probably need to validate that too lol
how would you count how many are selected?
check how many bits are set
that was what i was thinking, but was asking incase there was a function to do so by default
so onvalidate would be if current enum bits are more than allowed then set to previous enum value
bit stuff is black magic just google and people will have easy solutions for that kinda stuff
its just 0s and 1s, how hard could it be? /s
dammit i was tryna send the 'thousand yard stare' gif
is there a max amount of bits for a bitwise enum?
you mean like a [Flags] enum?
yeah
Probably 32 as it's integer backed right?
64 bits
you can make a long or ulong backed enum, which are 64 bits
but at that point might be worth considering other solutions like scriptableobjects
i could always just make a 2nd enum and validate them both against eachother, but that would prob be scuffed as fuck
but yes anyways thanks :3
I'm trying to make an easy way to create skills in my game in a way that can scale with many skills and is easy to add stats for each skill (Level scaling, requirements, etc.). I tried making a struct called Skill which can take the skills stats as an input and then created a script called SkillsHandler attached to the player which would dictate skill behavior. However, I cant add the skill prefab to skills handler, and im assuming it has something to do with the fact that the Gameobject rend is static? how do i get around that?
its not a member variable so that wont work will it?
But you can just load a prefab via Resources or Addressables to solve this
you're using static variables, why?
It throws an error when I try not to
Also your skill type is not [Serializable] so it can't show up in the unity inspector anyway
"an error" is pretty vague
how about you share the actual error
You can't use member variables outside of a function
can you explain it in simpler terms for me?
He means you have to do it like in my example
You've made a variable rendPrefab. You can't use that variable outside of a function.
but actually you shouldn't do either
you should expose it in the inspector
and assign it there
How do I do that?
For that to work your struct needs to have [Serializable]
reading the documentation isn't going to help you
you just need to apply the attribute to the struct definition
well I would like to understand what it does anyways so ill watch a yt vid or smth
fun fact: programming languages have lots of documentation in text form
The attribute is a built in C# attribute - you need to know how it works in the Unity context. This page will tell you ^
Namely this part
ok thanks for the help
How you protect important saved data? Example, player stats
at least being on a server
If the data lives on the player's device? You don't
you need to store the data on something you control
and you also need to ensure that the player can't submit completely ridiculous data
"I just killed 23 billion enemies" should not be accepted
Singleplayer game
Right now everything in json
If you want to at least make it annoying to cheat your stats, encrypt the file that stores the stats.
The player will be able to extract this key from the game, by definition
The game has to be able to decrypt the stats file
Yea you can make it harder but cannot prevent it
I did my own thing years ago to decode phasmaphobia saves, was quite easy
Nothing is safe. Question how easy it is to do it
honestly for singleplayer games i see no reason to lose any sleep over it
if people want to cheat in your singleplayer game, let them
I know, but small encoding wouldn't hurt to prevent average Joe to finish game in seconds
Who cares if average joe finishes the game in seconds
Do you think the "average Joe" is typically cheating in singleplayer indie games they play?
If you can go in and change number in txt, why not

Why do you feel the need to exact control over what someone does with their time, is the real question here.
How Im going to mine bitcoin. XD joke
im having an issue with my targetlock script. originally just to test if it would work i did a private gameobject target and set it to look for gameobject with a set tag in a void start and a void update of transform.lookat(target.transform.position) and it did work centering itself to look at the entity at all times. But now i wanted to make it when the player has their mouse over the entity with the tag and presses a key it locks on. And unfortunately it hasnt worked: ive tried void OnMouseOver and just tried looking for the set tag and i even have a onmouseover debug and that works displayed a message in the console with mouse over works. Im wondering if i have to take a different approach to how im meant to write it and if anyone would be able to help me
Maybe this article can help https://discussions.unity.com/t/how-to-raycast-from-mouse-position-in-scene-view/766356
Send also code for us to see your mistakes
this would be the version of it that isnt working to what i want it too
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
On your player's script you could do something along the lines of raycast like swortech was mentioning.
// As opposed to OnMouseOver
private void Update()
{
if(Physics.Raycast(...))
{
if(hit.collider.GetComponent<TheEnemyScript>() && Input.getkeydown(...));
hit.collider.GetComponent<TheEnemyScript>().LookAndReactFunction();
}
}
Do not use OnMouseOver. It is inefficient and depends on the
context Use a Raycast from the camera to the mouse position within
Update Then check the tag and, if it's Input GetKeyDown, assign the goal
Clean up your logic
@analog cypress
Excuse the English 👍
you need to fix your ide before anything
im not sure how to fix my ide i read it over the first time and updated to the newest version like it said and i thought that would be enough to fix it but i can go over it again if anything.
and i understood everything except assign the goal what did you mean by that?
pretty sure, essentially what im saying here *
'Once all conditions are met, tell it what it needs to do (goal)'
this wont be white
Assigning the target means: target = object hit don't go around so many times and check the variable
yeah idk why its not working i tried the help forum that Oz sent but it didnt even give me the option for Editor Attaching and i tried to make sure that all the options were checked and it didnt make a difference when i went back to open the code i had MonoBehaviour is still white and i tried making a brand new C# script it didnt include it and when i tried making a MonoBehaviour Script it still was white. and i did hit to regenerate project files already too.
you dont have to have all those checked off..
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
if its connected you should see the suggestions popout when you type
some like this
^
Also I noticed that and, I'm not sure what the poster meant. I assume an option back on Unity 2019
What happens is that the editor is not linked to unity
anyone down to teach me coding i have 0 knowledge
i don't think you'll find anyone willing to do that for free
Youtube
this may be a stupid question but, is there a way to make a kind of properties component for a gameobject without using a script?
no?
components are instances of scripts
yes
alr then
public vars or private vars that you force serialize
Now I faced a choice, do I make bullets triggers or not? 🤔
Is there an obvious answer?
no (there's not an obvious answer), there's also the option of raycasts
in my current game player shoot raycasts and bullets just trace that, however enemies meant to shoot fast projectiles
The inspector window B)
huh
is it even possible to make bullets capable of penetrating if they ain't triggers?
at least ain't triggers for enemies
I am a bit confused though, why would you want to 'get' a component of a gameobject without a script?. WAIT WAIT. ye i read it wrong
i meant like assign values to a object without having to make a script
I need sleep but the first thing that comes to mind would probably be a scriptableobject, but that requires scripting soo : | idk, sorry.
yeah dont worry about it, have a good sleep!
thats what a trigger would be for, or some manual physics query
Hey, Im a beginner in unity and coding and I cant figure out what causes this issue. when I move, the player "tilts" but that results in the player tilt over sometimes and just laying on the ground. There is also an issue with the wall clipping as you can se at the end. The room is build out of different tiles, each one has a box collider and the player has an rigidbody as well as an box collider (even tho a capsule sollider suits the mesh better, the player keeps falling over when i dont use a box collider there. If it helps, heres my player controller script ```csharp using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerControl : MonoBehaviour
{
// creating variables
GameInputs control;
Rigidbody rb;
Vector2 moveInput;
float speed = 5.0f;
void Awake()
{
control = new GameInputs();
rb = GetComponent<Rigidbody>();
}
void Update()
{
moveInput = control.Player.Move.ReadValue<Vector2>();
}
void FixedUpdate()
{
// Movement
Vector3 direction = new Vector3(moveInput.x, 0f, moveInput.y);
rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);
}
void OnEnable()
{
control.Enable();
}
void OnDisable()
{
control.Disable();
}
}```
Hey gang currently looking for a mentor of sorts, I have a solid game idea and have done some tutorials now to teach myself some basics and think im ready to commit myself to the project more but would like someone to help with some more experience and make sure the way of doing things im doing isnt total bs, im looking to make a 2.5D pirate single player game that follows a loose story, if anyone with experience in that sort of field is around i would love a 5 min discord chat
im new in unity and trying to do something from learn.unity or something, wich one do i do and where do i start?
you can limit the rigidbodies axis to only rotate around y for example, so it cant fall over to the sides.
depends on your project i jsut started also but i knew i wanted to make a pixel art esk 2d 2.5 d game so i found a game kit tutorial
I guess, the unity essentials will be the first pathway to follow
"New to Unity? This guided learning Pathway includes everything you need to get started."
I highly recommend trying out unitys own tutorials, they are a good starting point in my opinion
thanks i found it
2 weeks is a long time but its prolly worth it
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
hello guys
Hey guys, quick question.
I don't understand why i can't access the "scoreManager" values. neither "test", neither "score".
` [Header("References")]
public ScoreManager scoreManager;private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "EnemyProjectile" && secretInvincibilityTime <= 0 && !isDead) { if (scoreManager.life - 1 > 0) { // If still has health playerMovement.isFreezed = true; scoreManager.life -= 1; ...`
Error : Member 'ScoreManager.life' cannot be accessed with an instance reference; qualify it with a type name instead
I tried looking on the web to fix the issue, without understanding...
Do someone know how to fix it please ? Thank you ! I want to access the player's life
static means it belongs to the "class", not a "instance" of the class
eg. you would want ScoreManager (the class) not scoreManager (your reference to an instance of the class)
My gawd again you got me, quick, precise. Thank you ! <3
These variables shouldn't be static, you should be accessing the class via the singleton you've got, ScoreManager.instance instead
Oh thank you for telling me that !
this channel is for code questions only, pls be asking in the correct place -> id:browse (lighting questions go in #1390346776804069396 )
Sorry for the mistake, i will !
So I am trying to use Physics.ComputePenetration
how do I get access to the collider's position and rotation?
I guess position is techincally bounds.center
and rotation is... you can't rotate them right? get one from their transform?
this is pretty annoying, so this is a projectile-trigger hitting a torso
how do I even get the normal of this ""collision""
I tried to trace Raycast from a projectile position
Using info from Physics.ComputePenetration, doesn't work, sometimes the projectile is too deep for a meaningful result
I tried Collider.ClosestPoint from projectile center but if it's inside it seems to return transform.position
Elo, I'm following this tutorial: https://www.youtube.com/watch?v=BleaG3md1zY&list=PLgXA5L5ma2BuXG5L_hcXKc8RU2gNVdQ6F&index=7
I have created the scriptable object like the tutorial says to, and I have created the prefab, and my prefab type is a game object, and the prefab input needs a game object, but when I select it out of the list it says "Type mismatch"
Does anyone know why this is happening/how to fix it?
Attached is a screenshot of the code, and menu and problem.
Project files are here: https://www.patreon.com/posts/creating-game-in-75523545
Accompanying article: https://blog.terresquall.com/2023/02/creating-an-underwater-survival-game-part-3/
Ever wanted to create a game like Subnautica in Unity? In Part 3 of our guide, we go through how to set up a simple Inventory System for the game.
CodeMonkey Gri...
When you select it out of what list?
The list that comes up when you click the dot icon next to the area where it says "Type mismatch"
That's your issue
you're trying to assign a reference to a scene object on an asset (the SO)
assets cannot reference objects from inside scenes
The prefab is not in the scene
the prefab is the one that's in your assets folder
reference the prefab, not a copy of it from the scene
ohh I just dragged it from the folder, it works now, sorry idk why I didnt think of that, thank you :)
alright, tracing from the previous frame position to the current other.ClosestPoint(transform.position) seem to work
so much hassle for basic projectiles smh
does this line make sense as a check so mobs not hit themselves?
if (victim is BaseMobAI && victim as BaseMobAI == base_mob_ai) return;
victim might as well be a player or stationary object so
More context would help
You dont need to cast to perform a reference equals but yes it will work
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
classes do a reference equals comparison by default
I guess I ignore that?
Is victim and base_mob_ai both a class type then? or somethin else?
You can also do ReferenceEquals() to explicitly compare if 2 things are the same by ref
If one is an Interface this can often prompt such a warning
yeah one is an interface
https://paste.myst.rs/zagvmqn4
context (mostly) but you probably don't have to check it
a powerful website for storing and sharing text and code snippets. completely free and open source.
everything are classes except the victim
Ah then if one is a struct you cant compare accuratly unless you pass this via ref or keep it as the interface type and rely on boxing to ref compare.
A unique id is a nice and more reliable solution
I haven't really thought I can use interface with structs
lucky I ain't doing it so I won't face issues
so I see in some cases that comparsion may actually break
alright ugh now I need someone to explain why my code works while it shouldn't
public void FixedUpdate()
{
previous_pos = my_collider.bounds.center;
}
I got this bit
public void OnTriggerEnter(Collider other)
{
Debug.Log(previous_pos + " " + my_collider.bounds.center);
Debug.DrawLine(previous_pos, my_collider.bounds.center);
Debug.DrawRay(my_collider.bounds.center, Vector3.up, Color.red);
Debug.Break();
}
and this bit
according to the order of execution FixedUpdate executes before OnTriggerEnter
so I would expect previous_pos to be the same as my_collider.bounds.center inside OnTriggerEnter
however it still uses previous previous_pos and everything works
it's:
- FixedUpdate
- Physics simulation (things move)
- OnTriggerEnter
so they would be different, no?
(sorry i'm jumping in with not much context)
I got it now
so "internal physics update" means... everything does their things
I am surprised only now I stumbled upon that fact
that fixed update before that and collisions after
Hi!! I need some help. Is it possible to make my character "die" after the health bar (slider) go to 0? Like, restart or something?
That's the point... I don't know how to do it
Que listo eres no?
What do I have to code to make that happen?
venga va
"then do stuff"
I don't know what do I have to code, that's why i'm asking for help (if anyone knows) 😞
i'm not being rude...
i'm just saying that we literally cannot help bc we don't know how the code you made works
or how it should behave when restarting
yes, but i don't see how they could help here
Then what do you THINK do I need to send
well, in the decrease health function check when it is 0 or less
to be able to fully help: a full in depth explanation of what should happen and prob all the code
ok well, what you don't understand first of all
and how should the game restart?
like, what needs to change?
This is the last part of the code
well ok
My teacher sometimes sent us the code and we copy it because we didn't have enough time in class
So i don't really understand many things
I tried looking at the pdf's she sent
well, the first step should be understanding it then
first understand it, then try to continue
also right there, you have the spot where to execute death logic
ou
we literally cannot help
ok well, if you insult me, then i def won't help
i do understand something, ok?
bc it's similar to my language
<@&502884371011731486> you prob wanna look into him
Could it be that code is generated and bot placed comment there
well, they said their professor sent code
and they copy paste it
so that may be the reason why the comment is there
It's already been mentioned that this is an English only server. If you're also going to throw a tantrum, then please leave.
also, he insulted me in his language
you can translate it to verify
Hence the tantrum part. But they left anyway
So, his homework is to implement death() ?
maybe?
but he didn't know what the game needed to do on death
so he was basically asking us to help him understand what death had to do...
Simple version is to reset scene,
harder would be to reset health (also update UI) and move player to location you need
Yeah, i basically said it at the start
Tho i don't know what the game had to do on death
If there was any requirement
Don't bother, he got banned or left
He left seems like
Does somebody know whether Awake will be called in such a circumstances?
var spawned = Instantiate(prefab, inactiveParent);
// Is Awake called if spawned.enabled = true, spawned.gameObject.activeSelf = true but spawned.gameObject.activeInHierarhy = false
Hello! Is ok to ask questions about concepts here? Or is this mainly a bug help type channel?
It says in the channel description Ask questions and discuss anything related to beginner coding concepts in Unity so I think yeah
Oh w
Your example isn't really possible because that Instantiate call will not create the instance with any parent objects
so if activeSelf is true, then activeInHierarchy will also be true
I believe if it's not active in hierarchy when spawned, e.g. if you did Instantiate(prefab, someDeactivatedObject) then no I don't think Awake runs, but this is pretty trivial to test for yourself
Oh, I'm sorry it's wrong example. It should have parent when instantiating.
Just checked and it's not called. It's pretty strange in my opinion
what are you trying to achive actually?
Well, that is behaving as per the doc, so yeah.
Generally it's pretty easy to avoid instntiating anything as deactivated though
Will instantiating without parent and then immediate parenting work?
again what are you trying to accomplish
i mean probably yes but there are probably cleaner ways to do it
Awake must be already called after Instantiate
var spawned = Instantiate(prefab);
// Awake is already called
SomeOtherThing();
Can Harmony patches replace/disable an entire class, or is it only the methods?
#📖┃code-of-conduct no modding discussion in this discord
Oh sorry ok
@wintry quarry good cat by the way
Not really, I literally just had to remove him from jumping on my computer
ok so question, Im trying to make a perk system for my game, I was going to implement it like a inventory system so I was learning about different ways of going about it. I was looking at using hash tables or lists, and it might sound like a dumb question but why would you ever use a list over a hash table?
Lists are ordered
hash tables are not
They also tend to use less storage, since you don't need to separately store a key
I guess you mean - in the context of an inventory?
yeah
but this makes sense
You would use a list when you plan to access the inventory via numerical index
HashTable makes sense only if you plan to access it by some key
basically it depends what you are doing with the inventory and your planned access patterns
that makes a lot more sense thxs for the explanation
For example if you are using "stacks" of items in your inventory and you expect to frequently be accessing the inventory by adding or removing from existing stacks, it could be faster to use a HashMap. For example if you use hashtable and want to add one apple to the list, it's O(1) to find existing apple stack and add to it.But for a list it's O(n) to find an existing apple stack
if there are no stacks and you always add a new item to the end, you can just use a list
You may need both - stacks and ordering, in which case you might use a list anyway, or some combination of both - a list as the canonical data with a hashtable for optimized lookups
Question: i create instance of gameobject based by a scriptable object and i would like to when i instantiate them, changing their value or add prefix/subfix by random. What the structure would look like?
changing their value or add prefix/subfix by random
Can you elaborate on this? What do you mean by "changing their value"? What value? Prefix or suffix to what?
Ok
I have a item scriptableobject who have value such as damage,fire rate, level and rarity.
Like in PoE or diablo. The weapon can have additional bonus as prefix and suffix (+dmg,+crit rate,elemental dmg,etc).
Logically, the weapon will scale (in damage) with the level of the item
When i instantiate item now, it only pick the base value of the item.
Make a list of possible prefixes
and select one at random
You can use a weighted random selection algorithm if you want some to be rarer than others. (google it)
You can use ScriptableObjects to define the prefixes too
like maybe the "Heavy" prefix applies additional 10% damage, or whatever
the overall system you're discussing can be pretty complex, so this is just a small simplified piece
instead of changing the values at run time ( which you shouldn´t) you could replace the items with a new Scriptable object
so you would have different scripable objects for one item
oh sure - certainly don't change the SOs at runtime. Usually you want an SO and then a runtime data model which the SO can create
hi guys how are you, this channel is for people who wants help for his own game?
yes
oh good can I tell my problem/issue/bug
just ask
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
I dont understand
the point of the bot command is for you to read it, you dont have to actually do it
read what the bot message says
have you read #📖┃code-of-conduct or id:guide ?
this whole place is a support server
you can ask
the point of the bot message is that there is typically steps to take before asking here
now I understand
so are you going to ask your question finally
I'm making a horror game, and I'm stuck on a part where I have a doll/monster that's watching over me, and when I look at it, it disappears. But I've found a bug. When I look at the closed door and then in the direction of the monster, it disappears, and I don't want that. I want the player to see it in more detail; there's an event in the room where the lights start flickering, indicating that the player has to do something.
Sounds like your raycast for detecting if the player is looking at the monster isn't including other non-monster objects (in this case the door) in its mask, OR the code logic isn't properly differentiating such objects from the monster itself
I have a code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
Please don't share code as images
using UnityEngine;
using System.Collections;
public class ControleSusto : MonoBehaviour
{
[Header("Configurações do Evento")]
public GameObject monstro;
public Light luzSala;
public GameObject porta;
public AudioSource somSusto;
[Header("Configuração de Layer")]
public string nomeDaLayerMonstro = "Bicho";
private bool eventoAtivo = false;
private bool jaSustou = false;
public void IniciarEvento()
{
if (jaSustou || eventoAtivo) return;
eventoAtivo = true;
monstro.SetActive(true);
StartCoroutine(SequenciaDeLuzes());
}
IEnumerator SequenciaDeLuzes()
{
while (eventoAtivo)
{
luzSala.enabled = !luzSala.enabled;
yield return new WaitForSeconds(Random.Range(0.1f, 0.25f));
if (VerificarSeJogadorOlhou())
{
FinalizarSusto();
yield break;
}
}
}
bool VerificarSeJogadorOlhou()
{
// 1. Verifica se o monstro está visível pela câmera
Vector3 screenPoint = Camera.main.WorldToViewportPoint(monstro.transform.position);
bool noEcra = screenPoint.z > 0 && screenPoint.x > 0.3f && screenPoint.x < 0.7f && screenPoint.y > 0.2f && screenPoint.y < 0.8f;
if (noEcra)
{
// 2. Lançamos um SphereCast (um raio grosso) para facilitar a detecção
int layerMask = LayerMask.GetMask(nomeDaLayerMonstro);
Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hit;
// Se o centro da tela (ponto branco) passar perto do bicho, ele deteta
if (Physics.SphereCast(ray, 0.5f, out hit, 15f, layerMask))
{
return true;
}
}
return false;
}
void FinalizarSusto()
{
eventoAtivo = false;
jaSustou = true;
luzSala.enabled = true;
if (somSusto != null) somSusto.Play();
monstro.SetActive(false);
// Garante que a porta continua a funcionar
var doorScript = porta.GetComponent<MonoBehaviour>();
if (doorScript != null) doorScript.enabled = true;
// Fecha a porta na posição correta
porta.transform.localRotation = Quaternion.Euler(0, -45f, 0);
Debug.Log("Toy Chica desapareceu com sucesso!");
}
}
Can you verify the layers that your door and your monster have?
Layer Monster is Monstro and Layer of Door is Default
Also because I don't speak the language I'm not sure if this code is supposed to be for hiding the monster or showing it
wait I will translate
nah it's ok - I got enough
Ok so yeah - your raycast is only looking for the monster
that means it will pass right through the door
and it will see the monster through the door
What you need to do is a raycast that hits the walls and the doors also
So like:
int mask = LayerMask.GetMask("Default", nomeDaLayerMonstro);
// Do your raycast here...
if (Physics.SphereCast(..., out hit, 15f, mask) && hit.collider.gameObject.layer == LayerMask.NameToLayer(nomeDaLayerMonstro)) {
// We hit the monster
}```
This way if we hit the door that is blocking the monster, we don't treat it like we hit the monster
Ok Im gonna try
He gives me a error on ...
Sequence of caracteres not allowed "..."
This is not exact code
I was showing an example
you have to write the real code
oh ok
I was thinking in another thing maybe the capsule collider is not high enough
Because its very very small as you can is in the foot
I mean.. yes your object has scaling issues
you definitely want to fix that
How can I fix
What I need to do I dont know nothing about configure capsule collider I just put
in blender fix the character's scale and apply all transforms on it
Want to make branched level unlocking with requirements.
Abstract requirement class with check function.
List nodes with object id's and requirements array. When I'm going check and save levels, there will be unlocked levels and next levels to unlock.
How does it sound?
If you need to override requirement checking yes, otherwise it could just all be data and done the same for all
but this is hardly a beginner topic
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
okay
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
does anyone understand why the enemy just freezes in place?
Probably this?
if (bulletSpawner.burstActive)
{
movementSpeed = 0f;
}```
have you read the entire code?
yes
also your direction Random.range(-1f, 1f); is probably returning very small values
if this is a 2d game i see no reason why you shouldnt use ints here, to define either left or right
you dont have partially left or partially right
that too
yes it causes pretty odd movement but that isn't the cause
also slightly unrelated but whats the point of setting movement speed as a serialized field when youre overriding it in fixedupdate with hardcoded values?
Did you debug burstActive?
Have you actually done any debugging? Seems like the most obvious culprit is the line setting the speed to 0
if you completely remove that line does your enemy move?
if so then its almost certainly your burstActive state.
the logic in the BulletSpawner is pretty confusing/overcomplicated
so I wouldn't be too surprised if burstActive is getting stuck on
especially since you're essentially setting it to true every time you fire
he does move yes but the point of burstActive is to enable movement when it's false and restrict movement when it's true
and it never gets set false except in a coroutine that doesn't run until theere are 1000 bullets
yeah
right well, sounds like it's true when you don't expect it to be
do some debugging
it's really not worth speculating when we can just debug the code
once bullet count reaches 1000, the enemy stop sending bullets and a coroutine sets isBurst to false, in which case movementSpeed should be 0.5f but it doesnt
okay sure
I am not super comfortable with debugging but I guess I gotta learn to do that
debugging doesn't necessarily mean "using the debugger"
it can just mean printing logs
you can just log whenever you set burstActive to true or false
and when you set movement speed to 0
right I'll try that
figured it out
I assumed Unity would know what BulletSpawner was in MonsterMovement.cs
but apparently I had to drop the gameobject in there too
why would you assume this
you didnt assign it anywhere in your code
because BulletSpawner is a public class and I'm calling it in MonsterMovement
public BulletSpawner bulletSpawner;
line 11
youre not calling it
youre just creating a field
youre basically saying "ok if i had a bulletspawner, this is where it goes" but you never put it there, not in the inspector not in your code
yo can i get some help
ask away
(what if you had two bulletspawners, which one would it magically pick?)
in c# yes but in unity the drag in drop is ideal
aah okay
yeah especially if you just need a reference to the prefab, not the specific instance in the scene
I have never touched c# in Unity and I'm not great at c# outside of Unity either, my apologies haha
well, ask the question first
basically im making a mechic where a player picks up a shell and adds to a ammo counter a player can then shoot, problem is when i touch the shell ammo appears, i can shoot to clear ammo but a raycast wont appear until i actually input the amount of ammo in the inspector
but thanks for the help guys, I appreciate it!
huuh, wdym
can you record a short vid?
to explain
yea hold on
i think i understand... Their ammo counter is visually updating, but the weapon itself isnt
so they have to use the inspector to actually increase the ammo amount for it to be able to shoot
if that's the case, then he prob is just incrementing the ammo counter and not the gun projectile counter
bro i broke the shell pickup system trying to fix it holdon i gotta recode ds
i have this bug in my inventoryGrid where if i pick an item and i put it over another item to swap, it instead overlap and make the other item unpickable, try to pinpoint the issue
https://pastebin.com/LWViHidG
the PickUpItem is called normally,but when i pick and swap with another item it doesn't call twice
sorry, i change it to public
can you explain where in this code you're having problems?
the context here isn't that clear
Are these two PickupItem methods on two different classes?
I want all the relevant code yes, and more importantly an explanation of which parts of the code you're having trouble with
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
my inventoryController do the input and check if the item is place in a equipementslot or somewhere in the grid, it also check if you're out of bound or overlapped a item
the overlap check does work because it return true, so its cleary after the check
i was thinking that my CleanReferenceGrid method causing issue
thats where im having trouble, i can't find why my items are still overlapping
so the issue is items are being placed in overlapping spots?
if i place item over an item, they should swap, but instead it overlap and the on-top item remain pickable while the other become unpickable
the unpickable item lost its heigh and width gridSize
Generally when doing a grid inventory UI you want containers and a generic display that can show item information inside those
When you drag/drop you can either "swap" the views or just update the data and refresh the views
e.g. 0,0 -> 2,2
swap the item positions in inventory data then refresh both ui views to show new data
Might be a silly question but if I have a script for a bullet spawner behaviour that acts a certain way, duplicate a bullet spawner that holds that script and then want to make modifications to the bulletscript for that new spawner, do I have to duplicate the bullet spawner script and make the changes or is there another way?
there we go
these are c# basics, you use inheritance for this
it was more a swap in the selecteditem, the selecteditem get drop and the overlap item go in the selecteditem
in the mouse select
it really depends what the modifications are
mb look at it when yall ready
also this
if its entirely just values
you can use basic composition
Still a change in data isnt it? have you confirmed your drop detection works?
Btw you dont have to do that yourself with raycasts... just use the pointer events for drag and dropping https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.IDropHandler.html
@pine garden
but if the logic is actually different, you would probably need some base "projectile" class that your other ones inherit from
BulletSpawner already inherits from Monobehaviour, would it work to make a script inherit from a script which in it's turn inherits from monobehaviour?
I'm not sure what Monobehaviour does in this case
yes thats how inheritance works
if scriptb inherits from scriptA
and how MonoBehaviour already works 😄
and scriptA inherits from Monobehaviour
that means that scriptb also inherits from it as well
As for what Monobehaviour does, its a bit complicated, but to boil it down it basically tells unity "I can be attached as a component"
aah okay, so a base class for all spawners to inherit from and then modifications in the methods of the inheriting classes for different behaviours
MonoBehaviour inheritence is
object : Object
Object : Component
Behaviour : Component
MonoBehaviour : Behaviour
Its the shit name unity picked for user made components that they cant change anymore
heres an example:
public class Bullet : MonoBehaviour
{
public float speed = 10f;
public virtual void Move()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}
public class HomingBullet : Bullet
{
public Transform target;
public override void Move()
{
// your homing* logic
}
}```
the benefit over just duplicating Bullet and making Bullet2, is that if they share functionality, you now have to do double the work to update it everytime you have to
aaah right
So if theres some bug with the Move() method, and all individual Bullet copies have it, you have to fix it in every single one
thats no good
I'm 6 months into my studies in software development and we went through the basics of C# the first 2 months and have covered so much since then that I've basically forgotten all the basics 😭 It's partially why I've started with Unity
Honestly they should have named that shit "ComponentBase" or something
you need more practice
Oh yes a lot more
unless you're doing your own raycast checks you wouldn't wanna use Translate for bullet if it has rigidbody
ok it wasnt a serious example nav
i was just demonstrating inheritance
too much time being a family sitcom star
Back at the very start you could also use JS and Boo, C# relied on Mono so i guess thats why its in the name
Well yeah isnt the Mono of Monobehaviour just "it uses c#"
it's a high pace course so we also cover JS, frameworks, databases.. I have not held onto the basics well
mono means 1
and behaviour means rail
soon we will be free of mono but yea its legacy will be around for many years
but I'm hoping coding in Unity somewhat translates a little
Unity is just an API and you use C# to interact with it
nothing about C# changes
yes but it's also very different to say coding a back end in ASP.NET so idk how much it offers other than solidifying basics
Its an OO language so that is the same
You're talking about framework specific features / concepts but underlying c# is the exact same
making a List or even use factory pattern can both be used in those two framework
Unity concepts has the same like as mentioned MonoBehaviour, GameObject and so on
It shouldn't care what type of requirement it is
okay?
no idea what you mean im just saying how I would implement UI to reflect inventory/character data
okay that's true, do you guys also use SQL for databases in Unity?
You can use anything as long as its not stored on the client ofc 😛
I've used both SQL based and Object /NonSQL
sqlite is an option too
micro slop sql
hahaha
ya sqlite is great tbh.
we cannot use Microslop SQL Server on mac anyway xD
with docker no?
This is very imoprtant to understand!
When I said something about inventory, it's about level/map progression
maybe but the performance on sqlite is good so its more of the "if aint broken.."
one big thing I used to believe was that destroyed objects actaully disappeared from C#-land
haha you believed the unity == null lies!
oh for sure, sqlite is very fine and the syntax is arguably better
MSSQL feels extra in comparison
havent touched a raw SQL line in a while.. Entity framework spoiled me :x
haven't used it yet but I know it's standard
though I find object based sometimes more what I need anyway, like mongodb or amazons dynamodb
Ummm can i get some help now
fuck standards i converted a google sheet link into json
maybe... try asking a question
when i try and open my scripts in unity it just says select an app to open with (im brand spankin new)
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
choose your starter!
choose pokeball moment from professor oak
i mean its not relly a question
then what do you need help with?
basically im making a mechic where a player picks up a shell and adds to a ammo counter a player can then shoot, problem is when i touch the shell ammo ui wont change, i can shoot to clear ammo but a raycast wont appear until i actually input the amount of ammo in the inspector
ok but where is the code ? without it we can only gues
I already made an assumption about this
if the ammo counter is visually changing, but you cant fire
my guess is the ammo in the pickup script or whatever is doing the picking up has nothing to do with teh shotgun ammo counter
yeah this
was thinking the same
maybe the visual ammo counter is disconnected from the actual one for whatever reason
and the pickup script only updates that one
no ive rechecked it
wym?
I mean what I wrote 😛
and your ammo/weapon logic
share all the code
yes
the pickup and the shotgun and the ui
yeah ui too
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
pastebin is full of weird adware
Oh wait you changed the description of the issue
the ui isnt changing either'
then its almost certainly an issue with the ammo pick up
the debug log almost certainly confirms that the shell never gets added to your ammo count
check that last link for me 5
but "Debug.Log("Shell picked up!");" is being called 🧐
that means that gun isnt null
oh wait nvm its on the Player itself.. I see what they doin
it might be the AddAmmo function then
@feral mangosend us the script of whatever has the AddAmmo function
maybe there is a Copy of Shotgun in the scene and its picking up the wrong one since its FindObjectByType
the only thing that has the add ammo is the shell
Shotgun script
what
what do you mean by isnt?
because u said it wasnt defined but it should be
when did i say that
type t:Shotgun in your hierarchy. How many results do you have
lol had a feeling FindObjectByType was doing some like that
I would replace
if (other.CompareTag("Player"))
{
Shotgun gun = FindFirstObjectByType<Shotgun>();```
with
if (other.CompareTag("Player"))
{
Shotgun gun = other.GetComponentInChildren<Shotgun>();```
delete the copy first ofc

what do you guys think of this
i made a function that checks if the player has a ledge infront of him, scans the length of the surface above the ledge and returns an edge and checks if player could stand or vault over it
Sounds like a thing
I'm correctly thinking of implementing level progression?
Better than what I do XD
I just use a character controller
i remember doing something like this in a game jam once – it's a remarkably hard problem to solve if you don't want to have to pre-annotate your world with vault and climb points
yiss exactly i hae that
not done this way, atleast as far as ive seen
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
ctrl+r just refreshes unity to import any changes, which means it will compile if there are changes to code. is there a reason you need to recompile? surely your changes to the code were compiled when you either saved them or when you used ctrl+r (if auto refresh is disabled)
I'm using a serialized dictionary, but changes seem to only take effect after compiling
Which makes them kinda useless lol
That doesn’t sound right
Hello!
I’m a unity learner and I’m pretty really new to unity, and I’m curious about some things
How would I know where to put scripts and when to use them in their right contexts? Do I need to look at other open source projects?
Also, I’m not really a YouTube learner, so I just mostly depend on unity documentation and Google searches. Thanks in advance!
(By the way I know how to code in c# so it’s not the greatest worry of mine, I just hope I’m not using scripts in their wrong ways)
There’s technically no rule as to where to put the scripts, but putting them where they make sense can make things a lot easier.
Having a script for player movement would make sense to put on the player
start small and build up. don't overthink it
Sounds good, I was just having a hard time with it since I've moved from Roblox studio, and scripts there and scripts in unity are so different in terms of where to put them and stuff
when I have a regular spherecast against flat PLANE mesh collider for ground check - I have wrong gibberish normal all the time on X and Z, but Y is right, but when I change the collider to BOX - I've got the "right normal" without this random values in X an Z axis.
I just want to know - why it does that or is this "normal behavior" in general for stuff like that?
I’m not 100% certain how it’s done in Luau, but I believe you often reference objects and components in scripts by referencing them through their placement in the hiearchy? You can do that in Unity, but it’s much simpler (and performant) to simply make a public reference, then you can click and drag the components or objects straight into the script in the editor.
What kind of gibberish values are you talking about?
like values on those axis fluctuating at random rate, like -5 to 5, while Y is right and stable all the time
In Luau and roblox, basically what I used to do is I had mulitple modules that store functions and OOP objects, and in some scripts I initialize these modules so the game can run and I'm not sure how that would be done in Unity, which is just the primary problem. Anything else with unity is absolutely fine
Can you show those values? Because I don't believe you're interpreting them correctly
like I would have a module for player crouching and a module for player sprinting, and in one script called "PlayerHandler" it would initialize these modules. Im pretty sure its very different from that in unity but i could be very wrong
pic 1: whenever I hit the ground
pic 2: my code where I do the ground check/set normal
I don't see any problem with my code, but who knows, lol. it's only do that when I hit the mesh collider of the plane
it's unclear what that value is without seeing the whole thing
it's likely -6.76....e-16, i.e. approximately 0
(i.e. 0.000000000000000067...)
and you will always have this with floats, there's inaccuracy in calculations, and most values can't be represented perfectly at all
You don’t really need to initialize anything in Unity in the same way.
You can make prefabs, which are objects that you can “initialize”/spawn at runtime.
But the thing you’re refering to, I think, wouldn’t be necessary in Unity. Instead, you would just have to make sure your script is present on an object in the hiearchy.
If you have written a script to handle player movement, just be sure that it’s present somewhere in the hiearchy (preferibly on the player object).
If you have written a TimeManager script, for example, that isn’t necessarily pary of any object, you can just create an empty object and shove it in there.
The key is just that the script is present in the scene/hiearchy.
I appreciate this really much. Thank you!
okay, didn't think about that, lol. I've stretched a lot my editor a lot and it is indeed like that. sorry for that poor screenshot and my blindness.
but I still don't get the inaccuracy in plane mesh collider and not on box one. like, why does only mesh gives those error while it's pure flat and perpendicular and box collider is fine no matter what? or it's just whatever the engine gods do
You can't rely on the box collider being accurate either, but it's certainly simpler to find the normal of a box than it is a mesh, and the simpler calculations will result in more accuracy
ah, oki. thanks for the info!
hey so im pretty new to coding and i have been following tutorials and such on youtube to learn while piecing together my first project but with some things that are outdated or dont have a lot of people talking about in various forums i have been using AI to help make the scripts. I have been making sure i go through and understand the code it creates and such but i wanted to see if this is an ok way to learn or not. i just really dont want to stunt my growth with coding so advice here would be greatly appreciated
i would not recommend using ai as a beginner
learn coding without the use of ai, it is something completely different
alright, so what would be a good way to learn how to do stuff? i feel like i can picture the process of what i want to do with everything but i cant put it in the C# language. like I'm trying to tell someone how to do a job but they speak a completely different language.
if you are not able to put it in c# language that means you have to experiment and learn more. just learn the basics of programming without the use of c# in unity
ok i see, i appreciate you answering my questions!
you are welcome
Want to make branched level unlocking with requirements.
Abstract requirement class with check function.
List nodes with object id's and requirements array. When I'm going check and save levels, there will be unlocked levels and next levels to unlock.
How does it sound?
Hello guys , beginner in Unity , is there a way to "cap" the falling speed of some objects ? i'm making a 2D platformer where the gimmick is that you have to go down a lot but at some point , you fall so quickly that it's unplayable (and you clip thought floors)
Depends what mechanism it uses for falling. If it's a rigidbody, check if the velocity is larger than max speed and set it to max speed if it is
you do this every frame ? isn't it a bit "janky" ?
i will try i guess .
Every fixedupdate, yes
should I switch to vulkan? im on linux
ik it doesn't affect the output, just wondering if it's better during development
use vulkan, it performed better on my arch linux
does anyone have a simple 3rd person setup that can put on a capsule object and the movement just works including the camera? im trying to make a reliable player controller for 2 or 3 weeks and I just cant do it
you should have searched the asset store earlier
Any tips on how to make a 3rd person controller setup? moving WASD, rotating camera with mouse, not having trouble with weird colisions, wall clipping or other physics problems?
Nitku sent a link did you check it out
now I did 👍
void Update()
{
float ZAngle = gameObject.transform.rotation.eulerAngles.z;
float TargetZAngle = Mathf.Lerp(ZAngle, -50, 0.1f);
gameObject.transform.rotation = quaternion.Euler(new Vector3(0, 0, TargetZAngle));
if (Input.GetMouseButtonDown(0))
{
rigidBody.linearVelocity = new Vector2(0, PlayerInfo.JumpPower);
gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 10));
}
}
why is the rotation acting crazy?
only when you press the button or?
it is
it might be because i used quaternion and not Quaternion? idk
im gonna try
nvm still rotating uncontrollably
Btw you can access transform directly, you do not need to do gameObject.transform
oh interesting
quaternion exists
it's from separate package and it has an implicit conversion to Quaternion
ok
i hope somebody atleast answer on this question, if other ones get ignored.
GetInstanceId on scriptableObjects change between builds or playing sessions?
...what's your question?
(to be clear, it's likely an issue, but wouldn't be a compiler error)
if they're assets, i'm pretty sure not
the instance id is in the file
you can view it directly
because editor instanceid and build instanceid are not same. Also asked chat bot about getinstanceid and didnt advice for me to use it, because id can change
and it says that id changes between session, but for me it didnt change
probably read it as that it COULD change / is not GAURANTEED to be the same all the time.
i shouldnt use it or i have to make my own and store in field
If you need unique ids then use your own or in editor grab the guid and store it
I dont actually know if we can get an asset guid without AssetDatabase
hello ive been picking up unity/game devlepment again after years of not doing it
Pretty sure Unity doesn't have an ID that stays consistent across editor and builds. https://github.com/Unity-Technologies/guid-based-reference/ was created because of this. Other similar solutions also exist. There's a talk by William about this.
ive done coding alot before but just a little bit rusty but its starting to click abit for me
ok so this branched out to a less annoying bug..
void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
ZAngle = transform.rotation.eulerAngles.z;
}
// Update is called once per frame
void Update()
{
ZAngle = ZAngle - 0.1f;
ZAngle = Mathf.Clamp(ZAngle, ZAngle, -50);
transform.rotation = Quaternion.Euler(new Vector3(0, 0, ZAngle));
ZAngle = transform.rotation.eulerAngles.z;
if (Input.GetMouseButtonDown(0))
{
rigidBody.linearVelocity = new Vector2(0, PlayerInfo.JumpPower);
transform.rotation = Quaternion.Euler(new Vector3(0, 0, 25));
ZAngle = 25;
}
}```
for some reason now, it only lerps once(reaches -50) and is stuck at -50 no matter what i set the rotation to after that.
don't read back eulerangles, they may not be consistent
also what's with that clamp lol
you've set the max to -50
so it's going to stay at -50 once it reaches that
its cuz i couldnt just lerp cuz it would infinitely rotate
would probably be clearer if you use Mathf.Min instead of the Clamp
that wouldn't change anything, it just makes the problem more obvious
you clamped it and now you're saying the issue is that it's clamped
this is probably more likely to be the issue
what do i di instead of that
maintain your own variable and only assign into euler angles
just remove the ZAngle = transform.rotation.eulerAngles.z;
mhm