#💻┃code-beginner
1 messages · Page 463 of 1
learning from docs is fine for learning engines, but if you don't know how to code
then docs won't help with anything
I meant for learning code as well
guessing you didn't go the college route
this is someone that was asking why curly braces were included in their code. what makes you think they'd be able to decipher docs?
Rust, c#, python, all languages I know have written documentation, and that is the best way to learn
not for game dev, i'm finishing up my last year for CS though rn
might take a game dev course
They would know if they learned the basics from the written documentation microsoft put out
you provided the unity docs though
the unity docs don't give c# basics
What?
earlier you provided w3schools and the unity docs to that person
Yes, w3schools
w3schools is cool (although i've never found it helpful)
but the unity docs would be awful to parse through, no?
But even the docs would be good and easy to parse if they knew some basics by doing w3schools first
I HARD disagree with what you are claiming
did you learn your first language through docs?
Yes
That is what I am saying
10 years ago I used pythons own documentation to learn it. Then the pygame docs. Then microsofts documentation, then unity's documentation
how did you even understand the docs though. i feel like docs in and of themselves require some amount of knowledge of the language to understand
I peppered in sololearn and microsofts guide here and there
Because they are easy to understand if you are willing to put in any effort
If you don't understand a word, write it down. Then look it up. Then write down the definition next to it. Eventually you have a dictionary
Revisit and revise it as you learn
i learned my first language through experimentation with concepts that were shown in YT videos and then research, but i didn't even know what docs were until like 6 months in
i guess it's just a foreign concept to me that one can be self-taught entirely off of docs
youtube didn't always exist, books was the main way to learn
Youtube is just... such a bad way to learn. People do it, but they don't learn to learn at the same time, so it hinders their education
Learning how to read docs is so important. And learning FROM the docs teaches you that alongside whatever else you are learning
Also learning from books helps learn to learn as well
yeah but books aren't docs, at least books are presented in a readable format. then again, i've never accessed "beginner" docs, i only use the API reference
a major problem with yuotube is anyone can make a video, even bad ones
so i wouldn't know
Can anyone help me approach this task
I have a unity dropdown with around 40 items
is there a way I can a add a search bar to the dropdown?
to make a searchable dropdown?
thats a non-trivial custom-dropdown-widget implementation, certainly possible.
Thanks,
Can you please elaborate on how can I implement it
any specific approach? method?
thats too much to explain for a chat. You can look at the input field and dropdown implementation and combine them
any documetation/tutorial I can refer to?
no
just the code itself
stuff like this typically has a lot of edge-cases you need to handle, so you can't easily compose it from existing components.
Pretty sure UI-Extensions have an impl for it
it doesn't
thanks
Hey all good evening. I am having real hard time understanding things right now. I have a parent empty called Handle which is just a pivot for my door child object. On the handle I have this script https://hatebin.com/wzssvlswri. The save method works fine as I can see both the door rotation and handle rotation on my save file. I move the door on interaction with activating its animation. My problem is that when I load back. I expect my door to be open but it does not seem to read the values and put them back on my door.
These are the saved values
Well I guess people are not online. I'll try tomorrow.
so it saves them but doesnt load them?
Yes
where do you load the data
The load gets called on my other objects just fine
The ones that implement the interface that is
put a debug.log here which will tell you if it loads, and then log the VALUES that you are trying to load
okay I will do it now
they are either the wrong values so the save is wrong.
they are the correct values so you are applying them wrong / they are being overwritten.
or something that idk 😂
i would store them, log them, then apply them after
and if thats all correct
then you are probably overwritting it somewhere else by mistake
also make sure you log the object that you are applying it too
log everything that you need to log pretty much
I am reloading the scene to see if it works maybe there
but again my other objects are where I leave them
There is probably something I dont get with Parent Child relation maybe
Im being drivin up a wall with a bug in my game, hopefully someone here can give me an idea of whats causing the issue ><
whats happening
uhh im trying to remember the site to send code
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
but tldr when my player is in a trigger box, and they get teleported, the game still thinks they are in the box
so something like perhaps your using a rigidbody but move it by transform.position and need to update the rb's position?
ah using a CC, i think same thing applies
i have been self teaching through gpt >< im still extremely new
need to move the actual character controller too
ill try to see if i cant get it to work based off whatcha just said
ah looking at docs and google you might need to disable it and enable it before and after you change the position
oh wait you already do that huh 🤔
im stumped >< but ive also been working on this game for 22 straight hours now lol, if anyone has any ideas, ping me and ill troubleshoot tomorrow. I really need some shut eye.
here is my trigger box lightswitch script if it helps, i figured it might not be updating every tick to check if the player is still inside or something :/
anyone know how to make it so there is a script on object awake that changes the transparency of this shader from transparent to opaque? I got the first part down, but it only works on default URP materials. Idk how to make it change basecolor transparency on this shader.
nvm fixed it, reference in the shaader was wrong
wat game u tryna make?
since ur in gtag discord, prolly a gtag fangame
just swap materials
why dont the unity tutorials actually teach me how to script...
they gave me something to copy and paste instead...
because your following wrong tutorials probably.
probably just one thats telling you exactly how to do something
the best way of learning is just doing it yourself
i literally just started tho, i have no idea how to do it
for example if you wanna make a 2d top down.
you would need something for collision, something to move it around, then find out how to move it around, how to take input, etc.
you can find all of this on the Unity Docs for basic methods, then you can combine them to make an actual script
i think its much better to just look at the docs and try figuring out something yourself
okay
and before you do that you can follow 1 or 2 tutorials just to get a feel for Unity and how to navigate some basic things.
or you can do that yourself up to you
chat im starting to get the feeling that my ai is not evolving (someone pls help me i dont know why its not working)
in unity learning should I finish unity essentials or immediately move onto the vr one?
finish essentials?
thanks, now i can wait 5 days to get help instead of 5 hours 😀 /s
or, more likely, you'll actually get a response at some point instead of your question going completely ignored because ML Agents is not something the typical unity user has any experience with so a channel dedicated to AI tools such as ML Agents where people who have experience with that stuff hang out is a better place for that
You may want to actually provide information on your implementation as well. Your question is impossible to answer otherwise.
i was waiting if anyone wanted to help me and see my code before i uploaded the file
im not using ml agents, i would rather die than use ml agents i hand coded my ai
if you had bothered providing any useful information then maybe someone would have known that 🤷♂️
Baiting people actually makes people less likely to help. We require people to actually ask questions in entirety.
well can someone help me?
Finish essentials, THEN finish junior programmer, THEN finish common core, then make a game or two, THEN move onto vr
if someone knows, then someone will help
real quick.. if i instantiate an object within a trigger will its OnEnter get fired?
Nope
hm, what would be a smart alternative?
Probably just overlapsphere or use ontriggerstay
bet 👍 ill check out both
not sure if it'd be better to change which object detects what at this point
Not sure, depends on what it's for. If it's something like explosion radius detection, then you wouldn't use a spawned object at all.
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("IncomingProjectile"))
{
FuturePosition futurePosition = other.GetComponent<FuturePosition>();
if (futurePosition != null)
{
Transform specialMarker = futurePosition.GetSpecialMarker();
turretController.ActivateTurret(specialMarker);
}
}
}```
the turret has a big sphere so. when a projectile enters it gets activated.
but theres at times when the projectile may spawn within it.. but i guess that'd be a no-go for detecting it
I would overlapsphere (use the nonalloc method) this for sure.
It's just predefining the size of the array that will store the things it finds
So you're not making a new array each time
You will have to handle the nulls in it though, but that's simple enough
predictive projectiles and the rotation logic was hard af
now this.. (technically i need a collection of all projectiles within the dome)
remember to commit
and it'll focus on 1 until a hit is made.. and then switch to the next asap
Just in order of how they enter the area?
like this? or like send it?
i guess closests would be priority
nonono do not send it, like actually commit git changes
dont be losing projects now
but yes, first.. wait how would i incorporate both?
i dont want that on my hands 😅
lol.. first and then closest.. 🤔
You have to define that. Do you want closest always, or closest when not actively targeting something else?
Or is that something the player can toggle?
the player only has control of when to fire atm.. but im still brainstorming.. its leaning towards an autonomous passive system
Or technically, you'd probably want the one that is last to enter so that it has the longest amount of time to take it down

right now the projectile has to also find the turret.. so it can get the distance and do the math for projection distance
which is a mess.. its actually just a serialized private var atm.. it was outgrowing while i was building
That does seem backwards. The turret should be handling all of that in it's target aquisition logic.
yea.. its broken
the TurretRange finds the "IncomingProjectile" -> gives it to the TurretController to get its projected position
but the IncomingProjectile has to know the turret so it can do its distance/math
Why does the projectile need to know the distance?
it shouldnt but it does.. im workin on that right now lol
the overlapshere solves that too
Turret:
- Overlapsphere to grab all projectiles in range
- Find the cloest one by getting the
ProjectedPositionproperty off them and calculating the distance
It's really should be that simple.
so it knows how many seconds in front of its velocity to project the target
the thing the turret actually aims at to hit its mark
Then the turret can do that math, it doesn't need to be the projectile
ya. i agee it can be done there..
The turret gets the projectile and its velocity and calculates where it's going to be in the future
Makes more sense to me
Making the projectile calculate that seems to needlessly complicate things. Unless I'm misunderstanding something
ya it does now to me as well, while i was trying to build this.. for the past day and a half.. quaternions for the turret.. and the trig stuff got my brain melted lol
ur not.. it was also a learning experiment..
I can relate
you tryna make a CIWS?
I’m trying to make a mobile game I need help and a lot of it do you guys know were I should look
you can ask for help here for specific things, otherwise look at youtube and stuff for tutorials?
basically
I have been looking for hours and not one thing was about a mobile game that is 3d
they'll get more futuristic/plasma like before im finish
look for more specific things, no one will tell you how to make a whole game apart from a Paid Course usually
Do you know where I could find a paid course 😂
Just figure out how to make a game. Then do research on how to make it in the platform you desire (mobile).
I’m fine with paying
Udemy is the only one i know
Alright so just watch a bunch of tutorials
I have no idea what's going on here but if it's what you intended, good work!
Udemy, for instance
And also should I start trying to make a game that is the game I want to make in the long run or just make random games until I feel confident to make it
sounds like you dont really wanna learn but just push out a mobile game with ads to make money to be honest
I’m really really new to this stuff💀
I do not wanna make money I just want to make a game and don’t know where to start
Bucko
Truly HUNDREDS of successful game developers have posted long in-depth videos answering this exact quetsion.
start with just pc, why need mobile?
usually the best way is just make a Platformer, follow a tutorial or 2 then try doing it your self.
you can also make stuff like Flappy Bird / Clicker Games, basic thiings
I don't know, but I've seen experienced devs say to dont try to make your dream game on the first one. Make a few simple games first to get experience. I'm not an experienced dev though
for a beginner i would not do anything complicated
it will only break you and make you quit
trust me
i know
Alright thank you all for helping today is literally my first day
So just to sum up what you all said is to just slowly learn until I get good
you can learn fast or slow depending on how fast you learn, but take it easy and dont do anything to hard
when you learn unitys quirks (and general coding knowledge) then you can do something big
yeah, start with some basic tutorials then a few basic games then try making something bit more difficult on your own
not to say making a mobile game is difficult in your first few weeks, it absolutely is doable
but its better to not start with that AT FIRST
if you dont want to pay for a course i suggest !learn ing the basics of unity
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Do you know like how to connect the game to your phone or is their like a tutorial I can follow to do that
you can build it, or theres literally a Unity app which im not sure if that works still in 2024?
or theres probably some other way to mirror it also that i dont know
and the main thing is do you have android or iphone?
iPhone is that a problem
Hey I ain’t here for the easy work
and also if you wanna publish games its much easier on google play store
Alright good to know
you need a website and stuff, also costs TONS more money like £100 a year or something not sure.
google play store iis just a one time £25 i think
Is that like 50 dollars in us?
and if you wanna just play it yourself, then thats also pretty much only doable with like mirroring i think
nah like $120 😂
Just convert it and see . . .
Dam 😂 yea all I know about coding is nothing really 💀
^ its called GBP
It’s easier to ask
its not but alright
Hey I ain’t here for the easy work
💀
I am when I am able to 😂
litterally search up "currency converter" in google
Btw, to answer your original question, unity remote is still available both for Android and iOS I think. Though, it doesn't really run the game on your phone. It just forwards the output to the phone screen and input to the editor.
So if you want a proper test, you'll need to build.@twin wagon
thats extra work. just search up a to b lol comes up instantly
debatable
Build what?
Sorry I’m a bit slow
Build a build of your project
Probably shouldn't worry about it until you !learn the basics.
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Alright thanks
In case you missed it, typing !learn will give you a link to a lot of good tutorials.
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I am writing an automatic map-creation script, and I have a terrain that I am reading the alphamaps from and associating each location with a pixel in a texture I am creating. however, the alphamaps I am getting appear to be essentially random noise - am I getting the right thing?
here I cache the alphamaps in a float[,,] array CachedTerrainAlphamapData
CachedTerrainAlphamapData = terrain.terrainData.GetAlphamaps(0, 0, terrainwidth, terrainheight);
print("Terrain Length: " + CachedTerrainAlphamapData.GetLength(0)); // 1000 - length in inspector
print("Terrain Width: " + CachedTerrainAlphamapData.GetLength(1)); // 1000 - width in inspector
print("Number of Terrain Layers: " + CachedTerrainAlphamapData.GetLength(2)); // 8 - number of layers
int index = 0;
// find the most dominant texture index
for (int x = 0; x < CachedTerrainAlphamapData.GetLength(1); x++)
{
for (int y = 0; y < CachedTerrainAlphamapData.GetLength(0); y++)
{
int layer = GetMostDominantTextureIndexAtLocation(x, y);
MapColor[index] = colors[layer];
index++;
}
}```
And then I grab the dominant texture here index:
``` int GetMostDominantTextureIndexAtLocation( int x, int y )
{
int mostDominantTextureIndex = 0;
float greatestTextureWeight = float.MinValue;
for (int index = 0; index < CachedTerrainAlphamapData.GetLength(2); index++)
{
float textureWeight = CachedTerrainAlphamapData[y, x, index];
if (textureWeight > greatestTextureWeight)
{
greatestTextureWeight = textureWeight;
mostDominantTextureIndex = index;
}
}
return mostDominantTextureIndex;
}```
I have to swap the X and Y around because the alphamaps are funky in their ordering, but even if I swap em all around, it shouldn't create the even noise pattern shown here. One of my tests had 8 terrain layers, of which only 2 were used, and I was seeing values of 0, 1, 2, and 3 where 2 and 3 weren't actually painted anywhere
It seems like the problem MUST be in my most dominant texture at location function, but I can't see how I'm doing it wrong at all
Test with a simpler setup and step through the code.
Btw, where do you assign the colors array?
earlier in the flow - that being said, the colors themselves are totally working - the noise in pic 1 is a blend of color 0 and 1 that do indeed match visually to the only two terrain layers I have
I also overrode every pixel with colors[0] and it turned completely brown, no noise variation at all, so the problem isn't texture filters or something being blended visually - it's a sharp brown square
turning on debugging mode atm, so we shall see what's up
Thanks
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
alrighty. the texture weight at cell 0,0 is apparently 3.8322425E-29 which makes me think this is a rounding problem
adding a math.round to 2 places makes the noise much less pronounced
Floating point error
gross that it's a floating point error from GetAlphamaps though
that's unity's code 😦
That's to be expected. No code is immune to floating point error as long as it's using floating point numbers.
fair enough
It is kinda implicit to how computers function. You are storing an infinite amount of numbers in a finite amount of bits
If your dealing with a fixed range, try to always use uint, you get more precision. There’s probably a render texture data format that’s like this, but worse come to worst, you can store it as a buffer.
unfortunately the data comes out of the terrain as a float
Did you try rounding it to MORE than 2 digits?
I have not, trying that now
Not sure where to put this or what to google for this but every time i scope to a specific folder it resets on solution and/or project reload. Is there a way to permanently scope to a specific solution and/or permanently hide unwanted solutions from appearing here?
Hey peoples.. sorry if this is a bad question... but if I have two game objects and both have colliders and at least one has a rigid body they should interact right?
my next plan is to try to display the alphamaps themselves to see if something I am doing is just really wrong
What do you mean interact?
Your gonna need more context
They should collide even without the rigidbody
Physics messages require it though
They won’t move without a rigidbody
They have scripts to destroy each other when the colliders enter each other
OnTriggerEnter or OnCollisionEnter?
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
offtopic for the actual question i guess but without a rigid-body on either object how could you actually get them to collide?
yeah all those rules are checked
The Three Commandments of OnCollisionEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt not tick
isTriggeron either of them - Thou Shalt have a 3D Rigidbody on at least one of them
OnCollisionEnter?
What is the question mark for?
You have to manually move them without rigid bodies
@summer stump you forgot the forth commandment that the layer on both objects are an approved collision in the projects collision matrix
Colliders collide, a rigidbody is not relevant for that
I copied your text
I did not make those
The rigidbody is for movement. The collider provides the collision detection . . .
Well which are you using?.......
no but i mean without a rigidbody involved how could you even practically do that? how would force be applied to either object without just "teleporting" an object via position updating?
You mean collision resolution right?
OnCollisionEnter
Ok, make sure isTrigger IS NOT selected then
Teleporting will still collide. Even transform.position = will collide. Just not super reliably
But there is also the CharacterController
on both or at least one? I'm 99% certain it was working when both on istrigger checked.
Neither
OnCollisionEnter will never work if one of the two is a trigger
You can drag one GameObject into the other and see the collision. Though translating a GameObject by manipulating its Transform is incorrect, you will still receive a collision, albeit a weird one . . .
So you remember wrong. You likely were using OnTriggerEnter
Regenerate project files with all the check boxes unticked.
no idea why this isnt working but i have a script that starts a sound when you die can anyone help?
oh sorry its onTriggerEnter
Ok.... well show the inspectors of both objects
I won't get intellisense on those solutions if I do that, no? I wanna use the packages I just want a cleaner solution explorer
Wait he probably means collision resolution. Like, you can’t apply forces to get movement without a rigidbody, so you can’t get two objects to collide without physically changing their position
You do get intellisnese. This is unrelated. You just don't get unrelated solutions/projects.
Set collision mode to continuous. Then show the script
That collider on the second object is tiny it looks like
hm alright lemme peep that, ty chef
Collision Detection?
Might need to delete all the .sln and .prj files manually, as I'm not sure whether unity would delete all of them correctly.
Also, do you actually move WITH the rigidbody?
That’s what I’m asking, are you just detecting collision or do you want one to also resolve the collision
Where are you calling this method? Also, you're using Force incorrectly. This version must be applied every frame. You probably want to use ForceMode.Impulse . . .
What script is this? It is on the object NOT tagged Farmer, right?
sorry.. when did you ask me something? I've been replying to Aethenosity
correct
I have no idea what they are saying honestly. Very confused about all their responses
perfect ty @teal viper, i've tried that before but had some problem that must have been unrelated. on some bigger projects i get a suprisingly notable performance drop in VS with so many solutions loaded
I know it's not called every frame but you're using the default ForceMode which works correctly when applied every frame in an Update loop. It only works because you're using an insanely high value . . .
Ok, then 1, are you moving with the rigidbody?
2, put a debug.log BEFORE the tag check in OnTriggerEnter, see if that triggers
You didn't answer the first part of my response. Where is the method called?
Sorry I’m kinda lost as well, your original question was whether you needed rigidbodies to “interact”, so I was wondering whether you just wanted collision detection or resolution
They want the code in OnTriggerEnter to execute
Interact mean physics messages being sent
its called in another function which is called from an if statement in update
So just detection, then you don’t need a rigidbody
Absolutely incorrect
Why?
What do you mean by moving with the rigid body? The game object is moving via script the ridgid body is just for the OnTriggerEnter
OnTrigger requires a dynamic rigidbody on one of the objects, or PhysX will not send the message
It will be sent to both objects involved though, even one without an rb
Is that not the purpose of a collider to detect collision?
Did you place a log inside the method to ensure it runs?
bro i told u i fixed it mg
Like rb.velocity = or rb.AddForce or rb.MovePosition
both of the issues
Instead of transform.Translate or transform.position =
oh of course thanks... its not being moved with physics.. its script controlled
I thought you meant the force part. You didn't clarify . . .
i did tho check it
Well, everything I wrote is "script controlled"
@pulsar forum and @foggy saffron
Should have sent this earlier, but this goes into depth on every need for physics messages
https://unity.huh.how/physics-messages
I stand corrected, I’m pretty sure you can still do it with a bunch of raycasts or spherecasts
Yeah Im just confused because I have GameObjects that are interacting just find one has Rigidbody and one without and they are both checked for Is Trigger
Yes, physics queries do not require a rigidbody.
Those of course will not return OnTrigger or OnCollision messages. But they return RaycastHit or the array you pass depending on the query
Just show the movement code
And did you do the debug as I said?
#💻┃code-beginner message
not yet trying to keep up with this.. one sec
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
Ok yep, transform.Translate, PLUS the tiny collider leads me to suspect you are just teleporting right over it
Perhaps, yes
looking at it now and they are big enough to cross through each other
Generally if you have a rigidbody, you should move with it
Is the transform scale huge on the one not a farmer, bwcause you set the collider size to like .19
yeah no its small but they pass through. I'll get a screen
I mean, you are still moving with the transform though. Which is a problem
If you have a rigidbody, use it
You should pretty much NEVER move a player with transform imo
update on this: my problem was I was iterating over the terraindata.size.x and y, and I should have been using splatmapwidth and splatmapheight
I only have a rigidbody for the trigger should I use OnCollisionEnter instead so I don't need the Rigidbody?
OnCollisionEnter requires a rigidbody
just using it for a very basic project
Not sure why that matters
Rigidbody movement is quite simple
You said OnTriggerEnter requires it and OnCollisionEnter does not..
I never once said that
If someone else did, they were wrong
oh no you said they both need it
Have you done the debug.log. we may be chasing the wrong issue 🤷♂️
That log is absolutly crucial knowledge
I'm trying to make a flashlight follow where you're looking on a delay, and with a maximum "drift" from the center, but I can't figure it out
something about trying to get the motion of the camera's rotation maybe? im not really sure
damnit.. sorry one sec ..
A tool for sharing your source code with the world!
like that?
also is there a way to turn off gizmos without turning off debug rays its very annoying
Yeah, looks good
There is an arrow next to the gizmos icon. You can select which gizmos you want on or off
I dont want to manually unselect all of them and then manually reselect all of them once im done looking at a debug ray
I just want the ray to not turn off when gizmos are
Then no afaik
its working Looks like I'm getting a NullReference for the line 31 thats not being used atm
oh right, I've been through this before and I can't even turn the ones for lights and particle effects off at all
Man, the paste site you sent kinda sucks haha. What is line 31? scoreCounter? Hitting that nullref halts execution
So that is the problem. Absolutely nothing wrong with OnTriggerEnter or the interaction
whats a good one to use?
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
so I just can't turn these off?
gizmos , yes you can
You can, in the way I told you.
This is not a code question btw
#💻┃unity-talk
I unchecked all the boxes I can see. I ended up just making them really small
You didn't have to resend the code. A simple yes would have worked.
As I said scoreCounter is null. The nullref halts execution of code
That is it 🤷♂️
it shouldn't be anything that would mess up the OnTriggerEnter
Not sure. Ask in the right channel
It is...
oohh
I didn't realize that was killing the code
Ah
Errors should also NEVER be ignored. Even in other scripts or something
If you want to ignore them, the only "safe" way is to comment out the code causing them (or delete of course, or put behind a nullcheck condition in this case)
yeah of course.. that makes sense.. I just didn't realize that was killing the code like that.. and I didn't think to try at least commenting out that line to see what would happen
No worries. This is a good learning opportunity
No problem at all. Best of luck with everything
now I just gotta tackle the other shit I broke when I tried to organize this thing
can someone help me with this, the sfx isnt playing
I got this issue and im pretty confused about this namespace error.
Do you have no error underlines in VS?
i dont
!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 you're doing it every frame might be issue
its when you die
put debug, check if its running first
After it's configured properly go through this: https://unity.huh.how/compiler-errors/cs0246
maybe its muted in game window?
I have a list of issues you can go through that cover the ways audio might be silenced: https://unity.huh.how/audio/silence/muted-audio
Debug.Log(as.IsPlaying) after it, take screenshot of console
My visual studio and unity is all up to date. I don't know why it might not be showing me the errors.
There's more things than "up to date" that you need to configure
show your audiosource settings
is the object enabled?
nvm i think it would throw warning
try putting another audiosource on a new object and leave loop and play on awake on, see if you hear anything at all
Hi there, not sure if this is the right place to ask, I have a pretty basic level here, just a cube moving forward on a flat plane dodging some obstacles, but I've noticed that very shortly after beginning and moving a bit left and right using AddForce(-sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); (opposite of this for the right movement), my cube seems to slightly rotate, I've thought about adding a constraint on rotation, but then hitting objects wouldn't give me the same physics result that I want, having a proper collision.
Not really a coding issue, just looking for ideas on how to keep my rotation while being able to still rotate on collision.
Oh I restarted unity and visual studio and the error went away. There was no problem in my code or anything idk why it did that.
First off, never use deltaTime in your AddForce calculation like that. And make sure you're only adding forces in FixedUpdate not Update.
As for the rotation yes you'd either add a constraint or reduce friction with a physics material
is there a reason not to use deltaTime as I did? and yes it is in FixedUpdate.
that's the weird part about the rotation, I have 0 friction, really unsure what makes it spin
In this particular case(fixed update) the only downside of multiplying by delta time is that it's confusing you(or whoever reads it) and makes you adjust the value of the force to compensate the multiplier.
In fixed update delta time is basically a constant, so you're just multiplying your force by something like 0.02 every time.
Now if it was in update, that would be a problem, because then you'd make it frame rate dependent, as the delta time in update changes based on the frame time. So you would have different force applied every frame. However, due to the way unity physics works, the force is actually applied at fixed intervals. So basically you're introducing a variability into these fixed intervals.
As for the rotation, it could be that the cube is colliding with the ground ever so slightly at different points, which applies torque to the body.
Using deltaTime here WITH VelocityChange just makes this equivalent to ForceMode.Acceleration in this context. so you might as well get rid of deltaTime and just use ForceMode.Acceleration
ok this one has been confusing me for a while when using this script https://hatebin.com/bomtpcothv on the highlighted prefab how do I get the scorecounter on the prefab? am I needing to drag the script on the open prefab to save it there before its called?
it works because im using FindObjectOfType but that's not how I want to make it work right?
I see, was unaware of this, began yesterday so this is great help.
For the rotation I ended up adding a constraint up until collision point, after which it also applies an explosion force to enhance the dramatic effect that I desire.
Thank you PraetorBlue and dlich for the help.
Hello whats the best network tool for a first multiplayer project ?
I saw a lot of option like Miror, Photon...
I just want to make a 1v1 FPS game with LocalHost
Set the references from the script in the scene that spawns it.
Photon's newer products come with a lot of solutions useful for high quality FPS networking. Better ask in #archived-networking if you want more opinions.
Would like to bump this, good morning fellas
is this AI code or something?
Also what about this is "game still thinks they are in the box". The game thinks nothing here, no values are being saved and this method would just run once when touching the trigger and thats all. Whats actually happening thats not supposed to happen
does anyone know what the "PPtr cast failed when dereferencing! Casting from GameObject to Transform!" is about i cant seem to locate what needs to be fixed
can you post the actual error with the stack trace?
Yes it’s ai code, if my player is teleported while inside a different trigger box, the player can still interact with the trigger box (which is a light switch right now as per the second photo and code)
The second code isn’t ai and was built by a prof of mine
Which is why I thought the first would be the issue
dont use AI, the code is bad and you dont even really know what its doing.
Start debugging as to why you can still interact because that first script has literally nothing to do with interacting.
Honestly not even sure what you're trying to do with that 2nd script either
this?
The second script is just on a trigger box next to a light switch that when the player is in allows them to press e to start the light switch animation, and play an audio of a switch being turned on/off
When the trigger box with teleportation is attached to a monster, that paths into the player next to a light switch, the player does teleport but can now activate the light switch from anywhere on the map
Because the player never “onexits”
Or at least it’s not picking up that the player is no longer there, the value only saves once, if the player teleports again, the new location is saved and the bug gets fixed
so you wrote neither script?
Correct
add debugs to see whats specifically happening. You really arent gonna get much help with AI code that you dont understand yourself
I’ve been working with ai for 8 months and have an almost completely polished game, just a few small bugs such as this one remain, this is the way I’ve chosen to learn to code as being in a classroom setting with deadlines does not work for me
interesting way to "learn"
I understand quite a bit of the code that’s given to me at this point, it’s been painful but I have a lot of trail and error experience
turn in your programmer badge on the way out
then ask AI to tell you how to debug. you really arent gonna get much help with that code #📖┃code-of-conduct
especially since you have 0 debug logs in your code
I have tried using debug logs but knowing that onexit isn’t called doesn’t help me understand why it isn’t being called
Thanks, didn’t ask for an opinion on if ai code was bad or not. I’ll take my autism badge and wear it proudly.
Ai is a very valuable tool, if you don’t like it, don’t use it. But don’t call other people stupid for trying.
did you even read the code it gave you?
You cant call it a valuable tool when its filled with bugs you dont understand
your going to need a bigger toolbelt, one with debugging skills in it if relying on AI
< this is the last big remaining in my hour+ long game that has been in development for 6+ months, I wouldn’t be reaching out if I believed that ai could fix this particular problem
this is likely part of the issue from your useful AI code
// Disable the collider temporarily to force the OnExit event
playerCollider.enabled = false;
Hmm I believe that was added to try to remedy the bug and I had forgot to take it out before posting here
Because onexit was never being called I think..?
I’ll throw some debug logs in and come back with a more solid question
again, read the code you're actually using. AI doesnt know how to code. Its generating the most likely text to make you happy, and you've fallen for it. The comments are complete bullshit
its really clear you didnt even read the code. Look at these 2 lines
private void OnTriggerEnter(Collider other)
and later on
Collider playerCollider = other.GetComponent<Collider>();
Also part of the issue could be if you dont have a rigidbody (kinematic) on the character
I really appreciate the info, I’ll see if I can make it work based on that. Sorry if I was getting a bit heated.
yeah i do have rigidbody, using unitys FPC, ill look into the rest though
but i mean i did read the code, it looks good to my eyeballs... maybe? "if collider enters trigger, execute" for the first line right?
bah nvm lol ill look into it XD
working now, thanks
Not sure where to post this but i am having issues with my unity hub,some tabs being opened and closes looks strange like this
same thing happens for unity 6
What is 'strange' about this, I see nothing unusual
or am i the only one seeing this issue on my monitor?
I see it on your screenshot, but this is more likely to be a hardware or OS issue rather than a Unity one
Ah crap i was hoping it wouldent be the case thx
it may even be a monitor issue, can you try to use a different one?
i have a second one let me check
happens on 2nd one as well
did you restart pc at all? if not try that
did
Wonder if this could be a nvidia driver issue
did you check your windows event logs to see if any problems are being reported?
let me check quickly
definitely could be
yea nothing in event logs out of the ordinary
It was the latest nvidia game ready driver,tried the studio version of it and problem solved
excellent
Hey all. I'll post it again since it was late yesterday. I have this handle empty object parented to my door acting as pivot point. I play the open and close animation on interact. I am trying to save the handle's rotation on y. It gets saved to the file correct. Also logging the saved rotation seems correct. When I load however, It does not put the values back on the handle parent object, which is just the rotation.The script that is responsible for holding the empty's rotation data is on the child object. https://hatebin.com/rtsqhholku
Also the Load and Save methods gets called just fine if that matters.
Okay I had to disable the animator...
nice good you got it fixed.
like i said yesterday "something is probably overwritting it" 😄 , thats usually the error when something expected doesnt work
yeah you were right but I never thought animator would be the issue...
Thanks a lot for yesterday also. Was so sleepy and frustrated I went to bed 😄
yeah its probably stuck at the "idle" animation or something
which would make the rotation 0,0,0
Yeah now that you said it. It makes sense damn
I had an idle animation T_T
yeah fresh mind helps a lot.
i couldnt think of a specific reason yesterday, i just knew the general problem 😂
working too long on a project at once or late into the night isnt always so good
Haha yeah you're right. Thanks again!
Hello i want make a slow falling effect for my game (like in minecraft) someone know how i cant do it ?
3D game? You could add an upwards force to your rigidbody to counter the gravity.
Drag might give the effect you want too
Hey everyone.
I've recently built a player controller for my 2D game that lets the player move in 8 directions. It works well overall, but there's an issue when moving diagonally. For instance, if I'm moving southeast by pressing S and D, and then release the keys, the character goes into an idle animation. However, the character often ends up facing east or south instead of southeast. This probably happens because I don't release both keys at the same time. Any ideas on how to fix this? Perhaps a small delay might help, but I'm not sure how to implement it.
Thanks in advance for any advice!
Linear drag slows you down in every direction, yeah. So it might not be what you want
oh
Yes it simulates the friction of air over the rigidbody. Like with real life physics, drag increases exponentially the faster you go, the more drag you get
and i cant do it with only the Y axis ?
Nah drag is applied on the whole velocity at once. If you want the effect like the "slow falling" potion, apply upwards force only
how can i change asset pixel per unit programatically ? i try GetComponent<UnityEngine.U2D.PixelPerfectCamera>().assetsPPU = 300; but that dosnt work i got this error:
CompleteCameraController.LateUpdate () (at Assets/Scripts/cameraController.cs:28)```
This does work. You just get a NullReferenceException.
which is telling you that you are looking on the wrong object
There is no PixelPerfectCamera found
but i have a pixel perfect camera in my camera
You, probably, don't
screenshot inspector
so why use GetComponent when you can directly reference?
Why directly reference if it's on the same object?
GetComponent is correct, I'm just not sure why you do this in LateUpdate
I've checked assetsPPU and its setter does not throw any errors
Please, show the full code
that is exactly why you directly reference, because it is on the same object,
using System.Collections;
using UnityEngine.InputSystem;
public class CompleteCameraController : MonoBehaviour {
public GameObject player;
public Control control;
private Vector3 Origin;
private Vector3 Difference;
private Vector3 ResetCamera;
private bool drag = false;
private Vector3 offset;
// Initialisation
void Start ()
{
ResetCamera = Camera.main.transform.position;
offset = transform.position - player.transform.position;
}
private void LateUpdate()
{
if (control.gameStarted)
{
GetComponent<UnityEngine.U2D.PixelPerfectCamera>().assetsPPU = 300;
transform.position = player.transform.position + offset;
}
else
{
GetComponent<UnityEngine.U2D.PixelPerfectCamera>().assetsPPU = 150;
if (Input.GetMouseButton(1))
{
Difference = (Camera.main.ScreenToWorldPoint(Input.mousePosition)) - Camera.main.transform.position;
if(drag == false)
{
drag = true;
Origin = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
}
else
{
drag = false;
}
if (drag)
{
Camera.main.transform.position = Origin - Difference;
}
if (Input.GetMouseButton(2))
Camera.main.transform.position = ResetCamera;
}
}
}```
By directly reference, do you mean variable serialization?
Where is the 28th line?
transform.position = player.transform.position + offset; here
What does it have to do with PixelPerfectCamera?
just follow my player
There is no player?
there is ?
Debug it
public GameObject player;
Debug it
that work if i remove the GetComponent<UnityEngine.U2D.PixelPerfectCamera>().assetsPPU = 300;
that not a problem with player
Why do you have 300 pixels per unit, despite having 320x180 resolution
ok that work i make it in a other way
just put a [serialized field] pixerlPerfectCamera variable
ty for help so
I have a dropdown with long options, is there a way I can avoid options from overlapping like this
Please, show the dropdown along with its options
some options are long like "transformer room"
You have to either decrease the text's size or increase the dropdown's width to match the text's length
Unity tells me I'm creating a stack overflow, but idek what that means, can someone tell me what's wrong about this? According to my Debug Logs the error is at line 94.\
Oh yeah line 94 is the first line in the function
Or float
file >> build settings add your scene here
Ohhh nevermind it's because I accesesd the DeathTimer within the DeathTimer right? Inception typa stuff
First you should google what that is since you dont know what it means.
Then look at the logic being done, if dying is true, then do the same method + some value. Dying never changes between this and itll always call itself over and over
Well, the dying bool is changed from another function. My plan was that the float automatically increases itself when dying is true
It's not a correct approach, because it's impossible for dying to change once it enters the method as true
It is indeed not changed inbetween any of the logic happening if it is true at the start.
A lot of this logic also looks very questionable, I highly doubt any of this does what you think it does
Oh yeah I see
Even that else if statement would be problematic
Okay thanks I'll try improving my script, my approach indeed was kinda stupid
how about
Modding help isnt allowed in this server #📖┃code-of-conduct
You can also just google the errors.
baldi's basics community dead tho
last post was 2 years ago
💀
hey, when i try to disable the PauseMenu it doesn't. . . but when i press to enable it. it works here is the main code for it public GameObject PauseMenu; public PlayerMovement playerMovementScript;
{
PauseMenu.SetActive(true);
playerMovementScript.enabled = false;
Paused = true;
}
if (Input.GetKeyDown("escape") && Paused == true)
{
PauseMenu.SetActive(false);
playerMovementScript.enabled = true;
Paused = false;
}```
I tried using Input.GetKey for both of them and it didn't work
Generally you'd want to use getkeydown for these, since it runs once, whilst getkey runs several times during the keypress, keyhold and keyup actions.
Have you actually read this code?
if (Input.GetKey("escape") && Paused == false)
{
PauseMenu.SetActive(true);
playerMovementScript.enabled = false;
Paused = true;
}
if (Input.GetKeyDown("escape") && Paused == true)
{
yes in update
I don't understand
read it and think about the value of Paused
its normal
what happens if the first if is true?
it will allow the second to run
yes, immediately, so whatever is done in the first if is immediatly undone in the second
add an else
ok
Just want to give a tip here; instead of rising these things of happening with several if-statements that are basically the same thing, you can make it "toggle" with one if-statement here.
wdym, im stupid. . . explain simpler
if (Input.GetKeyDown("escape"))
{
Paused = !Paused;
PauseMenu.SetActive(Paused);
}
Like this for example, should give you the general idea.
For each press, the 'Pause' boolean will toggle between true -> false -> true -> false, etc.
i still dont get it
You'd have to complete this script with the player's movement in mind, since you seem to disable it when the game is paused, I believe you could finish it.
i replaced the if with an else if and nothing worked
If you don't understand it, it's fine.
then what am i supposed to do? . . .
show your changed code
ok
{
PauseMenu.SetActive(true);
playerMovementScript.enabled = false;
Paused = true;
}
else
{
PauseMenu.SetActive(false);
playerMovementScript.enabled = true;
Paused = false;
}```
you took the if out. Why?
cuz i didnt work too
I said ADD an else
else if (Input.GetKeyDown("escape") && Paused == true)
So now change it as Victor showed as that is much better code. But you really need to learn how to read code
i keep pressing ESC and nothing happens after enabling the PauseMenu
i will afk for a min sry
Can someone help me figure this out? I need changing colliders in my tilemap objects, and the only way I could think of is check for neighbouring poles and enable boxColliders accordingly. This for some reason gives the result as in the screenshots.
Pole script -> https://gdl.space/ipecuhotoy.cs
uh anyone here have tried using huggingface api?
im trying to find how to apply different model
but i dont know how
Is this a problem with how I placed the box colliders?
If there's a better way to do this, I'd appreciate it
why the hell my character flying when i grab my falling block
my grab code:
onWall = Physics2D.Raycast(transform.position, Vector2.right, 0.05f, groundLayer) || Physics2D.Raycast(transform.position, Vector2.left, 0.05f, groundLayer);
if (onWall && Input.GetKeyDown(KeyCode.LeftShift) && Time.timeScale != 0)
{
Debug.Log("grab");
isGrabbingWall = true;
animator.SetBool("IsGrabing",true);
rb.velocity = Vector2.zero;
rb.gravityScale = 0;
}```
Probably because you were using GetKey, not GetKeyDown. So holding the button for over 1 frame would reset it anyway
If someone has any idea, please ping
Newtons first law
that dont help me a lot xdd
the objet is not here so my raycast dont detect it why he continue grabbing
okay
anyone?
oh wait i think i know
I don't think they teach Newton any more, in fact I doubt they even know who he was
still doesnt work
They do, I'm not sure in middle school though 🤔
that work !
what do I do
What does your current code look like?
In any case - you should use what Victor suggested.
remind me, what ages are middle school?
Probably 10 - 15
I dont keep track of all the age groups and where they apply in the school districts
Definitely should be doing Newton by then, ffs I learned it at 9yo
i will send it give me a min
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
most of it is useless
I learned it in like maybe 3rd - 5th grade
why is this
else if (Input.GetKeyDown("escape"))
different from this
else if (Input.GetKeyDown("escape") && Paused == true)
?
i think i changed it, it was&& Paused == false
i changed it again to this
{
TogglePause();
}```
```void TogglePause()
{
Paused = !Paused;
PauseMenu.SetActive(Paused);
enabled = !Paused;
}```
is that better? but it doesnt work
setting enabled to false is a problem, it means the code wont run anymore
no, just remove that line, the rest is fine
ok
Do you have version control?
Git
Do you have a browser?
Huh? That's what CTRL + Z is for . . . 😅
Nah I did that for my project and almost lost everything lol
I always ask people that to see if they want to set it up
I must admit it: I have it, but I am terrible at using it/keeping up with it. It's definitely smth I need to do constantly. My commits are stories at this point . . .
Speaking of, it has been a few months since my last one . . .
Who needs commits when you can put your project in a zip folder and upload it to one drive. 😎
Oh, definitely; it's all on me. I'm too inconsistent when I sit down to work on anything, so I don't really do much to have a commit, and it slowly adds up over time . . .
That is pure insanity
I used to do that when I was new to Unity lol.
Wasn’t a good idea. Took 3 hours to zip the project
Insanity
yes
if you're going to do that kind of stupidity at least use Asset->Export
what?
Look up what Git is and what version control is
Or just look at a brackeys tutorial
On Git with Github version control
Well look it up
It tells you immediately what its about
ok but i still cant fix the problem
Did you follow what steve said correctly?
{
if (Input.GetKeyDown("escape"))
{
TogglePause();
}
}
void TogglePause()
{
Paused = !Paused;
PauseMenu.SetActive(Paused);
playerMovementScript.enabled = !Paused;
}```
i think thats what he said to do
idk if its correct or no
Looks ok to me. In what way does it not work though?
Have you confirmed that TogglePause even gets called?
when i press Esc it pauses the game
when i press it again, it doesnt continue or make the player move
yes in first if statement
Are you disabling the object that has this script?
Because Update wont run on disabled objects
oh
i was disabling the movement script on the player (and the script to pause was on the player)
Ok i will make an object for pausing
This kinda stuff is usually kept in a game manager sort of script, not on the player
Disabling a script on a player doesnt disable the player btw
ok, i thought its the player cuz player is the one that pauses but i didnt know update wont be running when disabled
but does it disable the script from running?
Yes
thats why, i was disabling the movement script inside the movement script
Is the code you showed in the player movement script?
yes XD
Well that's why
i remember when i did a loop inside a loop 1 year ago
Make a game manager script and do that there
ok
Make sure to reference everything you need
ok
ty
does anyone know how to open 2 Inspectors to reference a script inside another script in 2 different objects
You can press the lock icon on the top right of the inspector
Also you can right click an object -> Properties
It will open an inspector in a new window
wtf
i just restart my unity that propose me to update something and now i have code error anywhere
cant use tmpro or anything like that please help
close vscode, click regen project files in unity external tools
tysm that work
I don’t anymore 😭
im glad you dont
Hi, could somebody help me with Binary Space partition?
I want to tweak my algorythm to create a fixed central zone that can´t be changed by the algorythm
but the surrounding areas can
Im using a Bounds Int Space to Split, is it possible to make a "hole" in this space which represents the central area?
The simplest approach would be to pre-partition the space to create the central zone. For example:
Totally, I was thinking about that but I don´t know how to code that pre-partition with the BoundsInt
Hello. I've been doing some research and I'm struggling to find any good recourses. Is there a way to pull step data from smart watches to unity? How easy is it to test unity apps on an Iphone & apple watch?
I see that apple has their HealthKit API.
Actually, since this is BSP, the cuts would have to look like this.
https://medium.com/@rolir00li/integrating-native-ios-code-into-unity-e844a6131c21 Found a very confusing blog post ahaha
yeah, thanks for the diagrams by the way
To code this, just think about what direction and length each cut needs to be. The first cut is on the Y axis (or X/Z in 3D) and half the width of the center zone from the middle.
Does the animator have to finish its animation to update its state?
No, don't believe so
yes, but you can track it's progress via AnimatorStateInfo
At any point during the animation, you can transition between states with conditions or triggers
Or wait have I misunderstood the question?
Or I did
Wdym with 'its state'?
No, unless "Has Exit Time" is checked, in which case part of that transition condition is "This animation has finished"
Presumably "Run a transition into another state"
I have a door. It has Idle, Open, Closed states. I have 2 triggers which are open and close. On interact with my door i settriger Open or close if it is closed. I try to get the AnimationStateInfo and store it in a bool then print it to console. I had to write it in a coroutine because the bool returns false OnInteract
The animation state does not change right away when the transition condition becomes true. It'll happen whenever the Animator component receives Update. It won't change in the middle of a different component's update call
So, if you wanted to check if a transition occurred after setting a value, you would need to wait a frame to make sure it's had time to run
All right. Thats why I got confused then. I executed them in the same block it did not get updated correctly and when I waited a second in a coroutine it updated correctly.
You wouldn't need to wait a full second. Even just a yield return null would be enough
Oh, that's what you ment
Ah all right. Thanks a lot.
Yes sorry If i was not clear enough.
No worries
Hi, could anyone help me with cinemachine? I have 3 virtual cameras + main camera, when I switch to the main camera from virtual camera, it like orbits the player when rotated, until player moves, then the camera goes "inside the head", where it is supposed to be. Code for switching:
void SwitchToVirtualCamera(CinemachineVirtualCamera vCam)
{
if (activeVirtualCamera != null)
{
activeVirtualCamera.gameObject.SetActive(false);
}
activeVirtualCamera = vCam;
activeVirtualCamera.gameObject.SetActive(true);
isUsingVirtualCamera = true;
Debug.Log("Switched to Virtual Camera: " + vCam.name);
//camPosSave = mainCamera.transform.position;
}
void SwitchToMainCamera()
{
if (activeVirtualCamera != null)
{
activeVirtualCamera.gameObject.SetActive(false);
}
activeVirtualCamera = null;
isUsingVirtualCamera = false;
Debug.Log("Switched to Main Camera");
//mainCamera.transform.position = camPosSave;
}
Watch "fastshooter - Game - Windows, Mac, Linux - Unity 2022.3.18f1 DX11 2024-08-19 17-50-34" on Streamable.
You mean that initially you had the camera inside the head of your player, and upon switching, its outside and does not keep that position?
aha, and then upon movement it goes back, I see
Well it is under Player in 0, 0.4, 0 and when the player moves it goes back
yeah something like that
Right, what scripts affects the camera position?
my camera bobbing might be updating it, but shouldnt it go back by itself?
because the camera bobbing is caused by walking, and the camera moves after walking, so its caused by the camera bobbing
but other cameras move correctly automatically
In the hierarchy, you dont seem to have a gameobject holding the correct camera position, or do you?
And yes, sounds reasonable
uhh, no, should I have one?
This might just be a setting inside the virtual camera
sorry kind of a beginner in here
Just good practice
So I should try to do a "Main camera holder" ?
I'll take a look in the engine, meanwhile someone else might have an idea
Shouldn't change anything here, was just wondering
okay
I mean, a work-around would be:
- Create a camera holder, this will just be a gameobject (as a child) on your player character, where you want the camera position to be
- Once the virtual camera becomes active again, reset the position of it
This should make this issue resolved for the time being, until you can resolve it properly
it will work the same as before, but since the bobbing updates the camera position, I belive that the "standard" position of your camera would be in front of the player's head
you can try to remove the bobbing part of your virtual camera, and I bet you will see the cameras location ahead of the player
I removed everything that moves with the camera and found out that after switching back to the main camera, the camera is at the same position as the virtual camera before, not the correct place (in player)
@wispy finch should I have a main camera as well as another virtual camera?
so it knows where to go back-
When you removed "everything", the virtual camera is in front of the player's head? If so, it is as expected
yeah, the in front is the exact position as the virtual camera before switching back
You could use several cameras, that's up to you. Just understand that either you correct the position inside the virtual cinemachine camera, or you reset the position upon switching as said before.
I recommend making a camera holder - also as explained before - or you simply correct the position in the cinemachine, so that the bobbing of the player's head does not offset the position drastically.
Okay, thanks for the tips!
No worries, best of luck
guys ı have some dash mechanic
but player when touch any buıldıng that happens
how can ı fix
You are using a rigidbody2D or no?
Moving a rigidbody via the transform is not correct, it will lead to glitchy collisions and such
Move it with rigidbody instead. AddForce/velocity/MovePosition
yea rigidbody2d
but thıs ıs for dash
thıs need 2 locatıon and go to other locatıon
when ı look ınsıde the wall collider and dash there This choosenTransform wıll be ınsıde the wall
and player all tıme tryıng to go in wall
ı used stopcoroutıne or return break for stop thıs dash when goıng ınsıde the wall but dıdnt work
You could just try replacing transform.position = ... with myRigidbody.MovePosition(...)
Oh and better use yield return new WaitForFixedUpdate() instead, since you are dealing with physics here
Might need to change Time.deltaTime to Time.fixedDeltaTime, but not sure
Using the physics engine will indeed make the physics work better
Teleporting (using transform.position) will cause issues of course
but ıt ıs ınsıde the wall
and always while loop active
that ıs why never over
this is the problem
Please finish a message before hitting enter btw
That is not why.... simply finish the message before sending it....
But yeah, everything osmal said will fix that issue
when ı think 4-5 letter probably ı forgots first 1-2 letter
Maybe just stop the dash when you collide
You can just... not send it. You can stop and think of it, then continue typing. All without hitting enter or send
It is called message spam and is against the rules here #📖┃code-of-conduct #854851968446365696
ı tried to do it but ıt dıdnt work Do you know anyway for stop to while loop in coroutıne?
Like storing the started coroutine in a Coroutine variable and then using StopCoroutine to cancel it when you collide
yes
Make the while loop based on a bool, set the bool to false
the point is ı used stopcoroutıne but dıdnt work
Show what you tried
this is coroutıne
StopCoroutine takes the instance of the coroutine you started. Not the name of the method
Coroutine instance = StartCoroutine(Foo())
StopCoroutine(instance)
He meant show how you tried to do StopCoroutine
Not sure why you are showing this, I see nothing related to StopCoroutine
oh ı was tried it but didnt work
ı wıll try agaın
Do it like this
#💻┃code-beginner message
^That, except instance would need to be a private variable in the class
@verbal dome should this work?
this is the wall's tag
when ıt touch the wall thıs should happen
but still ın unıty same error
StartCoroutine returns a Coroutine that you should store in a variable
Then call StopCoroutine(myCoroutineVariable) when you need to
I strongly recommend using RigidBody2D here, as well as reading up on FixedUpdate() and Update()
Oh you are using it, but why then use the transform to move the character?
asking me?
Yes.
this is not for normal movement ıt ıs for dash
He was originally moving it with transform but I suggested to change to rb.MovePosition
Aha, must have missed that, I agree nevertheless
@wispy finch Fixed it! Now, last question, how do I do culling mask? Because it seems I can see everything even if I have set in culling mask to not see player body
the virtual cameras dont have any option for that
Great. Should work fine with culling masks, have you set the layers correctly?
It seems you did not read what I said
#💻┃code-beginner message
You cannot stop a coroutine with the method name
my english not enought sometimes ı can have trouble lıke that sorry
ı used this one but ı dont know
StartCoroutine returns a reference to the coroutine
You make a variable on the left, do an = sign, then startcoroutine
Pass that variable into StopCoroutine
It will never work with SpeedBuff()
StopCoroutine(SpeedBuff()) is incorrect
I can find plenty of things when googling for that, "Unity FPS game, hide player object camera", check it out
oh so ıt ıs not correct okay
Coroutine speedBuffRoutine;
void SomeMethod() {
speedBuffRoutine = StartCoroutine(SpeedBuff());
}
void OtherMethod() {
StopCoroutine(speedBuffRoutine);
}
Does that make more sense? My first example code was more like pseudocode
yes but my coroutine doesnt have a name
like " Coroutine "
That is a unity type
Use Coroutine, not anything else
I mean, you can save it as an IEnumerator iirc. But Coroutine is gonna be simpler
Mate...
xd
That is not at all what I wrote
when i click it it says project failed to open
this is a code channel. but you'll need to check the logs
ı am sorry...
You pass in the name of the variable.
I called it speedBuffRoutine
so StopCoroutine(string) is wrong?
Take a long look at this
Try to copy it.
#💻┃code-beginner message
It is almost copy-paste ready. You just need to put the StartCoroutine and StopCoroutine calls in the right places
is that wrong?
No, that is right! Good work
Because that's how all the Cast methods work. It needs a direction to move to
If you don't need a cast then try OverlapSphere or CheckSphere
can someone show me why my player is falling upwards? When I click play it's fine but whenever I walk off a ledge it falls upwards indefinitely
@summer stump maybe while loop is never stop with stopcoroutine
What bug
ah thank
ı am doing that yes
ı was already did that
maybe ı dıdnt undurstand because my englısh not well
Send your whole script !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
ı write in some website but ı dont know to use that thing
Press save 💾 , copy the URL link, paste it here
hello i have tried this for slow falling but it dont work void Update() { switch (levitation) { case 1: rb.AddForce(Vector3.up * 3f); break; } }
can anyone help me with this problem of my player falling upwards?
You were meant to call StopCoroutine from OnCollisionEnter2D
okay ı wıll do it
Should probably check if the coroutine is null or not, before calling StopCoroutine. Not sure if unity will throw an error if you try to stop a null coroutine
ı got it
How can I set the state of my animation in script without triggering the actual animation? What method do i use if it exists.
Set the state?
You can store the Animator and apply "SetTrigger()", "SetBool()" and such, to transition between states
if that's what you ment
I do not want to see the animation play though. For example I have this door and I want to set its state to open or close without seeing the door actually opening and closing.
ah, you mean literally "setting the state"
These trigger the animation thus making it play.
@verbal dome ıt worked but when ı so close to wall and press shift lıke 3-4 tımes ıt was happenıng agaın and ı put there 2 collider and problem fixed xd
did you fix your problem?
why's it not working
no
Please paste code as it should. !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
are you new at unity
why open caps like that
not really new but kind of a beginner ye
me too
https://docs.unity3d.com/ScriptReference/Animator.StopPlayback.html would this work you think? I did not totally get it 😄
you can be mad but dont effect that feelings on the people who trying to help you
maybe they want to fınısh first problems
Not sure, quite an interesting issue, you could not use the default state? You just want the door to go from closed to open or vice versa, instantly?
can someone show me why my player is falling upwards? When I click play it's fine but whenever I walk off a ledge it falls upwards indefinitely
'''cs
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
float speed;
public float sprintSpeed = 5f;
public float walkSpeed = 1f;
bool isSprinting;
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 moveDir = new Vector3(horizontal, rb.velocity.y, vertical).normalized;
rb.velocity = moveDir * 100 * speed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.F))
{
isSprinting = true;
}
if (Input.GetKeyUp(KeyCode.F))
{
isSprinting = false;
}
if (isSprinting == true)
{
speed = sprintSpeed;
}
if (isSprinting == false)
{
speed = walkSpeed;
}
}
}
'''
Well It works fine going to idle state at the start of the game. I am trying to save the state and load back. When I load them back though, I disable and activate the animator. It immediately starts from the idle state. I want to see it in the last state I saved.
why is it not working dude