#💻┃code-beginner
1 messages · Page 457 of 1
the more the better 😛
Pretty understandable
i was actually learning a bit myself as well
bout the whole out vs ref shindig
hey guys, noob question.
idk what to search for to try and start learning this.
how to get a move to point (mouse click) but having it so the character can only move a certain number of units per turn
can anyone point me in a direction to start learning stuff like this?
You'd need some type of algorithm , first define what a "unit" is
turn based movement unity or grid movement (per turn)*
I'll try those. I searched similar things but had no luck. much appreciated
ya A* usually will do the trick
turn based games are much harder to make than realtime games imo
you'll have to avoid the turn based combat stuff.. altho some of that stuff would still be useful.. (the turn counter stuff)
doing one on netcode rn 🤕
seems that way for sure, esp for someone like me that has very little to no experience
meh, it just depends on what u build around it..
the movement system.. itself is a bit more involvde than other methods..
but once u get that going its going already..
it just depends on how much junk u throw on top
tbh the hardest part i found was making specific shapes on a grid
for like attack patterns
I used tilemap but the hex on that is a bitch and half
I should've done square first 
for things like hit percentage according to cover amount, angle, and distance plus accuracy stat seems to be doable with a lookup table rather than calculations, but i guess math is still needed for puting together the 4 different values
math is everywhere my guy lol
I was thinking more of a baldurs game kind of movement. not tile based, but to move a certain distance per turn
thats easier to do just by using positioning tbh
you tellin me all computers are just math machines? D:
big ass calculator thats so loud 🫣
Hey so im trying to make a 2.5 fighting game but i have no idea how to add 2d sprites in the game
btw im using 3d unity
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
just put a sprite render on it, same way you do in 3D as in 2D
Unity is a 3D engine , the only thing that changes is the physics
2D or 3D you put sprites the same exact way #💻┃code-beginner message
i have no idea what just said
There's no such thing as "3D Unity"
It's exactly the same
2D is just a checkbox on the camera and using all the physics components that have "2D" at the end
so do i use 2d unity instead of 3d???
There's no such thing as "2D Unity" either
Again, it's just Unity
Wth are you saying????????
Hey, just out of curiosity, what is it called when doing something like this?
float a = bool ? value1 : value2;
im new to unity btw
man goo through the unity courses i linked you then.. start with the pathways..
I'm saying:
There's no such thing as "3D Unity"
It's exactly the same
2D is just a checkbox on the camera and using all the physics components that have "2D" at the end
There's no such thing as "2D Unity" either
Again, it's just Unity
ternary
Ternary operator
Alright thanks 🙂
that isnt really helping me
Okay so what's the specific question then
the question you asked was "How do I use sprites in 3D Unity" which I did answer.
im trying to make a 2.5D fighing game
If that's not your question, you should ask the one you really have
thats a statement, not a question
okay HOW do i make a 2.5D fighting game
Still not really a specific question. That's kind of a big ask
break down the problem into smaller steps
The bigger the question, the more general the answer has to be. The answer to "How do I make a 2.5D fighter" is "You do !learn and find out how to do whatever you want to do in Unity and make it to your specifications"
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Im tring to add 2d sprites in a 3d enviorment
Go through the courses you were linked.
So make a sprite renderer
https://docs.unity3d.com/ScriptReference/SpriteRenderer.html
When posting that much code, please use a paste site
Okay how do i make a sprite render
Bro.... they just linked the docs.
Click that link. Read it
The same way you add any component to anything
are u even clicking the links lmao
@summer stump Thanks for your input
this isn't a good start to making a game..
Can you please do so, so that I can actually read it more easily and help?
There is a reason it is the server rules to do so.
Without discrediting your workflow it woudl have been faster to just paste it into your editor of choice instead of a hyperlinking.
I am on a phone
Why should we do that
This ensures question visibility too
We don't need your code to work
It blocks a big section of the chat
Again, there is a reason it is part of the server rules to do paste sites for that much
I can 100% just not read the question and continue playing Minecraft
You're the one with a goal to your post
But ok... someone may be willing to help. A lot of people here are on phones or just prefer paste sites, but best of luck!
I didn't know of the posting criteria. I just read it now.
I don't know if this is the right place and such, but can someone help me?
I made this movement script, but I click on the "S" key and on the down arrow it goes forward
I'm using the character controller
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Holy cow. Not even a screenshot?!
PC can't take a picture with a program open
yet you can use a game engine ?
@slender nymph Hey pal can you help me with a #noob question?
I don't mean to call you, I just remember your usename.
Yes it can
Have you posted code properly yet?
Just for you, fine
No. For the rules
And being conscious of people other than yourself
It actually doesn't even meet the rule criteria. But there u go 🙂
Sometimes, I dream about cheese.
Sleepy me always misses the obvious signs, time for bed
https://paste.ofcode.org/8biXBq89vaKcHZRVJ38Wqe
externalVelocity: the velocity/float/bob of a moving platform. I apply this to the player's velocity so they move around with the platform.
The player applies downwards force when landing on floating platforms.
-
I know input/movement has to be framerate independent; Have I multiplied
TIme.deltaTimecorrectly? -
Should I apply
velocity.y += gravity * Time.deltaTime;every frame or just when the player is not grounded? When and why would you pick this? -
Should I call a second
Move()to apply apply gravity/external velocity after my initialMove()call? -
Do I even need to smooth externalVelocity? Keep in mind I want to avoid jitter from the camera/characterController. The floating platforms are intentionally springy when the player walks on them.
Do not ping me with nonsense. Blocked
@summer stump My disappointment is immeasurable, and my day is ruined...
If you're going to be a nuisance, you will be muted.
@frosty hound It's alright man=
!mute 310735647147163651 1w Prefers to be the nuisance.
__pipes__ was muted.
quick question:
i want a DDOL object to run a function every time a scene is loaded (because my DDOL GameManager object should set the player's spawn every time the player enters a room). which function should i use?
Alternatively make your own wrapper function around loadscene and just call that instead
hey guys is there a way to do something like that? I want to have already pre difined how many of each monster I want will spawn in each wave of my game. And then I can access each value like waves.wave.goblins to get the value of that monster in that wave..
I dont know the name of that and if it is possible. with list or something?
An array of arrays something liek that? I used like that in javascriptvar chests = [ { name: 'Small chest', amount: 5 } algo assim
Sounds like you're looking for a Dictionary, or possibly a List of dictionaries, e.g.
List<Dictionary<EnemyType, int>> Waves
On a side note, an MS Paint illustration of pseudo-code is a weird choice... just use text, yeah? 🤪
haha yeah sorry. Thank you ! Will check that dictionary .
Can someone take a look at this for me, please? Line 106, no idea why it's telling me this when the inputs are there in Unity. https://hastebin.skyra.pw/yorewebifo.pgsql https://i.gyazo.com/99f99f4fd6f96a0103123e5ac7048039.png
I lied, I fixed it
Thank you though, Raccoon
Well, I ran into another error sadly
The modifier 'private' is not valid for this item, line 160
I'm confused why it's not valid
because you are declaring a method within a method
Got it, thank you.
isn't that allowed
you just can't say private
not a code question #🔀┃art-asset-workflow
yes, you can declare methods within methods but you cannot use access modifiers
Hi all, I'm working on a flappy bird clone, and I wanted to move pipes when they're out of the camera view closer to the player and this is the code I've written for this: https://hastebin.com/share/emeqihomaj.csharp anyways, it results in some funky looking pipes anyone got a clue on why this is happening
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
It works fine when I do it with a singular pipe, but when I use the pipe as a prefab
this is what happens
Also, it's moving the pipes way after they're out of view. I don't know why this is, but maybe it's a cinemachine thing
Is it OK to define a dictionary with the key Vector3?
public override int GetHashCode() => this.x.GetHashCode() ^ this.y.GetHashCode() << 2 ^ this.z.GetHashCode() >> 2;
not really, no. Comparing Vectors which contain floats for equality is very hit and miss
It is logical
How do I set the layer of all the children and grandchildren of a parent?
When you change it to the father, it asks you if you want to apply it to the children as well.
if youu mean in code, a recursive loop on transform of the root object
how can i simulate granular particles without killing fps in 2d world?
but i wanna set the grandchildren as well
do i put a loop inside a loop?
Hello
that is why I said 'recursive' if you dont know what that is, look it up
I want to render icons and texts. Different elements have icon. For example buildings, items, etc.
The dictionary has the type <Vector3, IconData>
So, instead of defining icon position as a key, define a data structure?
For example <Gameobject, IconData>
why not just use GetInstanceId() of the gameObject which is an int and unique
I thought sometimes it is not a gameobject
every Unity Object has a Instance id
but yes, all icons that I want to show is related to a gameobject, perfect
how can i simulate granular particles without killing fps in 2d world?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hello brothers
I made my first game with tutorial
I know, it is so basic but it is not problem for me.
It is a car game
How do i copy Variables from a Duplicated Script with the Same Variables to the Original one? When i copy the Component i can only paste it as new,
@storm heath Great! You can post it in #1180170818983051344 . Please note that this is not a social discord and there's no off-topic here. #📖┃code-of-conduct
you can drive your car and you can pass through obstacles
The script itself is not an object and doesn't contain values except for static ones for its class. You instantiate the object the script is on, then all values will be duplicated.
I meant a Duplicate C# Script, another Class. They share the same Variables and since im kind of lazy and it has alot of Variables how can i copy the Variables from the First Class to the new One (Component Wise)?
Thank you bro, I will be more careful from now on
Reference the first class with the second and copy it's value
Alright.
Are you trying to do this at runtime or in editor? Edit does have an option to copy component with values.
Hi, i tried to make when the green image drag func is triggered, the red object (its an image) will be cloned as a draggable object. The clone works as expected but it wasn't visible in the game scene. how to fix?
this is the code to the green image: https://hastebin.com/share/anahocaxuc.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Yes it was Editor, but i made an function to copy it, copied the values at runtime and then pasted it in the editor.
I'm making a figihting game in Unity, and I want to start by porting an Input Buffer that I coded in Python into Unity. Here is my ported code:
https://pastecode.io/s/5igxvaxz
I have everything set up in the Inspector, but when I run it just looks like this. Pressing buttons creates clones in the Buffer gameobject, but nothing actually happens on screen. How can I fix this?
If you want to save values at runtime in the editor, the only way is to prefab the object.
It will save its current state
okay so i was going through the beginner scripting resource and i got to classes, and i notice that he has this script, so i put it into my code (had to make minor adjustments for what I was trying to do)
but what im trying to figure out is what exactly in this script is letting it know that wasd is for those movements
is it the Vector3.forward and Vector3.right?
i understand how the script works, mostly, since he's already explained floats and translate and all that in the ones before it, but i dont understand how it knows wasd is the intended way to move
You don't need deltaTime there, input is already per frame
Input.getaxis returns a value between -1 and 1
In unity settings vertical is set to W and S
and horizontal is set to A and D
And GetAxis alters it positively or negatively on input setup in the InputManager
This would dictate the direction the object moves when you press the keys
my little buddy kinda zooms out of frame when i dont have it attached
hold on ive lost the object
alter the actual speed
so if you swapped it round, w and s would move left and right and a and d would move forward and backwards
i think i understand now
thank you both
Np man
If u want to change the key for any reason, the settings are under Project Settings/Input Manager
Right, you are applying translation in update, you do need deltaTime for it.
startswith/endswith works at same speed regardless of string length?
It almost definitely scales with the size of the substring you're checking
not size im checking but size of the original string
I've built a simple 2d platformer game for Windows; the Fullscreen Mode is set to "Exclusive Fullscreen". If we open an application like a Unity Project, it will take some time for it to open in the background. In the meantime, if we open our game and Unity Project completes loading and opening, it will overlap our game while it is running.
Does anyone know how to fix this?
There's no fix, it's built into the window management system of Windows. An app that was opened last will take focus unless another app was focused in the meantime. Programs can also request the focus using a Windows API call
(This question also belongs in #💻┃unity-talk as it's not related to code)
Not strictly speaking true, a windows program can request to be 'Always On Top'
OpenGL looking good right about now
it's very trivial to write a wrapper program that does this if necessary
ait steve :p this is my first script in unity btw
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D body;
private void awake()
{
body = GetComponent<Rigidbody2D>();
}
private void Update()
{
body.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, body.velocity.y);
}
}
Does anyone know how to reference a .net assembly? I need to use system.windows.forms
ok, it's pretty obvious.
The error message is telling exactly where the problem is. Line 15
So body is null
where do you call awake from?
ohhh it tells you the line nice!
cannot reference windows assemblies in Unity
awake is NOT Awake, C# is case sensitive
Hmm how else would you allow the user to save a file at a different location than persistent datapath?
lol that fixed it :p
make a file picker or get one from the asset store
thanks guys!!
#1180170818983051344 for this kind of post
srry was just showing my meagre progress ^^ i'l post in there when i make something nice
im like following a tutorial online but when he types stuff, its gets proposed in the dropdown menu, with me it doesnt, is that like a setting somewhere?
!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
• Other/None
So im trying to make an inventory system but theres something wrong with a function that isnt working...
So as u can see i have a function called AddItem and it works in the item.cs and the inventory.cs but in my itemslot if i try to set the item sprite equal to the image(ui box) sprite it doesnt work, it doesnt even Log in the console that the item has been added...?
im using visual studio, stuff like GetComponent, Rigidbody2D or SerializeField dont get proposed in the dropdown
screenshot your complete VS Window
this means your IDE is not configured. So follow the configuration steps in the bot message
Hello I need some help with maybe a script problem if anoyne can help
Its more to do with restarting the scene and some components are disabled while others are enabled and idk what could cause that
and yet you've still not actually provided any useful information that would allow someone to help you. 👇 !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
Thank you! I'll purchase one ❤️
there is a free one iirc
im having issues with my inventory system, im trying to add an item to my inventory and if i debug it it should work but i dont see the item sprite on my UI image...
you need to get your !IDE configured
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
• Other/None
this is the problem?
no, but it is a requirement
Ait its configured
its not
now its configured...
show it
ok.
so have you tested OnCollision is working
yes its working
how have you confirmed that
if i collide everything goes good but the image is not in the inventory
debugged
how
well idk where that first log is coming from. but the second log only proves that AddItem is being called
well then it is being set correctly. if it isn't working then either you are calling AddItem on the wrong object, or there is something else incorrect with your setup that you've not provided any details about
it appears to be assigned just fine. see #💻┃code-beginner message
looking for gameobjects by name is pretty bad tbh @umbral rock
Help i cant set properties in a Unity Custom Editor,
More in Thread https://discord.com/channels/489222168727519232/1272146985608151074
there is no need to crosspost this all over the place..its not that important
ye i know but its a beginning to understand it for me
i just dont know where my error could be, code looks totally fine
because the code is totally fine. as you've shown, the correct property on the image component is being assigned correctly. something else is incorrect about your setup.
does the sprite in the inspector change? think i missed that part
could be because of the item sprite here? My item is red coloured but maybe the sprite i add is wrong?
the color assigned there has nothing to do with the actual sprite
yep it does, when u collide the imagesprite is set to the itemsprite, wich is what i want
hmm ok ok
in fact, the sprite renderer's sprite and the sprite assigned in the Item component are two completely different sprites
when i have not collided vs when i collide
even if you did use the same sprite though, the color property is on the SpriteRenderer not the sprite itself
its working no ? its just black..
yes, notice how it is assigned to the sprite in the Item component after the collision
what it supposed to look like ? change the tint back to white
black is tinting the sprite so you can't see anything prob
ye, but the item image is not showing
ohh
lol, how do i change the colour of it?
i'v set the image to green but not going to green
wdym this is just a tint, it tints the whole sprite not specific parts
ohh, how do i remove it?
what does original look like?
show what you changed
well naturally nothing changed here because there is no sprite assigned to that image component
but yes, look at the material as well
and of course make sure you don't happen to have another image on top of that one you have selected. you've not bothered showing the actual hierarchy so it's not possible to tell
removed the images and added one, now it works to change colour, and when i collide with the item the image is a bit blurry and changes a tiny but but no item on it, lemme show u
fix your Scale
theres a tiny tiny difference
let me guess, it's still being assigned to the "InputFieldBackground" sprite? the one you are explicitly assigning to it because that is the one assigned to the Item component?
at this point though, i am done repeating myself about what the issue is. so good luck 👍
@umbral rock why do you need rounded sprites at runtime on image in the first place, why not just spawn that UI image with sprite already.
not sure why you're doing any of it at runtime tbh, are the slots not supposed to be fixed to a dashboard?
i'v added the sprite to the image now, it works now and the item is basically added, but the sprite of the item that is added into the itemslot is not good because now the itemslot is becomming a circle, so i need to change the sprite of the item to the one i want, whats the best way of doing this
whats the best way of doing this
assign the correct sprite?
well, now the sprite of the item is a knob, so the itemslot changes into that knob
yes but cant add a sprite for some reason
wdym you can't add a sprite?
well, the item is a 9-sliced right?
you've literally described having added a sprite. just not the one you want
i cant set the sprite to 9-sliced
show the import settings for the sprite you are trying to use
i require some assistance of the "i fucked up and im not even sure where" variety
so i made a movement script, and that went well
had a bit of trouble with the camera script, but found one online i understood pretty well but i had to adjust it to my script and set up and whatnot
well im not importing a sprite but i just want to show the original object... its hard to explain look
i want the same if u know what i mean
video too big hold on
thank you
drag the sprite you want to assign into the slot on the item component
i got a simpler video to quickly show the problem
Hey guys, Im working on a gravity gun-esque tool for a 3d physics-heavy game and I noticed that when a given object is "held" by the tool, there is visible jitter. Now, interpolation is the solution for these kinds of camera-tracking situations, however I havent really used it before and so I have some concerns. First of all, if I have hundreds of objects with interpolation turned on, can this introduce a noticeable performance overhead? Could this be avoided by only turning on interpolation for a given object when it is interacted with by the tool? Can interpolation cause problems if I have some outside force affecting the held object, like an explosion or another object bumping into it, etc, or is this handled by the physics system internally?
okay so the camera moves, which is great
absolutely perefct
problem is that the entire thing is moving, and i realize that part of the problem is that its attached to the player object, which is kind of lower on my concerns
thats the problem i cant seem to be able to drag it
my primary concern is that i can go through objects, which wasnt really the goal
well since you're not providing any useful information, i don't know what to tell you. and i'm not going to play 20 questions just to get a tiny scrap of info. so post a full description of your current issue to a relevant channel (since it is not a code issue any longer it does not belong in a code channel) and someone who has the patience to help you will do so
its because you're rotating the player's x not the camera
oh my b theres a physics channel lol I'll go ask there
yeah i gotta figure that out. im not entirely sure how to do that separately because i want it to to rotate it on the y axis, so the actual player moves, along with the camera
but i also don't want the player object to rotate on the x axis
obligatory "use cinemachine"
also the answer to your issue is to just rotate the camera around the X axis, don't rotate the player around the X axis
i am unfamiliar with cinemachine and what it is but uh
i think the problem comes with that last line
to note, this is from a tutorial's script but due to me having a different movement set up, it functions a little differently
bad tutorial
i had to throw out some stuff
don't multiply mouse input by deltaTime, it is already framerate independent
i mean it gets the rotation working
its just i have everything turning
and separate the axes of rotation and only rotate the camera around the X axis
i dont know how ;-;
im this 🤏 close to just making two individual scripts 😭
but surely it can be done in one
look at where you are rotating the object and think for a second
i will attempt something
instead of making things more confusing , make actual fields for your transforms that are important
Transform cameraTransform Transform playerBody
etc.
transform.rotation depends a lot on where you place the script.
pretty obvious putting this NOT on the camera but player you are rotating the whole player..
Hey guys i have one question, where should I start learning on how to use unity?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
oh thanks
something like this?
i forgot serializefield was very much a thing
fair point
will try
you dont need to YRotate the camera though if its child of body
the body rotation of player will take care of that
ideally it won't be a child of the player though
why's that?
my god
wait huh?
if i set one to 0 won't it just refuse to move the y value
right
it worked
yes, they would ideally be separate so that you can control when the camera's position and rotation actually update to ensure that it happens on the correct timestep to ensure completely smooth camera controls
now i have to figure out why i keep going through objects
i thought having a collider would just prevent objects from... well just going into each other
it entirely depends on how you are actually moving
ohhh I see. Thought this was more issue with rigidbody since its fixed update, character controller seemed ok
for example, if you move via transform.Translate or transform.position that completely ignores collisions because you are teleporting the object

yes don't use translate
slap a character controller on it
the direction n stuff doesn't change, replace it with cc.move method
how do i send a script ;-;
use links ⬇️
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
cant send here directly?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
this was the movement ;-;
yes, like I said. Put character controller and just replace the Translate to characterController.Move
that should fix collisions as you will be using a physics object + collider
you can remove any colliders you have on player, as character controller comes with one
will report back once i finish fighting getcomponent to work
im working on this project where i want to save the coordinates of gameobjects that the player can spawn during the game but im wondering what would be the best way to do this so im just on here for some advise about that. I've attached a video and i want to save the location of the orange platforms/triangles
What isn't working about it? You give it a type and it returns a reference to that thing on the object you call it on
im not even sure but give me a bit
i went from 10 errors to 4 so clearly im going in the right direction
(?)
no it seems im stuck
i tried to use getcomponent but i might have been wrong in my selection
sorry to come back to this guys but ive been trying for a wile now and cant seem to find how to "configure" it or what to configure
look at the message directly below the one you replied to. the bot linked relevant guides
i checked the guide, i did all that i think, its just telling me to update but its updated
these statements are pretty much not useful to us 🤷♂️
that is not all it is telling you to do
which guide did you check?
the first one
so visual studio ?
before the Updating part, there are quite a few more steps
jup, did all that
did you verify you had Unity Workload?
ok so go into external tools in unity again, close vs., click Regen Project files, open script from unity..wait till it loads n report back with a screenshot
that would be the page, yes did you read the rest of the sentence
yes but this is where i got stuck
did you close VS ? do it. Click the Big Button Regenerate Project Files
open script again from unity
i fix one thing and something else breaks 
welcome to gamedev/coding
joy
that did it thanks man
i am now moving relative to my position in the game world instead of just my own position and i dont even remmeber how to undo that
colliders work though
oh right translate is local afaik and Move is not
use Transfrom direction or use transform.forward etc.
Vector3 uses world position
goodbye vector3 it seems
its still a vector3, its just already rotated according to transform
transform.forward will give you the objects local forward for example, still a v3
thank you 🙏
on the bright side from this experience, if i ever want to make a ghost game i now know how
so I'm new here and idk if anyone will know how to help, but essentially this is my first time ever coding/designing and on unity hub i tried to install the editor but its stuck validating the editor application... any tips?
!install
- Make sure you have enough space including on
C:drive. - Check that it's not being blocked by antivirus/security programs.
- Look through the logs for a real reason why the setup fails they are pinned [here](#💻┃unity-talk message).
If you still have issues, perform a clean install in another location:
- Install the Hub and Unity in a non-system drive or a clean new folder in the root of
C:drive. - Failing that use the recovery Refresh option or reinstall OS entirely then repeat the previous step.
also not a code question. #💻┃unity-talk for installation issues
using System.Collections;
using System.Collections.Generic;
using System.Security;
using JetBrains.Annotations;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;
public class GrabItems : MonoBehaviour
{
bool isHolding = false;
public GameObject objectHolding;
Rigidbody rb_objectHolding;
public GameObject hands;
public Vector3 farness;
Camera cam;
void Awake()
{
cam = GetComponent<Camera>();
}
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
{
var ray = new Ray (cam.transform.position, cam.transform.forward);
if (Physics.Raycast(ray, out var hit)) {
var Object = hit.collider.transform;
objectHolding = hit.collider.gameObject;
if (objectHolding.TryGetComponent<Rigidbody>(out Rigidbody rb_objectHolding))
isHolding = true;
}
}
else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
isHolding = false;
}
void FixedUpdate()
{
if (isHolding) {
//objectHolding.transform.position = hands.transform.position + farness;
//objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
rb_objectHolding.MovePosition(hands.transform.position * Time.deltaTime * 40f);
}
}
}
why is rb_objectHolding gray?
that's actually an unrelated local variable named rb_objectHolding not your field of the same name
remove the type on that line and it won't be declaring a local variable and will instead use the field
my bad new to the server as well
hover over it (the greyed out parameter) and see what the pop-up says . . .
also, Rigidbody in TryGetComponent is greyed out as well . . .
"name can be simplified"
there you go. it's telling you, you can simplify the code. use the Actions or click the light bulb for options . . .
it doesn't help
I want to use trygetcomponent as a check and assign rigidbody to rb_objectHolding
I don't understand the sentence, do I do it like that?
yes
you can clearly see that it is now using the field rb_objectHolding rather than declaring a new local variable with that same name
oh I'm dumb I got to the solution before, I just forgot to add rigidbody to the object I'm raycasting
Well, what boxfriend said is also important
it's because you specify rb_objectHolding as a Rigidbody making it a local variable. remove Rigidbody from TryGetComponent<> and the argument . . .
yeah
having the generic type parameter there is perfectly fine, just a bit redundant since the method can infer the type from the output parameter. and if they want it to remain clear about what type it is supposed to be getting then leaving the generic type parameter is perfectly fine. the only issue was the declaration of the local variable as the output parameter
Yeah, I was just clarifying about why Rigidbody and the variable name were greyed out . . .
hi, all. does anyone know real quick why it is saying object reference not set to instance of an object with this line? hpfohud.SetText(currenthp.ToString());
the code actually works perfectly, and does what i want, but for some reason it throws that error..
Somethiing on that line is null but you're trying to use it anyway
but it works, though..
i dont understand how its null
current hp should be 200, and it displays 200, even the placeholder text where the hp is says "hps", not like i set it to 200 or something
but when i run the game it sets it to 200 correctly
Something isn't
You might have one of these running properly
but the existence of this error means there exists at least one instance of this script for which hpfohud is null
i see, ill try and look for that
AH
thank you
i SOMEHOW put it on some random block in my level
using System.Collections;
using System.Collections.Generic;
using System.Security;
using JetBrains.Annotations;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;
public class GrabItems : MonoBehaviour
{
bool isHolding = false;
public GameObject objectHolding;
Rigidbody rb_objectHolding;
public GameObject hands;
public Vector3 farness;
Camera cam;
void Awake()
{
cam = GetComponent<Camera>();
}
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
{
Debug.Log("clicked");
var ray = new Ray (cam.transform.position, cam.transform.forward);
if (Physics.Raycast(ray, out var hit)) {
Debug.Log("raycasted");
var Object = hit.collider.transform;
objectHolding = hit.collider.gameObject;
if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
{
Debug.Log("got component");
isHolding = true;
}
}
}
else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
{
rb_objectHolding.useGravity = true;
isHolding = false;
}
}
void FixedUpdate()
{
if (isHolding) {
//objectHolding.transform.position = hands.transform.position + farness;
//objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
rb_objectHolding.useGravity = false;
rb_objectHolding.MovePosition(hands.transform.position);
}
}
}
how can I make it slower?
rb_objectHolding.MovePosition(hands.transform.position);
in FixedUpdate()
what's explained in unity site does bugs
Well, you're teleporting it every frame, so if you want it to go slower, teleport it to a closer position every frame
That will teleport it to a position that is 1/10th of the distance from the origin to where the hands are
That doesn't make much sense
void FixedUpdate()
{
if (isHolding) {
//objectHolding.transform.position = hands.transform.position + farness;
//objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
rb_objectHolding.useGravity = false;
rb_objectHolding.MovePosition((hands.transform.position - objectHolding.transform.position) * 0.1f);
}
}
still doesn't work
Every frame, it will teleport to 10% of the distance from objectHolding to hands, meaning if neither object moves, it'll get there in 10 frames.
how can i make it so a bullet always goes the way of the barrel
wait thats kinda stupid leme send a screenshot to explain it alittle better
Set the bullet's rotation to that of the barrel. Propel the bullet on it's local forward axis
as u can see the gun is pointing up and so is the bullet yet the force is being added vertically
Depends on how you're making the bullet. Usually you'd spawn it with the proper orientation then just have it travel on local forward
Bullet.GetComponent<Rigidbody>().AddForce(transform.forward * BulletForce); this is the code that makes the bullet go woosh
how do i make it travel on "local forward"
Use transform.forward
i am
You're already doing that - it's forward just isn't aligned with the gun's
Then your bullet is moving local forward. It's just not facing the direction you want
So you need to make sure it is
it is tho look in the screenshot
its facing up just like the gun
Is that forward for the bullet though
When you click on the bullet and look at the local transform gizmo, is the blue arrow pointing in the direction of the bullet
Hi. I have a problem: I want to refer to the component in the script: "Localized String Event". I was able to find the name, but I can't access the Entry name. How do I access the Entry name?
no
i meant yes
It would seem that this class doesn't have anything named "EntryName", so what are you trying to set?
its pointing up, just like the bullet
rb_objectHolding.MovePosition(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f));
idk what I did but it seems to be fixed. Is there a way to make the object go on the same speed when I'm dropping it? so that basically if I drag the mouse up fast and drop the object then I'm throwing the object. That way it would be more fun
Instead of trying to teleport it some percent of the distance, why not just get the direction you want it to go in, multiply it by some sort of speed, and add that to the current position?
Seems like you're applying the force in the forward direction for whatever object this script is attached to. Apply it to the bullet's forward instead
That doesn't look like it belongs to LocalizeStringEvent, that's a property of StringReference it seems
ya, transform.forward only works.. if thats on the bullet..
you want me to attach that script to the bullet?
if its not on the bullet u need to do bulletReference.transform.forward
as ur direction
You could. Or you could just use that object's transform
Ok. Thanks
do I have to use addforce instead?
thanks
basically thank DapperRaccoon, i just elaborated on what he said
Possible. There are many ways to move something. AddForce is one, MovePosition is another. What I suggested was just a simpler way to write what you're trying to do
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
{
Debug.Log("clicked");
var ray = new Ray (cam.transform.position, cam.transform.forward);
if (Physics.Raycast(ray, out var hit)) {
Debug.Log("raycasted");
var Object = hit.collider.transform;
objectHolding = hit.collider.gameObject;
if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
{
Debug.Log("got component");
isHolding = true;
}
}
}
else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
{
rb_objectHolding.useGravity = true;
isHolding = false;
rb_objectHolding.AddForce(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f), ForceMode.Force);
}
}
void FixedUpdate()
{
if (isHolding) {
//objectHolding.transform.position = hands.transform.position + farness;
//objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
rb_objectHolding.useGravity = false;
rb_objectHolding.MovePosition(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f));
}
}
Do I do it like that? (in else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true) part)
also I think MovePosition isn't the best way...
because it's not really colliding
@polar acorn Should I keep it like that and move on or make it perfect?
Correct, teleportation does not respect collisions
You can very easily move something straight through a thin enough collider, even with interpolation enabled
should I move on?
Any idea why my camera is bouncing like this? float n = (_right + _left) / 2f; _zoom = n * Mathf.Sin(_angle * Mathf.Deg2Rad) / _camera.aspect; and float n = (_up + _down) / 2f; _zoom = n * Mathf.Sin(_angle * Mathf.Deg2Rad); should've fixed it but it for some reason didn't. Not sure what I'm doing wrong
At the very least consider simplifying that math. This suggestion would be a much cleaner and more controllable way to handle movement: #💻┃code-beginner message
I don't know how to simplify it, I can only put it inside the variable
I told you how. Get the direction, multiply by a speed, add that to your position
why when i click the button the log is executed but the uxml is not changed? ```csharp
private UIDocument uiDocument;
private void OnEnable()
{
uiDocument = GetComponent<UIDocument>();
if (uiDocument == null)
{
Debug.LogError("UIDocument component not found on the GameObject.");
}
}
public void EnterFactory()
{
Debug.Log("Entering factory");
string path = "GameHUD";
VisualTreeAsset newAsset = Resources.Load<VisualTreeAsset>(path);
if (newAsset != null)
{
UpdateUI(newAsset);
}
else
{
Debug.LogError("VisualTreeAsset not found at the specified path.");
}
}```
Fixed, nevermind
rb_objectHolding.useGravity = false;
float speed = 0.4f;
Vector3 direction = hands.transform.position - (hands.transform.position - objectHolding.transform.position);
float finalSpeed = 1f - speed;
rb_objectHolding.MovePosition(direction * finalSpeed);
I tried to simplify like that but it doesn't work the same way
ah yes
So... I have an animations. Here my video:
And, while reading the notes, the animation does not go off in idle, as shown in the video, but the current animation, which was activated before, continues to run. Can you help me with this? I need to activate idle animation white reading the notes.
Here code of notes:
https://hastebin.com/share/fupabeyego.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
there is nothing about animations in this script you sent
Hi. I have a problem with languages: When I change the language to another one, all the numbers disappear and just a word remains. How do I save the numbers after changing the language?
Example: "I love you: 100%", I change the language and it turns out: "I love you" without numbers. How do I save the numbers?
I have a different script for this. A script for movement. One second please...
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
void FixedUpdate()
{
if (isHolding) {
//objectHolding.transform.position = hands.transform.position + farness;
//objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
rb_objectHolding.useGravity = false;
float speed = 0.4f;
Vector3 direction = hands.transform.position + objectHolding.transform.position;
rb_objectHolding.MovePosition(direction * speed);
//rb_objectHolding.MovePosition(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f));
}
}
idk honestly this is what I have right now, I'll just move on then ig
thats not direction
ur setting isMoving bool parameter to true everyframe
if (Input.GetKeyDown(KeyCode.U))
{
gameObject.SetActive(false);
}
quick question
this is basically designed to just let me turn a text prompt on off and the screen
is there a way to make it so that it keeps setting it to the opposite?
as in, "okay well this object is false so lets turn it to true" and vice versa
make a bool you can use then invert it
! is the "not" operator that inverts a boolean.
You can get the current active state of the object with gameObject.activeSelf
Note: If this object is disabled, update doesn't run so you won't be able to have this object re-enable itself
active = !active
theObject.SetActive(active)```
Don't quite understand what you're talking about
you don't know your own code you wrote?
Know. Just don't understand... Sorry, sometimes I'm going to be dumb.
im so slow i was trying to figure out why it wasnt working but it was because at some point i had renamed the gameobject but didn't update it in any of the lines 
You shouldn't be tying the name of a gameobject to any code functionality for exactly this reason
You should avoid things like Find
remmber when I said using object names wasn't good
this..is why
alr made my dragging perfect (wasn't worth it tbh)
how can I make player not collide with objects and make it a toggle?
disable player's collider?
no, not collide with some specific object when I don't want it to
maybe you should begin with the beginner unity courses
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I see there are some layers, how can I add a custom one?
Well, I wouldn't write to this channel then.
how do you expect for me to help, I'm pointing out something about your code and animator
the way to fix it is learning how the animator works
then learning how the transitions affect the animations, the code is affecting that transition
Have you done !learn ?
That should be done before you move onto doing things on your own or asking for help here.
There is beginner, and then there is a stage BEFORE beginner. You need to have a foundation of understanding for anything we say to make sense
Best of luck!
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hi there, ive never had this issue in the past but whenever I edit code e.g. adding new public variables, they never appear in the inspector unless i manually reimport the script. There are no compile errors and im definitely saving the script. unity version 2022.3.19f1, vs version 2022 [17.10.35122]
have u tried to restart to know if it still persists?
i have restarted both unity and vs and it still happens
Privet pediki pososite
Perhaps domain reloading is disabled in preferences
Does it compile when you hit play? Or just never
let me have a look rq
when i click play it compiles yh
afaik that only deals with playmode
should this be enabled?
sounds like you have compiling script issue not so much domain reload issue
VS prob not triggering compile for some reason
any suggestions ?
Also check General > Auto Refresh, and double check your External Tools settings 👀
nicee
using System.Collections;
using System.Collections.Generic;
using System.Security;
using JetBrains.Annotations;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;
public class GrabItems : MonoBehaviour
{
bool isHolding = false;
public GameObject objectHolding;
Rigidbody rb_objectHolding;
public GameObject hands;
public Vector3 farness;
Camera cam;
void Awake()
{
cam = GetComponent<Camera>();
}
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
{
Debug.Log("clicked");
var ray = new Ray (cam.transform.position, cam.transform.forward);
if (Physics.Raycast(ray, out var hit)) {
Debug.Log("raycasted");
var Object = hit.collider.transform;
objectHolding = hit.collider.gameObject;
if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
{
Debug.Log("got component");
Debug.Log(hands.transform.parent.parent.parent.GetChild(1));
Physics.IgnoreCollision(hands.transform.parent.parent.parent.GetChild(1).GetComponent<Collider>(), objectHolding.GetComponent<Collider>(), true);
isHolding = true;
}
}
}
else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
{
rb_objectHolding.useGravity = true;
isHolding = false;
}
}
void FixedUpdate()
{
if (isHolding) {
rb_objectHolding.useGravity = false;
Vector3 direction = hands.transform.position - (hands.transform.position - objectHolding.transform.position) * 6f;
rb_objectHolding.velocity = hands.transform.position - direction;
}
}
}
why does the line with Physics.IgnoreCollision(hands.t
discord size is limiting me
why that line doesn't seem to do any effect?
I want to make player not collide with an object when he's not supposed to
use a paste-bin website if discord is limiting.. too big of a codeblock for the channel
oh wait I think I figured out
no
tried this Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), hands.transform.parent.parent.parent.GetChild(1).GetComponent<Collider>(), true);
hands.transform.parent.parent.parent.GetChild(1) is quite the traversal... You might consider storing a direct reference such that it's less likely you'll make a mistake, and the code can function independently of the configuration of the hierarchy
didnt even notice. that.. cursed line of code for sure
The GetChild at the end is just icing on the catfood
if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
{
Debug.Log("got component");
Debug.Log(sigmaCapsule);
Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), sigmaCapsule.GetComponent<Collider>(), true);
isHolding = true;
}
well, changed it to sigmaCapsule but it still does no effect
you tried google? 
Are you certain that you are witnessing a collision between objectHolding and sigmaCapsule? Have you tried logging the objects involved in the collision event?
no but I'm sure there's a collision
the script is attached to main camera tho but I don't think it has to do something with the collision
I can't think of any good reason for IgnoreCollision() to not work, unless you have some other code which is consistently re-enabling collision. But an alternate solution may be to just change the held object's layer while held.
I got starter asset first person controller which is an official and popular asset I think
I didn't change it except some settings at the start of the script (they're not important)
this is the only "Physics" there
hey i have a pb with my item script( i cant put the item) if you have other script or if you see the pb tell me pls
do you have any errors
its supposed to do that
yes but its with other i think
doesnt matter
an error is an error
needs to be fixed
i have that
I'm not too familiar with IgnoreCollision(), but I would think to slap a script on the held object with a
OnCollisionEnter(Collision collision) {
Debug.Log("Held object collided with " + collision.gameObject.name, collision.gameObject);
}
just to double check my assumptions and hopefully narrow down the problem space
open the console, see if theres anything else
So im trying to make an rts kind of game where a building is generating points but the problem that i have is that its not constantly adding points, only when i place a building i get points, and i wanna put my function in the update function but it doesnt seem to work...
how do i make sure my points go up the whole time? basically updated
i have thats
how do istop unity from collecting 4mb of ram per half second and eventually eating all of it because i accidentally ran a while function for too long
because you need to pass a number in the brackets like the method requests
i started unity in 2024. But today i could
serious for unity.
Because i am a student and i had a so many homeworks and project
i need help for jumping
yes indeed, how could i fix this?
just pass a number?
but i already have in the if(){}... everytime i create a building the amount of buildings go up?
with jumping code
so you want to have points constantly going up? as well as when you place a building? or
what about it
you havent even written the if statement for it yet
character
so when i place a building he generates points constantly, 2 points, and if i build another one i would get 4 points bcs he generates 2 also
i see, so you have a value 1 for example which gets added every second or frame.
when you place a building you want to increase 1 to for example 3 correct?
bro idk how i can write a jumping code for character
have you attempted just using that same translate for movement, but translating it upwards?
not sure exactly how jumping works outside of a rigidbody, but i assume you just need to move it upwards
So do PlayerCapsule and Capsule both have colliders? I think your hands.transform.parent.parent... thing was targeting Capsule, but that log indicates that it's colliding with PlayerCapsule
Thanks
what you should have is multiple different methods, 1 for adding score, 1 for increasing the Number the score is increased upon
im trying to have it write a game save using a json file, but when i close the program i get this error. i checked, and the locallow and defaultcompany folders arent read-only, so i dont get why this could be happening
did it like this, is this a good way to do it? so i made an extra variable to store the amount of buildings and then i pass it to the function
PlayerCapsule doesn't have a collider, Capsule does
Capsule
yeah sure thats fine, as long as it works then you can change things up later
CharacterController is a collider
if you click the CC w/ gizmo's enabled u'll see the green capsule
ah
so I should keep my thing only on charactercontroller or capsule as well?
what's cc?
shorthand for Character Controller, sorry bout that abbrev.
Unless you have a specific reason for a separate discrete collider, probably best to just rely on the one which CC already provides
cant see the button
protip: CC's collider works as is w/ OnTrigger methods..
but for Collisions it has its own method https://docs.unity3d.com/ScriptReference/CharacterController.OnControllerColliderHit.html
the button i press first is the Gizmo's Enable/Disable/Hide etc
when i select the CharacterController gameobject (when CC is collapsed it hides it when its expanded it shows it)
collapsing components is a good way to get rid of unwanted gizmo clutter (while keeping the actual gizmos enabled)
yo guys.
why do these two scripts(SequenceGraph.cs and Start_Node.cs) keep disappearing from visual studio?
I've tried to delete them and re-add them in hopes that the issue would be fixed but they keep disappearing.
I've also tried "Add existing item" option in visual studio but these two scripts will still disappear for no fucking reason!
they are there in file explorer but i just cant get them to show up in visual studio code, and unity dosnt recognize refrances made to those scripts!
here is my unity console
i have also restarted visual studio. didnt fix a thing
private void FixedUpdate() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, 1000, layerMask)){
pos = hit.point;
}
}
i wonder if the Ray is needed here? cant i just do this?
if(Physics.Raycast(Camera.mainScreenPointToRay(Input.MousePosition), out hit, 1000, layerMask)){
pos = hit.point;
}
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
damnit, keep forgetting about it, sorry about that...
is my pc haunted or something? please help 😵💫
I've not seen that before... But you might try right clicking and reimporting them within Unity
And possibly regenerating the project files from External Tools
ill try that
They are one and the same - either would be fine 👍
Sometimes the extra variable is nice to make things more readable, or if you had another use for the ray like debug-drawing it
aah okay, thank u!
restarting unity,(which reimports all scripts i suppose) fixed it. ty
Excellent 😁
Hard to explain so I recorded it.
https://pastebin.com/T0PHL0nw
My character semi collides with cubes. It can stand on the cube, jump on the cube and slowly falls into the cube. How can I fix it?
i feel like i have a problem i shouldnt have so uh
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
that's what the current script is, and when i click U, it unlocks the mouse, and freezes everything in place (minus the player rotation but thats a bit lower on my concerns)
but since thats the intended goal, i tried to apply that to another object, the menu
so i basically copied and pasted the script bit for the inventory, and then tried to apply it to the menu
locking the cursor doesnt stop from reading its values
you have to disable the movement / look script if you want the player stop when window prompt is up
v2 (exactly the same thing, just recorded differently)
let go of the cube when you're ontop of it
noted, and thank you
the problem however is not hte inventory
its the menu
hold on lemme get a
im trying to redo this and if it just suddenly decides to work im going to lose it
would only help with the flying part, on ground it's still weird
I'm using unity FirstPersonController
hehe, im actually working on teh same thing
weird in what way?
My game has different ranks (C,B,A,S) which are enums how can I make sure that if a condition evaluates for rank C, it also evaluates for higher ranks, for example, I can obtain this C rank item with a C rank Weapon, but also with B,A,S rank weapons
character controllers dont do well w/ collisions (esp physics based ones)
lol i remember running a gmod server I needed this plugin
a simple solution would to be to check if the box (the thing ur carrying) is lower than the players feet
if it is.. u shouldnt lift on it edit: havent tried this myself.. just guessing
I'm still like half gravity when I'm jumping on the cube while the cube is on the ground
without doing the if(rank = C ||rank = B || rank =A || rank =S) all the time
nice
idk from the video alone its hard to tell
looks like ur having as much fun as i had when i was workin on it.. lmao
my main problem was the pickup distance.. + throwing it
main part on 0:18
when i release i have to dampen the forces
maybe its ur script
its saying you're grounded when you're above the box midair
since ur character controller isn't sinking thru the ground
oh wow I didn't even see it lol
should I just add in Update a thing that just does grounded = false?
when I'm touching that cube
how would I detect touching cube tho if I disabled collisions between them...
im confused what im seeing.. when ur above the box.. (an sink thru it) are u actively lifting that object
(is ur script doing anything to the box)
show the current code. seems ur raycast or whatever is going to far
how would I detect touching cube tho if I disabled collisions between them...
im working on this right now.. because when i run forward w/ the box it jittters off of the players collider.. but i do want to be able to stand on them..
- you can disable the collisions between the player and the box (only when ur carrying it)
thats what i intend on trying first.. and then i'll see
code is there
ya, but the code you sent is to pick up the object..
in the video it appears u fall thru the cube w/o ever picking up the object.. (which shouldnt happen)
but i could see it possibly happening if ur interacting w/ the cube and messing w/ its physics
what other code do I send?
it's kinda the only code I got
my solution for moving objects was to use AddForce instead of directly seting the velocity
there's also playercontroller I can upload it to pastebin
well ur playercontroller would be why its falling thru the cube.. (if its just a regular rigidbody cube w/ a regular collider)
the pickup code shouldnt have anything to do w/ the player falling thru the cube (if ur not picking the cube up)
cube is regular
b/c its not even being run at that point in time
with rigidbody
as is mine.. you can see here i toggle off my pickup script entirely..
https://pastebin.com/SgCeNYAj this is player controller or how it's called
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.
it's not actually affecting my player in any way
does ur player consider the cube ground?
my ground check detects everything for now..
maybe it doesn't respect the cube as being the ground. so it phases into it.. until it actually touches the normal ground
hmm no idea
private void GroundedCheck()
{
// set sphere position, with offset
Vector3 spherePosition = new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z);
Grounded = Physics.CheckSphere(spherePosition, GroundedRadius, GroundLayers, QueryTriggerInteraction.Ignore);
}
Can anyone tell me why Carry triggers immediately and not after the timer?
create a normal rigidbody cube.. and test if u can stand on it
see if its any different than the cube ur using to pickup
I can stand on that cube before picking it up
that effect just happens after
Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), sigmaCapsule.GetComponent<Collider>(), true);
Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), plrCapsule.GetComponent<Collider>(), true);
have you saved? does carryHoldTime start @ something less than carryThreshold..
- Put a debug in there.. right before the
Carry();method
Debug.Log($"Carry will be called. CarryHoldTime: {carryHoldTime} and CarryHoldThreshold: {CarryThreshold}.");
ohh then yea thats what ive been trying to ask for a while now.. soo you only fall into it while trying to pick it up
soo yea, its the pickup script for sure then
instead of directly setting velocity use RB.MovePosition or RB.AddForce, ForceMode being ForceMode.Acceleration
I only slowly fall after doing the Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), sigmaCapsule.GetComponent<Collider>(), true);
Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), plrCapsule.GetComponent<Collider>(), true);
I think the problem happens because of firstpersoncontroller
it appears the carryhold time is already way higher than the threshold when u begin that funciton (or when that log gets called)
is it possible to reset it to 0 each time u go into that if statement
when you interact -> set carryHoldTime to zero..
then ur if statement starts to increment it
i would agree.. its because of the CC the reason we have to use special movements and stuff to deal with it..
if its a rigidbody character controller.. u could move ur physics objects any way u wanted to. and you'd have more luck
I don't understand. Could you show me an example?
it's a unity asset character controller
wherever u set isCarrying to true..
if its like an input..
if(Input.GetKeyDown(KeyCode.Space)){
isCarrying = true;
carryHoldTime = 0;
}```
this would set it to 0 before the if statement started adding on to it..
I already have it like this.
then why does it debug 1,5000xxxxx
very strange.. 🤔
maybe I have to do something with ground layers? they're complicated tho
hey im trying to get that when the key "W" Is pressed it adds force to the player cube. can anyone help ?
oop sorry
how can I change layers of a cube? what is a default layer?
nvm I got it
but what are these 5 layers?
are they just 5 layers with random names?
but like
can i save a scriptable object, with GO references to specific scenes somehow?
named with sense for organization?
The best thing you could do is attach the debugger, slap some breakpoints in the places of interest, and step through it...
But short of that, could you post the full script on a paste site? The excerpts you've shared thus far don't describe what you're seeing by themselves, but there's also not enough context to understand how they all connect
can someone tell me?
they're anything you want them to be..
but do default 5 ones have some special meaning or not?
they're used for layer masks.. layer based collisions.. comparisons etc
or it's just organization?
no, someof em are important..
default, ignore raycast for example
wouldnt wanna mess w/ those
the rest is up to you and how u wanna use em
so these 5 are with special meaning?
the original 5 you shouldnt try, or even want to change/modify
you have 32-5 other ones you can use for w/e
can 31 layers be not enough?
This is in the animator the parameter is there but it says it isnt when I run the method to activate it did I do something wrong
void fadeIn()
{
animator.ResetTrigger("Fadein");
animator.SetTrigger("Start");
}
void fadeOut()
{
animator.ResetTrigger("Start");
animator.SetTrigger("Fadein");
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
if ur using all 31 layers.. you either have a chunky game.. or ur doing something wrong
add a line break after the cs to make the syntax highlighting work
like that ^
Got it thannk
yw! 🙂
Anybody know?
bamboozled 🪄 ⭐
word of wise.. try to use different names for ur clips vs ur transitions
it'll get complicated quick if u dont
even if its just FadeInClip vs FadeIn for the transition
Ignore Raycast is omitted from the default physics query layermask...
TransparentFX - apparently lens flare will be visible through these objects? 🤔
I don't think there's anything special about Water 🤷
Aaaaand no clue about UI either, unless it has something to do with input handling for UI shtuff... Or maybe just a convenience for a UI camera...
It is very strange that these don't seem to be well documented anywhere
ya, Water is a wasted layer 😛
AHH we cant even remove it
This is going to haunt me
just repurpose it 😛
Water is my new Ground layer
- Default: The standard layer that all GameObjects are assigned to by default; used for general-purpose rendering and physics interactions.
- TransparentFX: Intended for objects that require transparency and special rendering effects, often used for visual effects like glass or water surfaces.
- Ignore Raycast: Objects in this layer will not interact with raycasting, making it useful for objects that shouldn't be detected by raycasts (e.g., background elements).
- Water: Reserved for water-related GameObjects and effects; often used in conjunction with water rendering and physics systems.
- UI: Specifically used for Unity's built-in UI elements, ensuring they are rendered and managed separately from 3D objects.
the mo you kno 🌈 ⭐
Still mysteriously vague, but satisfying enough 😁
default, ui, and ignore raycast being useful
private void Start()
{
movementScript = GetComponent<MovementScript>();
}
and
if (!inventory.activeSelf)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Time.timeScale = 1;
movementScript.GetComponent<MovementScript>().enabled = true;
}
is "movementScript.GetComponent<MovementScript>().enabled = true;" this line not supposed to do this
im not getting an error but now if i called the component in start, do i need to call it again later?
no, movementScript is already a MovementScript instance
i tried to just write movementScript.enabled = true; but then it just fails
how can I change layers through script?
NRE ?
idk if I'm trying to do something weird
what?
probably not
Check the GameObject docs - look for applicable members 👀
https://docs.unity3d.com/ScriptReference/GameObject.html
like im very sure it'll work but i vaguely remember being told that having the script keep using get component is not a good idea
no it is not, you only do it once as you do in start
ah yes I forgot it's a GameObject property
yeah im not sure how to get it to true
'Component' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'Component' could be found (are you missing a using directive or an assembly reference?)

You do it as often as needed. If you get the same component multiple times, it is more than needed, since you can of course save it
you typically cache the variable.. and use the cached version if u need to repeatedly access it..
private PlayerMovement myPlayerMove;
public void Start()
{
myPlayerMove = GetComponent<PlayerMovement>();
}
public void Update()
{
//now if i want to access playerMovement i already have the reference..
myPlayerMove.enabled = true;
myPlayerMove.DoSomething();
}
What did you write? GetComponent<Component>() ?
perhaps i am the flaw
show the declaration of movementScript
public Component movementScript;
private void Start()
{
movementScript = GetComponent<MovementScript>();
}
man i should not name these the same thing
so change Component to MovementScript
You should never make the type Component
MovementScript movementScript is good enough for naming.
camelCase being the reference.
Well MovementScript inherits from MonoBehaviour and has access to its properties.
Component comes earlier in the inheritance chain and does not
UnityEngine.Object > Component > Behaviour > MonoBehaviour > MovementScript
The ones at the end have access to the ones before it. The ones at the start have absolutely no clue about anything after it
GetComponent<MovementScript>();
you are asking to return something of Type MovementScript, so the variable you set it to should also be declared as the same Type
You can totally store a reference to your script in a Component-type variable because as Aethenosity describes it is a Component due to it's inheritance chain, but then you can only access members which exist on the Component type. If you want to access the members you've declared within your script, then the reference must be stored in a variable of your script's type
unity been beating my ass all day 
Every time i think i get something i proceed to break another thing i didnt even know was a problem
You could even store it as a UnityEngine.Object
You just wouldn't WANT to
how else do you plan on learning ?
class InventoryData
int Id;
Item item;
public InventoryData(Item _item){
item = _item;
Id = _item.id
}
My question is... Do I need to give Id as a parameter? Or can I just do this and set the id to the given item's id in the constructor?
sure, no problem, you could also do
int Id ( get { return item.id; ) )
and not set anything
I am trying to understand why he also adds id in the parameter. Isnt it just easier to just give the item whenever you new the class and set the properties/fields inside?
Think it makes the most sense as its readable and all?
Ah yeah makes sense
I should work more on the properties and get used to them.
if you find yourself duplicating data then properties are usually the answer
All right. I understand. Thanks!
its fun until every step forward is rewarded with a step back
i got the menu and inventory pausing like i wanted to and now the mouse keeps getting locked and unlocked regardless of what i want so
time to figure out which part i fumbled this time
i am so close
I am also having trouble with my mouse getting locked and unlocked T_T havent tried yet but it may work different on build as people here suggested.
gonna keep powering through. something is going to work.
whats setting me off is that menu and inventory basically have the exact script, except one always seems to have a problem the other doesn't
When i go to the menu, the mouse does not lock as its not supposed to
when i try to click the inventory, it lets the mouse move around until click on screen again and then it locks
but it looks like its glitching because it keeps flickering in and out
does ur menu use the Escape key?
in the editor Unity uses escape to undock the mouse from the game.. it will override any cursor locking you have
until you click back onto the game so it goes back to focus
thats why people say in the build it will be fine
i tend to use a different key for when im building/testing the game.. and then when right before i build i replace it back to Escape
the backtick ~ key is a good alternative
took me a solid 20s to realize im the odd one with the qwertz keyboard and was wondering why you would want to break your fingers every time for that test 😄
where is the ~ key for you?
right alt + pinky right next to the enter key
oof, ya edit: if ur using a QWERTZ keyboard.. maybe dont use the tilde key
^ is on the same key you got ~, ° with shift
° is a cool key.. i wish i had it.. for degrees i always have to make due with *
i think i have used it twice since I know how to use a keyboard, one of those above
im always impressed by those that use keyboards that try to pack 3 or 4 character on 1 key.
w/ StreetFighter type combo's to access them 😄
that key is the definition of wasted potential on qwertz 😄
last offtopic question: where do you live that uses qwertz?
its so prominent and both signs on there have to be amongts the rarest every typed unless you're a ^^ type of person
germany
ahh cool! i'll have to remember that
i can use both qwertz and mac keyboards (from work) and i can find some keys on english keyboards because ssh doesnt care what you got plugged in, if its set to english you better find those keys
as long as WASD is in the same spot we're good 👍 or i'll need to have a rebinding menu for my game to be international
except for y/z all letters are in the same place, + we got äöü on here
but yeah, the y/z switch is a pain sometimes in games, "press z to lie down"... one broken finger later
ya, the more i learn the more i figure that have a remapping input system would be a great addition
i mean the input system makes it easy with the auto-capture remap function 😄
what's the best way to manage the explosion radius for my grenade, should I spawn/acivate a sphere collider in trigger mode and check who is in the collider, but that mean that player could receive damage behind walls, or should I use a raycast to check what's the distance between the grenade and the players and check if their are collider /object between them, but that will mean that even tiny object could stop players from taking damage ?
2d or 3d?
i think an Physics.OverlapSphere is best for that
Okay, I'll look into it.
thx !
does this chek if there are walls blocking the way? for 3d
do you want it to not damage if they are behind the wall?
No but you can get all targets with that and then send a raycast to see if its blocked
but that method will only check if the center of that object is behind the wall, not if for example a foot is sticking out
I think that's not a big problem
yeah then just collect all targets with the CheckSphere and then send a raycast to each of them, if the raycast is blocked by something else you remove them as a target
you can make the targets just be of a certain layer too, so it doesnt just get all random objects
oh yes that might be usefull
I've just remembered that if a small object is in the way, as in my example, if I use only a raycast the player won't take any damage even though his whole upper body is exposed to the grenade.
use multiple raycasts
at each height
ive seen it solved by having a collider on each body part, head, torso, arms, legs and raycasting to each of them
dont even need different colliders if you want, just do multiple raycasts
ok can I just say that instead of targeting the whole player, the raycast has to target a specifique bone of this player ?
you can set the transform of the bone you want as raycast target and check if they raycast gets the whole distance to the bone without any collision with walls or stuff
ok thx a lot for your help !
Fun fact: This is how explosions work in the original DOOM. If you had a drop that was like 14 pixels or more below you, Arch-Vile explosions wouldn't actually damage you, since their origin is the ground in front of you. This means you could stand on a staircase and be immune to most explosion damage
3 positions is how i do it as well as gr4ss said
So, if you fix this problem you've got a leg-up on John Romero 😄
its used more for just grenades too.. (when enemies are lookin for the player.. they need to be able to see his feet too)
Is it ok if I use like 4 or 6 instead of 3 ?
Input.GetKey("a"); is this the check if key was just pressed? like not the key is being pressed and not that the key has been unpressed but that the key was exactly just pressed?
It checks if the key is currently pressed. GetKeyDown() is true if the key was just depressed this frame, and GetKeyUp() if it was just released this frame.
Yeah
"pressed" and "depressed" are synonyms, albeit it's not a super common usage of the word 😅
can I make some cooldown like 5 seconds? do I have to save previous time or what?
save previous time somehow and then -?
Sure yeah - you can store the time of the event and check if the current time minus that is greater than your threshold. Or reset a timer to 0 and add Time.deltaTime each frame until it's greater than your threshold.
Or the super nifty route is to use a coroutine, in which case you just yield return new WaitForSeconds(threshold); and Unity will resume your code from that point after threshold seconds have passed
coroutine is kinda messy and for smart people, isn't it?
what about simplier way like
getting unity clock
or os clock?
or whatever clock is it?
read the 1st part of his message, do that
oldTime = clock()
if clock - oldTime > ...
ok
Check out some of Time's static members
time.time() is nice?
It's not a method, but yeah - that would fit the bill 👍
They're not too crazy - they just take a little experience to get the hang of.
Broadly, they're just methods which will run up until a yield return something statement, where something is an instruction to Unity to tell it when to continue running again - in a frame, a few seconds, when the color of a dog turns blue, whatever.
Everything you can do with a coroutine you can do without, but it can definitely be a more clean and convenient way to write that sort of incremental logic
An awesome tool to have your toolbox - well worth learning at some point.
typically, you place them on the GameObject that you want to have that behavior, but depending on the type of script: controller, manager, singleton, etc.) it will be on a top-level GameObject . . .
if you have a static class, non monobehaviour, you can't write to the Console log in anyway, correct?
you can still use Debug.Log
oh hrmm, ok will try that then
is it a good idea to have different scripts for different buttons even if they're on the same screen
Why would you want that
I'm not sure what you're asking... Whether or not they're on the same screen usually isn't a factor in whether two objects use the same script 🤔
sorry
so its a panel, and on the panel, there are two buttons with different functions
is it better to just have them with different scripts for each purpose?
Often times UI buttons need no script at all - you just assign a method to execute when clicked to the Button's OnClick Unity Event
(And usually that method exists on whatever logic you're affecting rather than the button - like a "Volume Up" button would execute a method on a SoundManager or something, rather than on the button)
there is no "better", do what makes the most sense to you. Though keep in mind that SOLID principles state that each class should have only a single responsibility.
When i'm making menus I typically put methods that buttons will call into classes where they serve similar purposes (like audio related buttons go in one class, resolution ones go in another, etc). it helps keep things organized
Hello, first of all im very beginner at coding. Want to handle slide down if i jump to a slope. Not for a game mechanic, I want to make an RPG (just a hobby learning project) and i want something like World of Warcraft physic. When my character slide down, its stop sliding near the ground.
my code: https://pastebin.com/7AVV51mY
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.
and im realizing my spread doesnt work either
That's related to physics, not to code. Create on your protect window with right click a component called physics material, apply it to the character and try touching those options... I'm not entirely sure of the answer since I don't have Unity in front of me right now, but there's nothing to lose by trying.
i'll try it thanks
you appear to be missing some code, nothing here has anything to do with "reangling the bullet". all this does is create a ray from the center of the viewport
Tell me if it works for you 😉
I realized i sent the wrong code and I figured out the error, sorry. thank you for trying to help
I have none physics material
You have to create it by right click on your protect assets and selecting the new physics material option...