#💻┃code-beginner
1 messages · Page 580 of 1
Instantiation is the method by which you create a GameObject
when i talk about make it an object i wanna say make it an instance of my class
not spawn it
What are you going to do with the instance?
If your class is a mono behaviour, then it can only exist attached to a game object, which you would create with instantiate
you want to make an object of Enemy?
like i said, you simply don't do that, you tell unity to do it
Or, if you want an existing game object to become an enemy, you could use AddComponent instead
yes i wanna tell it to unity
that what i try but dont work
btw have you completed the beginner courses at !learn ?
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i dont but i understand better when i practice
Show the !code for enemy, and where you tried to make an object become one
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
we've told you quite a few times, if you want to instantiate a gameobject with Enemy, you can do so via Instantiate, or you can add Enemy to an existing gameobject via AddComponent
you can't instantiate Enemy on its own
you should go do the unity essentials course in unity learn
I'm not going to download a text file to read it please share it using one of the links provided
You cannot practice without knowing fundamentals
i don't think messing with quaternions quite counts as "beginner", you might want to try #archived-code-general
The first case will add the enemy component to the game object currently running this script.
The second one is illegal
the first one dont work in my case
What doesn't work about it
i try to do this Enemy trainingDummy = gameObject.AddComponent<Enemy>(); trainingDummy.SetPv(10); Console.WriteLine(trainingDummy.GetPv());
and that dont write it
unity does not use Console.WriteLine
you would use Debug.Log to log stuff in the editor console
this is why we told you to go over unity essentials
go over the essentials
Vector3.right (normal you projecting to) is world space. If your camera yaw is rotated it will not behave same.
Your player uses Vector3.up which works because your player always stands upward
This Yaw/Pitch is what I do to calculate same stuff if you need reference
https://github.com/cathei/RotationMath/blob/main/Packages/com.cathei.rotationmath/Runtime/RotationMath.cs#L105-L121
My camera yaw is not rotated at all. I only change its pitch with my mouse input.
Yes. After fixing all of the cache stuff I got the GC alloc down to 54kb from 129 previously (I couldn't cache some stuff because I'm saving those in a dict). And now the performance changed very drastically. With deep profiling the results were pretty much the same, around 15fps, but without it the fps shot up to 120 minimum. Is performance really THAT sensitive to GC?
yes, it is
You mentioned that it is player’s child object. It’s yaw would be rotated if player is rotated.
Yeah it gets rotated with player but nothing changes considering the Y axis atleast on my Camera.
Thats its local yaw I believe no?
The one that doesnt change.
No we are talking about worldspace yaw
Because Vector3.right is worldspace
So do I have to minus the yaw from my camera somehow to be able to calculate correctly?
How do you change variables across functions in c#?
sounds like you're asking about scoping?
Scoping?
wdym by "across functions", exactly?
If had a variable in one function, how do I change it in another?
what's the relationship between those functions?
is one called by the other?
or are they just unrelated?
are they in the same class?
I don’t think you should solve this with plane projection. Given that your player also rotating to target, there is no one “correct plane normal” to use here.
All you need to care about is the direction’s Y, and calculate destination angle based on it
in general, you just don't do that
there is 1 pattern where you would, but considering you're asking about it i don't think it's the right solution for you
it sounds like you may have an https://xyproblem.info, but i can't be sure since you've given very little information
Here's the code:https://pastecode.io/s/va7pva21
All right. I will take a look at it. Also checked your github, there are too many Math functions for now. I'll make sure to study them as well.
Thanks
pro builder window not showing? anyone could help me out?
wow that is.. something
I'm using visual studio.
so what variable and methods are you talking about exactly
its different now.. create a shape..
and ull see a new tab on the left above ur toolbar
Draw1
i see, i figured they changed it thank you
Draw1 is not a local variable
Then how do I make it one?
..do you want it to be one?
Yes
You don’t have to read all, just Yaw and Pitch. Those are just calculating angle with trig
you wanted this to be accessible across different functions, right?
Yes
a local variable isn't going to be accessible across different functions
Then no.
seems like your code already does what you want it to
Ah thats cool then. Thanks for your time.
i havent figured out everything yet but so far thats what ive gotten lol
uhh why is "1 meter" deforming
No worries I was playing around with the settings before, just didnt realize they changed it lmao thank you again 🤞
its not.. if u notice its just centered..
the rest of the meter is cut-off until it actually hits 1 meter
b/c probuilder does auto uv's and tiling pretty well last i used
i did not notice that, thanks for pointing that out
i think you were moving too fast for me to notice since im not familiar with it lol
ya, i work too fast for my own good sometimes 🤣
hello, im trying to access this softness in script so I can turn it from 0 to 100 over x amount of time. the only problem im having at the moment is accessing it in script. I looked around but couldnt find help if anyone has advice
public TextMeshProUGUI textMeshPro;
public float faceSoftness = 1.0f;
Material textMaterial = textMeshPro.fontMaterial;
textMaterial.SetFloat("_FaceSoftness", faceSoftness);
``` i think something along the lines of this
My issue still isn't fixed and I don't understand what you're telling me.
- what is the issue?
- this class is doing too much work, and getting overly complex and cluttered. seems like you should modularize it
Thank you for the reply, ima add the change over time and see if this works. appreciate it
just remember if that material is being used for other text elements.. they may change as well
might need to make a copy of the material to apply a new instance of it (after changing it) to that text and only that text..
question, is the " _FaceSoftness " part a tag or layer
that is the name of a Material or Shader property
so i got an error called CS0106: The modifier 'private' is not valid for this item
how do i fix it?
remove the word private ?
sound like you wrote that inside another method
which would be invalid
hold on gonna send code i wrote according to unity learn
local method definitions cannot have access modifiers
using StarterAssets;
using UnityEngine;
public class Collectible : MonoBehaviour
{
public float rotationSpeed;
public GameObject onCollectEffect;
public float jumpForce = 5.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(0, rotationSpeed, 0);
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange);
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
// Destroy collectible
Destroy(gameObject);
// Insantiate particle
Instantiate(onCollectEffect, transform.position, transform.rotation);
}
}
}
}
asi in i defined a void in a void?
they are called functions/methods
no, void is a return type. A method is a method
void is just a return type for a method (means return nothing)
so i just remove the 'private'?
you have a method inside a method
that's bad
you have to move the method inside to not be inside
//valid
void Method1(){
void Method2(){
}}
//not valid
void Method1(){
private void Method2(){
}}```
thats called Local Function ^ but 98% of the time you wont ever need local functions
aside from that OnTriggerEnter is a Unity callback / event invoked by Unity so you don't directly call this method, especially if its inside another method Unity won't see it.
huh weird, it worked before
it worked probably because it was outside of Update as it properly should be
does it have to do with me accidentally removing and readding a }?
i completely broke the script i think
can you count?
is your IDE even configured?
i have visual studio
probably not then
screenshot your entire IDE
if your didn't get that CS error in the Visual Studio console or underlines in red , its likely not
⬇️
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
you very obviously have not put the } back where it belongs
that is very much possible, but i already cut and repasted the code to readd the {} correctly
also that Jump would need Impulse forcemode
that is why I asked if you could count
velocity change is just a mass-unaware impulse
Oh okay so its good for one-frame events also?
yeah
those colors are bugging me lol why aren't methods Yellow and classes are white..
velocity change = Δv
acceleration = Δv/t
impulse = mΔv
force = mΔv/t
ahh ok.. wasn't there an Image somewhere here used to go around?
yes, i have no idea where it's from
(impulse is aka momentum, p = mv)
found my mistake i think
I mean.. you literally just needed to close the Update method..
it was closed
no it wasnt
i just placed the private void in the update void
yeah something is wrong with your IDE
thats the jump function
its giving you basic syntax error but not missing component
right and where did you define rb
that should be underlined red.
You need to close VS go into unity and try regen project files
weird thing is, my visual studio isnt showing any errors
because its stuck into some weird state
it should be underlining more, even if it says Assembly-CSharp which is correct, its like halfway
do this first #💻┃code-beginner message
void Update()
{
transform.Rotate(0, rotationSpeed, 0);
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange);
}
}
yes yes no need to show me this, the error is already clear
I never said reboot. I said close VS go into unity go to External Tools in Preference and do Regen Project files, then open script again from unity
oh
and yes you shoud keep it in english so its easier for us to read it and you to search online
nice, it underlined the rb now
ok good good
now you're coding properly
it was like "stuck" or something , Anyway. To fix this error should be pretty clear, you have to define something before you use it
no void is for methods, why would you put void
please go and learn some c# basics
yes you need basic c#
i am, through the learn.unity website
check out the Unity Pathways like Essentials and Junior, they will teach you
i am in essentials rn
oh okay, so they certinly showed you how to make a reference and use its functions
look carefully
i just realised im stupid, i put the code in the wrong script
yep it compiled correctly now
this is a code channel
where would i put this issue in?
thank you
also it looks like you don't even have grid snapping on, something you should probably be using. I keep all my pivots at the corners so they are easier to align
I see thank you for the help
- I want to make the variables change across the voids.
- I don't understand how to do it.
I want to make the variables change across the voids.
that's not an issue, that's what you're trying to do. and you're already doing that
also, those are methods returning void, not voids
Then why isn't the other circle showing???
BTW I updated the code: https://pastecode.io/s/fmf6iysz
you haven't given any context to have that make any sense to me...
you really gotta learn event lists in inspector or something to avoid that static code for each button click
public ParticleSystem runParticles;
if(stateIsActive && isGrounded)
{
runParticles.Play();
runParticles.emission.enabled = true;
}
Could someone tell me why the runParticles.emission.enabled = true; throws an error?
Here is the scripting reference
you need to store the emission module first
And also the error would be good to know...
yeah my visual studio is in german and i need to change it first because these errors are weird to translate 😄 I should change the language instantly. But as you said it works now. Could you try to explain, why i have to store it first?
Huh, I've never seen that particular one before.
When did this come up? After installing a new package?
Nope, it just randomly came up
because of the way structs work and properties
Unity (or some other program) is using that file in a way that's preventing it from being opened
(the executable)
Would this be same in a c# Console App or is that unity specific?
its the way structs / properties work, its a c# thing
I'd quit the editor and reopen it. If the problem persists, delete the Library folder to make Unity reimport everything.
This will take a while, and it'll dump you into an empty scene on startup
It's a really funny corner case
Structs are value types. They are always copied. You don't "share" a struct
Therefore, doing something like this is, normally, pointless
https://unity.huh.how/compiler-errors/cs1612#direct-modification-to-value-types
I can find another link but was stepping out
Ok thank you, i will read about structs / properties. Only know Classes and Objects etc.
transform.position.x = 3;
You'd be modifying the Vector3 copy returned by transform.position, which is a property
so, reading transform.position is like calling a method that returns a Vector3
Now, on the other hand, the particle system does something very interesting
also useful https://unity.huh.how/value-and-reference-types
All of its modules are structs -- but they have properties that wind up calling into native code
its probably ur ide, close VisualStudio
yeah PS its weird because some you can directly change
It still confuses me sometimes
So even though ps.main is a struct, changing its properties affects the particle system it came from
I just restarted my pc, lets see ! :D
in the end you access a valuetype (struct) when accessing directly, that would just copy it and not reference it, so you are changing the modules fields, but only the modules copy when doing particlesystem.emission directly
You get a unique copy of the main module struct, but it points back to the original particle system
So, in theory, it would make sense to do ps.main.whatever = 123;
But the compiler refuses to let you do this.
Thank you alot for sharing the links
But as i understand reference and value types. in theory the reference types points to the location where the variable is stored and every value type get its own storage or?
Why do variables in different methods change in unity but not visual studio?
wdym by that
how do you know they change in unity but not in vs?
I will grab a book or read some articles about structs, i should get it then 😄
That was the problem, Thank you @swift crag !!!
Because my circle in visual studio won't show if I press a button.
value types are held directly
reference types are a fixed-size "pointer" to the actual object, which lives somewhere else
what? I actually dont get what you mean by that
circle in vs ?
are you talking about a breakpoint ? what is a "circle in visual studio"
This is unrelated to ref parameters and returns, by the way: they let you share the actual variable with someone else
this is a !cs question
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
What do those have to do with anything?
you should never have variables a1,a2,a3,a4 etc.
what does this have to do with unity ?
Nothing
especially the circle nto showing when hitting the button. This explanation is so random for someone not in your project
So I should just pair program at this point?
Try to give it some thought and ccome back with something anyone can understand apart from you
again this isn't a unity question
@tender breach This is the Unity server, and this isn't the first time you've been told non Unity questions don't belong here. Next will be moderated.
that explains a lot
You know what? I'm leaving this server since people are being mean to me for no reason!
See ya!
do you even have unity installed
Yes
how is telling you to ask in a more fit server (the c# one) mean ?
are you a child
I have autism.
I think we can all calm down now.
out of curiosity... was the thing you were asking about, related to unity at all
No
Osteel has already taken care of it and anthony knows where to go to ask.
Do you all try to avoid playing with single euler angles? If so can you please explain why?
why ?
I'm about to leave.
Yeah like. Why is playing with single axis is bad.
I don't think I've ever heard that?
Oh you were asking why would it be something to avoid my bad.
at most, dont ever directly modify euler angles or use them for calculations
always use Euler -> Quaternion and vice versa
the arrow means convert them, change whatever you want then convert back to Quaternions?
yeah like if you want to change euler of x, dont do transform.rotation.eulerangles.x =
Euler angles can exhibit very weird behaviors
do Quaterion.Euler (myval
consider quaternions to be the "canonical" representation of rotations
the most obvious one is gimbal lock, where changing two different axes produce the same rotation
Modifying euler angles will most likely run you into issues like gimbal lock and so on. thats why you should let quaternions take over the calcuations and then you can access the euler angles again if needed
slight rotations can cause your euler angles to change dramatically, too
Aa so its fine to convert Quaternions to eulers, play with them and back to Quaternions for calculations?
No.
Unity would turn the euler angles back into a Quaternion anyway.
You should, instead, use the Quaternion methods to manipulate rotations
Oh okay. I see
If you want to spin a rotation around an axis, use Quaternion.AngleAxis(angle, axis) * oldRotation
the * operator combines two rotations
actually, I have that one backwards, don't I
lhs * rhs gives you the result of applying the lhs rotation, followed by the rhs rotation
There are very spare situations where it makes it "clearer" in code when working with eulerangles, but only if you really know, that you dont hit the limits. But as Fen said, get used to quaternion operations in unity would be the profound way
Quaternion multiplication is associative, but not commutative
Ah. Makes sense. I think it was you the other day too Fen. Who taught me about Vector3 methods so I could avoid this?
(A * B) * C = A * (B * C)
A * B /= B * A
I may have brought that up, yes :p
@rich adder https://unity.huh.how/ This Website is huuuuuuge! Thank you for sharing
np! one of the mods here made it
(thanks for making me typo that word 50% of the time)
vertx ftw
Yeah I am studying them still. Thanks. I'm still trying to make my player's camera to look up or down at my lookTarget
but I managed to turn my player object to face my target today woho!
rotations are still bane of my existence, grateful for those quaternion functions
Having below average iq doesnt help. I'm struggling real bad without progress
hey would someone help me with a* pathfinding project package that i installed but cant get to work perfectly
well you have to show whats wrong and what the specific issue is , otherwise no one can help
sure i was going to send a video
Helo, is the bottom two go in Start cause thats where I put it. I did some testing and im not seeing anything change, if you look to see what ive done, I could share
my guess is one of those distances you have set are too large
can anyone help me fix this thing where i cant see a list pop up
the distance between points n such
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
alr, ty
Wow. I just learned about that site UnityHow. What a great site!
it works better when the distance is lower but i wanted to make a ranged like enemy so i dont know how to make it without this
this has nothing to do with being ranged or not, this is for when your character will start heading to the next points, hence why its cutting across trying to reach the later points
if you want a Ranged enemy, you have to do a distance check(eg Vector2.Distance) then stop / resume the A* pathing from there
thanks i understood now!
btw what do you think is the best way to sort layer orders in top downs ?
i painted my tile map with specific layer orders
and sorted by Y axis
like rendering layers?
yes
yeah thats usually the best way
so you don't have to shift the Z pos
I don't do much 2D so I can't really give you much advice there 😅
maybe #🖼️┃2d-tools or #💻┃unity-talk
thanks for the next waypoint distance advice saved me a lot of time
have a great day
i updated the editor through package manager and checked for other updates, but i still dont think it works properly
any idea what im doing wrong?
thats one step of many
make sure you diligently check the other steps
need to do all of these then?
not likely, which link did you click, I cant tell what page this is
and which ide you got
(installed via unity hub)
maybe check the troubleshoot page
not exactly sure what you mean by this, sorry
ok go to Preferences -> External Tools
screenshot what you have selected
Hello
Open by file extension, nope. select visual studio there
yeah you didnt do all the steps then
Like the first step coming up when oepning the link and you skipped it 😄
the side bar is not important, look read the titling
you click the link and it deep links you directly to that dropdown...
yes the content is in the middle lol
you can skip the one under it obv "Add a version of Visual Studio that isn't listed"
resend, helo. Ive been testing this and Im not seeing anything change if you would like me to send what I did
Do you have a link for it? I think I know that site, but I havent been able to find it for a while since I lost the link
when building this mechanic i would probably consider making a drastic change first and make sure ur interacting w/ the correct object/material/etc all that jazz.. it may help to make different materials and feed that material straight into the inspector using a public or [SerializeField] private variable for the material itself.. or u can create one dynamically / a copy
but run debug logs to make sure the values are correctly changing.. and then figure out whats changing.. where rather..
google is pretty unhelpful searching "UnityHow" because it just gives a million results of people asking questions 🤣
im only changing the face color.. but its similar code.. what do u have?
when I change the number in game, I can see it change in log but nothing really happens
and since TMPro is basically a mesh.. (i think).. if u do anything to the other stuff like outline width, underlay etc.. then u need to call
UpdateMeshPadding() * see // below
check the tmpro element's material
or.. let me fix a mistake of mine.. we're not actually doing a copy
but getting a reference to the material instance already being used by that specific TMP element
you could however create a copy and apply it back but thats kinda pointless imo. maybe for specific reasons..
hmm yea, now that i have a project open i can get the font-face color to work.. but not the softness
doesnt seem to have a FaceSoftness
its okay if not
ill do like a fade out instead if anything
i appreciate the time and help
wait one
Hello, I created an assembly definition and get this error:
The type or namespace name 'BurstCompatible'
I added Unity.Burst to the .asmdef... Is there something else that has to be done?
hmm,... I haven't been using unity for a long time, I remembered that I have a habit of doing AddListener and then RemoveListener when the listener is destroyed to UnityEvent. But I went and read https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Events.UnityEvent.html to see on how to do it, but the example doesn't use RemoveListener. Am I not supposed to do that? Is it safe to not do that?
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Portals : MonoBehaviour
{
public HashSet<GameObject> portalObjects = new HashSet<GameObject>();
[SerializeField] private Transform destination;
[SerializeField] private Transform Entry;
private float cooldown = 5f;
public Vector2 velo;
private void OnTriggerEnter2D(Collider2D collision)
{
velo = collision.GetComponent<Rigidbody2D>().velocity;
if (portalObjects.Contains(collision.gameObject))
{
return;
}
if (destination.TryGetComponent(out Portals destinationPortal))
{
destinationPortal.portalObjects.Add(collision.gameObject);
}
collision.transform.position = destination.position;
collision.GetComponent<Rigidbody2D>().velocity = -velo;
}
private void OnTriggerExit2D(Collider2D collision)
{
StartCoroutine(Cooldown());
portalObjects.Remove(collision.gameObject);
}
private IEnumerator Cooldown()
{
yield return new WaitForSeconds(cooldown);
}
}
how do i make this so the portal, shoots out the object entering it, in the direction its facing.
anybody know why my player is showing up behind my background tilemap??
i know it has something to do with layers but i cant figure it out
it's layer is probably set behind it?
increase the sorting index on the sprite renderer
change the order in layer to 1
check. Z position / Sorting layers
dont spriterenderers ignore Z position?
no
oop that worked well
ok tysm
unity is still a 3d engine
yo, want to make a save system. i need to store relatively simple data: what level you have unlocked. coins, inventory, ect. anyone got anytips? needs to work when i upload my game as a browser game to itch.io
i would also enjoy if you could link a coherent tutorial along with it. ive found lots of documentation on but nothing that explains how to put all of the code together into a working save system
you can always use playerprefs which wont let u do everything but depending on the size of the game and scale of the save system its not awful and would work out of the gate with a browser game
i personally lik json
you can also serialize it with json or binary and save with playerprefs
i couldnt get json to work when i tried initially for some reason so i did binary but apparently its less safe so if it was a multiplayer game itd prob be a bad idea
for simple stuff json.. and the jsonutility been great for me
would this work for a browser game tho? would u have access to their files? or would u save with playerprefs so that it goes in the browser's storage
i can use pretty print and get nice lookin structs i can read in any notepad / markdown editor
ohh no.. idk
most ppl i hear using playerprefs
id think browser limitations will get ya more than what u chose to use tho
im not web-savvy when it comes to that
err, ok i think im getting it... so if playerpref works out of the gate then something like this should just work?
IIRC for web your json file needs to be in StreamingAssets… something to do with security preventing you from getting the data externally. PlayerPrefs does work for web tho I know that much.
public List<object> OldValue;
public List<object> NewValue;
why would this not show in the editor?
I don’t think you can show C# objects in the Inspector
You might want to instead be using Unity Objects
cant, this is for saving data and transforming it from anything
im making a undo and redo system
with different types of data, like vectors, and more sooner
lets not save loads of json in player prefs 😐
What’s the best practice for web builds then?
The only other way I know you can read from json (and I assume write to it also) is to have the file in StreamingAssets.
any ideas for something better that would work in inspector?
Oh if its for web i presume it goes to local storage? may not be soo bad in that case
or should i just make my own inspector for debugging
i already have my own inspector i guess
browser has its own API
If it can be anything then you probably can’t show it in the Inspector. It needs to know what it is.
Hey guys. I'm not sure why, but when i try to rename a blend tree and press enter it changes the text in the number "60" for some reason... Do you experience the same issue? Version: ''6000.0.34f1''
yeah i figured that would be the case lol
You could probably write a custom inspector that can figure out the type.
And then pass the type for the Inspector to draw
yeah but its just for debugging
would probably take a lot of time to write
anyone familiar with light2d? Why does this work on editor but not on build https://pastecode.io/s/tnzfw065
x and xdone is being called in build btw
just the light doesnt turn on
#archived-lighting rather than coding?
yeh, and I do not think, your code magically changes due to build time, so your code might still be fine in build.
But as you want to look at the code, could you show the full code and not just parts of it?
that's what im worrying about
If you can show the code, like where you start what exactly, things might get clearer
It's not just the gc, but also you probably never profiled without deep profiling.
Performance is sensitive to many things.
Could there be a quality setting / configuration, that disables lights on "low" performance or something?
let me check quality
"Project settings> Player> Other settings> shader precision model> use full sampler precision by default…" from some forum entry. Worth a shot
And this could also be related
https://discussions.unity.com/t/urp-light2d-working-in-editor-not-on-windows-build/930727/8
And now I gotta get some sleep, best of luck to you
thanks, Imma try reading on this
I guess this is what's actually happening, since we all added the lights as component via code
Why am I not getting proper syntax highlighting in vscode with unity?
!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
click the vscode one
thank you 🙏
does anyone know about pixel art websites where you can download as a pdf because for my game i made a character and a spike on a website called pixilart but it downloaded as a ".pixil" and i cant drag it into the sprite renderer
tyyy
it was actually that... reflection being the only possible solution sucks tho
or I could just not add lights via code
i literally just made a little goober
also how do i make my floor a solid object that the player lands on? the player has a rigid body 2d and the floor has a box collider 2d but it still isnt solid
Awesome
if(GameManager.Instance.State != GameManager.GameState.Active)
{
GameManager.Instance.ChangeGameState(GameManager.GameState.Active);
}
Is there some syntactic sugar i could use for that if statement?
Have you tried setting the floor a rigidbody too
no i thought that would just make the floor fall
The player also needs a collider.
A Rigidbody2D doesn't have any physical shape on its own.
It just causes an object to be influenced by the physics system
it didi
ty!
ofc it did 😄 unless u untick Simulated or change gravity scale to 0..
but ur floor doesn't really need a rigidbody anyway unless its doing some crazy acrobatic stuff
the only reason i could see to have a rb on a floor is if its a moving platform/ elevator..
but even then it all comes down to the type of character controller u have trying to interact w/ it
ok best way to do very specific math is strap bunch of action events to the character
also how do i fix the object reference not set to an instance of an object error in this code? because idk where the thing is(to my knowledge it means something i wrote doesnt exist)
https://pastebin.com/KFVE4iMm
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
means that the object hasn't been set (usually in the inspector)
looks like in your case. yeah, you haven't put the rigidbody into the script in the inspector
How to update the rotation of Combat Camera so that it starts looking where BasicCam was looking? and vice versa, I'm using Cinemachine
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
im asking here because i dont know how to word this for google. For an array with only one value, you would use the .length function to check how long it is. But in this example, my array contains two items. I want the length of only the item on the right, the left is not important. how would i find that?
.length - (however many items from the right you want to ignore)
isn't length just an integer?
blarg... cant be used as a method
I mean you can select the thing inside the array
.length(0) to select the item left of the comma, .length(1) to select the item right of the comma
are you sure that's c#?
yes
I believe it's GetLength(1) to get the length of the 2nd dimension . . .
Ooh yeah that's the one
oh right, forgot GetLength exists. never actually needed it before
I've never needed to make use of such a thing before, but I knew I've seen something to this effect before a number of times
dont crosspost
how i do indexer by string?
if i want access by test["stuff"]
other than dictionary, i want that functionality for class itself
Hey everyone!
I'm currently working on a speed buff in my Unity project, and I'm running into an issue where the buff isn’t expiring after the intended duration. The speed seems to keep multiplying and then never revert's, and never being reset after 3 seconds. Here’s a brief overview of my setup:
I have a Buff script that applies a Speed buff to the player when they enter a trigger zone.
The speed is supposed to increase by a multiplier and then revert to its original value after a specified duration using a coroutine.
However, the coroutine appears to start, but the speed reset doesn't seem to work as expected.
Here's the key part of my code:
void ApplyBuff()
{
switch (_buffType)
{
case BuffType.Speed:
playerController.Speed *= _speedMultiplier;
StartCoroutine(RemoveBuffAfterDuration(_durationSpeed));
Debug.Log("Speed buff applied");
break;
case BuffType.TimeAdd:
break;
}
}
void RemoveBuff()
{
switch (_buffType)
{
case BuffType.Speed:
playerController.Speed /= _speedMultiplier;
Debug.Log("Speed buff removed, current speed: " + playerController.Speed);
break;
case BuffType.TimeAdd:
break;
}
}
IEnumerator RemoveBuffAfterDuration(float duration)
{
yield return new WaitForSeconds(duration);
RemoveBuff();
}
Buff. cs - https://pastecode.io/s/s5o0dufr - full buff script
PlayerController.cs -
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
[SerializeField]
private float _speed = 50.0f;
private float _movementY;
private float _movementX;
public float Speed
{
get => _speed;
set => _speed = value;
}
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnMove(InputValue value)
{
Vector2 inputVector = value.Get<Vector2>();
_movementX = inputVector.x;
_movementY = inputVector.y;
}
private void FixedUpdate()
{
Vector3 movement = new Vector3(_movementX, 0, _movementY);
Vector3 newVelocity = movement * Speed * Time.deltaTime;
newVelocity.y = rb.linearVelocity.y;
rb.linearVelocity = newVelocity;
Debug.Log(Speed);
}
}
refrence video
don't continuously append to a speed but instead make a seperate speed variable like:
Normal speed = 10,
Boosted speed = 20,
then toggle between the two
or if you want to make a multiplier then -> Boosted speed = normal_speed * 2
Could be completely wrong but the coroutines probably stop running when you set the game object inactive so it never removes the speed
dividing to get the original value is a problem. especially if you can stack buffs. add to a modifiedSpeed value, then add—or multiply— that value when calculating your speed . . .
also, you're don't need to multiply by deltaTime when assigning the velocity . . .
thank you that fixed it
thank you , i fixed it
thank you
Hello,I just started learning Unity and recently completed a basic 2D and 3D course. I want to create a motion capture or computer vision project. Where should I start? What tools should I use? Do you have any recommendations for beginners, online courses, or YouTube tutorials
I know almost nothing about this subject but take a look at this
https://unity.com/products/computer-vision
A bit ambitious for the first project, but hey, you do you
is this a game you are working on or for a certain project ?
Hypothetically speaking, for the mouse movement script right, could I make the head slightly move forward when looking down? As funny as eating your own neck might look it's not quite the feature I'll want lmfao
Of course you can. Bones are just transforms and you can move/rotate them however you want
even if i just use the neck as the parent for the mouse movement then the neck would be the issue coming out of the body at the bottom of it lmao
If you have animations, you need to do the head rotation in LateUpdate
Or use thte animation rigging package or other tools
That sounds like a weight painting issue
Could rotate the neck a bit and the head a bit, or maybe only the head
I don't think humans rotate the "neck bone" as much as "head bone" when we look up/down
trying to just simply move the head forward by X amount when looking down via code or vise versa for looking up
Well if you want the head to move then yeah you need to rotate the neck
What type of game is it?
Well, mainly what perspective does it have
Honestly I'm just making a mini dungeon type game, nothing fancy but its more so directed towards learning wouldn't really have a set directive but more of a silly vibe in a way i guess you could say
think of mucks style its just gonna be simple like that in a sense
With perspective I mean is it first person or 3rd person or what
fps
The main objective to just slightly moving the head forward or backwards slightly is just so I dont just look inside my body without limiting the abillity to look up and down by too much
obviously still need to clamp it but I don't wanna just give it like a 20 degree angle and call it a day 🤣 cause that honestly wouldn't be fun lmao
Since it's just for the first person view, you could just make the head invisible and rotate the camera around the neck/chest
Or use a "viewmodel" with only the arms and don't render the rest of your body at all
True first person body is kind of a pain
using a full body model in order to get a more accurate hitbox if i can lmao
That's not the reason people use full body FPS models
The hitboxes (colliders) can still exist in the correct places even if you aren't rendering the skinned mesh
also wanna see the legs slightly when looking down and moving
Every fps full body model does not have a head
A lot of games only render the legs and the arms
Well they do but just for shadow casting reflections it does not render in the main camera
Yeah
Just need to make sure your camera doesn't see the inside of your waist etc.
i guess all you really see is your torso and down anyway so really don't need a neck or head lmao
yeah i suppose that makes sense
For example in arkham asylum, a tps game, for the fps segments they twist the entire head 180 inside the body
Brutal
But efficient
A couple of other ways of doing it are scaling the head down or having it as a separate mesh and making it invisible
I guess the fps segments came later in production and seperating the mesh was not a option
Yeah it still talks too in that mode
I wrote a tool that automatically splits a single character mesh into multilpe
The spheres are volumes that ensure certain vertices are includen in certain submeshes
The rest relies on bone weights
(Don't mind the topology lol, it's a decimated LOD mesh)
dont make fun of my topology :(
This makes it a lot easier to iterate on the character models without having to use separate meshes in blender
now it should in theory keep my parent setup from blender right? it was a simple method to make animations easier since its a low poly model basically everything is indirectly parented to the torso, fingers>hand>forearm>Upper Arm & Shoulder>torso
it seems like a weird way but it works so that way i can rotate the upper arm which rotates the rest of the arm and then move my way down the hierarchy setup till i get something i like
I just toss on rigify and call it a day
hello everyone so I basically made a 2d character with the walking cycle but there is a problem like I want it so that when the animation starts and no key is pressed after it it should stay on that state like if in the walking animation I stop pressing the key the animation shouldn't play from the starting but the state it was in. I made that and it works fine for the first 2 frames but the 3rd and 4th frame are sped up and appear at the same time to reach the 1st frame
Like you want it to continue on the last frame it was on when you stop holding the key down? Maybe I’m not understanding it correctly?
yes
so basically when I stop pressing the key the animation stops on that frame and then continues from it
where do you find that? lowkey looked for that a while ago because i found it once before lol
like this
Thats really cool. Part of the gore system ?
It's a package you can download right from blender. My animation friends though tell me it's actually not the best for video game animations though but I use it fine
that + automatic weights can really pump stuff out quickly
after that where do i find it?
check the docs
You want it to do that or you want it to not do that?
I want it to do that and I kinda make it work like the first 2 frames work as expected but the 3rd and 4th frames appear at the same time and speed up to reach the 1st frame
using System.Collections;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private bool isMoving;
private Vector2 input;
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
}
private void Update()
{
if (!isMoving)
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
if (input.x != 0) input.y = 0; // Prioritize horizontal movement
if (input != Vector2.zero)
{
// Set movement direction for animation
animator.SetFloat("moveX", input.x);
animator.SetFloat("moveY", input.y);
// Resume animation
animator.speed = 1;
// Calculate target position and start movement
var targetPos = transform.position;
targetPos.x += input.x;
targetPos.y += input.y;
StartCoroutine(Move(targetPos));
}
else
{
// Stop animation, freeze at current frame
animator.speed = 0;
}
}
animator.SetBool("isMoving", isMoving);
}
IEnumerator Move(Vector3 targetPos)
{
isMoving = true;
while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
{
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
yield return null;
}
transform.position = targetPos;
isMoving = false;
// Freeze animation at current frame after moving
animator.speed = 0;
}
}
Here is the script
ahh i see just the automated rig, seen that before in a vid. but theres a simple method, that i actually used in a project before where i just animated it by moving the parts manually in the animation
btw the blend trees between idle and walk have transition value of 0.1 to achieve the thing I want
that's pretty much how animations work ;p
and actually now that i think about it this isnt the right channel anymore since the convo branched off into animations lmao
0.1 and -0.1?
no 0.1 and 0.1
rigify does provide IKs for you so that's sorta different
Let me get on my pc
{
if (collision.gameObject.tag == "Platform")
{
Destroy(collision.gameObject);
}
}```
am I going insane or shouldn't this check for a tag with anything it collides with and if it has the "Platform" tag it should delete it, no?
not quite. using == does not check if the tag is valid. use CompareTag instead
I'll give it a try
Didn't change anything, does activating "Used by effector" on the platform cause any other side affects?
Originally made it so I can hide parts of the mesh under clothing to avoid clipping.
But yeah it comes in handy with the gore system too. There's no dismemberment yet though
Why aren't you setting the bools in the if and else statements?
animator.SetBool("isMoving", isMoving);
debug the tag of the collision
Try putting animator.SetBool("isMoving", true); in if and animator.SetBool("isMoving", false); in else
It's not colliding in the first place apparently
I don't think it would change anything btw when I use walk for a long time it just freezes as the idle state
Also you're only setting the bool at the end of Move(), remember to also set animator.SetBool("isMoving", false);
so you need to check your setup. it's not a code problem
using System.Collections;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private bool isMoving;
private Vector2 input;
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
}
private void Update()
{
if (!isMoving)
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
if (input.x != 0) input.y = 0; // Prioritize horizontal movement
if (input != Vector2.zero)
{
// Set movement direction for animation
animator.SetFloat("moveX", input.x);
animator.SetFloat("moveY", input.y);
// Set isMoving to true in animator
animator.SetBool("isMoving", true);
// Calculate target position and start movement
var targetPos = transform.position;
targetPos.x += input.x;
targetPos.y += input.y;
StartCoroutine(Move(targetPos));
}
else
{
// Stop animation, freeze at current frame
animator.SetBool("isMoving", false);
animator.speed = 0;
}
}
}
IEnumerator Move(Vector3 targetPos)
{
isMoving = true;
while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
{
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
yield return null;
}
transform.position = targetPos;
isMoving = false;
// Set isMoving to false in animator
animator.SetBool("isMoving", false);
// Freeze animation at the current frame after moving
animator.speed = 0;
}
}
something like this?
will you please use a paste site for large blocks of code, you are flooding the chat
ok sure
Yeah
now the animation is just stuck at the idle poses and no walking ones are shown
In all directions?
yes
does anyone know how i can fix the issue by the place where ive commented
follow the instructions given by that error
i tried
i get the issues below it
and nothing happens
when i follow the instructions
but does the red error go away?
no
it wont let me do anything when i follow the steps
the yellow bit just shows up below the error
What about the animations themselves? You said the first couple of frames works fine. Can you show the timeline of one of the animations?
sure here
If you mean the ⚠️, that's a warning, and does not seem to be related to the error
Likely a Unity UI bug
would make sense, it comes up when i try to click some buttons to fix the error itself
I think the issue is that you got rid of animator.speed = 1; in the if statement
So naturally it wouln't resume updating the animation
hmm let me try it
thank you for pointing it out
thx it fixed the 2nd issue that the player would freeze in idle animation after some time but still the speeding frame exists
https://qtext.io/8gnd updated script
Oh.. Like it speeds up the longer you hold it down?
no like first when I held it down after some time the walking animations would stop entirely
You did set them to loop?
no they are not looping
ok lemme try
yeah it did nothing
hell yeah i got the book thing working, and it barley took 30 mins of my own time
Now let’s say I wanted a GUI to pop out of the object whenever it’s on its “open state”
like let’s say whenever the book was opened, a picture of a page would pop up, and there’d be a “next” and “back” button to go through the pages
You could try actively checking the state while you're testing it https://puu.sh/KmEQj/83a55303df.png
See what it does when you hold down a button
ok lemme see
would i need to make the GUI a child of the open book model? or how would i do this
especially with the “next page” and “go back” button, would i need an array with a bunch of PNGS?
That's one way to do it
looks fine to me
i thought of having it work like this, i insert a page or text onto the open book model and you’d press a button that’d take u to the next/previous pages but idk if that’d look weird
That's very interesting
Why would it look weird?
Please use one of the paste sites in this bot message !code
The one you used is weird, the code is shown in a small box that covers maybe 5% of my screen lol
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
Also do you mind stating again what is the issue
I'm curious as to why you'd want idle states when you want the character "idle" state to be a walk animation frame?
Also, can you show the transition conditions?
You are using animator.speed which I assume will affect the speed of the transitions too
So setting it to 0 would not let a transition progress
so basically I want it so that when I move the player and then leave it the state is then freezed and then the animation continues from it
you have a point Ig
And when the walk anim freezes you want to go back to idle?
And when you walk again it continues from the same point in the walk anim?
no like the animation should continue from the then like when freezed in 2nd frame of walking left and I press the left direction the animation should continue from that freezed frame
Basically the animation freezes and resumes
o let's go Melton was right the idle is unnecessary
now the game works as I wished thank you very much to both of you for taking your valuable time out for me
I'm glad it works 😄
Guys, i have a question, struct is better than class in optimizing right? cuz its a value type, should i use it whenever i dont use inheritance ?
use it when you don't need references to it elsewhere. Best you can do is pass it by reference to a function
but if you have an array of a struct you need to loop over a lot then you will benefit greatly from it being a struct (as it all gets allocated together in memory)
I usually just stick to classes unless I'm doing serialization
or start with classes then refactor into structs for polish
Hello, can RuntimeInitializeOnLoadMethod only be used on static methods? If so are there any alternatives?
Any reason you can't just entry point a load scene
it's for a generic storage class, like List. Hooking it up everywhere would be tedious, and sometimes non monobehaviours can contain it.
And you can't accomplish this by loading up some singleton and keeping it in mem throughout the runtime?
I mean I guess I can but it seems nicer to just do List<Type> CoolList;
Rather than ListStorage.Instance.CoolList
But I don't super need this though, it's just for easy caching in the storage class, game will be fine without RuntimeInitializeOnLoadMethod too.
(to be clear I didn't make my own List, just using it as an example)
it can just be a static field instead then?
what do i need to do from the build settings menu?
Add the scene as specified
scene is an assest in your directory
Drag it or use the "Add Open Scenes"
Yeah classes are easier to start with, especially since they can have default values for fields where structs can not
^ which shouldnt be a problem with newer c# versions
missing a lot of goodies that structs have
I dont think I can, cached data is unique to every instance
just comes up with this
but it doesn't matter
try reseting the editor
Perhaps you need a static constructor?
but that is only useful to init data once for a "whole class" statically
if its seperate per class instance then well just use Awake or the constructor normally...
still
no
how do i make sure something counts as a scene
make a new scene asset in your directory and try that
Try resetting your layout too
huh weird, every time i start visual studio after starting pc, it is in a "broken" state, so i always need to regenerate project files. any way to fix it?
also i got an error, that Getcomponent(Type) is a method not valid in given context
nvm i think i figured it out
!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
hmm, this might be a good one, thank you and rob5300
guys i need help im trying to make a simple 3d movement game just a beginner friendly game i made the script by following a toutorial but its like not coected to the(Player) anyone willing to help?
did you added the script to the player gameobject ?
idk how to do that
a script need to be added as a component for it to work
take your script in the project files, drop it onto the player game object, or with the Add COmponents button in the inspector type the name of the script and add it
who are you watching ? maybe search for tutotrials with the basis of unity
it just says
your class needs to inherits from MonoBehaviour
i have like no idea what that means is there a toutorial that explains it?
after the name (if i'm not wrong) you write class MyClassName : Monobehavior
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Go through that before doing anything I suggest
alr ty
ty
np
how can i lock my camera to normal head movement? this current code does not work(i wrote it similarly to the original code)
void MoveCamera()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensivity * 0.1f * Time.deltaTime;
transform.Rotate(Vector3.up * mouseX);
verticalRotation -= mouseY;
verticalRotation = Mathf.Clamp(verticalRotation, -90f, 90f);
if (playerCamera != null)
{
playerCamera.transform.localRotation = quaternion.Euler(verticalRotation, 0f, 0f);
}
}
the 0.1f is because the vertical rotated too fast
does anyone have an idea as to why i cant see the clouds in game?
in the scene menu theyre over the pipes
probably layered wrong?
but then ingame theyre nowhere to be seen
not sure where to change it for particles
/how to fix issues with layers for them
show the clouds inspector
wdym "normal head movement"
oh like u can look behind u
u want a 180 degree cone
yea
oh they are particles?? u need to do 2 things then. Make sure they are emitting and make sure they are layered correctly
if theyre visible in the scene section when the game is playing
then theyre emitting prob right
theres a preview mode thing
which will show them
but u can change their layer under renderer in the particle thing
higher is better
np
changed layer to 3 but its still not visible even over just the default background weirdly
u need to relate the rotation to the direction the player is facing i image. Have you done that at all
also with adding the Y rotation, the X rotation has extremely slowed down for some reason
try looking at the emission preview
you should be able to see the outline of the particles emitting even if you cant see the actual thing
not sure how to do that...
actually it previews automatically if ur looking at the object
so if emission is on you should be able to see it
are u sure ur emitting on play?
well if emission is on i guess it would be
im ass at particles smh
i thought having prewarm and looping on would help
thats what i read atleast
not sure how else to set particle emitters to emitting
i just realised somehting
the vertical rotation is somehow getting counted as horizontal
do u see the particles moving or doing anytging in scene view
not unless i press play here
and the horizontal rotation is not getting counted at all
Not directly related but don't multiply mouse input with deltatime. It is already framerate-independent, doing this will just make it framerate-dependent again
Also, you are using quaternion which uses radians, not Quaternion which uses degrees
oh
on play, do u see them moving in scene view? to confirm it isnt behind smtn
finally, it works
Nice
i'm gonna have to lower the sensitivity a bit since its still a bit too high, but at least movement works now
You removed * deltaTime right?
yeah
Yep then you need to make your sensitivity about 50x to 100x smaller
Because it's no longer being multiplied by delta which is a small number
@warm field Just curious, did you get that part of the code from a particular tutorial?
the original was generated by gpt, but since the movement code got quite messy over time as i was telling gpt to add more stuff(there was animated player model), and when i removed it(the model), the code was broken so i had to rewrite it manually using the original without animations, as the player is now a invisible capsule
Okay, I was just wondering where this incorrect mouse * deltaTime keeps coming from
I know a couple of tutorial videos did it, including Brackeys
it was coming from gpt(it worked but then i decided to remove the model since animations were pain)
Oh my lord.. Yeah, I just tested with GPT
mouse sens isnt frame dependent even in update?
also, should i delete deltatime here?
void Movement()
{
float currentSpeed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : movementSpeed;
float moveForward = Input.GetAxis("Vertical") * currentSpeed;
float strafe = Input.GetAxis("Horizontal") * currentSpeed;
Vector3 move = transform.forward * moveForward + transform.right * strafe;
if (move.magnitude > 0)
{
rb.MovePosition(rb.position + move * Time.deltaTime);
}
}
i mean get axis
GetAxis with mouse just returns the distance the mouse moved since the last frame
(In pixels I think?)
So it is already "scaled" to the frame rate
Where is this method called from? Update, FixedUpdate?
void Update()
Well, it might work in this case but it's generally good to do physics movement in FixedUpdate instead
Is it a 3D game? Is your rigidbody marked as kinematic? Does it need collisions?
yes its a 3d game, rigidbody is not marked as kinematic, do you mean like can it collide with cubes and other?
Yeah, like should the player ever be blocked by anything it hits
Because MovePosition is meant to be used with kinematic rigidbodies and doesn't produce good collisions AFAIK
yea otherwise u can just use the built in rigidbody add force and stuff
Normally you'd move a non-kinematic body with rb.velocity or rb.AddForce
kinematic means controls whenever physics affect the rigidbody
Pretty much
so its better if i enable it?
Other non-kinematic bodies can still collide with a kinematic but the kinematic body isn't stopped by other bodies
surprised move position was even working at all
(Although there's a physics setting to enable kinematic-on-kinematic collisions)
It's useful for making object completely controlled by the script and resolving collisions via scripts without using forces.
this is what i found on google
nah u probably want to disable it and just do add force etc
yes but u need to manually account for everything which ill assume ur prob just needing it for basic stuff
Yeah, if you use kinematic then you should do your own collision checks which gets more complex
Just go with non-kinematic and use AddForce/velocity
that would probably get too complicated for me
alright, thanks for helping
can I have multiple Class libraries or projects in the same game?
That's what packages are . . .
i dont mean as a dll
i mean in my base code to seperate stuff
I don't know what that would entail.
You can use assembly definitions to break your code into multiple assemblies. This is useful if you have some code that doesn't need to know about the rest of your game's code.
You can split that off into an assembly that's referenced by your game assembly
It's similar but you just have the scripts since you created them. As Fen said, assembly definitions is probably what you want. If not, give us an example . . .
If you just want to give things more distinct names, that's what namespaces are for
What sort of game sud I make as my first game??🤔
not a code question
Ok where can I ask that?
the very first thing you should learn, before even thinking of making a game, is how to research, #🔎┃find-a-channel
yes, sorry for the insanely late reply
if i pause while testing then go to scene view it seems fine too
I bet they're behind the camera
Turn off 2D mode
getting errors please help
dont cross post
looks smthn like this..
did you search docs
https://docs.unity3d.com/Packages/com.unity.xr.core-utils@2.1/api/Unity.XR.CoreUtils.XROrigin.html
pay attention to what namespace it's in
set their z to 0 just in case but not sure anymore im running out of ideas, id probably need a screenshare or the project at this point
it was behind the camera
ty for all the help
Can someone help? OnMouseDown/OnMouseEnter/OnMoseExit doesnt work in builds
right off the bat i would think that maybe ur UI is moving in ur build because its going full screen
try changing ur window size in unity and seeing if that moves ur ui components
those methods are for MonoBehaviours attached to objects with colliders
if you are using those methods in UI objects, then you're doing something funky
same here
window is not fullscreen but it doesnt work
is it ui or what
whats it tryna tell u
is it making a build only sometimes
or is that irrelevant
What
its saying build failed in log but also build succeeded
its always in build
asa is pointing out the error in the console
its old build
but that's just a build that didn't succeed
I'm not aware of anything that would get in the way of the OnMouse* methods.
Try setting your game view to a very high resolution, like 4K. Does the problem happen in the editor?
I don't know if the UI can block the OnMouse* methods, but it's certainly plausible
ah thats a good one too yea
im not sure if onmouse gets blocked by raycasts but maybe
no
works in editor
even with 4k
you mean Physics.Raycast calls? definitely not
i tried disabling raycasting on UI elements
oh, UI raycasting
i mean like onclick for ui
yea that raycast
I'd try using a raycast to check what the mouse is actually hovering over
Maybe another collider is getting in the way, but only in the build
I don't know why that would happen
You could do something simple like this
void OnGUI() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out var hit)) {
GUILayout.Label("Hit: " + hit.collider.name);
}
}
You'd put that on any object in your scene
it'll display the thing the ray hits in small text in the top left
The event system inspector will state what the current hover/click object is btw if you want to tell if its UI or something else if using a physics raycaster with it.
(only with the old input manager, annoyingly)
Oh shit not on the new one? that sucks 😦
apparently ui raycasts DO block it
he said he disabled them and still not working
but still
Yes, !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 #854851968446365696
did you read the channel title?
when you say title do you mean the conduct page?
thank you
u only got 1 eye?
no I mean the bit at the top of this page
👇 this
o. no i did not lol
why not?
😅 why am i being bullied already
😛 i just woke up.. gottta tease a little bit before the real work begins
if i was to make a player, should i use input action or just straight up code it using mono script
this question doesn't make sense
up to you.. i still use both input systems
so are you guys ok with me posting scripts in here?
you're asking if you should buy a car or buy gas
like for controlling
you need both
you are not being bullied, it's being pointed out to you that you are not paying attention
alr
if u think its a code- issue yes
you need to define the kinds of inputs (input axes in the old system, input actions in the new system)
here is fine.. use the Ask embed that was sent to see what u need to include to get a decent answer
and then you need to use them
good point
def is a code issue.
well anyway,
im trying to make an inventory manager script. my inventory itself works however i feel like im forgetting something this is my script to allow it to show up on my object.
ur technically doing the same.. both methods
"allow it to show up on my object"?
do you mean that you can't find it in the "Add Component" menu?
If you mean that inventorySlots isn't showing up, you need to make sure InventorySlot has the [Serializable] attribute
First you should configure your !ide though
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
ehh kinda so for instance i was trying to make the script to have a field like this idk how to explain it.
my other scripts works but for some reason my current script just doesnt show the fields that i am trying to create
i have a serialize field though and it still show up like this
that's not what he said though
read what he said
this chat is just "fix your ide" and "read what they said"
that's what happens when the message with actual advice (osmal's) is ignored
because 99% of the time that is all that is required
perhaps the unity editor could do a better job of having ides work out of the box but anyway
go over to -general or -advanced coding and see how often u see those
literally nothing does this
I haven't seen people have issues with Rider yet 😬
(no-one uses rider)
how should unity have control over 3rd party software?
...Wat
i just mean have the packages needed install or prompt you. unitys fault for needing extra stuff for vs/vs code to work properly 🤷♂️
I mean majority use VS or VSC yeah
no-one that needs help configuring their ide uses rider lol
i haven't seen any beginners using rider at all
vs and vsc have more reach
Rider became free recently (for noncommercial purposes)
that is true of any app, nothing to do with unity
damn i just fixed my ide and it looks hella different now LOL
Visual Studio works right out the gate if u install it via the unity hub when installing the editor..
id say no, unreal usually works better as they expect you to use visual studio on windows
looks POWERFUL now
But it seems to break randomly for people, they have to keep hitting that "regen project files" button
thats good but guess no beginners here do that
so you'd rather every development tool change config files and download extensions for other software without you knowing?
i was wondering why my vs looks like a notepad before haha
ya. lots of ppl ignore basic things
and think they gunna gung-ho a RPG multiplayer game in a day or two
b/c they played a "gorilla tag game" or w/e
i think a "you need to install this package in unity for vs code to work! [yes] [no]" popup would be beneficial
