#💻┃code-beginner
1 messages · Page 749 of 1
Well yea I think you need to do it a good way to achieve what you want
trying to take a shortcut by "finding all uses of the sprite rn" will surely backfire
Also #🎥┃cinemachine
I'm using the game data to perform the actual spells and stuff, but here I just want to do a simple thing in the presentation layer, that's why
the most permanent thing is a temporary solution and all that
my visual studio is having a fit today 😐 constant stream of errors, visual studio installer not finding the installation.. grr
Okay @grand snow and @wintry quarry and @dark laurel , thanks for your advice. Guess I'll do it the "real" way and not use shortcuts ...
You're right
I mean, you can do it however you want.. but I promise that if you do something like foreach gameobject in my entire scene every frame, your game's framerate will quickly go to a flip album and you'll wonder why
I am so confused becasue like 20 people are telling me diffrent things can you sned me the whole script because I have been told 20 diffrent other things and am having a brain anurism
last time i ignored that i ended up with a vector2 called realplayerpos that had 0.5f added to the y position for some reason
I guess I've already done the hard part, where the wizard can cast spells that all the other players are carrying. I just hoped for something simple and rewarding now, where I draw a simple line between the wizard and the spell items on the other players
I personally think the previous suggestion to use layers to locate the head (so you can show/hide it) was unwise.
Ideally its best practice to use serialized variables (which you should learn about early on when using unity) to locate and do stuff to certain objects.
@fervent bramble All the advice you've been given is correct and while overwhelming.. just needs some time (on your end) learning. 🙂 Just go back to the editor, read the advice, google what you don't understand, and try again and you'll get it.
ideally your system has quick and performant ways to find the corresponding presentation layer objects for the data model objects in question
Hmm that shouldn't be too hard to create, thanks for the clarification
Should actually be doable in like half an hour, thanks again
Hey, don’t know if you’re still on, but I’m a little confused on the y => . Would you basically check if the enemy is inside the enemy list?
This is called an "expression lambda" if you want to google it up. In this case, the two methods (OrderByDescending() and FindFirstOrDefault()) take a parameter that restricts what they search for, but conveniently plop it into a variable you can use yourself.
public class Thing
{
public int Speed;
public int Size;
}
...
List<Thing> allTheThings = ...;
var speediestThing = allTheThings.OrderByDescending(x => x.Speed).First(); // assumes at least one thing
var speediestThingBiggerThanTen = allTheThings.Where(x => x.Size > 10).OrderByDescending(x => x.Speed).First();
var fattestThing = allTheThings.MaxBy(x => x.Size);
the "x" just means "declare a variable named x that is a Thing for the parameter"
To be more exact, lambdas are a way to define "anonymous functions" which can be used as delegates
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/
i figured it out all i had to do was make the camera a child of the player head under armeture not the mesh and i didn't evenneed a script
It's also not at all necessary for your code (like, it's unrelated to unity.. it's just a fancy C# thing to reduce code). Simpler code, if you're used to for loops, is something like this:
Thing biggestThing = allTheThings[0];
for (int i = 0; i < allTheThings.Count; i++)
{
if (allTheThings[i].Size > biggestThing.Size) biggestThing = allTheThings[i];
}
Gotcha. Still have a little bit of learning to do with this, but this definitely helped. Thank you so much!!!
is it normal that my character's position.y is 0 but when i test the game it's set to something like 0.07999989 and no matter what i did i couldnt keep it 0
are you certain it is actually 0.079 and not a number in scientific notation that just happens to start with 0.079 then has E-(some other number)? because that would just be floating point imprecision and is effectively the same thing as 0
Check the parent
it's exactly that much, it was higher but when i changed the character controller settings a little, it dropped down to that point
it's parent object
it sounds like you are applying some sort of gravity to your object and it is simply falling to touch the ground
i used claude for my playercontroller script but i checked it and not sure what does that
well you'd have to show the code, but you'd also have to find someone willing to help you debug AI generated code
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
so people still code their scripts by hand, i thought everyone uses ai then debugs the code for scripts
I find AI is sorely lacking in a lot of things, and being competent is one of them
It's never actually helped me once in programming
Only use I have for it is for it to be my rubber ducky and help me explain my issue better 
The companies usually just steal work so im just generally against it
i can write my own code too but it's usually like 10 times slower since i'm beginner
People who use AI tend to not learn and lean more on the AI to do the thinking for them, I can't say this for certain with everyone because I don't know everyone but if you're starting out using AI is probably worse for you because it makes things that look correct
heyo was wondering, as i'm having a little hard time understanding
i have bones in a skeleton as a prefab in the scene, a standard character
if i need to get the children of a parent bone in that hirearchy is there a way with a specialized bone class or it's a matter of hirearchy sifting?
couldn't find much online
How about giving the bone a tag
a tag?
How are you selecting the bone btw?
oh wait i see what you mean
no worries
i don't think that's a way to go tho
i have the parent bone game object reference directly
i'm struggling tho to navigate from there
this is working with importable characters meaning relying on a pre set tag wouldn't really work
i have the user directly pass the game object from a displayed prefab hirearchy
via drag and drop
How about shooting a ray and using an interface
oh this is for the editor i should have mentioned
which thinking about it
not sure if i should have posted this in editor extensions, thought being a beginner question it would fit here more tho
tho i'm not sure anymore

Im sorry but im too tired to understand what you mean XD
i'm extending the unity editor with a plugin
but i thougth the how to navigate a bone hirearchy was a beginner question so i thought this was the more fitting channel
Oh idk much about that you'll need to ask someone else sorry
yeah no worries, was my bad for asking editor extension stuff in the non-editor extension channel, cooked by the hour too almost 2 am, thanks tho^^ 
hi i would like to know why i got these errors bc i think i did same as in the vid
Show the vid
🔴 Get bonus content by supporting Game Maker’s Toolkit - https://gamemakerstoolkit.com/support/ 🔴
Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and...
11 min in
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 196
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2025-10-14
puplic
Configure your !ide so you don't make spelling mistakes like this
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
oh shi mb yo im dum
You need to configure your 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
Take this as a good opportunity to learn how read the console. It prints text there for a reason.
Going by the very first command shown here, what is it telling you?
@wicked venture can't blame you for asking that kinda question as it's absolutely something that can be done in a bunch of varying ways.
I tend to have them instansiated or enabled/disabled living somewhere under a UIManager esque object. In your specific example it sounds like you have just the 1 instance to manage but in more involved cases something like this may warrent some sort of object pooling too.
You also mentioned re-using in multiple scenes, Depending on the way your game is setup you may want this UIManager to live in a scene that is always loaded (via additive scene loading) or existing in the DontDestroyOnLoad scene
I think some people have messed with UI Toolkit nowadays for this kinda thing since I believe it's less gameobject/component based?
I spent some time tinkering with Unity's older GUI stuff to see if it was worth it but there's some issues with the lack of batching and font scaling that put me off it
eg. this little test gif was entirely powered by Unity UI/IMGUI stuff with no canvas or anything
yee I tried first the instansiate method but for some reason the icon could not leave the borders of the item I am hovering on (probably some sorting layer method or something i am missing ) , yeah I will just instansiate it when I hover and destroy it when I move my mouse away won't leave clutter behind
I am completely Ignorant on unity Toolkits in general I am new to unity only used UE4 before for college projects thats why I am still not sure on whats the best way to do things here
wow this is what I want to do yeah , is there a link for examples on how this was created
I'll have to chuck my example project up on git, I'll let you know if I do. Although overall I do recommend against this route for the reasons i've described
If you detail the problems you we're running into here it might be the fastest way to resolve your issue
Yeah I will have to rewrite it since i deleted all the work after it did not work , but in general I wanted to confirm the right path if instansiate is one of the correct solutions I will go with that again
also checking ui toolkit might learn something new that will help me in UI in general , its about time i learn about UI
Ok that UI tookkit is insane wish I knew about this way sooner thanks man
i just installed hdrp package and all the shader graphs i made are purple now help
shadergraphs are built to target either built in, urp or hdrp pipeline
you would need to remake/adjust/modify them in order to replicate the same behavior in the differing pipeline
ok
Anyone have any idea why my textmeshpro button and texts are gaining focus whenever I hit a TMP dropdown? I have a 50% opaque background applied on my SettingsPanel and it is getting overriden in just the text and button spots. Maybe something to do with layers or tags? A bit new sorry, any help would be appreciated, video a bit laggy but you should get the point
what the different between these 2
u can change what canvas appear ontop via the sort order ther
is that like a zIndex essentially?
Sweet, this worked perfect, thank you so much!!!! @rugged beacon
Hard to tell, without the context for the methods? What is being cleared or disposed?
im just looking a way to release all
Okay, so it's for the ObjectPool class. That helps . . .
Since they both have the same description, I'd assume that these are just aliases(calling the same api internally) for backwards compatability or something. There's a slight chance the docs are being dumb though. Maybe browse to the source code and compare both.
It is a bit confusing. It seems they both have the same functionality to clear the list for later use. Typically, Dispose is used to clear up (memory) resources for an object no longer in use . . .
hey i made this marching cubes algorithm and i also tried interpolating it but i always get these weird artifacts idk how well you can see the in the image. i dont know how to fix it or whats wrong but its very annoying
these are the most important pieces of my code:
https://paste.mod.gg/lueynfznykew/0
A tool for sharing your source code with the world!
also these artifact lines are always on integer y values
He did that just fine, you can see the error is vague.
Is there like an easy way to have one canvas on top of another?
Aka like its priority is higher?
But i still need both of the canvases active at the same time
Nvm theres a sort order setting
Does unity run a script event if it is not in play mode ? Like the drawgizmo
yes it will execute those functions in edit mode
and if you add [ExecuteAlways] then it will even run Awake/Start/Update/OnEnable/OnDisable/OnDestroy in edit mode
Oh
Thanks
i don't know much about marching cubes so i'm more then likely wrong, but in your code you're rounding your values to ints, then interpolating the rounded values. this could possibly be causing your edges to share the same value if they're similar enough?
Hey, can i ask here 2d Coding Quastion?
yes
also 3d?
read the topic.
where can i find it? im using Discord not often. Most of the time my Brother.
"Ask questions and discuss anything related to beginner coding concepts in Unity?" this?
yes, that is the channel topic.
The below bot msg is gonna be useful for you too.
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
Thank u
Guys this is my code, I want my movement script for the character to be in a separated script, how do I do that?
a pdf is a new one
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
oh xd
Anyone have answers?
Maybe when you share the code properly
sure give me a moment, I am trying to understand how to use paste.mod
How do I share it?
the url will change when you paste your code, copy that
A tool for sharing your source code with the world!
ok.. that's obvs not done it
wdym?
I mean.. look at the url, it's obviously not a unique address that's going to take us to your code..
Click the save button, top left, first.
A tool for sharing your source code with the world!
there we go
mb xd
any idea on how to separate the movement part into it's own script?
yeah, create a new script.. then cut and paste all the movement code into that
no shit, but idk which parts to separate
don't wanna mess up the other things going on
make a backup, so you can play freely with it
Yea i thought of that too but when i use the raw unrounded noise data it results in 7649 errors
Can someone tell me how to separate the movement script to it's own script without messing up the rest of the code. Pretty pls ❤️
I don't see anything other than movement related stuff in that script. What exactly do you want that should stay in the old script?
I want the camera movement, animation stuff, friction, etc to stay. I want the character movements only to be moved to another script
❤️
Why?
easier to understand + can add more things easily, also need present this in school so would be nice for them to be separated to not cause confusion.
Lines 82-103 are the ones that handle specifically the character movement so you can copy-paste them to another script but then you have to set up all the communication between the scripts and references in the new script so IMHO it just becomes more complicated for no real benefit
If you want to make it cleaner and easier to expand you can just move it to another method but still keep it in the same script
hmmm how would I do that
true... 🙁
The same way you've made the UpdateAnimations method. Make a new method (void HandleMovement() { }for example), move the code there and call the method where the code used to be
ahhhh okkk
Although the code looks AI generated so you probably didn't make it
sadly I didn't do all of it, I had ai help with camera movements bcs character movement and camera movement were colliding with each other
please dont ask for help with code you didn't write
I literally wrote most of it, I don't see the issue
Hello there,
Quick question :
For handling asynchronous operations, I have a cubic game where I generate chunks of voxels. The generation takes time aswell as the instantiation in Unity, so I can't make it in the main thread.
What would be better :
- Async/Coroutine tasks for each chunk
- Second thread that generate each chunk
I'm not sure if the first or second one is better, I would think the second one would make less overhead for large amount of chunks generated, but the first one could be easier to code
Also, is their a way to force an execution to slow to takes less CPU ? For instance i don't want the CPU to overload If i want to generate 100 chunks, I want it to slow down but the general execution of the game continue with low impact.
Hey
why should i learn coding or make a Game?, i have that feeling in my Stomach that everthing i try to learn is usless because? Why would sombody ply My Game? there is hundreds of better Games.
are u guys also struggelying with this feeling?
CPU overloading isn't something you need to worry about. It's typical that games take up all the CPU resources they can use. The OS will start limiting it automatically if it the processor gets too hot for example
You probably shouldn't if you've got no reason to
Its more like, i want to limit the chunk generation thread to ensure it doesn't reduce performance of the main thread that much
Its like seeing chunks generating in the distance but without having a lot of frame laggs
i have, i dream since im a Kid to make a Game. I Never startet... Now im 19 Years old, i dont have much time enymore, im getting old and i need to invest in my Future. But this Dream i have consitently "Remmbers" me on my thought i had as a child. But evertime im sitting and Code Somthing the problem rise again. Like "Why would sombody in the World play u game"
sorry for Bad Englisch
i have the feeling the i maybe lose to much time for somthing thats nobody cares
Most computers have multiple cores so what you do on one thread won't affect another
im learning it bc it seems fun idc about people playing my game
I'll say it in another way for you to understand, at 23, why learning how to paint, sing, dance if you can't be a professionnal because everyone started much earlier and are better ?
Why ? because its a habbit and its pleasing to you, if you do it for the money its not probably the best idea, if you want to do it for the fun/learn, then go for it
So to come back to the first message, it would be better to make it in a thread instead of async/coroutines ?
If i have a lot of instances of async/coroutines, it would swarm all the threads
u probobly right. i guess im try to the best of it. i mean its fun just the Drawing kills me evertime
so i will Continue, thanks G u really dont know how much that helped me even it is basic reasons? (sorry for my Bad Englisch Skills)
Coroutines aren't threaded
What's going on with the brackets..?
HAHA
Didn't knew that, any better ideas of what i've said to generate meshes async without puting the fps down too much ?
They're not just for decoration, you know
put u code in the Update Function, inside of the Brackets
{
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Ich springe!");
rb.velocity = Vector2.up;
}
}````
Hi ! I want create a good characontroller for a platformer 3D in Unity 6 but I don't know how to take me.......
There's the job system: https://docs.unity3d.com/Manual/job-system.html
!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
please don't spoonfeed, btw.
what is spoonfeed?
providing full code like what you did - it takes away agency for the asker to actually learn themselves
3 bits of advice
- its not something you can half commit, you have to give it your all and make sure you're making an effort to retain what you lean.
- if your goal is to just make money then you're going to fall for a trap that many people do. if you focus all your time on one big project then you're going to get burnt out quickly, start small and try to make a variety of different things
- do the little things that might seem pointless. like taking notes, explain to yourself out loud, or to someone what lines of code do, this helps you commit to memory what you've learnt. and once you've learnt a little bit, always attempt things yourself before asking for help. it might seem silly leaving notes, but trust me they are like gold.
it results in askers/beginners relying on answers rather than learning how to fix issues
ahhh, i understand what u mean. I mean its the same code from him. i just triyed to say that he need to but it in the {}
wdym they won't affect each other lol, they still share a large chunk of memory
it isn't the same code though
one of these is not like the other 😄
where theres an opening bracket { there must be a closing bracket }
u have 1 that doesn't have an open
pair them up... and find the one that doesn't fit..
its a rogue bracket
it changes the behavior, without really explaining the core cause
imagine they just copied the code replacing their Update
they could leave or remove more brackets than necessary, leading to the same issue
if they did place it correctly, they'd now have different inputs and different outputs, and no guarantee that they actually understand why it worked
support servers aren't just answering machines, there's somewhat of a duty to teach here as well
@scarlet pasture
all that aside - their ide isn't configured.
if it were, there'd be a lot of errors complaining about what's wrong lol
yeah i knwo
don't forget - the first step is a configured ide (#🌱┃start-here)
Hello, does anyone know how to make this wheel rotation smoothly? I'm rotating using z but it's a little bit off
make sure the pivot is set up correctly - it's most likely a #🖼️┃2d-tools/#🔀┃art-asset-workflow thing, rather than a code thing
hi, i made this script to make any object that block view to the player transparent, almost everything works fine (material changes to the instance, the settings are all ok) but in the game i cant see the opacity change of the material until i update any setting manually
making it with layers changed nothing, i use URP
a powerful website for storing and sharing text and code snippets. completely free and open source.
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
is it really a code thing though
seems more of a #1390346776804069396 kind of question
change the pivot so its centered
there are also probably existing ways to do so, like near plane clipping
added the code link
If you only change .sharedMaterials or modify the shader without reassigning the renderer’s material array, Unity won’t push those changes to the renderer until a manual refresh (e.g., when the inspector reserializes or scene repaints).
the problem is camera might be far from player's model, so i would like to make the blocking objects transparent
let me try
try copying the material.. changing it and applying the copy
just to test real quick if im right
yeah it works if i check the fallback check
- Renderer.sharedMaterials edits the shared project asset (not instance-specific).
- Renderer.materials makes runtime instances that can be updated per object.
not 💯 this is correct (google overview) but i do recall needing to copy it out
You might want to consider trying to cache the materials n things you need — so you’re not constantly creating new instances all the time
is there any other way i can do that?
^ oh yea i forgot bout that
https://assetstore.unity.com/packages/3d/characters/modular-first-person-controller-189884
u can use the assets store.
its better to learn how movement works
as a bare necessity.. nothing wrng with using assets as referenece..
but i wouldnt build off that
well if they asked to make one then ill just throw them a link
Hey, how can i check if the Player runs. I want Play the idle Animation.
from my Player. im also using 3d and only Character Controller
https://www.youtube.com/playlist?list=PLx7AKmQhxJFYC6IBfqiu8x6BV-wcNfYOy maybe check out this series..
don't discount learning basics tho !learn
easy.. check if ur applying the run input?
Applying the run Input?
yes... when ur input is running.. u just mark a flag/boolean
like isRunning
float ix = Input.GetAxisRaw("Horizontal");
float iz = Input.GetAxisRaw("Vertical");
Vector3 inputDir = (transform.right * ix + transform.forward * iz).normalized;
how would i manage that=?
if (Input.GetKey(KeyCode.LeftShift))
{
isRunning = true;
}
else
{
isRunning = false;
}
``` something like this
can i just say "If the Player isint pressing somthing like WASD he is not Running?"
u could also just check if ur movement is greater than something..
using its magnitude
this!
how to i do that?
U might wanna learn blend tree
say ur end movement vector is movement
it'd be
if(movement.magnitude > x){
//ur running
}
else
{
//ur not running
}```
magnitude is always positive no matter which direction ur going..
i dont like them, i only need a few Animation like maybe 3 or 4 for a Horro Mobile Game. I Animatet the Players "Breatch Animation" and i need to play it correctly otherwiese it would overwrite my Camera Script
Thanks U!
debug the value at first just so u can get an idea..
if any movement counts as running u can just check if its greater than zero
or some small value like .01
that way it'll ignore any tiny input (deadzones for example)
i will Check, is he Pressing Somthing and a small value he need to be faster to count as Running
Ok? If it's overwriting your camera then there is something wrong with your code. Just saying
this would be safe?
Really, i thought if i Animate the Camera rotation and Position it gives me some dumb Rections
so i need to fix my code not my Animation?
could just check if(inputDir == Vector3.zero)
Nice!
Thanks u so much!
But why is my Code bad if the Animation of the Camera overwrite my Code?
may want to check the x and z seperate tho..
if u have verticallity.. wouldnt want to count that as running/animation
well, if it doesn't break anything its fine..
but if u want ur camera moving w/ code only.. then animating it's gameobject will overwrite or lock up the code
so instead u'd do something like animate a empty gameobject
put the camera inside it.. and run code on the camera..
that way the animator isn't controlling the actual camera's transform..
but it would still influence it.. b/c its moving its parent
OMMMG thanks
THANK YOUUUUUUUUU
theres hundreds more on the asset store if that one doesn't fit ur needs
best just play around with them.. inspect the code.. see how they work..
do a little research urself.. ask around parts u dont understand..
eventually you'llwant to know it inside and out.. and how it all works
movement code is the backbone of most games
okayyy thanks for your help I'll try to watch all that, I found videos on state machines do you think it would be good to use them? https://www.youtube.com/watch?v=Vt8aZDPzRjI
Learn the fundamentals of programming State Machines in Unity with this new video break down!
This tutorial explains important concepts of the State Pattern, and how to use State Machines when programming! Today we will walk through an example project to showcase the benefits of using state, the state pattern and state machines in Unity!
This ...
So the breathing „animation“ would be better if I coded it?
hey is there any way to subtract the last frame's platform velocity and the current one?
record it each frame and then update it after using
if ur doing platforming tho. u might want to find one that has momentum.. or find out how to do that urself (like aircontrol)
100 percent..
do what chris say
i've tried
rb.linearVelocity += (TargetVel - LastPlatVel) * Time.fixedDeltaTime;
basically:
var oldValue;
void Update() {
var currValue = getValue();
var difference = currValue - oldValue;
// ...
oldValue = currValue;
}
you sure you need the Time.fixedDeltaTime in there?
it's already a velocity delta between frames
i do.. breathing is prettty simple sinwave or mathf.pingpong
i use seperate containers to keep my logic seperate to avoid conflicts and frustration..
main root gets rotated left right
then down one object moves up and down
then i have my "bobber" or cam breathing code..
andthen finally the final child is the camera.. (nothing is actually running code in it) just all its parent containers
it's just what i see most velocity calculators use. also the value is extremely small and i've tried many configurations with no avail.
are they perhaps applying deltaTime to acceleration
make sure you actually understand what's happening rather than just copying blindly
Debug.Log(movement);
Debug.Log(movement.magnitude)
Debuig.Log(etc)
TargetVel - LastPlatVel is a delta of velocity
if you multiply in deltaTime, you end up getting a value that represents how much extra distance the new velocity travels compared to the old one
you'd be adding a delta position to linearVelocity
Ahhh thanks I will need to make some research about that
Thank u Rental
Actually use string interpolation so i can mark what they are
Debug.Log($"Movement of player is: {movement}");
Debug.Log($"It's Movement Magnitude is: {movement.magnitude}"); and so on
good luck
CurrentVel: (1.32, 0.25, -4.60) LastVel: (1.28, 0.24, -4.63) Final: (0.04, 0.00, 0.03)
TargetVel - LastPlatVel
yeah the value's barely move the player.
what is the goal here exactly?
im really confused
you're getting the acceleration and applying it to the player as velocity?
yeah that's.. that doesn't make sense come to think of it lol
ya, im a bit confused too.. i thought we were talkin about magnitude for animations and stuff.. i got lost when u started talkin about platforms
i'll link the last conversation. #💻┃code-beginner message
anyway on a side note.. i'll throw ya a bone 🦴 https://paste.myst.rs/kap36emz here's the CameraBob affect the video i sent shows:
float yOffset = Mathf.Sin(Time.time * bobSpeed) * bobDistance; being the Sinewave i was talkin about @scarlet pasture
a powerful website for storing and sharing text and code snippets. completely free and open source.
ok yeah big https://xyproblem.info there lol
there are 2 different people asking here
lmao.. i wouldn't have noticed thanks 👍
Hahaha im Bad_GameDev the guy with the camera breathing
Thank u for the code and the commentary’s
So I can understand the code also better
lol, #💻┃code-beginner message yea i figured it out eventually
ok going through the math - it seems like there would be / deltaTime and then * deltaTime, so no deltaTime is correct
is the platform already moving when your player gets on it?
yeah.
and whats not working exactly?
is it still when it changes directions?
and do you add the platform velocity to the player when the player gets on?
well if it has a massive change of velocity and that get's applied to player and slides off. it's fine when it's at a constant speed.
I'd just use a rigidbody to make it less complicated, but basically, if you want to do it, you get the floor's position, and match it to your player position
i am using a rigidbody.
ya, but if it has any kind of horizontal movement u wouldn't wanna overwrite ur players movement
unless u lock it to the platform (not allowing movement)
I mean, if it doesnt use velocity anyway, you add a position already when you use wasd
@patent wedge do you have this
you need a kinematic rigidbody then I think
for the platform
that seems... detached to the issue
yeah that works but that would be un-optimal and the player can walk on moving rigidbodys(props).
soo are you gonna answer this
the previous answer about transform positions was.. not relevant to the question lol
yeah i am currently applying the platforms rigidbody when your own it.
that's not what i asked
the moment the player gets on - is the platform's existing velocity applied?
is that baked into the delta check?
yes! i am checking the rigidbody's velocity using hit.rigidbody.GetPointVelocity(hit.point)
the platform following code is on the player, right?
yeh.
sidenote, this answer seems.. weird
kinematic rbs can move, and making platforms kinematic doesn't affect props either
we can get back to that though
and have you debugged that to make sure that's applied correctly?
also, check how you're moving the player, make sure you aren't resetting the velocity or anything
what do you mean? the fact that moving kinematic rigidbody's work?
if so yes!
Hey, how do I open the Windows system dialogue to allow the user to select/upload local files?
yes.
i don't think making the platform kinematic would really affect.. any of this logic
just that you'd have to retreive/manage the velocity differently
but again - leave that for later
focus on the actual issue
have you debugged the velocity applied when you first get on the platform
what do you mean when you first get on? i don't have extra logic that handles the frame you get on. do you mean about how the last platvel will be zero before the player gets on? also that maybe an oversight but it's not the main issue rn.
{
string json = "";
// Open file dialog to select JSON file
IOManager.LoadSpellsFromJson(json);
}```
Very simple snippet
consider a platform that's moving at constant speed. deltavelocity is always 0.
where you do apply that speed to the player initially when the player gets on the platform
it could be with the lastplatvel thing
or it might be the GetPointVelocity you mentioned?
at this point you're just being cryptic, just share the code so we actually know what's going on lmao
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Unfortunately unity does not have something usable for this outside of the editor. You can use the win32 API to do this or a third party cross platform file picker
Raw C#
i'm going to make a thread and show my code ok.
where's the file picker
Director Class is what is used to create custom file pickers
they asked for the windows system dialog though
Awh ok!!
I'll give this a look
so, i rewrote the script, now it works fine only if the og material is transparent and not opaque, so what i have done wrong?
https://paste.myst.rs/kvo0da4d
a powerful website for storing and sharing text and code snippets. completely free and open source.
maybe i forgot smth
Absolutly Greate, Thanks Again!
@tulip stag https://gist.github.com/cdanek/16d6d8e805b87a757863a680b7f88803 - I wrote this a few years ago but it works pretty well for me since figuring out the comdlg32.dll bridge is a bit of "wasted learning" (ie, learning that's hard that you'll do once and forget about.. as I have) for most people
Note that this was for local use - ie, not public facing. If you're planning to give something like this to users it might need some more bulletproofing and error handling.
Good old win 32 com
imho this ought to be something that exists somewhere in the unity API.. seems like a file selector is pretty common for apps (maybe there is one on asset store 🤷 )
There is something for editor use but not runtime
Probably because it's only applicable for desktop
I did use a cool in unity file browser before but forgot it's name
File browser on ios/android seems useful too though.. maybe not often for games but certainly for "apps"
Hey, im trying to implement my Camera System for my First Horror Game. I dont understand why the Lean Effct dont work? can it be that the HeadBob overwhrites my Lean Effect? and how do seperate them? how do Unity Devs do that?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
use the large code blocks section
how can i use it?
click one of the links, paste your code there, hit the save button, copy the link here
Okay!
https://paste.mod.gg/epvjbxsubsft/0 here is the Link
A tool for sharing your source code with the world!
thank u Chris
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
you never use targetRot anywhere
you're only assigning to it. you aren't using its value anywhere
ahh i only defind it but never used it
Yeah i dont know why i dont saw that, Thanks u Again!
just inexperience, you'll learn to check for that kind of stuff as you get more experience
yeah, i will give my best. I learn everthing more about code
how bad is it to have 31k tris and 95k verts per chunk in a procedurally generated open world? (16x16 units)
with 16 chunks thats nearly 300k tris and 1mil verts
You'd have to test that. No way to tell; especially without the environment models . . .
okay thats 400fps with ease on my 2070 super
thats not even that bad
except id have to render or atleast load many many more for a viewdistance that isnt equivalent to minecraft on a raspberry pi
i'm researching reference types, in particular, classes, i already know how they work, but i've always wondered, when do you opt to use a class as opposed to just using a second script? or is it purly prefernce? i know that making a new script creates a new class anway, i was just curious if there are circumstances where it needs to be allotted into the same script
a class as opposed to just using a second script
this doesn't make a lot of sense. your scripts presumably contain classes (or other types if you are them)
if the distinction is "defining a class within the same file" vs using a new file, then you should prefer using a new file as that keeps your code organized better and more easily searchable at a glance
sorry for the weird phrasing, you essentially answered my question 😅
alternatively - if a class only really pertains to a single other class, you could have them nested, potentially even inaccessible from the outside, for example in something like this
public class LinkedList<T> {
Node<T> head;
private class Node<T> {
T value;
Node<T> next;
}
}
Anyone know why my sprite has another outline when I export it into unity? It happens as soon as I put it in unity so the settings are all default.
this is a code channel, ask in #🖼️┃2d-tools
ok thanks
I don't know why this is happening but out of nowhere whenever I set an object to the player it starts floating away whenever the player moves, this wasn't an issue before and only started happening after updating from the security risk.
Send script for the object plz
using UnityEngine.PlayerLoop;
public class Pickable : MonoBehaviour, IInteractable
{
public Interactor player;
public BoxCollider Collider;
public Rigidbody rb;
public BaseScriptableObject objectData;
private bool isHeld = false;
public bool Interact(Interactor interactor)
{
player = interactor;
isHeld = !isHeld;
if(isHeld && !player.isHolding)
{
transform.position = player.pickupLocation.position;
transform.parent = player.pickupLocation;
transform.rotation = player.pickupLocation.rotation;
player.isHolding = true;
rb.isKinematic = true;
}
else if (!isHeld)
{
transform.parent = null;
transform.position = player.dropLocation.position;
player.isHolding = false;
rb.isKinematic = false;
}
return true;
}
}
Maybe some funky interaction between setting the transform before setting the parent?
Try swapping the order for that and if it doesnt work im not too sure
it was not an issue before, this all started happening after I updated from the security risk editor
you're not using something like Rigidbody.MovePosition to move the object, right?
no literally just setting postion and parenting
i see that in this component. i mean in a different component. because MovePosition is how you move a kinematic rigidbody so simply making this object kinematic won't stop that from working
I can send the interaction code as well if that helps
parenting a rigidbody to a moving object would count as moving via the transform wouldn't it 
which would be a physics desync
so making it kinematic just does nothing?
no, it certainly makes it kinematic. whether that has any impact on preventing your existing code from working on it is unclear because you've not shown how you normally move that object
it keeps the rigidbody from falling due to gravity
they're letting the parent transform move the object's transform
this is how I move my player, don't know if it affects it or not
{
Vector2 input = movementControls.action.ReadValue<Vector2>();
Vector3 finalMove = new Vector3(input.x, 0, input.y); //Converts 2D movement to 3D
if(canMove)
controller.Move(finalMove * playerSpeed * Time.deltaTime); //Moves character by world time
float smoothing = 10.0f;
if(finalMove != Vector3.zero)
{
transform.forward = Vector3.Slerp(transform.forward, finalMove.normalized, Time.deltaTime * smoothing);
}
//If Player not grounded apply gravity
if (!controller.isGrounded)
{
controller.Move(new Vector3(0, gravity * Time.deltaTime, 0));
}
}```
you should not be calling Move more than once per frame, btw.
Also shouldnt you be using fixedDeltaTime for this kinda stuff?
you shouldn't check isGrounded to apply gravity either, you kinda need gravity to check for the ground continuously
no, that's a charactercontroller, it's framebound
(also might want to add normalization to the input)
i'm getting off track, these issues can be fixed later 😅
and what's weirder is before it worked perfectly, didn't change any code relating to player or objects
and even if it weren't a CC, deltaTime returns fixedDeltaTime when accessed in FixedUpdate anyway so the distinction would mostly be pointless
that was likely by coincidence if i had to guess
im pretty sure (though not 100%) that it's kinda a case of this
I used to just set the position every frame but that was dumb in so many ways
it's fighting the physics engine, but the physics engine tries to cope
and it was surviving the other times you tested, but not now
not sure if it has to do with the update though
if only I could disable rigidbody during play
i did find this... maybe could work as a bandaid?
https://discussions.unity.com/t/attach-a-kinematic-child-rigidbody-to-a-parent/916865/8
apparently joints might help? im not familiar with those, but might be worth looking into
omfg
I got it
I did change something on the objects
I set the rigidbody interpolation to interpolate
setting it to none fixes it
i mean for most cases i believe it should be interpolated
im frankly scared to find out why that "fix" works lmao
and we're absolutely certain that there's no MovePosition calls happening on this object during this time frame?
Can somoene can help me … like tomorrow evening bcz i started today and i am really lost …
would that be a line of code?
Thats when you ignore the red flags and move on untill you have to redo the entire thing in the future XD
!ask 👇
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
then no, I don't remember typing anything of the sort
so in Visual Studio.... if I do Rename, it seems to impact the same name on multiple files? Is there a way to easily change all the names only on the same file?
For example if I have the same name "bottomAd" in Script A and Script B.... but I want to change "bottomAd" to "botAd".... it'll apply it for both Script A and B even though I only want it for Script A
also what is the difference from interpolate and extrapolate because extrapolate works but interpolate doesn't
make sure your ide is configured so it can follow references i guess?
you miss understand, its updating the var where its used smartly
so use find and replace to not do this
you could just find&replace for more control (checking individual instances) i suppose, but vs should be able to track references accurately
if the ide is properly configured it should update that specific variable in all places used and not anything that just happens to have the same name but is unrelated
surely it renames the references in both files, because those are all part of the same reference. It wouldnt allow for a partial rename because in the other file it'll have a broken reference
Yea exactly
ive seen it just do a find & replace all in contexts where it can't figure out references (uninitialized project kinda deal)
Hm thankfully i havent had it be that dumb yet
Something I wonder is they say that A and B have a property with the same name. Suppose that the properties dont actually reference each other, would visual studio then have ctrl+r+r rename both of them?
it would not if visual studio is properly configured. whether it would do that when unconfigured is not entirely clear
Hey everyone, Im new to unity and Im taking this tutorial: https://www.youtube.com/watch?v=7PYREq2OmHA
Would someone know why my wheels are spinning in circular motion and not adhering to the parent (Car).
please se video attached.
In this video, I walk you through how to create a complete off-road vehicle controller in Unity from scratch. We’ll build everything step-by-step, including the car setup, physics, custom wheels, suspension system, and working skid marks.
📁 Get the code & project files, and other links:
GitHub Link: https://github.com/SimonVutov/Simple...
hello guys im hoping to get some help with a small bug thats driving me insane 
i made this character controller script and attached a cinemachine free look camera to the player
everything works fine and dandy but when i move laterally left and right, the character doesnt go in a straight line but like curves slightly (look video)
ive been struggling to find out what is causing this
https://paste.myst.rs/jjx6iut7
a powerful website for storing and sharing text and code snippets. completely free and open source.
the behavior is possible, but maybe not put into that feature
i remember using rename in vs code with c++, it brings up a window letting you select which instances are renamed (which is just by reference by default, but it shows instances even in commented code)
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
my bad ill fix it rq
A tool for sharing your source code with the world!
Hello, I am new to C# and learning is going smooth. However, I am curious on how I should handle cleanup when it comes to lists and arrays of objects? For example, if I instantiate a prefab a few times into a list, do I need to clean that up, by destroying them and clearing out the list, or let the garbage collector handle it? I don't think Unity will tell me if there's a memory leak (I don't know that for certain).
Hi guys, I'm currently working with jobs, and I have an issue.
Here is the problem :
I have a quite big data input that is stored in a class, this class (in the job) is only used to read data
The job returns values.
However in jobs, you can't have managed variables (ie, classes)
I don't want to transform this class into a struct because its used elsewhere where I would like to preserve references. And also because I don't want this big data copied over and over.
Is their some key words or stuff like that where i would be able to use that class as readonly without reworking the whole code ?
Or some other ways ?
Use c# threads instead
It's in general very difficult to create a true memory leak in C#. You don't usually need to worry about that, just do what the game needs to do anyway (i.e. destroy gameobjects that aren't needed anymore) and let the garbage collector do its thing. When a scene ends everything inside gets cleaned up and while working within a scene it's best to reuse things instead of destroying and creating new stuff
It is a pain that with how jobs are designed we are restructed to blittable/unmanged types even without burst
I had counter suggestion for Nitku xD
Well, its generally good, but sometimes its hard to make it work as you want.
Well you asked for options and that is one option, up to you to figure out which one is the best
The job system is better suited for unity related components/apis but general data doesn't have to use it
UniTask makes it easy to use a thread pool and await results on the main thread
yup ^^
That's also why i'm asking this rn, i've dug a lot into the job system and I don't know all of the keywords and stuff like that.
I vaguely remember some Ref readonly stuff for things you don't wanna copy (mostly because the guy worked with ECS too)
But i don't know if its a good path to go
its used elsewhere where I would like to preserve references
Just curious what you meant here, struct store the pointer address of reference types in struct
In short, i want to use the job system to generate chunks meshes without running them in the main thread. And then instancing them in main thread
Ah right then the job system may be best as I know there are structs made for this. I guess you can make a struct to hold this input data
That's the issue, I have a class named Chunk which handle all the voxel's data and will handles some triggers
It will be called if the user clicks to add or remove voxels for instance
In the same time, i have to send the chunk to the mesh optimization algorithm to be able to work with. Because a chunk is 50x50x50 voxels, copy/paste using struct (value type) can be bad for the memory
And because its used in jobs, the burst don't want unmanaged types anywhere in the algorithm
yea I mean, if it was just data (normally value types) why not have it as struct
you can use ref to avoid copies in some places
unusable with async though
C# is pretty smart when it comes to memory management, afaik it was probably a core principle for the language when they designed it.
Unless you get into the more technical aspects of managing data, think of memory management more like "objects (every type,class in C# is an object) , really only exist if and whenever you need them too" https://learn.microsoft.com/en-us/dotnet/standard/automatic-memory-management says
Automatic memory management can eliminate common problems, such as forgetting to free an object and causing a memory leak, or attempting to access memory for an object that has already been freed.
C moment
Because its a big data, having a struct would mean each time its passed to another function, the data is copied, so if the chunks have a nativeArray inside to match the job system requirements, it would overload the memory quickly
Also, the GC probably knows more than you do, so don't try to outsmart it.
you can mess things up, but eeehhh, i dont think its ever become a concern for me in all my time using c# (im no spring chicken)
That's the kind of things i searched, i just don't know how it works
Well unless c# can do copy elision but I doubt it
when using ref we can force a reference to be passed to a function instead of a copy.
if anything the only thing that i have had to deal with in C# is the ability to make infinite loops that hang the process 😆
Thanks for the replies. I am comming from a ancient history of c++, where if you make an object and use it, you have to free it. Also more recently, my coding skills have been with Python and variants of it. Another thing I noticed, is that when I run my game and close it, the memory in task manager increases for Unity, which makes me wonder; but it gets all cleared out when I fully close everything.
Luckily this is all done for you... the only time its an issue if you create an inifinte loop the memory will keep growing until it crashes (unless you forced Task End early)
C# is pretty smart when it comes to memory management
Yes and no, it has a GC which can "easily" be passed and have a lot of leaks, that's a thing I both like and dislike with C# compared to C or C++
Its managed automatically but its not perfect nor intelligent, the compilation doesn't provide optimisation in these areas.
Compared to C and C++ where you have to handle all, but at the same time you can pinpoint where the leak is from
A basic thing we can't do in C# is static size arrays, you can't have a fixed sized array, it will always be handled like a variable size. Technically you can use Span or stuff like that but you'll have to explicitly write unsave and also its a pain to work with
🥹
You can still cause memory leaks, is just very very slim
(mostly when dealing with events and not cleaning properly)
Thanks !
Thankfully we can do things like stack allocated arrays with span but tis a shame its not easier
If arrays were dynamic, I wouldn't need List 😛
Lists are just arrays anyway 😛
Doesn't matter, clean up is the same if I have to handle it. It's only a concern to me when a scene changes or app closes.
wait till you learn about manged shell objects
Vector3 moveDirection = (camForward * _movementInput.y + camRight * _movementInput.x).normalized;
your movement is dependent on the camera, you need to seperate these 2 out
I am also trying to understand another quirk. While running the game (roll a ball), I notice dips in the fps which is capped at 60, whenever a instantiated object is deactivated and reactivated (i am using pooling). But I noticed the exact same thing when I was creating and destroying prefabs. So is using activateSelf creativing over head similar to creation/destruction?
no there should not be cause all the items are loaded into memory
its also hard to judge exact numbers in the editor, the editor has overhead and even interacting betwen windows will cause spikes up/down
If you want accurate numbers you should always run it on a build
I'll have to figure out how to make a debug build (that shows info), thanks. I just thought, because prefabs were being activated/deactivated and moved, that it was causing it. Maybe it was a coincidence.
yeah maybe.. I'd keep in mind the script itself can still have runtime operation that could cause other garbage
complete coding noob following the programmer pathway here:
managed to get WASD movement for an isometric controller (script screenshot attached)
but my 'player' phases through solid objects with enough pressure,
even though it has a collider (tested with both box and sphere presets) & rigidbody.
additionally, i've also been unable to get normalized vectors to work (prevent character moving faster diagonally)
things i have tried:
- change the character collider from sphere to box
- increase invisible bounds' collider thickness
- make the character move slower
- implement player control the rigidbody way, using AddForce (specifically Velocity.Chang) & increase linear damping to reduce 'slipperyness'
- but Input.GetAxis + transform.Translate still feels the best for what im trying to achieve, just a simple 8 direction movement with no jumping
well Translate will phase through solid objects no matter what you do with colliders
you're literally bypassing the physics
oh that seems right
sucks though because rigidbody feels so unnatural and i haven't been able to get a good combination of parameters to fix it
you get a weird time where it does collide cause it has time to "catch up" from the physics scene
should i move back to rigidbody AddForce(Vector3, ForceMode.VelocityChange)?
you could probably use .linearVelocity and get a similiar feel to Translate
I think of translation like warping to the point, so there is no collision happening, you're just there.
remember the physics are running in a separate scene
normally PhysicsMove/Simulate => Pass information to the Transform
if you do Transform -> Rigidbody you get weird inaccuracy because the physics is trying to catch up
threads got nothing to do with it
is just a "separate scene"
there is even a class for it
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/PhysicsScene.html
how could i do that?
i don't see a force mode for that though
thats because you're overriding any force types / mass and other external forces like Drag
so there is no "force" its just "bam start moving now idc how much you weigh, how much friction the floor is etc"
idk havent done this kinda thing before
but you can see your camera rotate left right abit which affect your left right movement
youre right, i wanted the player to move with the camera
ill just try a bunch of stuff
maybe stop rotate the camera when you move left right like that
so it's the default mode when you don't specify anything?
just set the x move to the player transform.right ?
or maybe
camRight.y = 0;
should be
camRight.y = transform.position.y
yeah i think camera forward is enough
excuse my stupid ill try that right now
yea collision solved
BUT sideways AND diagonal movement is still way faster
camRight * transform.right
cant multiply transform.right with camRight
and setting the camright to that just makes my character jump repeatedly lmao
have you tried clamping magnitude like ?
move = Vector3.ClampMagnitude(move, 1f);
no I meant
transform.right * _movementInput.x
nope
but this is what i wrote to get the correct movement in relation to a diagonal camera
moving transform twice is first i have seen
usually you combine the direction and move that direction
..oops
yeah you outta combine those
yeah no that makes it so when rotating my camera the player just keeps going in that initial direction
grtrrrr
ill just turn off x axis damping for now i cba
its the slight camera follow that messes it up
ill need to rewrite that part to be independent it seems
if you rotate the character already then left right dont need to depend on the camera rotation
when they dont then i just end up going in one direction, it only rotates the player when moving forward
wait shouldnt this be
Vector3 moveDirection = (camRight * _movementInput.x, 0, + camForward * _movementInput.y).normalized; ?
ill give it a try
alright im gonna go watch some more tuts
thx for da help
i love getting stuck on the smallest things!! truly
better than something complex where you take days to figure out 😭
oh i didn't even see this
how?
also yeah you should only call a move method once
idk havent dont this movement based camera before i would just spam a few tutorial and see what work then comeback later
takes me back to a boss i made for an elden ring clone
absolute nightmare
how does one merge movement directions and still specify where to go with what keypress
the example is similar to what I sent above
finalMoveDir = new (moveHorizontal * speed, 0, moveVertical * speed)
add sidway and forward ig
whered you get the 0 from
the Y movevement should be 0
vector 3 is (x, y, z)
if you put another number it will move up/down
Cannot convert initializer type '(UnityEngine.Vector3, int, UnityEngine.Vector3)' to target type 'UnityEngine.Vector3'
i hate vectors ive always hated vectors
hey in a top Down Game, how can i Attack in Diffrent Direction, With the Mouse? What is the Logic behind?
wait can you show what you wrote exactly
you rotate and you shoot
like top right, top left, down left and down right
Vector3 moveDirection = (camRight * _movementInput.x, 0, camForward * _movementInput.y);
put = new ( etc.
get the direction from (mouseWorldPos - currentPosition).nornalized
that works too, you can omit that in newer versions of c# 9 +
Vector3 moveDir = new Vector3 (
Vector3 moveDir = new (
var moveDir = new Vector3 ( ```
these all work
Vector3 moveDir = new Vector3(camRight * _movementInput.x, 0, camForward * _movementInput.y);
Argument type 'UnityEngine.Vector3' is not assignable to parameter type 'float'
interesting
where did the float come from
ah the .x
is a float
v3 is 3 floats
then im confused at why im getting the error
what is camRight a float or v3 ?
camRight and camForward are all v3s
oh and then i send this final direction to the ClampMagnitude method?
ahh thats why..
i thought they were floats mb
so im cooked?
then you just need
moveDir = camRight * _movementInput.x + camForward * _movementInput.y);
myb I'll take a look rq on a computer now I'll better be able to give a solution, was hard on mobile lol
yea
thats what i had earlier haha
did ya ? I think I accidentally clicked someone elses link lol
can you send the codebin link to it
a powerful website for storing and sharing text and code snippets. completely free and open source.
this is the original code i came here with
and heres the video if you havent seen it
but yeah i noticed when i turn off damping in the cinemachine camera it stops doing that so its gotta be something with my cam setup
weird..are you sure its not the lookat
honestly its just some code i grabbed from a 50 second short showing how to do billboarding
wait nvm i thought it was the sprite tilting but that shouldnt affect the movement cause its seperate
i wrote the rest of the movement based on another project of mine
but its the first time i use cinemachine
so i dont know the lil quirks
does it work fine if you remove transform.Rotate
Waut that's how it technically works? Damn
interestingly, the behavior doesnt change at all
its definitely got something to do with my billboarding
since the camera damps, and the sprite always looks towards the camera
it just conflicts
lowkey might have to write my own camera script 😮💨
I think it might be cause of conflicting rotation
im 100% sure thats the case
as you move your char left - right your camera is rotating too
but your camera is trying to fllow player at the same time
so its a weird circular thing going on
im gonna need to find a different solution or turn off x damping entirely
ya I can see why the damping is causing that
man guys I need some very specific help, i used a character controller to make my guy move, and now Im making moving platforms, and now I have no clue how to make my character stick to the moving platforms
needs specific help, doesnt ask help in specific/exact way.. 👍
Sorry, about to drop my code
just sorting the paste out
A tool for sharing your source code with the world!
I believe the issue lays with how character controller moves in world space, and as a result anchoring movement to a locally moving object is kind of difficult/or I am not seeing a hacky fix before me
btw with character controller you can normally just parent it to the platform
Parenting?
make the player child of the platform
Ahhh ok, I will see to it
rider is generally considered "better" (mostly because of its better UI and analyzers), but they are both tools that get the job done so use whatever you like
thank you, rider it is
just note that rider's licensing is more restrictive than visual studio's is. you can only use rider for free if you are working on a non-commercial or open source project
So I could attach the character to become a child of the platform in the code when the player makes contact with the platform?
Huzzah!
yes
use a script OnTriggerEnter to parent and OnTriggerExit to unparent
I used simple raycasting to pass on velocity
might be hackier than needed but it works
whatever works
yessir, I feel like a bethesda dev already!
I will test parenting tho just to get a proper grip on it, since this seems much easier than the hoopty way I did it
depends on the game, passing velocity is the physics way normally
Character Controller is basically kinematic so you can get away with parenting also
Gotcha boss! And yeah thats what I thought as well and Im glad it worked out
Also worth noting that in general getting player controllers to work nicely on moving platforms is one of those things thats just really tricky to get feeling fantastic
If your struggling that's not necessarily a you issue 😄
hi i have another problem
so my jumping and moving works pretty well
only thing is that theres a bit of momentum
like it keeps moving even after I let go
how do i stop that from happening
depends on whats causing it, without at least seeing your specific setup how can we tell for sure
Question if I choose to simply not await an async method will it still return a value or will it be null since I didn't wait for it to finish?
should i send all of my code?
if you mean doing something like var x = SomeAsyncTask(); instead of var x = await SomeAsyncTask(); then your variable will contain the Task<T> rather than the result of the task
Doesn't that depend on the return type?
it would have to return a Task<T> if it were awaitable and returning a value (or if relying on unity's built in stuff, return Awaitable<T>)
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded())
{
rb.linearVelocity = new Vector3(0, rb.linearVelocity.y, 0);
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
private void FixedUpdate()
{
Vector3 move = new Vector3(0, 0, 0);
if (Input.GetKey(KeyCode.W))
{
rb.AddForce(Vector3.forward * force, ForceMode.Force);
}
if (Input.GetKey(KeyCode.S))
{
rb.AddForce(Vector3.back * force, ForceMode.Force);
}
if (Input.GetKey(KeyCode.D))
{
rb.AddForce(Vector3.right * force, ForceMode.Force);
}
if (Input.GetKey(KeyCode.A))
{
rb.AddForce(Vector3.left * force, ForceMode.Force);
}
}
public bool isGrounded()
{
return Physics.Raycast(transform.position, Vector3.down, 1.1f);
}
heres my movement code
assume everything else is initialized fine
so no matter what the Task<T>/Awaitable<T> is returned by the method. then it's just a matter of whether that has been awaited or not
Yeah, you're right. The compiler would throw an error at non task or void return types.
moving via forces means you need some counteracting force like linear damping (aka drag), friction, or literally an oppositely applied force using AddForce in order to slow the object down. not enough of that counteracting force will make it take longer to come to a stop
you probably want to move by assigning the velocity if you want entirely snappy movement with no momentum
like .linearVelocity??
and if you go that route you'd want to consider using GetAxisRaw rather than polling the keys individually
but then jumping doesnt work properl
don't overwrite the Y velocity then
it wont use the momentum
oh
how do i do that?
do i just to rb.linearvelocity.y?
SHITT i didnt think of that
can you access variable.Result and read the return value of the method if you dont await it?
GetAxisRaw only works for x and y though
right
yes, that would block until the task is complete though
or am i tweaking
it's the same buttons though
thank you
"Horizontal" a/d - left/right arrow
"Vertical" w/s - up/down arrow
Input.GetAxisRaw("Horizontal") would be left and right
also using GetAxisRaw will allow you to create a Vector3 from your input that you can normalize or clamp the magnitude of to prevent moving faster by moving diagonally
hello, can you help me about unity ai. i cant use it
just asking how input buffering is implemented
trying to set up an attacking state and i have the input set up like so, but i want this to combo into a seperate light attack animation as well without having to press it at a specific time for it to work (as far as until the initial animation ends)
im just wondering how most people do it? timer with a bool? or like..whar
if my question isnt specific enough ill try to elaborate more, just kinda tired rn from running around all day
im using isAttacking as a bool for my walking state and targeting state to determine if they can transition into the attacking state or not, in case that causes any confusion
finally fixed my jump
I know the basic structure of C
C# cool
There are probably many ways you can implement combos. A simple idea I can think of is:
- have a combo manager that keeps a list of the recently recorded inputs.
- record the time of the first or last input in the list(design choice).
- have some kind of time threshold. When the time since the recorded time in previous point exceeds the threshold, evaluate the list of inputs, if the sequence matches any of the combo definitions, perform a combo, otherwise just the last attack/input in the sequence.
- after that clear the list.
There might be many nuances that you'd want to adjust or change in that logic.
thanks, i already have an attack index set up that has a list of the animations for the attacks, but i have yet to set them up or try to connect them. Hopefully i dont get overwhelmed by this but gotta learn stuff somehow
https://paste.mod.gg/jvulnnsfgjqj/4
Once again tearing my hair out because i dont understand whats wrong. Current Error being thrown is "Invalid Layer index -1" so i initially thought "oh so it doesnt like negative ones" so i removed all them from the code yet it still threw the same error???
ive fiddled with it for the last hour but i cant even get a compiling error out of this code anymore, it just hates that -1 and i have no idea what to do im sobbing
A tool for sharing your source code with the world!
hi i would like help with something
is there any way to rotate the camera when i collide with something?
what im trying to do is in the objects onCollideEnter() method Im checking if the player collides and if it does then turn the camera
but im not sure how
Those CrossFade methods have a default value of -1 for layer https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Animator.CrossFadeInFixedTime.html. If you don't provide a value, -1 will be used.
But how does that affect my issue? It says the -1 is invalid.
Should I remove the = -1; from the ComboStateIndex in Attack.cs
I’ve already tried that though so that can’t be it
I’ve shut my computer off for the night anyhow, tired and don’t feel like ruining my scalp anymore with how much confusion I’m developing
It’s probably an issue with my assignment of values in unity knowing me
Hello everyone 🙂
How to learn unity
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
you'd need to show the relevant setup/code. a script for growing plants and an object sliding sound completely unrelated so id assume you just have some rigidbody business going on in there
Does anyone use Unity Dialogue system by Pixel Crusher here? Would anyone be able to guide me on how to create a dialogue flow where.
The user speaks to the NPC. After 1 turn, the custom dialogue panel will open the panel to my custom survey.
Depending on whether the user has completed the survey / close the survey, my dialogue continues and the different dialogue conversation depending on whether the user has completed or closed the survey panel.
my visual studio randomly just vanished from my pc and so I installed Visual Studio but its not showing correctly in VS. does anyone know how to fix this?
could you show the full screen of visual studio?
I know the problem. You gotta download the purple visual studio. not the blue one.
When you do get the purple one tho. make sure to check on the unity addon
and uninstall this version
Im colour blind, is there an obvious difference between the two?
Ah I installed VSCode not VS?
oh god, yeah, their logo's as far as i can tell are identical
one simple way to tell the right version is to check if there's this assembly or mischiveous text on the left top corner
please do not send random .exe's here
the logos are different
left: visual studio
right: visual studio code
Sorry... just thought it would be convenient.
got careless.
fwiw, vscode does also work with unity. there's a bit more setup, but it's mostly a one-time thing.
it has less language/unity-specific features than vs, but if you're used to vscode you can use it just fine
also note that vs and vscode are not different "versions" of the same thing, they are completely separate apps.
blame microsoft for the confusing naming 😢 (it used to be worse, too)
Worse? how?!
there used to be another, "visual studio for mac" that wasn't a port of visual studio for mac, but actually just a different app with the same name and logo
it was deprecated/sunsetted a few years ago though
3 very different apps with "visual studio" in the name and similar logos
ah, makes sense considering how many apps microsoft has killed
now that i think about it.
Okay im back to unity after a very long time last i was using it the player input script was just added i used it and all worked fine but i didnt stick with it cuz i felt like the code approach was more controlling and better but now when im back after a long time i see people are using player input only is there a specifc reason as to that?
the new input system is intended to replace the old one and emulate it if needed, while also having support for/flexibility to do the sort of things you eventually need in a real game like key bindings
hmm understandable thansk
You still have the code approach with the new input system . . .
Uhh, both images have it . . .
yea im blind
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
is this a good way to handle jump and stuff?
[SerializeField]
private InputActionReference move;
[SerializeField]
private InputActionReference otherMove;
private Vector3 _moveDirection;
private Vector3 _otherMoveDirection;
[SerializeField]
private Rigidbody rb;
void Start() {
}
void Update() {
_moveDirection = move.action.ReadValue<Vector3>();
_otherMoveDirection = otherMove.action.ReadValue<Vector3>();
}
void FixedUpdate() {
rb.AddForce(_moveDirection, ForceMode.VelocityChange);
rb.AddForce(_otherMoveDirection, ForceMode.Impulse);
}
I wanna use monocraft (minecraft) font for visual studio code but it ended up looking like this, any fix?
(it's already applied)
This is visual studio community not code, which may slow your search
so I can't use it?
It should work, dont use community for quite some time so cant help
Just saying if you were looking for fixes for code, it wont be the same
oh okay
how can i access the linear damping from a rigidbody in code?
okay nvm it seems like my ide isnt able to fetch the methods
thats weird i can access the update and fixed void functions pretty easily
Wdym it can't fetch the method? Are u using the right rigidbody class?
https://docs.unity3d.com/ScriptReference/Rigidbody-linearDamping.html
i meant my ide itself coudlnt do it
like there was no auto complete when i was like rb.
Are u using vs code?
hi, i have a problem with changing materials through scripts, the problem is i have this script (https://paste.myst.rs/kvo0da4d) that makes the material of object blocking view from camera to the player's model transparent, and if the original material is transparent it is working as intended, but if it is opaque it just doesnt show up in the game until i manually change any setting of the material (it is still changing from opaque to transparent in material's settings, but the changes are not visible in the game)
a powerful website for storing and sharing text and code snippets. completely free and open source.
which code path is the one not working? a bit hard to grasp without debugging 😄
I remember having the same problem with an object. I just set it to transparent with no transparency, but believe you don't want to do that. It was Unity 2021.3.
that is a bad idea to do on plenty of objects 😄
I can hear the profiler yelling from the corner
Steam Game
I'm currently working on a steam multilayer game
I know the basics of Lobby , relays , NGO.. but like I wanna get the steam name of the player and after that just use it so on.. i searched the web for some guides they use mirror and idk what i don't wanna go into something not that good after all just need the way to start..
Any suggestions?
Are you asking how to get the steam name in Steamworks.NET?
yeah , could I just stick to Lobby and relays and just get the name from Steamworks.NET?
you have to get the steam info from steamworks, and Steamworks.NET is one package you can use to do so. none of the other packages you mentioned have anything to do with steam (at least directly)
https://youtu.be/7Eoc8U8TWa8?si=1rW8ZxBe-LGBXioq
would this Vid help me so?
In this video I will be showing you how to get your unity project set up. How to host lobbies and how other people can join them. In the next episodes I will be going over how to display users, sync movement, create character cosmetics and much more. So make sure your subscribed to not miss out. :)
------Tutorial Links------
Mirror: https://ass...
why does it not log anything?
presumably the errors are causing the code to not work
!input 👇 and stop hiding your errors
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
no errors here tho
is this even during play mode?
exactly
you do know there's not only a search bar, but there's also several folded categories there, right?
but this says its inside player only
it is in there..
and even the search bar leads to player
yes, and inside the Player settings which you are looking at, you have FOUR folded groups of settings
maybe in "Other" settings.. i wonder..
maybe in some of those other Menus that u havent expandded yet
its interesting how many people now have this input issue but glad they still changed the default
How are u applying it?
i made the default grav to -18 from -9.8 in project settings
feels right i suppose
what even is this
That changes the entire world's gravity for all objects
-9.8 is the real world gravitational acceleration.
It may fix your problem for now but may cause more issues if u want the game world to obey real world physics
A texture in your project does not have the imagery data to render
I think this is the editor problem
I've been trying to fix this problem for 6 hours.
what did you try to fix it
also probably not related at all to #💻┃code-beginner
Looks like a common issue for new editor version?
- Install different versions of unity
- Search on the Internet
- Run the program as an administrator
- (What did you regret) ask the AI
- Deleted the library folder
I don't remember what else I was trying to do.
I have installed all versions of unity
where did you install the editor at ?
C:\Program Files\Unity\Hub\Editor\6000.2.8f1\Editor
is this a new project ? what operation did you do when this error popped up ?
Yes, this is a new project. What action did I take that caused the error: Created a project
You tried a plain ol PC restart?
yes
I've tried reinstalling the project, and I've tried reinstalling unity.
wdym "reinstalling the project"
and which versions did you try
I deleted the project and then created a new one
all
It's likely tied to Visual Studio. Even if u install different editor versions
what is "all"
Unity 6.2
Unity 6.0
Unity 2022.3 LTS
Unity 2021.3 LTS
hmm then idk most likely something wrong on your PC... maybe permission issues or something not launching.. Check the logs and see what they say exact
!logs
Editor logs
Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log
Unity Hub
Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs
you want to check "Editor logs"
if its too much stuff you can delete them, initiate another error then check logs so you get a more "clean slate"
It's a bug?
I'm on mobile lol I aint downloading all that.. check it and see any indications of issues with more recent timestamps to when you launched it
aha
@hoary tanglehi
did you tag yourself to say "hi" to .. wat? also no offtopic
no it said on the green leaf next to my name to say hi
when I clicked it, it tagged me
then I addded hi
because it told me to say
hi
so that was why i
did that
we can do without the spam
I can see that
bee_backend: error: Couldn't launch process
...
GetLastError: 5 (0x00000005)
I usally like type many messages because I remember what I should say after I've typed done already
can you refrain from spamming the channel with further offtopic crap idc about ? thanks
ok
which platform are you on ? btw this should probably be threaded and in the correct channel #💻┃unity-talk
Windows 11
How do I make a simple movement system that doesn't glitch thru thin walls?
When I made my movement system a long time ago, I just went into walls and kept glitching out when walking against them.
How do I make an actaul good one? Just W = Forward, S = Backward, D = Right, A = Left and Space = Jump.
making the colliders move proper
making sure the character is moving respecting physics
- moving via physics instead of direct translation
...capsule collider?
Yes the capsule collider
What is translation? What is the diffrence
so did you put a rigidbody and move it with its velocity
if we just change transform.position (known as translation) we bypass physics and thus can easily move into walls and other colliders
We need to move via physics forces, velocity changes or using the character controller component to obey physics
https://docs.unity3d.com/ScriptReference/CharacterController.html
I would check for any type of antivirus blocking and all that..
also if you wish to continue make a thread in #💻┃unity-talk
I just did playervector + vector3(1, 0,0) or something like taht
Yes that was what I did
yea thats direct translation, add force/change the velocity
Why is it called translation
well you're skipping the physics, you're not gonna get proper collisions
smart people said so
colliders are physics
Windows defender? :?
Yes I understand now, I will use forces instead. But why is it called translations?
It's like attaching a rope to your object and drag it instead of teleporting it to new position each frame
Yeah
its a Term in geometry iirc
translating / shifting the object's position in 3D space without altering its orientation or size
there ya go ^
Thanks I will look at that
That seems logical
Okay now I know
How do you use forces then in Unity 6?
Someone said it with more details, but I'm just gonna list the methods u can use:
- Use a dynamic rigidbody and
AddForce() - Use kinematic rigidbody and set the velocity instead or
MovePosition() - Use character controller and
Move()
MovePosition does not respect colliders
other physics bodies will respect it, and its motion but not other way around
in the tutorial FPS micro game the hints show a hand,, that is in unity 2020, i have unity 6.2 i cant seem to progress its not clear what to click on,, the animation shows clicking on the hand,, which is now the pan tool i think but that does on unstick the tutorial
For 2d rigidbodies it does but for 3d no which is kinda annoying
ohh yeah those interesting quirks of 2D engine.. hella weird.. also probably related to the fact that kinematic rigidbodies in 2D have velocity and in 3D they just get set to 0 every time
What is the diffrence between a kinematic rigidbody and a normal rigidbody?
Does MovePosition add a force that pushes the object, or does that just do what it looks like when you read it. Just directly move it to a position in the world?
I responded to the wrong person
Now it's right
Kinematic in a nutshell is a body not affected by external forces
Its probably actually due to 3d and 2d not using the same physics engine (box2d vs physx [default])
there's not really a "normal" rigidbody - every one has a body type, either dynamic and kinematic.
dynamic rigidbodies are simulated, they respond to forces and collisions, and they drive collision detection
kinematic rigidbodies are not, they represent things that interact via physics but aren't themselves simulated through physics
So basically if something comes at it with lightspeed and hits it. Nothing will happen?
correct
Okay thats is good to know
Thanks
thats why most character controllers are kinematic, you usually wouldnt want everything hitting your player pushing it
moving platforms, etc. all very viable for kinematic bodies
Aren't moving platfroms more like not viable with kinematic bodies? If you stand on the moving platform, the rigidbody wont makes your character follow it?
Or do you mean it's very viable because you can move the player on your own with code, and simulate the physics better that what the dynamic rigidbody would do by itself?
with character controllers it gets complicated a bit, but it will push another body up / down per say but not let that object stop it from moving up / down
What is Global Volume object in the unity explorer?
similar to just using translation but its "physics conscious" and other bodies respect it
easy to lookup stuff you should use google for
is just Post Processing Volume, its set to "Global" by default meaning it affects the screen no matter what, instead of using "trigger zones" for camera
Old Post Processing (concepts are similiar)
new :
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.1/manual/integration-with-post-processing.html
Well, dynamic is just like real world objects. It obeys physics and interacts with other body types by default
Kinematic is like a blank canvas that lets u enable certain physics interactions by your own rule
For example, if u throw a dynamic rbody at a kinematic body, it won't push the kinematic body unless u let it to
But if u push a kinematic body at a dynamic body, the dynamic body will automatically react to that force
Ok.
https://www.youtube.com/watch?v=pYEAwiKFKeg
following this tutorial because its the easiest one ive found on offscreen indicatiors, but im stuck around the 7 minute mark where he says to use an edge collider 2d on your camera, because he is working in a 2d project
i would need the edgecollider to have a space to spawn my indicator, but im not sure what the 3d equivilent of this would be, as far as i can tell using the edge collider 2d in 3d does not seem to work very well if at all when im trying to attach it to the camera view
does anyone have any further resources on this or another way i should be doing this?
Support me On Patreon : https://www.patreon.com/the_game_guy
It'll mean alot to me 💖
In this video i will show you how to make a simple indicator that will point towards the enemies (or any other gameobject) outside the camera view so we can know where the enemies are coming from.
and there are a lots of ways to go about doing the same thin...
huh you probably dont need colliders for this
You should be able to just check if an object is outside the bounds of screen / camera
some like this probably https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Camera.WorldToViewportPoint.html
guys how hard is it to rewrite an algorithm i took days to make using c# so it works with a compute shader? how much time did i waste?
Depends on its complexity
As long as u learn something. Otherwise, if u just need something that works, find a tutorial
i made a marching cubes algorithm. could be squished to about 150-200 lines of code if i remove the noise etc used for generating terrain data
thats the problem. there are like none
i can this is rly easy its about finding the exact place i need to spawn the indicator in world space
in the tutorial he casts a ray from the object to the player and when the ray crosses the collider he uses that point to spawn the indicator
I mean thats also pretty easy to do it with a lil math, without physics
alr, should i just cast a ray from the object to the player and ask when the ray shows up in the camera to spawn the indicator then
another way to do screen indicators
is by using a regular canvas and converting the worldspace -> ui-space
as I said, that involves physics / colliders.. No need to use physics for that
i haven't implemented the off-screen portion yet tho
You can use Mathf.Lerp to get a point between two points Ie (left corner to right corner etc.) and see where the object is between that
how do u best convert world space to ui space is there a doc i can read
hm ok i will try this, ty
simple as this