#💻┃code-beginner
1 messages · Page 545 of 1
ty guys lmao
NP.
Don’t forget the most important thing…using the debugger to step through your code and see what happens.
anyone know what the easiest/best method of removing these broken installs?
reinstall windows lol
uninstall windows lol
does anyone know how to fix this?
ill never trust unity vc or plastic
same problem within the hour, its gonna be one of those lol
better patch quick
plastic sucks anyway
what should i do tho?
try remove VC package?
i was coding a simple player movement script, but for some reason the jump code makes it so i am continuously launched in the air with no input. it gets worse the more i try to fix it
https://pastebin.com/jNR7qES8
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.
Code looks ok. Show your character's inspector, all components it has and its children's components too
Okay so CharacterController will not work with Rigidbody. Both will try to move the character = 💥
You need to pick either one
save ur scene
?
as in var thing = GameManager.us?
yes
You could also just write a shortcut method
i dont think a shortcut method would be faster than either GameManager.us.whatever() or in the cases of method spam (which you wouldnt run into if your code is halfway decent) var us = GameManager.us; us.whatever()
it wouldn't be faster
to type
it could be more convenient
but i mean, intellisense is a thing anyways
if you're using the same method in a bunch of places, it could make it more convenient
oh you're refering to GameManager/proc/whatever() { return us.whatever();}
ehhhh i mean it would work
i dont like bridges tho, still have ptsd over a mountain of shitcode built on it
do have a bit of a skewed outlook since to me less wrappers == cleaner code
With method spam you excessive amounts of method calls or what?
as in like
//set stuff up
GameManager.us.do_x()
GameManager.us.do_y()
GameManager.us.do_z()
GameManager.us.do_w()
What's wrong with that
If the issue is that it does GameManager.us repeatedly, I would assume that the compile probably optimizes that
lets take an example from my code
so im doing golf, and one of the things i needed to do was a sick ass animation of every element floating away when the ball goes into the hole
now i could do some
void OnColliderEntry(gameobj){
if(gameobj.hastag("ball")){
var gm = GameManager.us;
us.yeet_map()
us.load_new_map()
us.spawn_ball()
}
}
ball whatever code
but realistically all of it should be in us.load_map()
the hole handling loading the map aside
Agree
now im not saying "dont have functions that do a lot of stuff"
but if you're calling a bunch of stuff on a diff class perhaps said class should have a proper handler for that
Yeah. And ideally you'd make these private: yeet_map, spawn_ball etc.
So you can't even call them accidentally
ehhh that one is up to preference imo
i personally dont like the modifiers since all that ends up with is me having to correct a private to a public when some new usecase pops up
even if said usecase is nonexistent
I do understand that and agree in some cases. But in some cases it's clear that a method shouldn't be ever called from the outside
But yeah worrying too much about encapsulation just slows down my iteration speed tbh.
yuh
GameManager.Wahtever(); seems shorter than both of those to me
yes we came to that conclusion already
less wrappers == cleaner code
Basically the entirety of using a high level programming language and a game engine is to introduce layers of abstraction to simplify the code you need to write
Not sure how this is any different tbh
Wrapping things is how you make things clean in programming
wrappers as in f.e
public bool drop_item_on_floor(){
return move_item_internal(...)
}
or getters or setters that only just return the var
that's a wrapper that doesn't seem to add anything though, which has no purpose
Those have a purpose, which is to enforce encapsulation
nuuh
that also enforces encaapsulation
not in any meaningful way
the property lets you have a different access modifier on the getter and setter
neither do getters
this one just makes a private method public
disagree, see #💻┃code-beginner message
link doesnt work
yes it does
idk if its a me issue
It just goes back to this
oh
if the internal method has no params - suer, but if the wrapper passes some params to the method, then it's not just making a private method public
well what if i need to mock a var
agreed
i shouldnt have to, but what if i do
What about it
a setter would break stuff then
how so
say im doing chess and i need to mock a piece being in x place
and lets say you have a setter on the piece holder whatever that updates the hud
the mock would erroneusly update the hud
well, update meaning "place a piece on the hud"
board whatever
You wouldn't call that setter in that case.
yeah, you'd just assign to the var directly
Are you arguing against any accessors with side effects at all?
and reset after
because that way leads to madness
im arguing against prohibiting regular var access
in this case setting
That's a huge mistake and inviting way more bugs than the other way around
my usual approach is - make everything private by default, if necessry expose something
This example seems super contrived. Writing a unit test for a chess game you would simply provide the whole game state as a starting point, you wouldn't be calling some in-game setter.
i just skip the privating part since 4 times out of 10 my projs are solo-dev
~~the 6 remaining times are in an engine where access modifiers are through an optional lint
~~
my projects are also solo ones, but it's just nicer to not expose random things and only expose what's meaningful to the outside
its an example i ran into
needed to mock a piece not being/being in x place to check if it would cause a check
yeah but at that point its personal preference
obviously if you're doing a library throwing privates at eveything is prefered
even in personal projects... you can't randomly change many variables from the outside without breaking something, so exposing them makes no sense... make methods that would keep the object in a valid state instead 🤷♂️
it's just easier to work with, because in a month you wouldn't strictly remember what's what, and which variable you can modify safely
you can have both
so, while it would work and it's not a strict requirement for a solo project, the moment you're not doing solo it would be, so it's better to get used to it 🤷♂️
both public var access and functions that dont leave the program in an undefined state
fair
Which programming language does Unity use?
C#
Is programming only possible using C# or are there alternatives?
realistically only c#
Sorry if I am asking too many questions I am new to using Unity and learning game development on it
no worries
ive been constantly trying to get this sdk to work, ive tried reinstalling vs code and my computer. I checked my system variables and manually assigned its path. Yet it still doesnt work, if anyone can help that would be awesome
Hey, I am new to unity and I am acutally working on a Flappy bird game, Do anyone know why my pipes are behind the ground in 3D view but in front of the ground in 2D ?
this is related to 2d sorting. your sorting layers determine what is drawn on top. and your z position determines where in the 3d view they appear
with different sorting layers and/or order in layer, the z position isn't taken into account
https://docs.unity3d.com/6000.0/Documentation/Manual/2d-renderer-sorting.html
^ this.. u can actually have all ur 2d objects BEHIND something and have them all render in front of it.. using sorting layers
Thanks I will read this html file
Do you have a class named LogicScript in your project?
I don't see it in the script list in VS
I see a NewBehaviourScript, which is the default script name when you create one, did you forget to rename it?
because it doesn't exist
Yes. I forgot to rename it.
aren't u a comp-sci major? that had to learn c++ and python? im sooo confused..
i'm trying to get this vehicle to abruptly change from acceleration to deceleration (or otherways) but i'm not sure how to make it more abrupt.
void FixedUpdate() {
if ((goingSpeed > 0 && YInput < 0) || (goingSpeed < 0 && YInput > 0)) { // gets triggered when the player switches
goingSpeed = Mathf.MoveTowards(goingSpeed, 0f, dccSpeed);
print("change from acc/dcc dcc/acc");
}
else if (Mathf.Abs(YInput) > 0.1f) { // gets triggered if the player is just holding
goingSpeed += YInput * (driveSpeed / accSpeed);
print("going forward/backward");
}
else { // triggered when the player releases all forward input
goingSpeed = 0f;
print("stopping vehicle because no input");
}
goingSpeed = Mathf.Clamp(goingSpeed, -driveSpeed, driveSpeed);
// Driving
float motor = goingSpeed;
wheel3.motorTorque = motor;
wheel4.motorTorque = motor;
wheel1.steerAngle = steerSpeed * XInput;
wheel2.steerAngle = steerSpeed * XInput;
}
notably it barely ever prints the change print statement, and making goingSpeed = 0 does not really do much in terms of doing lots of slowing
My project cannot compile because these two functions use AssetDatabase. They're meant to grab a file from the Assets folder, without the need for a Resources wrapper folder.
Class with both functions (GetRuleTileByCodename and GetSpriteFromPath): https://hastebin.com/share/maxunijaqu.csharp
How can I change the functions to preserve the functiionality but remove AssetDatabase from it?
if its runtime you need to use the functions for runtime, IO, Resources or Addressable
oh and streaming assets ig if you don't consider that IO
I don't understand
which part?
AssetDatabase is part of Editor classes, you cannot use Editor classes in a build
alternatives are the ones stated above
System.IO , Resources or Addressables
has anyone here worked on motorbike physics before? or more on the wheels part of it. I need help with setting up my bike properly. Im running into the wheel bouncing when torque is added to the wheel collider and the suspension bouncing all over the place
What collider are you using?
wheel collider
I don't really know how to introduce a Resources folder. Do I place everything inside it, like another Assets within Assets?
pretty simple, you add a Resources folder and put whatever Sub folders inside you want to grab at runtime
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Resources.Load.html
But what I need are specific files of any kind, for now a RuleTile and texture. I don't know what to do, as theyre in separate folders. Some in Graphics > Backgrounds > 00 > 04.png, some in Game > Tilesets > StoneBricks > StoneBricksRuleTile.something (.RULETILE? .asset?)
for example*
not sure how that changes anything
I'm unsure how to decide what folders to move to a Resources wrapper
do I include Prefabs? Scripts?
i personally don't like using it and just go for Serialized references or SO containers.
but generally just whatever you're loading now with AssetDatabase
gpt isnt helping me at all rn hence why i came here
don't post crap AI spews as answers to questions #📖┃code-of-conduct
I think I share your opinion. How would I go about the SO?
for example as SO can contain an array of SOs and you just need to keep that 1 SO where you need to access those ruletiles
SOs are good containers for other Asstes, so you only need to reference 1 thing to access multiple Assets
Try to make wheel collider more inside i had same issue and that helped
just letting you know the physx wheel colliders (default in unity) are awful garbage. Its difficult getting them working for a 4 wheeled car, let alone a balancing motorcycle
Otherwise you can use Assets like:Realistic Motorbike Controller
raycasts are the answer
@untold raptorYou should look into getting better "wheel colliders" off the asset store, or building your own if you're interested. Building your own is actually pretty simple.
you just have to juggle creating your own friction
oh boy 😄
A lot of people don't realize that cars in video games are actually just hover crafts 😉
the wheels are 100% visual
this has gone from simple drag and drop to create my own physics lol
nah its not that advanced
You dont have to make your own physics, just use for example: a raycast to create up and down suspensions instead of relying on wheel col
so just scrap the colliders in a whole cos they are trash?
99% they are trash
gotcha
Yes, basically what navarone is saying.
Send a raycast down from the wheel position. Think of this raycast as a spring. How much is your "spring" actually compressing? (between 0% and 100%)
then just add force upwards
proportional to the "compression" amount
I have a 2 wheel game but I use 4 rays on that but you can probably force it to only work on 2, I just never bothered
alrighty i'm back at it again with the gap issue - i've got some progress with it as now only ONE tile has the flickering gap, and it's always the first tile that gets moved that causes this
another interesting point is that the flickering can only be seen when the tiles are moving
I have checked that the tiles are on the same ordering layer ( having different ordering layers doesn't change anything), and that the Z axis is also the same
I've also tried deleting the tile and putting it back in case i messed something up
here's the code:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class LevelScroller : MonoBehaviour
{
public Sprite sprite;
public Transform[] tiles;
public float scrollSpeed;
public float tileHeight;
public float pixelsPerUnit;
// Start is called before the first frame update
private void Start()
{
tileHeight = sprite.bounds.size.y;
for (int i = 1; i < tiles.Length; i++)
{
tiles[i].transform.position = new Vector2(tiles[i - 1].transform.position.x, tiles[i - 1].transform.position.y + tileHeight);
}
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < tiles.Length; i++)
{
tiles[i].transform.Translate(Vector2.down * Time.deltaTime * scrollSpeed);
if (tiles[i].transform.position.y < -tileHeight)
{
float highestY = GetHighestTileY();
tiles[i].transform.position = new Vector2(
tiles[i].transform.position.x,
highestY + tileHeight);
}
}
}
float GetHighestTileY()
{
float highestY = tiles[0].transform.position.y;
for (int i = 1; i < tiles.Length; i++)
{
if (tiles[i].transform.position.y > highestY)
{
highestY = tiles[i].transform.position.y;
}
}
return highestY;
}
}
im picking up what your putting down. after the hovercraft analogy, that really helped me understand what i need to do now
there are multiple good videos on youtube that explain the math behind it
https://www.youtube.com/watch?v=CdPYlj5uZeI&pp=ygURcGh5c2ljcyBjYXIgdW5pdHk%3D
its for car but the same concepts apply
A detailed look at how we made our custom raycast-based car physics in Unity for our game Very Very Valet - available for Nintendo Switch, PS5, and Steam.
BUY NOW!! https://toyful.games/vvv-buy
~ More from Toyful Games ~
- Physics Based Character Controller in Unity: https://youtu.be/qdskE8PJy6Q
- Instant "Game Feel" Tutorial: https://youtu.be/...
float springCompression = 1 - (hitDistance / raycastLength);
is basically gonna be the heart of the equation
my man 👊
such a good vid
thanks man
Thought you released it on the store, was looking for it
Wait that's not you
Didn't you make a video on a car controller a while back though? Or an asset?
a little bouncy but yeah good example
can even play around with the center of mass
i imagine doing a bike would be relatively easy
esp comparing it to unity's wheel colliders 🤢
the difficult part about the bike is just keeping it upright
honestly making my own wheels sounds kinda fun
i have better.. but yea.. first example i came across on my own.. u can also raycast downwards to place the wheels relative to the ground
would u say using a mesh collider better than using any other? (with convex)
if you sweeptest, you can simulate the actual shape of the wheel 😉
single lined raycasts make icky wheels. <-- afaik the physx implementation does this
true true.. ive thought of doing this once or twice.. and i still might..
but for arcade type stuff 1 ray is plenty
hey guys im making a pixelated 2d cool game and im looking for a scripter i curently just made sprites
like in a radius from teh center? or like a half arch from the car?
which would u do?
gimme a sec ill briefly upload a video
nah, no multiple raycasts
sweeptest is raycasting basically an entire mesh
physx handles it behind the scenes
ohh interesting..
ill show you how nice this looks one sec
lol
oh yea, thats noice
same operation, just sweeptest replaces raycast
that suspension flexing is amazing
I did actually try this also (both examples), but the gaps between the raycasts caused serious issues
you'd need like tens of thousands per wheel to make it viable
well i done something wrong here 😂 gotta add some stuff to stop it from turning into an oppressor
A low center of mass helps with stabilization
You can manually modify Rigidbody.centerOfMass
also make sure mass is not like 1 or something, these things are pretty heavy usually and have decent amount of mass
nver had good luck with mass below 1000 with suspensions
gotcha
bump, tried feeling around the sprite tools too, no dice
you need PixelPerfect on your camera
Missing context here
can you show video of what it looks like
hi
yep, one sec
im new
Hi new
haha no, im GALADIXO
I'm dad
so i have this system where tiles are placed on top of each other to simulate an infinite scrolling level
before i had an issue where each tile placed left a 1 pixel wide gap inbetween the tiles, i got past that except for now this only one tile that leaves a flickering gap
huh normally the ortho size of camera is grayed out when pixel perfect is active
ah it's because the ortho is the same size as the pixel perf
just increased its size
I mean normally pixel perfect controls the ortho size
ahh
maybe its urp/unity6 thing
yeah i could update to unity6 as well
it's currently on 2022 LTS
and everything is backed up on github in case that screws it up
hmm i think its more to do with using BRIP instead of urp the camera
did you check out the scene view?
does the same thing happen if you zoom in
you should start with a 4 wheeled vehicle until you understand what's happening. It will make the process a lot easier.
Forget having a car model for initial testing. Just use a stretched cube with 4 raycasts (one at each corner)
i've also tried sprite atlas, sprite material with the pixel snapping turned on, nothing is changed
one part that i have definitely noticed is when the LateUpdate() is changed to FixedUpdate(), the gap turns larger
but it's ONLY for that tile
you've got to be fucking kidding me

i just fixed it
i just moved the translate part of code after the if function

i mean it MAKES SENSE, since code goes top to bottom, it'd do the translate first and then the if
and since my pc is a good boy, it did the translate + if really fast, making the tile overlap and flicker at that one little point
Order-of-operations can be very important
within a function, between different objects...
ngl cuz of color key looks glowing enough for me
ik but the surrounding area isnt
probably because you dont have Post Processing or Bloom Cranked up
idk what that is
I think the glow is supposed to come from the Light2D
i have light 2d
yeah but post processing should be enabled for urp
check camera component make sure PP is on and you have a Volume with a profile
i dont understand any of this 💀
start googling lol
so i just go to main camera and its in inspector or what
yes screenshot the Camera component
post processing, do you see that checkmark?
gameobject with volume component + profile inside
Volume
Global, sorry
create a new profile make sure you got enough bloom
where do i do that
Volume has option to create new profile iirc, then do Add Override -> Bloom (play with threshold and intensity)
make sure volumetric is enabled on the light2d
and what is your values for bloom
actually Iirc for 2D lights all you need is the Volumetric option instead of sprites
that was it
haha yeah 2D is qirky.. this lighting stuff is new got confused 😅
you still need PostProcessing/bloom for glow in sprites n stuff tho
alr
thanks
my textures look like this now
any1 know what happened
did you delete the Global Light 2D?
idk
that was what happened
btw non-code questions in #💻┃unity-talk this a code channel
alr thanks
goddamnit now i wanna make a wacky racing game with cars bobbing like that
testing gameObject != null sounds a bit weird here
The error is happening because you're trying to access the gameObject property of your MonoBehaviour-derived class
Trying to access this property on a destroyed object is invalid
If you really want to know if your own object is valid, you'd do if (this)
but how can the object be destroyed if im accessing it in OnDestroy()
cause its marked to destroy
well it's not OnBeforeDestroy (:
Is this happening as the game exits?
I'm pretty sure that the object only becomes invalid sometime at the end of the frame, normally
But I know that this changes when exiting Play Mode
i managed to fix it, i think the sounds were parented to the object that was being destroyed
or something like that
If you destroy a game object, all of its child game objects are also destroyed
is there no way to "cancel" a destroy btw?
seems weird that all children are just doomed for destruction and cant be unparented or anything
You can unparent them before you destroy the parent
If you want to play an audio clip as a thing is destroyed, consider this..
I believe this is 3D-only, since it doesn't let you set the spatial blend
so it would be inappropriate for a 2D game where you don't want to spatialize audio
i meant like after theyre "marked"
oh wow thanks, i had no idea that was a thing
is there a way to have a Bot know what path to a player has no obstacles without Raycast? I know how to use raycast and I have used it a lot, I just want to know if theres another way
unity has a built in pathfinder
navmesh
ok ty
Should I use Unity AI navigation because its newer (less than a month old)?
unity ai navigation is navmesh. and it is not less than a month old lmao
mb the version is less than a month old
@latent gladehttps://docs.unity3d.com/6000.0/Documentation/ScriptReference/AI.NavMesh.html
if you want to steer rigidbodies, you'll want to extract the path and steer the rigidbody using addforce to each waypoint
so in a platformer, could I still use linearvelocity for the x value?
yes, you can steer with velocity
the important part is that you don't natively use the rigidbody as a navmesh agent
because unity will forcefully override it's transform, which bypasses the physics engine
ok thank you
based on this, i'm going to assume this is for 2d. which would mean navmesh does not work for it out of the box, there's a third party asset that will allow navmesh to work with 2d but you'll have to search for it. there's also assets like aron granberg's A* Pathfinding Project which are great for 2d
Im finding a bunch of tutorials for 2d, is it doesn't work with platformers or it is outdated with 2d or something? Because you would need addforce for jumping and stuff?
navmesh does not work with 2d out of the box.
wdym out of the box? the camera?
no, i mean that navmesh does not work with 2d. there are assets that allow it to, but it does not work with 2d by default
"out of the box" meaning by default, It won't work.
oh ok
as in, it only works with 3D 🙂
Just found it, its $140. What assests would I use to make navmesh work for 2d?
you can google it. but there is a free version of that asset
just make a 2d game in 3d 🧠
If you want something simple, you could always just make a 3D scene, but still have the camera fixed in place like a normal 2d platformer
"AI" shouldn't be all too difficult for a 2d platformer in the first place tbh
you could probably just make something yourself
Yeah I was thinking about that
navmesh is typically for more complex problems. Like a character finding his way out of a room
Would raycasts be a good way to do it or would that slow the game down too much?
raycasts aren't a problem for performance unless you're doing tens of thousands of them
alright sounds good
device is an InputFeatureUsage<float> so its TryGetFeatureValue out param will be a float
but you used a bool
i.e. bool isPressed
you mean CommonUsages.trigger is an InputFeatureUsage<float>?
no
device is presumably an InputDevice
oh - maybe
I'm not that familiar with XR stuff, I was imagining TrtGetFeatureValue being an extension method with device basically as the first param. But that makes sense too
yeah that makes more sense
Basically this one is being called, but your out param is a bool @grand rose , so it's not happy
or the other way around - it thinks it's the bool version but you provided InputFeatureUsage<float> Either way it's a mismatch.
yeah, it's trying to figure out some way to coerce the things you provided into something that exists
i see thanks
Also, surely !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
ah, yes, i didn't notice the missing error in the code editor
hey yall im kinda confused that when i create a script it doesnt come with the using System.Collections; and using System.Collections.Generic lines
Depends how you create it. But it really doesn't matter
Those would have come from a file template.
Unity 6's file template doesn't have those
Oh i see
the easiet thing to do is to just add whatever you need when you create it
You can and should be using a fully configured IDE that automatically adds using directives as needed.
I was following one of the unity courses and the guy created a script and it came with those
ok, well, it's not important.
But you should really try to use the same version of Unity as the tutorial you are following
or you will see lots of little differences that might confuse you if you are a beginner.
which one can i use, im using vscode since i have a really low spec pc but barely enough to run unity
Rider or Visual Studio
Rider is best IMO
Visual studio is slow
That's a really vague question. Rider is fast, after it does its initial indexing.
I have not tried rider yet
VSC is pretty fast as well but it all comes down to personal preference
alrighty
choose which IDE you want to use
im used to the vscode interface so idk if rider is quite different
also i barely know how to code
You will learn them over time
you would have to use it to make your own judgement, or look at reviews of it
got it thanks
#🏃┃animation not a code question
/*who knew programming was this much fun
Just learned Prefix (++x) and Postfix (x++) operations Lets goooooooooooooo*/
Is there by chance a quick and easy way to get all Vector3Ints within a circular 2d bounds? 🙂
You could start at center + (-radius, -radius) and do a quick for loop over that rectangular area, checking if each point is within the radius of the circle
can you use vscode for commercial gain? im just kinda confused about rider's licensing
lets say i want to release a game on steam for free would that qualify as commercial use?
awesome. I can just use the Contains method? Thanks for the idea!
The Contains method of what?
I'm seeing that bounds include a contains method
If you mean Bounds, that will not tell you if it's in a circular area.
Bounds is the AABB of the collider
Assuming you're talking about a CircleCollider2D
Basically it's a rectangle
yes
im not sure what to use between rider, vs2022 or vscode
if you can get/use Rider, go for that . . .
i like vscode but i dont want to be having problems down the line
thats the problem it's a quite heavy IDE and im honestly afraid of the licensing fees
Nothing is going to happen with licensing fees
You can always switch to another ide🤷♂️
Rider has the best Unity integration, that's why I recommend it
i see
I'd just stick with visual studio as a beginner.
yeah, the integration is ridiculous . . .
got a little circular fog of war going now. thanks praetor!
what im curious is that if i keep using vscode that it will be lacking in some aspects
i like the plugins and themes for it
VSCode tends to break with its Unity integration randomly
at least in my experience
and then you waste time trying to figure that out
Also last I checked there was no functional debugger for it.
oh dang
is there not a more lightweight version of rider?
At some point, you need to make a choice.
This is your choice to make
Pretty sure there is. Coming with the C# extension. But yeah, I wouldn't recommend vs code for C#.
we can't make it for you
i see
I might be a bit outdated, since I haven't used it in a long time
You can always change later
youre right
ill see if my system can handle it with other windows open
and if it can ill keep it
fog of war ahhh
based on my personal experience vscode is ok, im using it now because my visual studio installer bugged out. just that the autocomplete can be subpar.
in this case it recommends a visual studio namespace before recommending unity's ui namespace
M comes before U
i believe that's in alphabetical order . . .
if theres a way to remove this namespace from being recommended/prioritising unity's namespaces to be recommended ill gladly take it
is there an easy way to reset a variable if it remains unchanged for a bit?
a timer?
use a timer: once expired, check if the variable has the same value since the timer started, and reset (if true) . . .
reset it to what? If it hasn't changed, doesn't it not need resetting?
basically yes - write a little code.
i take it you mean, "remains unchanged," after it has been changed, no?
I think intellicode can figure it out
yeah, its for a melee combo system
it counts up the number of attacks made and changes the next animation played based on that
it just doesnt reset the number if you stop attacking right now
ill do the timer thing
Basically i'd do something like:
- Make a property to change it which also sets a timer. Only set it through that property so it always sets the timer
- In Update, check if the last change was over some threshold. If so, "reset it".
Me and a friend are fairly new with Unity, we're trying to make a 2D platforming game
Here we've ran into a problem that we've tried searching for solutions online but haven't managed to find one so far
In the video you can see that there's random audio icons everywhere and the referenced script on the behavior is missing, problem is we don't know what said script is because it's listed as unknown
Does anyone know how to fix this? Thanks (If I chatted in the wrong channel let me know I just joined this server and have read the rules)
The icons are gizmos for the AudioSource component
you can disable them by disabling gizmos in general, or that specific gizmo
As for the warning - check all the objects in your scene and check all your prefabs
one of them will have a broken component on it.
I don't know how I didn't assign the variable.
I thought I did everything I was supposed to do
It's the audiosource variable GameOver
show where its assigned
Did you actually assign the variable though?
nothing in your screenshot seems particularly relevant to the error, which is presumably in a different script.
How id it supposed to look like if I did assign the variable?
Like not saying None in these slots
(this is an example from my game)
Here's how it looks unassigned
Note that you didn't even provide a screenshot of the inspector
I'm going to have to get back to you later. I was tampering with my own game and now I can't make the bird fly anymore
thx for the answer mate. but, it still like this. The game and the scene, it like its switched. I've tried to disable the gizmos, it's still happen like this
Should I make a thread for this btw? To not clog up the channel
Gizmos are still enabled in your screenshot
Disable them with this
ah i tred it again and it works now.
thanks alot mate
Hey i'm looking for some help with something - if anyone has experience making xcom like games !
who can help me?
i need to know how to start a script
please i need someone who can help me
Create a new script and start it. It's probably the first thing you learn if you !learn properly:
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
how do i create a script?
Via the context menu in the project tab. This and a lot of other basics are covered in the beginner pathways on unity !learn. Go and learn properly:
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
bro 750 hours is to much i can learn it in 3 days by only using it just tell me what to do
750+ hours is all the content on the platform. Not just the beginner tutorials.
You're not gonna get much help with such attitude. Show us that you have put some effort.
I told you were. Try reading my messages again.
type again
there is no context
where tf is script?
Just go and learn properly
!learn first, ChatGPT later (super later)
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
again, you don’t need to do all 750 hours
Bruh there's literally an option called create and it's the very first one
Always agreed on that, ChatGPT is a powerful assistant, not the answer. It can do a lot and save you tons of time, but you need to know programming to break down your needs to it.
talk is cheap
claims to be learning from ChatGPT
doesn’t know how to do a unity fundamental
isn’t willing to use all the different learning platforms people are redirecting them to
Optimally at least some YouTube videos would help. GPT is a good learning tool but it’s not useful if you don’t know how to navigate unity lol
They will realize that eventually.
Google brackeys lol
Hi,I would like to ask a question, assuming that orange and blue are two UIDocuments, and their Panel is the same. I now want to place the blue one at the bottom of the screen. How should I do it?
orange is startup and blue is dialog
probably a question for #📲┃ui-ux or #🧰┃ui-toolkit
Thank you, I will go to the corresponding group to ask.
Hi, I can't understand what causes my game to freeze.
I followed this tutorial https://www.youtube.com/watch?v=QTSWm1RsvzY and as far as I can tell I have everything exactly the same.
As I read online if I enter infinite loop whole editor should freeze, that's not the case.
I also don't get any errors in the console (well, I was getting one, people online said it was due to the lack of subscription to the Unity Version Control so I deleted this package completely but it didn't solve anything)
Here is my code: https://paste.ofcode.org/cfHdGctDZqyMFwMeWtjAM2
If smoothTransition is true, then my character moves by .20 (instead of 1) or rotates by 10 (instead of 90)
In this video we make a super simple first person controller for a grid based dungeon crawler style game. This style of game has been around since almost the beginning of video games, though there's been something of a resurgence of late.
The reason I'm making this video is because I am taking part in Dungeon Crawler Jam 2021, a game jam where ...
It works as expected if smoothTransition is false
use the profiler and see if anything is running wild
i dont see anything in code that could freeze anything..
test to see if its actually freezing?
debug.log in the update for example would be a really simple indicator
my guess, you are missing an else here
if (targetRotation.y > 270f && targetPosition.y < 360f)
{
targetRotation.y = 0f;
}
if (targetRotation.y < 270f && targetPosition.y > 0f)
{
targetRotation.y = 270f;
}
without it the code makes no sense
ohh true!! if those conflict w/ each other or toggle back and forth. the logic might be stuck in an endless update loop..
the if (true) triggers me
(not technically frozen) but just not doing anything useful lol
if (targetRotation.y > 270f && targetPosition.y < 360f)
{
targetRotation.y = 0f;
}
else if (targetRotation.y < 270f && targetPosition.y > 0f)
{
targetRotation.y = 270f;
}``` throw an else in there
that way only 1 of those can be true at a time
So far I'm following tutorial, there will be collision logic as soon as I fix my current problem
then at least use a variable there.
Sadly not the case, these don't affect the movement yet it won't work as well
if(eventually){
}```
its still an issue..
- targetRotation.y > 270f && targetPosition.y < 360f is true, so targetRotation.y is set to 0f.
- Now, targetRotation.y < 270f && targetPosition.y > 0f is true, so targetRotation.y is set to 270f.
brrrrrrrrrrrr
read your code. if the first if is true then the second will be as well so rotation.y will always be 270
ye noticed it, changed to
if (targetRotation.y > 270f && targetPosition.y < 361f)
{
targetRotation.y = 0f;
}
else if (targetPosition.y < 0f)
{
targetRotation.y = 270f;
}
just one less thing u have to worry about
what's with the 361 there?
also add some debugging
do you perhaps mean <= 360 instead?
tomato tomato?
not for floats
ahh tru tru
ye he right but still not the actual problem, its something in here but can't understand what
transform.position = Vector3.MoveTowards(
transform.position,
targetPosition,
Time.deltaTime * transitionSpeed
);
transform.rotation = Quaternion.RotateTowards(
transform.rotation,
Quaternion.Euler(targetRotation),
Time.deltaTime * transitionRotationSpeed
);
i mean of course it is since that's the part that will differ between smoothTransition on/off
what if u used a little margin of error? b/c it could be that it never really reaches the target?
if (Vector3.Distance(transform.position, targetPosition) < 0.01f)
transform.position = targetPosition;
else
transform.position = Vector3.MoveTowards(
transform.position,
targetPosition,
Time.deltaTime * transitionSpeed
);
if (Quaternion.Angle(transform.rotation, Quaternion.Euler(targetRotation)) < 0.01f)
transform.rotation = Quaternion.Euler(targetRotation);
else
transform.rotation = Quaternion.RotateTowards(
transform.rotation,
Quaternion.Euler(targetRotation),
Time.deltaTime * transitionRotationSpeed
);``` something like this
Will see gimme a moment
would snap it to the desired positon and rotation when its close enuff
does unity hang or is it just that nothing is happening?
MoveTowards and RotateTowards should handle that fine
this isn't SmoothDamp that asymptotes
or Lerp or Slerp
im just spitballing.. as theres nothing really i see in there that would cause a "Freeze"
try commenting one out, and then the other, to see if they work individually, maybe.
Character moves for 0.2 instead of 1, then its unresponsive, unity works as expected, game doesnt
lol.. thats usually the case 😅
how is targetGridPos set?
so its not unity freezing.. its:
the character becomes unresponsive after a brief moment
where is your targetposition and rotation if any?
As I read online if I enter infinite loop whole editor should freeze, that's not the case.
From my original message, could be more descriptive tho ur right
they're set in MovePlayer
@lyric rapids?
you should probably send the entire script
When I did:
// transform.position = Vector3.MoveTowards(
// transform.position,
// targetPosition,
// Time.deltaTime * transitionSpeed
// );
transform.rotation = Quaternion.RotateTowards(
transform.rotation,
Quaternion.Euler(targetRotation),
Time.deltaTime * transitionRotationSpeed
);
Nothing worked, maybe there is some functionality depricated
nope, all thats still relevant
well ok you should probably debug AtRest
also your IDE will tell you if something is deprecated
and also targetGridPos
btw, why are you doing this in FixedUpdate?
would probably make more sense to do this in Update
I was wondering that too
sidenote: in AtRest, you can just return the boolean instead of checking if the boolean is true then returning true
I'm a web dev who got assigned to make a game for university, I'm making buttons on the website go jumpy when u hover over them n give u directions on google maps to nearest pizza hut, its my first time with unity so i'm following tutorial
- if (x)
- {
- return true;
- }
- else
- {
- return false;
- }
+ return x;
..uh, ok? i have no idea how this is relevant to my question lmao
Csharpier is shouting at me whole time for syntax, not using braces etc
there's no relevant braces when you return a bool
Im following tutorial 1 to 1 and it still doesnt work, trying all i got, not trying to understand it
you should start trying to understand the logic
I read thru that code, after it stopped working I tried to get whatever author of the tutorial had
and debug where the logic stops working
Hey, guys! I would like to know how to enable and disable my cursor when pausing and unpausing the game?
Yeah ok but by default when I am entering the game the pointer is enabled right?
Yes
you could set it on awake/start on some central script
This one also applies: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/CursorLockMode.html
I have here an issue you know when I am pressing escape button to resume the game I still view my pointer
Okay, so the question is not specifically about disabling the cursor then
In the Unity editor pressing escape enables the pointer again. In build mode this behaviour doesn't exist
Something about not locking yourself out
If you press escape
I mean even if I resume the game yes
I don't know if this behaviour can be changed
You can implement behaviour around this so it works properly in editor mode, but note in a build this is different
CursorLockMode.Locked also hides the hardware cursor. However, the cursor is only locked and hidden after you click in the Game view.
I can't really understand how this behave?
I mean locked and confined
I mean I see nothing in Game View
oh wait give me a sec
Yes I have tried them all but didn't notice the difference
The only thing that I have noticed is that when I have it Locked I can't interact with my UI buttons and anything in the game view but when it's none I can
Locked: locks to center of screen
Confined: keeps cursor in the window
None: Isn't locked and isn't confined
So, when do I have to use those 3?
I mean when I want the cursor to be enabled then I am using none but when I want it to be disabled then locked?
I am going to test it right now
how do i move an object programatically
first thought was obj.transform.position.Set(...) but that doesnt seem t owork
scrap that im being stupid
transform.position = new Vector3
already fixed it
but it depends what you want, if you want physics you would not use that
my issue was that i was setting it to itself
hey all working on a top down rpg game and cant figure out why my tiles are like making weird black lines when i am moving.. is this my pc issue or something else?
pay attention to the pond and the top of one of the trees
its like making lines in between my tiles
also not sure why the fps dropped a little bit into the recording (sorry)
Locked to center of screen + hidden -> Doom, Skyrim, any fps game really
Constrained + visible -> Civilization V, Path of Exile (it's a toggle here)
None + either visibility -> Random indie game off itch where you accidentally keep clicking other apps
does setting position not affect children
ofc it does
it doesnt for me
n not sure what im fucking up
show setup
var old = map.gameObject.transform.position;
old.Set(old.x, old.y + 2, old.z);
debug code
doesnt seem like the map is moving
probably am missing something obvious but am too tired to tell
do you know what Set does?
You are modifying a struct in place
why are you using that
ah

modified structs don't do anything lol
im just doing what the holy editor tells me to do
which one? I dont think i ever seen Set being used on V3 lol
You can do this, just gotta assign it back to transform.position
vsc?
youcan do
var old = map.gameObject.transform.position;
old.y += 2;
theThing.position = old``` btw
yeh tryin to rn
Though you could just do transform.Translate(0, 2, 0, Space.World)
OH SO += WORKS BUT ASSIGNMENT DOESNT
Or transform.position += Vector2.up * 2
no nvm it doesnt lol
cannot modify the return value of 'Transform.position' because it is not a variable
you're modifying the copy not the property which is usually the error
ah im still doing it inplace nv,
so
var old = map.gameObject.transform.position;
old.y += 2;
map.gameObject.transform.position = old;
```?
its like trying to modify a method
yes but do you know why?
cause you're just changing the copy first
structs are copies
yeah i do
had to do the same stuff with transform matrices back on [cursed engine]
+= is assignment lol
obj.transform = obj.transform.Scale(1, 2)
yup thats just doing old.y = old.y + 2
Yeah a += b equals a = a + b
ermmm technically you can implement one and not the other htrough operator overloading 🤓
Can't overload operators on existing types though 🤓
+= still is assignment
it's literally called addition assignment
i cant, whos to say someone else didnt 
also, += can't be overloaded
can it not?
assignment operators can't be overloaded in general
there is slight difference ig.
reason+= events since they are immutable and cannot be assigned with =
well this engine is suddenly 90% better
this has nothing to do with the engine lol
I did recently see some C++ livestream where the programmer had to separately implement -=, += even after implementing + and -
(I think it was c++)
yup
newer versions at least added <=>
i personally steer clear of overloads in general, never results in anyhting clean
math stuff is typically already implemented for me
I don't think I ever needed to use them either
you dont
its pure syntactic sugar
same as properties
nothing you cant do with either of those that you cant through regular functions
i mean everything is just syntactic sugar for machine code
I mean if I had like structs that I need to + then I would implement it
give a non-math example
you never need to + stuff though, you could just Add
strings.
I didn't mention non-math
But yeah strings come to mind, its builtin tho
obfuscating that its secretly immutable array access also that stuff is builtin
for example, sets in c++ use < to compare values
so you can overload < to define a sorting for the set
java doesn't have operator overloads, and instead uses an interface, Comparable, to define a method, compareTo, used for the same purpose
stuff involving strings, not just string itself
for example, adding 2 stringbuilders together
that sounds like more builtin stuff
i guess you could argue for that in cpp land where everything is stapled on top of c
by "builtin" here do you mean builtin to the stdlib or to the language
but you already have "" as a core part of the lang here (i think)
but either way, you might make your own string-based stuff and want to concatenate them without having to do "" + first because that's more expensive
if you're worried about string operations being too slow you would probably also not want to abstract what you-strings are
i have no idea what you're trying to say there
use an array and make resizing explicit
no that's not what im talking about lol
thats the only means i can think to make strings more efficient
im not talking about making your own strings
hten what do u mean a string builder
i mean making stuff that's based on the concept of strings
that's a separate line of thought lol
json and such?
uhh no?
like for example you wanted to make format strings, new FormatString("This is a number: %-3d") or something
and internally it was parsed in the constructor, breaking the string up into a list of nodes
then you could overload + to combine format strings by extending the internal list instead of having to reparse a new format string
what i read was you might make your own string-based stuff and want to concatenate them without having to do "" + first because that's more expensive
reasoned tha tyou meant "make strings more efficient" and by extension "doing your own string stuff"
no lol
rip then lol
"" + might be unreasonably expensive for cases where you have an internal format that would easily make it more efficient
but like, the structure/overload doesn't have to specifically be for string efficiency
like in this case if you didn't overload + you would have to do, say, new FormatString("" + fs1 + fs2), reparsing the whole thing
so handling of FormatString("hi this is") + FormatString("bob") ?
yeah
ah
just to recap; you of course, don't need the overload, but given its contextual usage, an overload makes a lot of sense
Hey guys, i have this field in an SO. public Transform[] teleportTarget; im trying to assign an empty gameObject to it, but all of a sudden it says type mismatch. If i then click the field and press delete, i can assign the empty gameObject, but it's deleted automatically whenever i run the game. Has anyone experienced something similar? And sorry if im in the wrong channel!
You can't reference scene objects from an asset.
The resulting error is not very intuitive
alright so i have this script: https://hatebin.com/mnzewoicug
and the thing is, that it works perfectly (except moving camera up and down but i dont care about it right now)
but unity suggest me to use Quaternion.Euler instead of EulerRotation and when i use just Euler for some reason rotatating on left and right doesnt work anymore, i just want to understand why
did you read the warning message?
why not make the camera a child of the player so you don't have to manage the position and yaw separately
yeah but what does that mean
it uses radians instead of degrees
these are two different units
2pi radians is a full circle; 360 degrees is a full circle
Also, this entire thing is bogus
Quaternion.EulerRotation(player.transform.rotation.x, player.transform.rotation.y, player.transform.rotation.z);
rotation.x is not your x-axis rotation in degrees (or in radians, or in anything else)
It's the X component of a quaternion (which has four values -- X/Y/Z/W)
It might have happened to work in some situations
also you could just transform.rotation = player.transform.rotation;
yes, that's all you need to do to copy the player's rotation
but also with this you could just not have to copy it at all
really you'd need to copy the player's yaw only
ie, the rotation about the y axis
yeah, that's why i did on the beginning but i wanted to make that moving camera up and down works so i changed it to quaternion and it confused me
so transform.rotation = Quaternion.Euler(0, player.transform.eulerAngles.y, 0), i think?
(or just do this to have yaw done automatically)
This would work, yes
i assume unity doesnt have such functions as "get the initial position of an object/state of a variable"
? ,
var grabStartPosition = thing.transform.position
I wouldn't expect it to!
as in getting hte state of the variable you set in the editor/have defined in code
Serialized properties are applied to the object when it gets created
prior to pressing play? no i don't believe there's any mechanism to do so
never used a non-shit lang, explain
this isn't a C# thing
and it'd waste 2x the memory for something rarely used
drag a prefab into a text editor and you'll see a bunch of YAML
depending on the implementation
this is all of the serialized data for that object
no, it would not depend on the implementation
unity applies it during object creation
that did worked, thank you a lot. I just didnt understood the euler right
I guess you could look at the values on the prefab, if you're using prefabs
But Unity isn't going to hang on to the data it applied during object creation
if you designed a lang around lazyiniting vars adding initial() wouldnt be wasting memory
but thats besides th epoint which is why i tilda'd that comment
no that's not how any of it works lol
if you want to both have the current and a previous value, you have to store both of them. simple as that. if you don't want to store them in memory, it's gotta be in storage, and you have to pull that storage back into memory later anyways
is this still a continuation of array vs json?
no
no we just love arguing with eachother
i meant in that sort of lang adding initial() wouldnt be wasting any more memory
this seems irrelevant
...because you already waste it?
it is
yes
how is this a valid argument at all lmao
"the engine wouldn't waste it because the interpreter would be wasting it instead"
how is this a valid argument for validifying these for unity? its not lol
alright i have no idea what you're even saying anymore 😂
good
lets drop it
unity uses a sane language that doesn't use more memory than it needs to, and doesn't waste memory itself, so it doesn't have that feature
what is it with you trying to make ridiculous points that have absolutely no basis lmao
seems like you just irrationally dislike c#/unity and you're looking for any excuse to shit on it for stuff that it's doing right 😂
why are you even here lmfao
Thank you so fking much!
? ,
this convo isnt me shitting on unity
just asking if it has a feature im accustomed to
which i already assumed in advance it doesnt
to answer the original question: you generally record initial state in Awake or Start
Awake is appropriate if you want to grab the value immediately after object creation (literally before the Instantiate call returns)
what kind of shit language has this behavior lmao
one that makes all variables unalloc'd by default and retrieved from a prototype when accessed (so that stupids [which its trying to pander to] dont blow up their game by throwing a ton of variables on the base class)
but again
wildly off topi
c c
doesn't answer my question tho lol
what, this?
: 3
consider moving on
^ ^
im just curious what language has this behavior now lmao
since lemons can't bear to mention the name, im convinced they're just bs'ing at this point 😂
if you say so :3
it's not worth the argument that will occur from going further in the conversation
i mean, if i just got an answer to this, i'd be done with the topic, but well, look at how long it's gone
Consider moving on.
Lets say I have a tilemap like this, what are different method I could use in order to connect the different section dynamically in code?
I would want to make sure I am connecting sections that are within a certain distance of each other and support rigid (straight lines / 90 degree angles) and more organic looking corridors.
I'm confused by the example.
Is this six pre-defined spaces with a couple of obstacles in each one?
which you want to link together?
yea, I am trying to figure out how I could connect these currently disconnect area in a tilemap dynamically
Just think what you want it to do and break it down to simple tasks. Treat each island as single array collection.
Find nearest island.
Find closest tiles to each other.
Start creating tiles in the nearest direction from them.
Create more tiles around each to create a "bridge volume"
is there a way to detect a collision between two objects with BoxCollider2D components if I'm moving one of them via transform.Translate? or do I have to use a rigidbody and move it with that?
one of them needs to have a rigidbody to handle the physics
one of them does but it's not the one Im moving
doesn't specifically matter how they're moved, though moving via transform on a GO with a rigidbody could cause problems
then there shouldn't be any issues there
just gotta make sure they fix the collision matrix
these are the relevant components on the static and moving object respectively
a static rb doesn't itself trigger collisions
but OnCollisionEnter2D doesnt trigger when they overlap
you need a dynamic rb on one of the objects
oh I see
yup, now it works
ty
I dont really understand the purpose of a rigidbody on an object that never moves
yeah it might not really make sense to have that?
is the other object, without the rb, the player?
generally that's what's given the dynamic rb
then stuff like walls won't need rbs
sure that'd work yeah
the other objects are the level constraints (invisible walls)
I thought I needed the RB on them to make sure they physically block the player moving through them
you could then set a velocity on the rb, set low linear drag, and just, literally fire and forget lol
I was worried about performance when there's dozens of projectiles on screen at once I suppose
confirmed that that was never the case and I was just being silly oops
You put a rigidbody on something to tell the physics system that it's going to be moving around
pool them
even if you spawn and destroy these very rapidly, it's not going to be particularly bad
computers are really fast. don't worry too much about optimization at this stage, worry about it when it becomes a problem
as long as that area is not huge and there are not hundreds of them you probably are fine
Pooling is a good idea for when you have a very large number of projectiles, where the overhead of creating and destroying all of those objects gets noticeable
if you need an abundance of projectiles you should most likely pool them
fair enough. just trying to be a bit more diligent about efficiency tha I usually am lol
(you just recycle the same bullet objects)
aye, will look into that as well, ty
depends on the computer 
computers in general are fast
it really doesn't depend when the lower end of the scale is still in MHz
I mean anything even remotely measured in MHz does a silly amount of operations per second
i don't think anyone is gonna expect to run 3d games smoothly in kHz amounts of operations
this is a 2d game anyways
I'll make sure to report back and blame you specifically if it ever runs choppily 😌
a drop in the bucket of me blaming all the problems in my own game on myself lol
jokes aside, thanks for the help
more than anything this is an exercise for me to explore all these questions and discover best practices
You don't need rigidbody on a stationary object. But it you want to have something like moving platform it has to have one if you want for physics to interact properly. Because you would need to move it with Rigidbody2D.MovePosition.
to get a similar effect of using transform.Translate((some direction vector)) would I use Rigidbody2D.MovePosition(currentposition + direction vector)? or is there some neater way to do that?
wait this was already answered for my use case by this, wasnt it
yeah
I swear I can read
could use AddForce
even if you wanted to use translation, it would cause unreliable collisions when using a rigidbody
and then you would multiply a normalized direction vector by a given magnitude
there was a similar convo, it was either impulse or velocitychange
impulse would be mass-dependent, velocitychange would not
so it's much better to use one of the physics methods for it
gotcha. physics stuff seemed overkill for what Im trying to do because I dont have any gravity or anything like that acting on it, but I suppose it makes sense for collision detection purposes
if the mass of the bullet doesn't matter (and is set to 1) then both would have the same effect, but you might want to use the bullet mass for stuff like, recoil or knockback, idk
Yes, don't forget to use it in FixedUpdate as well
I've been wondering a lot about Update vs FixedUpdate
FixedUpdate is recommended for stuff that needs to happen at a consistent real time frame regardless of the framerate, is that the idea?
use any rigidbody/physics based methods in it as it produces better results
and FixedUpdate has a specified tick rate that it'll process physics stuff by
and is not framerate dependant
I remember learning to multiply stuff with time.deltatime way back in the day to account for framerate differences but this is discouraged for a bunch of reasons I take it?
you shouldn't do time.deltatime in rigidbody (i.e addforce) methods as it does it already but in general it's fine
gotcha
uh no not quite
Good rule of thumb if you are messing with physics components like rigibody. Run it on FixedUpdate and do Time.fixedDeltatime.
you don't need that either
50hz is the standard polling for FixedUpdate yeah? and presumably this should be sufficient even for fast paced 2d games?
well yes those methods do time.deltatime already no?
some stuff in rb methods are inherently time-dependent, so they do stuff basd on physics ticks
but not all of rb methods are time-dependent
all physics uses fixed physics generally i think
FixedUpdate is already using fixed frames you don't need to add delta
and this 
MovePosition, for example, just does the move in the next tick, so if you're using that as a replacement for transform.Translate, then you would add a time component to that
(or, i mean, you'd use MoveTowards.)
You would use Time.fixedDeltatime inside a coroutine that awaits fixed frames and you need to get that time frame, for example.
I ended up going with the velocity approach for the projectiles for now either way
assuming all the internal logic still happens on fixedupdate ticks but it is indeed nice to just "fire and forget"
rb.MovePosition(Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime));
well I was mainly talking about the addforce, velocity methods for example because moveposition is practically translation but complies with the rigidbodys interpolation for kinematic bodies right?
i mean, idk what you meant to talk about, since "rb methods" does encompass moveposition and friends
ah right, I should have been more specific
Hello everyone,
I start to create games and here’s my problem.
Every time I transfer my image and they cut them in 16x16 or 32x32 for example. I create my Palette then I insert and the images are small in the grid ( I'm french)
set the pixels per unit option in the asset importer
(not a code question)
not a code question. bu tyou need to adjust the pixels per unit in the texture import settings
I'm sorry
dang i was too slow lol
Have a nice night and thank you
hey yall how do i make code thats not a bunch of if statements
is it just practice and more knowledge?
also don't be scared of if statements. they are perfectly fine
^ h
you can research guard clauses if you want
thats a p easy way to deshittify your code
I was making the clone skill and it's showing me this error, and I don't understand why
and here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Clone_Skill : Skill
{
[SerializeField] private GameObject clonePrefab;
public void CreateClone(Transform _clonePosition)
{
GameObject newClone = Instantiate(clonePrefab);
newClone.GetComponent<Clone_Skill_Controller>().SetupClone(_clonePosition);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Clone_Skill_Controller : MonoBehaviour
{
public void SetupClone(Transform _newTransform)
{
transform.position = _newTransform.position;
}
}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class PlayerDashState : PlayerState
{
public PlayerDashState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
{
}
public override void Enter()
{
base.Enter();
SkillManager.instance.clone.CreateClone(player.transform);
stateTimer = player.dashDuration;
}
public override void Exit()
{
base.Exit();
player.SetVelocity(0, rb.velocity.y);
}
public override void Update()
{
base.Update();
if(!player.isGrounded() && player.IsWallDetected())
stateMachine.ChangeState(player.wallSlide);
player.SetVelocity(player.dashSpeed * player.dashDirection , 0);
if(stateTimer <= 0)
stateMachine.ChangeState(player.idleState);
}
}
Something on that line is null but you're trying to use it anyway
What line has the error
Debug.Log(shopRT.position.x);
im debugging my position in update just to check stuff and its not showing correctly to what it is in the inspector and i dont know why this is
it says my x position is -8.5
but in the inspector
its 33 for some reason
That's because position is your world-space position
The inspector is showing you a local-space position
This isn't anything specific to a RectTransform, mind you
you'd see similar things with a regular Transform
Your local-space position is where you are relative to your parent. If you have no parent, then it matches your world-space position
Ah, the other issue is that this is anchored to the left side of its parent
you could check if this is why by anchoring it to the center and setting Pos X to 0
I'd expect a local position of zero, then
I believe the inspector is showing you the anchored position
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/RectTransform-anchoredPosition.html
It's 33 units to the right of its anchor, but that's quite a few units to the left of the parent Transform
thank you that makes a lot of sense
Try this myb:
public class Clone_Skill : Skill
{
[SerializeField] private GameObject clonePrefab;
public void CreateClone(Transform _clonePosition)
{
GameObject newClone = Instantiate(clonePrefab);
Clone_Skill_Controller _controller = newClone.GetComponent<Clone_Skill_Controller>();
_controller.SetupClone(_clonePosition);
}
}