#💻┃code-beginner
1 messages · Page 378 of 1
and maybe even System.Numerics.IAdditiveIdentity<Quadruple, Quadruple>
(these new walls of interfaces look so silly)
2nd of all, your spherecast probably overlaps with a wall, which mistakenly thinks that you're grounded, so you can jump
decreasing the size of the spherecast should fix it
it can usually be very small if its at the leg of the player
hope this helps
i only heard of "BigNumber", not that i ever used it . . .
you also have "big integers", which are...integers
those are important in cryptography
they don't lose precision; they're variably-sized
@quick pollen THANK YOU I decreased the size from 0.4f to 0.1f and its FIXED!!!
Can anyone by any chance help me double check why I am getting this error?
I checked every single asset and the script and it still says value cannot be empty.
First step is to read the full error message
luckily for you though this is very familiar - it's from an AudioSource
Ah
you're trying to play an AudioSource that doesn't have an audio clip assigned
That makes sense, at first I thought it was talking about the scoring system values tysm.
Is this one common too?
Object reference not set to an instance of an object, what on earth does that mean.
you have a variable that is null (not assigned) on line 17 of your ScoringSystem script . . .
it's the most common error you'll see . . .
yes it's common, the most common error you will see
Welp, time to get use to it then I see.
the variable, itself, is a reference variable. there are two types: a reference type, and a value type. knowing the difference is paramount and will help you understand where a problem lies . . .
When you have a variable for a class you wrote, that variable is a "reference", because it is used to hold a reference to some specific object. So when it says "Object reference", it's talking about your variable.
"not set to an instance of an object" - this means your variable was not properly set up to point at any object. Yet you are trying to use this variable which is not properly set up. Hence the error.
i.e.
public MyClass myVariable;```
This variable is named "myVariable" and it is a reference to a specific instance of MyClass
But if you don't assign it, it's not set to an instance of an object
And if you try to use such an unassigned variable, you get an error, as you saw
look for any reference variable on the error line . . .
look at the line the error is coming from
you are trying to use a null reference somewhere on that line
the error provides the filename and line number where it's happening
That will take you right to it
Either scoreText is null or it has no Text component on it
0 is not a variable. that is a number . . .
scoreText could be null or GetComponent<Text>() is returning null
what variables are on this line?
scoreText?
yes, that is a reference variable. it must be assigned a value before you can access it. make sure you assigned it a value before this line . . .
Now, where do you assign a value to scoreText?
Within the diamond collectibles.
ok, great. now there is another reference variable, but it's harder to spot because you access it using the GetComponent method . . .
This one right?
GetComponent<Text>() attempts to return a Text component from scoreText, but it cannot find it. probably because you're using the incorrect type . . .
Does this object have a Text component on it?
Note: TextMeshPro is not Text
yep. what component does the scoreText has?
Use the type TMP_Text to reference it
you need to use the correct type. TextMeshPro is not the Text component; it will be TextMeshProUGUI, but as Digi stated, use TMP_Text as the type instead . . .
Guys what happened to charactercontroller? I was working on my game and eventually It spawned some errors on script that i didn't edit
- https://screenshot.help
- you probably created your own class called CharacterController and it is trying to use that
- also always start with the first error in your console, not the last
Do I just like change ().text to TMP_Text instead?
you need to change the type you are getting from GetComponent to that, not the text property
Scripts are bugged too
you need to put the correct type within the angle braces . . .
It doesn't show me the inspector elements
because you have compile errors. and for the love of god stop photographing your screen. take a screenshot.
I'm using a phone to write thats why, i don't like Discord on PC, thanks anyway
My guess is you wrote your own script called CharacterController and that is confusing the compiler.
use it in the browser to send a screenshot then. don't take pictures of your screen if you want proper help here
Aight
Thank you guys it worked.
You probably created your own class named CharacterController
oops, I was scrolled back
aight i fixed the errors thank you all
Is it okay if I check in Update wether my mouse is on top of certain UI element to show an icon???
It would be much easier to use the event system
IPointerEnterHandler/IPointerExitHandler or the Event Trigger component
yes
you can also just use the EventTrigger component if you don't want to implement those methods manually and want to do something pretty simple in response to the events
what is the EventTrigger?
i have a question, how do i build manually a skeleton on a 3d model?
Thanks for watching! In this Blender tutorial I cover: How to create a skeleton (Armature) in Blender that lets you control / pose / animate your 3D character! This Tutorial covers the basics of armatures & bones, IK constraints & copy rotation constraints, parenting your character mesh to the Armature (with Automatic weights & to specific bones...
thank you
is amazing . . .
I´ve searched it and I am using it now, thanks!!
Does anyone know how to move an object to front in a UI
UI draws in the order it is displayed in the hierarchy, so move it further down in the hierarchy to draw on top of other elements
the thing is I have a description box which is child of an item slot which is at the same time a child of the grid layout
UI is rendered back to front in hierarchy order
If it's later in the hierarchy, it'll be in front
but in my case the problem is that it is in front of the slot it belongs to (it is a child of) but in the back of the other slots in the grid layout
if this is like a tooltip thing, then you probably don't want it to be a child of the grid layout so that you can position it however you want on top of everything
Or make it a child of a grid layout element, not a child of the grid layout itself
That way it draws on top of the element, but is not subjected to the layout rules
yeah but then it doesnt appear next to each slot
maybe I´ll just add the description box a part from all of the objects
I don't know what you mean by this
Ah, if it spans multiple elements then you'll need to have it not be a child of that element. You'll need to have it further down the hierarchy than the grid elements
You probably want a floating tooltip object and position it at the currently hovered object without it becoming a child of it
hmm okay it makes more sense
and in terms of legibility, would it be nicer to see a separate box that stays in the same place all the time and shows information, or this thing I´ve told you about?
In your opinion at least
It depends entirely on how visually busy the rest of the screen is. You'll probably need to try both and see what looks best as part of the whole picture
i'm having trouble with this condition. I get this return error and i dont know how to pass throught this :/ if anyone knows how to fix that would be really helpfull :)
you've messed up your inequality operator. it is instead a null forgiving operator on the GetChild call then an assignment operator trying to assign null to the method call
so like, if (Isco.transform.childCount > 0)
{
Destroy(Isco);
}
i tried but i didn't find good videos
how did you get that from what i said? but yes, that is something you could do instead of fixing what you have there
english it's not my main language really, so i just assumed the problem was the null
no, as i said, the problem is your inequality operator. it should look like != but what you have is ! = which makes two separate operators
i will note that your childCount comparison will likely be faster so just use that anyway
really? the whole internet and you can't find anything ?
i didn't search for long
thats why i didn't find the video
thats more like it
So, in FPS games there is a thing where you can only see your hands, not body, but other players do see your model and animations. Is there a way to do this in Unity? Thanks for help in advance
in a multiplayer game, different objects can be activated for different players
Each player's game turns off their own character's model
and leaves everyone else's character models activated
How do I set that up?
Nope, but the character is set up and ready to go
Depends on your specific networking framework, but all of them should have a concept of detecting whether any specific object is "yours"
whether because objects are actually "owned" by clients, or because you just wrote that down somewhere when the game started
Until I setup the multiplayer. What do I do with the character? I have the full body ready to go, but it keeps going threw the camera and its really annoying. That's why I want to add this in the first place
hey guys
@swift crag
have you been following any documentation or tutorials
they should get into code that checks if you own an object or not pretty quickly
I'm not sure what topic do I search for. I didn't find any video
since you need that for stuff like...say, not turning on 16 cameras all at once
what are you even using?
Netcode for GameObjects?
Mirror?
I'm using mirror
you need to read mirror's documentation, then
you're going to have to get used to reading. multiplayer is complicated
Aight. Can you send me a link please?
Yes I heard haha
you should also get used to doing a basic google search:
"unity mirror documentation"
GIYF
Is starting multiplayer important at the start of the project? can I do it mid way through game developement?
Also, doesn't the networking depend on what you're using? Like for example using steam has its own way, etc?
i have this problem that the navmesh didn't map the zones that i circled, and whenever i go in this zone the player just go under the map and it fells the collision doesn't work only in those areas i don't get why
wildly more difficult to start single player project then inject multiplayer in it
Steam has a networking system, but that wouldn't really affect the multiplayer library you're using in Unity
I'm thinking of putting the game on steam. But I need to make sure that development goes smoothly. Can I like write the game using the steam networking and testing it before paying the 100$?
no we don't know why, all we have is a screenshot. How useful is that to debug logical error ?
start by showing the inspectors
navmesh agents don't have collisions, so something already doesn't sound correct
I don't know about that.
No worries. I will check it out
the complete player inspector..
how do you move it, what are the components on it
is player not a navmesh agent?
yeah
wait i'll send you the screens
@rich adder
so the player is a kinematic rigidbody
it would not fall unless you have code applying gravity
also its a trigger
do you have some sort of raycasting cause , makes you wonder why it will phase through map lol
idk but i probably found the error
wait
now it works
when i started making the map with terrain editor i've painted accidentaly holes but i still could see the map so i didnt care and the patterns reminded me of those holes i painted so i just removed them and it works but i dont know why i could see the terrain in those areas if there was holes
I still dont understand how navmesh relates to your rigidbody kinematic player 🤔
navmesh sould have literally no effect
thats strange
can you show the Player Move script
@rich adder
!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.
yes please use link, I'd like not to get flashbanged again
why is it moving a character controller but you have a kinematic rb on it , didnt even seee a CC component
so much strange stuff going on here
is it an error? i thought i should add it
yes, the character controller is all you need
aight
it already has OnTrigger detections so you dont need another collider or Kinematic rb
it mix collider with rb(kinda) all in one
ok thanks
hey, I checked out the Code Monkey Video and I think I understand more or less, so thank you
i have another problem sorry if i disturb. I have this spawn ui script that makes appear "E" keyboard image and a text whenever you are near to an npc, i've added the same script to multiple npc but it works only for one npc in the other npc it doesnt work, they dont spawn even tho the debug says that i am in the area where the ui should spawn. Why? @rich adder
yeah play around with them is your best bet to get it truly clicking in the head
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnUI : MonoBehaviour
{
[SerializeField] public GameObject player;
[SerializeField] public GameObject e;
[SerializeField] public GameObject interactTxt;
void Update()
{
if (Vector3.Distance(player.transform.position, transform.position) < 3f)
{
Debug.Log("E keyboard should spawn in this area.");
e.SetActive(true);
interactTxt.SetActive(true);
}
else
{
e.SetActive(false);
interactTxt.SetActive(false);
}
}
}
share the code as it was shown to you via bot msg
!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.
damn i forgot to put the backquotes
I think Im going to separate between overworld collectable(which will be classes) and UI craftable items (which will be SO)
sorry
and do you have errors in console?
yea, pretty much I use in one project SOs only for the recipes n the "reward"
public class SpawnUI : MonoBehaviour
{ [SerializeField] public GameObject player;
[SerializeField] public GameObject e;
[SerializeField] public GameObject interactTxt;
void Update() {
if (Vector3.Distance(player.transform.position, transform.position) < 3f)
{ Debug.Log("E keyboard should spawn in this area.");
e.SetActive(true);
interactTxt.SetActive(true); }
else
{ e.SetActive(false);
interactTxt.SetActive(false);
}
}
}
yeah no errors in console
Yeah, I might use it like that
!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.
jesuss..
!code ```using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpawnUI : MonoBehaviour
{ [SerializeField] public GameObject player;
[SerializeField] public GameObject e;
[SerializeField] public GameObject interactTxt;
void Update() {
if (Vector3.Distance(player.transform.position, transform.position) < 3f)
{ Debug.Log("E keyboard should spawn in this area.");
e.SetActive(true);
interactTxt.SetActive(true); }
else
{ e.SetActive(false);
interactTxt.SetActive(false);
}
}
}
📃 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.
why didnt you just paste it into a link, what did you do to the formatting
Do all of the objects with this script refer to the same e and interactTxt
yes
Then every frame, every one of these you are not next to disables e and interactTxt
The only way they'll ever be active is if this particular SpawnUI happens to run last
Because anything that runs after it is just gonna turn them off again
thanks
How do I get the width of a gameobject? Like, not the scale, the current Width of it in the scene as I want to know how much I should move the game object based on the width.
I am doing this float partWidth = partRenderer.bounds.size.z; as z axis seems to be the width but it is giving a very small amount
ive fixed the code and now it works thanks again @polar acorn
renderer bounds
x is the width
So basically what I did right? partRenderer.bounds.size.z
where Part Renderer is basicaly GetComponent<Renderer>()
Isn't it Z here?
yes,x is width, z is depth, y is height
Or am I wrong?
switch it from Global
does it look the same?
Nope
It's X
Man but it's moving a bit too much, lemme check with Debugging Values
btw in Center mode you may not be seeing where the true origin is
Center throws me off whenever I accidentally enable it
Ohh
so it should be Pivot
I feel it's giving incorrect values
It says the width is 0.3669179
but 0.206 is the amount I need to move the object to position it exactly at the end of that slice
no idea whats is supposed to look like , I just see a screenshot 
so where was the pivot?
when you move a transform thats where you move from
Wait lemme show
you have the size but you have to figure in the offset of pivot
The pivot for each slice is at the centre of the entire object
Is that bad?
Because I am moving the whole object, not just a slice
what is it you're trying to do exactly line up knife with cuts?
Yess
I have different "Fruits" which have different cuts of different widths, so I am trying to make a dynamic way to move the fruit so it lines up under the knife
are they all different sizes?
Yeahh a bit
gotta do some mathin
I did make a way that moves based on a fix offset which does work but it looks kinda weird in some areas.
you mean putting sepearate objects between cuts?
No no, I just put a default offset of 1.5f and made it move 1.5 to the left after every cut
ah yeah that wont work for not evenly sliced cuts
i was thinking the hackey way of putting gameobjects between each cut and then you have "pivot" spots to line up
I thought of another way to make it by using a raycast from the knife that will make the object move until it stops hitting the current slice you are supposed to cut but it sounds a bit overkill and might have room for errors
or just do the math and count each size of the slice through collider/mesh
you have to factor in the offset of the center
how do i make it so that i don't have to add the 2. vector because you cant add Vectors?
My Code:
bRB2D.velocity = (BulletSpawnPosition * 11) + prb2D.velocity;
Yeah lemme try that
You can't add vectors ?
So basically, use the collider's width instead right?
What's the error say
idk do you get different numbers if you check size of slice with renderer vs collider?
@scenic saffron yes you can't do V3 + V2
and vice versa
Okay lemme check
You can't add two different kinds of vectors. You'd want to either cast BulletSpawnPosition to Vector2, or prb2D.velocity to a Vector3
oh ok thx
This is pretty strange how these 2 lines of code cannot be added to Vector2 and Vector3 respectively
public static Vector2 operator +(Vector2 a, Vector3 b) =>
new(a.x + b.x, a.y + b.y);
public static Vector3 operator +(Vector3 a, Vector2 b) =>
new(a.x + b.x, a.y + b.y, a.z);
Yeah gives same values
I think I figured a sweet spot just to use the shortcut method of moving the fruit the same value. I will just make it a bit dynamic based on the fruit, I feel that's easier as I am running out of time xD
Thanks for the advice <3
Hey I´m have been using chatgpt for my game and it has worked up till now when i try getting a targetingsystem to work. I have googled but tutorials never show misstakes. and i cant figure this one out. my debug logs say that target is being found but for some reason the targetindicator doesnt show up, the targetindicator script doesnt get initilzed. I´m guessin it is something in the code i dont understand. but i also dont know where to find the answer.
The same goes for Vector2Int and Vector3Int, which both have to be explicitly converted.
ur welcome :))
be careful with stuff like this, plugging in random values is always recipe for disaster
I have a relevant answer for you:
- Don't use ChatGPT to write you the code, which you don't understand and won't thus be able to modify after copypasting it once
Sorry for the ping @rich adder but I should Local Scale and Transforms in my case right?
yea but since there is noway to learn i kinda have to. i cant afford courses that doesnt give me anything usefull. and yT tutorials dont work for me. and the unitydocs is not understandable. so i tried this route instead. atleast im getting somewhere this way.
I got a question, when creating code for player movement what tends to be the leading cause behind ASDW key set moving the player in different directions?
Use Debugs to figure out the exact issue to see why the script isn't being called
I don't think that the variety of games, which can be created with ChatGPT, is wide.
Also, imagine publishing your game and receiving a bug report from the player. Then you go: "I cannot fix it, because I have no idea how my code works. Sorry!"
the localScale to do what ?
Imagine if Rockstar did that with GTA 6🥶🥶
I mean Local Transform to move them back to their original place. I thought I would reuse the same Gameobjects instead of destroying and instantiating them again. I think this concept is called Object Polling, so I want to reset the position of the slices back to their places, so wanted to know if I should use Local Transform values
I have a big confusion with local and global at times as it's been a while since I used unity 😭
if they are child of a parent then keep track of their localPosition sure
Why is my Player sometimes just stopping for no reason and slowing down by like 50% when landing from a Jump?
if (Input.GetKey(KeyCode.A))
{
rb2d.AddForce(new Vector3(-300 * Time.deltaTime, 0,rb2d.velocity.y));
}
if (Input.GetKey(KeyCode.D))
{
rb2d.AddForce(new Vector3(300 * Time.deltaTime, 0,rb2d.velocity.y));
}
if(rb2d.velocity.x >= 6)
{
rb2d.velocity = new Vector2(6f, rb2d.velocity.y);
}
else if (rb2d.velocity.x <= -6)
{
rb2d.velocity = new Vector2(-6f, rb2d.velocity.y);
}
Ahh okay okay thankies
You're not getting anywhere, using the code you cannot understand. It's also important to know what ChatGPT's code usually doesn't make sense and is absolutely useless unless writing the patterns or asking for the small snippets, which cannot be found on the web. In the latter case, you'll still surely have to modify them to
-
- Work properly and not throw any errors
-
- Work specifically for your game
ignore that im stupid
Why are you using Vector 3 for 2d?
its easier to do operations with v3 since transforms are all v3
Ahh makes sense
Why do you assume the game is 2D?
Alright.
i got alot further this way than with tutorials and spent cash. ive spent around 1000$ and cant do shit alone. cause tutorials and courses arent made the way i need them..
You're surely right
nah they were using V3 + V2 earlier ,its a correct guess
Ahhh I see
nvm got it to work 😄
$1000 damn, I spent like $6 on a unity course
ive done alot of them 😄
Let's not include college cuz college overpriced 😭
any reason you're mixing forces with setting velocity
It's also important to not forget about Vector3s in 2D games, as z axis is used to correctly layer the objects. Simply using Vector2s results in z axis being 0, which can place the object with initially another z position in the undesired position and make it not visible to the camera
I have spent nothing and see no reason for you to spend this much to then write your code with ChatGPT without being able to properly modify or debug it
You got ripped off then
my brain is probably 2d
probably true but that doesnt change the fact that it is true, so getting courses from unity /udemy is ar ripp off 😛
than you are alot smarter than me. cant understand how you have learned anything.
I would doubt that. You, surely, can learn a lot by using Unity's official site !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
if you want courses then do something non-engine related like shader coding and concept of computer graphical design
those are pretty fun and educating
the amount of free resources is staggering, I still got flashbacks from 56k modem days billed by the minute, so to me all this free shit is crazy
i guess now days free is expected
i have done alot from there. still cant even make a pingpong game by my self.
Then do again.
And don't simply repeat everything. Add your own changes.
do you want to learn the API , The Editor or just C#
you might be doing too much at once
i dont know, i want to be able to have a simple idé and just do it. dont i need all 3 then?
but you should not necessarily start with all 3
Is it possible to run a script even if the Gameobject is disabled?
how do i know which one to start with?
imo you start with C# first .
just code and logic. No UI not dealing with other crap like inspector, just fundamenetals
you only realize later on how much of this basic stuff you're doing but on a bigger level
from there you can easily read the Unity API and so forth
when you disable a gameobject it'll stop the update method, coroutines, and some components like rendering modules
Correct
I believe that is only when disabling the script only. Disabling the OBJECT will actually disable all code from what I remember
But it's been a while since I tested. Could be wrong
The gameobject is disabled from the start as I don't want the player to see it. But I want it to get its initial position values assigned in the script attached to it as another script controls its movements even when it's disabled. 😔
well, it applies to per component (script) or if you disable the whole gameobject then it'll apply to all.
Then disable the renderer
but otherwise you can still call methods of those scripts with them disabled or not.
That's the issue, the gameobject has several child objects which have renderers
Make an array of renderers and loop disable them
I mean yeah, I can do that using a for loop, but I hoped there might be a better approach
Lmaooo alright alright will do it
Not really. Could have all renderers under one parent, and the code on the root
Disable the renderer parent and keep the root active
Transform values should still be obtainable and settable even if it's disabled
I called it in the start method of the script
oh, right if it's in start it wont run.. but awake may still work? I forget actually
i have done a course in C# in Highscool level, cause that was the only short one i could do at the same time as work. and i wrote some simpleprograms, i even tried to make my first "Game Idea" into a console program i got it to work, but it got to be to much work with classes and shit so i gave up that idéa it feels like it is some functions of C# that isnt taught.
Wait lemme test it out
Start wont work because the update loop never starts, but awake may work as you're creating it
Nope Awake is not called either
I usually will keep my stuff enabled, but disable it in start (for prefab stuff)
Yeahh, I will disable the gameobject after getting the values instead
thanks i have done that one too but i gave up when i didnt understood the assignment.
Ur not alone
which assignment ? a lot of this stuff is simple operations like calculator, or working with arrays n loops
I can't either
Ping pong game is pretty easy ngl
cant remember now just remember that was the reason when i saw all the text.
why dont ya make some tictactoe in c#, battleships, checkers, ect first
I know, but i don't know well the unity api
Understandable
Or make Text Based Games
thats what the documentation is for
I take a look a few times to learn something or I learn by watching video tutorials
Hey guys is Character Controller automatically an collider?
then learn it, game dev in Unity (or anywhere else) takes time and effort, there are no shortcuts or free rides
Yeah I think it comes with a Capsule Collider iirc
It derives from the Collider class
Alright cool thanks.
tutorials only show you how to do something, its your reasonability to make value of what you learned. Assuming the tutorial is decent enough , that still requires good understanding on what to recognize as wrong or to be improved on
I am learing, i use unity like everyday(also so i can practice and become Better) becouse i am working on a project. Last day i used unity for like 8 hours
Correct me if I am wrong on this, but the Capsule aka Player Controller collider should be placed touching the ground yes?
You were right, just having them enabled in the starting then disabling them in Start worked flawlessly, thank you
Aight thanks for the info
If you want it touching the ground, yes
Or above it, and apply gravity 🤷♂️
only 8 hours? I use Unity for 18 hours 7 days a week, and I've been doing it for a very, very long time
i mean, you consider the collider as your character, so yeah, it's only natural for the bottom to touch the ground if you don't want it flying around

Damn thats really a lot, good job
How can you be awake for 18 hours?
Alright thanks
Back to figuring out collision scene change.
you mean you sleep for more than 6?
I sleep for a good 8-9 hours a day
damn, I could not do that if I tried
cause i dont know where to start.
Yeah, but you don't eventually lose focus doing unity for 18hours a day i don't know if you do it constantly tho
People will barge about how much they're overworked and how f'd up their sleep schedule is, like it's a good thing
What a world we live in
Nope, 100% focus and concentration, the hours fly by
xD I sleep from 12 am till 7 am then from 4 pm till 6 pm after gym cuz I get exhausted
Cool
Dude dedicated
I lose focus quick, Adhd moment
don't really know how to say this. If you really want to be great at this job you dedicate your life to it, to the exclusion of all else, not because you have to but because you want to
How to draw zigzag lines with unity line renderer so I can apply it to these lines?
I'm not even gonna comment on that lol
You work for a company? Or you're just making a big project?
I'm retired, I did say I've been doing this for a long time
Aight
i love c# there i said it lol
draw with array of points, idk what you're asking sorry lol
get a room!
@rich adder i will !
I am currently creating a liquid pooling system and am needing to reference all the tiles a part of the pool that are in the "top" position, (the top pool tiles to display fill amount) and am wondering if it is more worthwhile to loop through every tile in the pool (to find the "top" tiles), or to store all the "top tiles" in a list that actively gets added/removed from, for pools that are potentially hundreds of tiles large is a foreach loop over all of them slow? And would storing all the "top" tiles in a list be faster significantly?
I assume so, but I am just making sure that a list of GameObjects wouldn't be significantly hard on memory or whatever.
Is this a 2D grid? I'm having trouble visualizing what you're describing
Yes, sorry.
Liquid tiles each with a float between 0-1, I am creating a pooling system which will overarchingly control all necessary tiles to save on needing a script running on every water tile when they are "inactive". However, the pool needs to know the "fill amount" of all the top tiles in order to determine if the liquid falling onto a pool should be added, or not. (based on if it can hold more liquid).
Currently my script loops through all child transforms of the pool (parent) and checks for a "isPoolTop" bool on each child, when I really could just determine when each tile is added to the pool if it should be a "PoolTop" or not and not need to constantly loop if I had a list storing them.
what does this float represent? The amount of water in the tile?
Don't have a script on each tile or a game object per tile. Use pure code to run the pooling and render with whatever is most optimal
Yes, so if it were 1/1 it would be "full"
I'm still not sure I understand what you mean by a "top tile"
I'll draw a reference, one sec.
also I fear the term "pooling" is being conflated or confused here with the whole concept of these being water tiles
To be clear are we talking about object pooling?
I'm not sure how the object pooling part relates to the "top tile" part
Haha, that's true. I am creating a (water) pooling system, so adding water tiles to a "pool" parent, which determines if it should be drained, filled, etc.
so is the idea here that there will always be only empty tiles at the top, only full tiles at the bottom, and only the row in between can have anything between 0 and 1?
because the vessel fills bottom up
right, exactly.
I would just keep an int currentFillingRow or something
So in theory the non "top" tiles don't need to update at all unless a block tile beside them is broken or removed, which it will create a drain, which will remove from the "top" of the pool evenly.
which is the y coordinate of that row
unless there can be multiple pools
with different levels
in which case you can use graph algorithms
in weird edgecases the pool can be a weird shape with multiple "top" layers, so it'd likely be a list to reference.
https://en.wikipedia.org/wiki/Cellular_automaton
- and just loop through the top to simulate
A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model of computation studied in automata theory. Cellular automata are also called cellular spaces, tessellation automata, homogeneous structures, cellular structures, tessellation structures, and iterative arrays. Cellular automata have found application in various areas, in...
i dont think you really need this https://leetcode.com/problems/trapping-rain-water/
I am currently using a Cellular Automaton base, however it is extremely laggy if it isn't pooled.
That's an old fashioned sand like water system. But having water that can go round a u-bend, that is difficult!
That's currently what I am trying to simulate and my current system "works" but it can definitely be optimized.
Currently it only needs to run any non pooled tiles and a single looping function for each "pool".
So having a "pool" system where it can be drained and filled via the pool itself is much more elegant than default cellular automata would be.
Oh wow well that's cool. But how? It should know what pressure is behind to climb up a pipe
Right, so it's not perfect at the moment but the main idea is that a "top" tile is any tile on "top" so if there is a large pillar of water connected, it will "level" itself between them based on their y coordinate, tiles can also store an overfilled amount based on a simulated pressure of tiles above it, which unlock the ability to flow upwards, adding their overfill amount above them. There are definitely some bumps to level out but it is pretty elegant currently.
If you'd like when I get the shaders done I can send how the final result works if you'd be interested to see further!
Ok well you should GitHub it!
I plan to create a detailed video explaining it, but it is also to be used in my game so I'll likely create a devlog series when the game is further along, I have created quite a few unique systems that I hope to make my project stand out!
Color randomColor = colors[Random.Range(0, colors.Count)];
plateMaterial.color = randomColor;
Why is this not changing the material's colour? 😔
because you need to reassign the changed material back
Ohhh
it only works if color is mapped to _Color in the shader
The material's colour is not even changing in the first place. Is it cuz I am using a shader from Asset Store?
Ohh
correct
otherwise _Color for vertex color
Okay lemme try
could also make your own color property field and connect it to vertex
plateMaterial.SetColor("_Color", randomColor); didn't work either >:(
is this a custom shader and do you have vertex color connected
it probably has another name iirc you can look at the material in debug mode to see all the prop names
Yeahh
Okay yeah it works, thanks!
ah, SRP shaders did change the naming convention up a bit
still various components that include their own shaders rely on the old naming convention
like spriterender for instance
Does anyone knows the way to replace the deffault c# script icon that appears on the game assets to a custom one?
I've seen that some people do that... But i don't exactly know how
select the script in project view, in the inspector now you can click the icon and assign it
I know you can change the icon of the folders using Plugins like Rainbow Folder
they did not ask about icons of folders
I assumed it had some functionality for that
Didn't know the inspector thing existed, we learn a new thing everyday xD
oh, true Thanks!
and is there any specific size of the image you would recommend me to use?
true, that's not exactly what i wanted, but is usefull to know it!
at least 128 prob
prob less, the biggest version of it you will is the project folder
64 at least though
Hello everyone,
So I do not know whether this would be considered an issue more of scripting or not. But I have started looking into 3D game dev, I am now considering recreating the old game Tom and Jerry war of the whiskers as an exercise for me to enhance my skills (not selling just for me).
I watched some tutorials on character animation, so I decided to create a state machine with the help of the input system. The issue is the code doesn’t give any errors but the run and move animations don’t work meaning when I press the specific button to move it doesn’t react to it.
Here is my code:
https://paste.ofcode.org/s8LFkxbubWeDLzrCBs4Bf5
https://paste.ofcode.org/v76rg8MbnY8ZcZ9LZpYHL8
Attached is the inspector of the “Tom Object”
Please tell me if any more details are required.
please do not post photos of your screen, use screenshots
How do I check whether I am on PC or Mobile?
Is it just "Application.platform == RuntimePlatform.WindowsPlayer" and for mobile "Application.platform == RuntimePlatform.Android"?
that will work for Android devices, not for IOS
Yeah iphoneplayer for IOS
IPhonePlayer
I remember doing this in another way using something like #If Platform.OS == Android or something along that line
those are compile time directives, not runtime tests
Ahh
So rn, it's
if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.LinuxPlayer)
For PC, I only care about PC right now.
That is not just PC, it is most standalone platforms
My bad sorry.
Do you have an idea or do you want me to resend ?
tbh, I think you should add some debugging to your code and then post the console log because atm it's all guess work
I actually did after sending, they all run. Which is making me think it is something wrong in the inspector.
and we are supposed to know that how? magic?
Sorry man 💀
By default, send images in acceptable formats. Taking physical pictures of your screen is like mailing someone a floppy disk
You may notice a button on your keyboard named "PRT SC" or similar. Press that button to print your screen.
Describe the problem, describe why it's a problem, describe the approach you have tried.
A pretty beginner question that I never really thought about until now...
In functions you have your "private void FuctionName(int int1 = 0, int int2 = 0, int int3 = 0)", with the name and default values of all those... but if you just wanted int3 to be 2, would you have to type in 0 for all the things before it, or otherwise how would you skip to a variable?
You can use named parameters to pass them out of order: Method(int3: 42069)
Why can't I assign this function
public void OnPointerDown(PointerEventData eventData) { if (eventData.pointerEnter.name == upButton.name) { upButtonHeld = true; } else if (eventData.pointerEnter.name == downButton.name) { downButtonHeld = true; } else if (eventData.pointerEnter.name == leftButton.name) { leftButtonHeld = true; } }
To an Event Trigger?
why are you trying to assign this function that makes no sense
because the parameter type is not the same
This script is attached to a game object that's not the Button. That's why
not sure how that explains why
the event will pass a parameter of type BaseEventData, and while it likely will be a PointerEventData it isn't stored that way so you'd have to cast in your method if you need to use that data
The event header shows the expected method signature:
just call the function you want directly ?
okay soo, I have three buttons, Up, Down and left. I want them to continuously run a function when clicked and when you stop pressing it, I want it to stop running the function
Your method needs a parameter of type BaseEventData to appear here
hey! I have this script to clamp the camera movement but it's very rigid, how do I fix it to be more smooth?
using UnityEngine;
using Cinemachine;
/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Y co-ordinate when the player reaches a certain position
/// </summary>
[SaveDuringPlay]
[AddComponentMenu("")] // Hide in menu
public class LockCameraY : CinemachineExtension
{
[Tooltip("The y position where the camera's y position will be locked")]
public float lockYPosition = -11f;
// Reference to the player transform
public Transform player;
protected override void PostPipelineStageCallback(
CinemachineVirtualCameraBase vcam,
CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if (stage == CinemachineCore.Stage.Body)
{
var pos = state.FinalPosition;
// Check if player's y position is less than or equal to the lockYPosition
if (player != null && player.position.y <= lockYPosition)
{
// Lock the camera's y position to lockYPosition
pos.y = lockYPosition;
}
state.RawPosition = pos;
}
}
}
Basically, I am trying making a 3D player animation using the input system.
The issue is it shows that it reacts to the buttons but nothing is reflected on screen, I tried using debug.logs but it seems to working fine so I don’t think the issue is in the code.
For example when I click left shift nothing happens although the character is supposed to run.
Code link:
https://paste.ofcode.org/s8LFkxbubWeDLzrCBs4Bf5
https://paste.ofcode.org/v76rg8MbnY8ZcZ9LZpYHL8
Attached are the ss
Hey guys, I have a question regarding the input actions on my Quest 2. Basically, I want to reference the grab button or any button on my right controller and log something out. I set up the project via the Unity VR core template, and there are XRI default input actions defined, but I have no idea how to use them. Do you guys know how to do it?
When I load a new scene, why is my 'Explosion' audio source no longer applied to my Handle Event script?
most likely you had it assigned via inspector, and i'd guess that the root object there is probably a singleton that destroys itself if an instance already exists. so when you loaded back into that scene the new instance loaded by the scene destroyed itself because an instance already exists in the DDOL scene. so any references to that instance (or any of its child objects) will be "null"
The audio manager parent object is a singleton.
If that's the case, would I need to assign the prefab to the script?
i have no idea what you are referring to there. but your options are to either redesign your audio system so you don't have to rely on inspector references since those will be destroyed when you reenter the scene or get a reference to the existing instance of the objects in Start when the scene loads instead of assigning via inspector
Got it. Thanks for your help!
It also doesn’t walk, but it breathes (still state).
Having trouble deleting stay projectiles in 2D
They fly out of my scene, I tried making a rectangle around my play area that catches them and deletes them I’ve tried messing with layer matrixes, colliders, istrigger
Nothing
why not add a timer to them
Hi, Does anyone know how to make a waiting method? I'm been trying every since I started Unity and could never get it to work. Here is my corutine so far
Wait is this considered to go in advanced channel?
📃 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.
how do i setup ide tf
Wait so what does the website do?
your code is small enough such that you can use the ``'cs option there but the pastebins for larger code for future reference
The inline is for discord itself. It formats the code and highlights the syntax
bleh cant example it else it formats it
says it on the info up there anyway
I forgot to read the posting rules sorry
the bin is fine though and mostly preferred as discord still hard to read on mobile (and people will sometimes post hundreds of lines of code)
ah ok
But so far the code only counts down and not pause the code. I used WaitForSecondsRealtime but it doesnt do anything
IEnumerator wait(float waitTime)
{
float counter = 0;
while (counter < waitTime)
{
counter += Time.deltaTime;
yield return new WaitForSeconds(5);
}
}
you need to return the WaitForSeconds
well a few things here. You send a waitTime into your method
but you're using wait for seconds which actually shouldnt be what you want
so your code should be something like
IEnumerator wait(float waitTime)
{
float counter = 0;
while (counter < waitTime)
{
counter += Time.deltaTime;
yield return null;
}
}```
that's really it
WaitForSeconds is another way to wait, but it's not frame time specific so it's less preferred in a way than doing this
It just made the wait into doing nothing. Theres no counting or anything
it does count. It adds deltaTime each frame. The most basic way to add a timer to your code
just in a coroutine
Wait so should I put it in a FixedUpdate if I don't want it to depend on frame rate?
because I don't see any type of pause
Both codes do not work
show what you actually tried
and keep in mind that starting a coroutine does not delay the code on the lines following the StartCoroutine call unless you yield the call inside of another coroutine
why does this line break if its multiplied by time.deltaTime
define "break"
as in it doesn't work
Is it possible to yield outside of the corutine to pause it?
Doesn't work, as in doesn't subtract?
yes
no, if you want to delay code then you can put it in your coroutine or check if the coroutine is still running or something
Try debugging the relevant values.
so try debugging the value its getting subtracted by?
Both
Doesn't matter
alright
Everything runs in the corutine but no pause or any coutdown
You see it when it's rendered to the screen. It could be changed multiple times before that.
well i can also see it in the component but if it's different then i trust you
so the 1 value gets turned into zero when you multiply it by time.deltaTime
interesting
Same for the component. You only see it when it's rendered by the UI.
Try 1f instead
i don't think that would work as the slider takes in whole numbers
So there's yield return in the "yield return new WaitForSeconds(5);" So it should pause because of the yield but it doesn't
Well, assuming it takes an int, how do you expect it to work? 1*delta time would always be less than 1, and discarding the fraction, it's gonna be 0
interesting
then how i would make the variable scale with time
since if your fps are high it'll go faster right?
Are you starting the coroutine correctly, or maybe the gameobject is disabled. Also, add back your console logging
Well, how much do you want it to decrease? And how often?@snow girder
i want it to decrease every frame and i still haven't decided how much i want it to decrease
was planning on testing that after i got this figured out
Don't make it an int
It's a multiplayer game so it spawns when you load into a room. I'm using "StartCoroutine(wait(5f));" to start it
Track the value as a float and cast it whenever you need to display it or use it as an int
Show the code
the "StartCoroutine(wait(5f));" is in a private update in a if statment
id isolate your multiplayer idea and try your concepts, especially stuff you're not familiar with, in a non-network environment
I'll try that
IEnumerator wait(float waitTime)
{
float counter = 0;
Debug.Log("We have waited for: " + counter + " seconds");
while (counter < waitTime)
{
counter += Time.deltaTime;
yield return new WaitForSeconds(5);
}
}
But like I was saying, you're using two different waiting methods here which is not what you want to be doing
This coroutine is very strange. You add 1 frame of time to your counter, then wait 5 seconds, then add 1 more frame to the counter.
What is this coroutine even doing? Counter is a local variable so it seems to just be wasting time for no reason
Because w is forward and d is to the right... thus together they make a diagonal.
What do you expect it to do?
So on a separate project I made it so if you left click, it waits and does a Debug.Log when done waiting and it says it has waited for zero seconds. I tried just using yield return new WaitForSeconds(5); and nothing happens
I'm trying to make a pause for a few seconds and then continue once the wait is done. I'm new to corutines so don't expect me to know stuff
Did you debug INSIDE the coroutine, or on the line after StartCoroutine
Your log is right after you create the timer variable, so of course it's going to display 0. You haven't added anything to it yet
oh i see i now
there's also the whole problem of this coroutine not delaying anything. #💻┃code-beginner message
before the while loop in the corutine
thats what the "yield return new WaitForSeconds(5);" is for
lol no it isn't
float counter = 0;
Debug.Log("We have waited for: " + counter + " seconds");
surely you see why this log does nothing for you
that's just delaying your counter. it does not delay the code following the StartCoroutine call
But what is the delay doing. All you're delaying is the next increment to counter, which is a local variable. Absolutely nothing in this coroutine is capable of affecting anything
if it did, your entire game would freeze!
So is this code supposed to count down and pause?
Also chill out I just want to solve this issue
Odd. If the x variable is 0, then it shouldn't go to the side based on that code.
Try this instead:
Vector3 moveDir = new Vector3(
Input.GetAxis("Horizontal"),
0,
Input.GetAxis("Vertical")).normalized;
gracz.Translate(moveDir * speed * Time.deltaTime);
Everyone is chill. Please don't do that
you are misunderstanding how coroutines work
StartCoroutine tells Unity to start running a coroutine.
It does not "wait" or "pause" until the coroutine is over
that would completely freeze your game forever
It immediately continues to the next line after starting the coroutine.
mb I thought the opposite
If you want to make CanHit become true after 5 seconds, then you need to set it to true inside of the coroutine
When you yield return new WaitForSeconds(5f);, you're telling Unity "please wait for 5 seconds before resuming me again"
so if you do something after this statement, it'll happen about 5 seconds later
I did that before and it never reaches that
because your timer code is also very messed up
while (counter < waitTime)
{
counter += Time.deltaTime;
yield return new WaitForSeconds(5);
}
This adds Time.deltaTime to counter once every 5 seconds
This will be a very small value. It's the amount of time one frame took to render
Then you changed something
This doesn't make any sense.
if only we had a counter for the number of times people have said this 😆
If you want to wait 5 seconds, just ask to wait for 5 seconds once
at 100 FPS, this would take 500 iterations of the loop for counter to reach waitTime
which would be 2,500 seconds of total time
instead of guessing, you should be adding debugs to see what specifically doesnt work
each iteration is adding 0.01 to counter
It would take five seconds to complete if you just did yield return null;, which tells Unity to resume the coroutine on the next frame.
So would this work? https://gdl.space/zatususili.cpp
and I need it in seconds instead of frames so do I need FixedUpdate?
This method will yield a WaitForSeconds with a value of 100 million seconds
Unity will wait for 100 million seconds before resuming the coroutine
The coroutine will then end.
(and nothing happens because nothing was delayed by it)
this is a non-sequitur
i never said anything was counting frames
I did say that, if you add Time.deltaTime to a variable every frame, that variable will reach a value of 5 after about 5 seconds
This is not counting frames.
you sound very confused about some pretty fundamental concepts here
https://docs.unity3d.com/Manual/Coroutines.html
you should really just read the docs, and copy the examples to see what they do in terms of a game. Change things, see the outcome.
This coroutine would start, wait, then end, doing literally nothing else. It's a completely pointless coroutine that does nothing.
Again, the code does not wait for the coroutine to end after you call StartCoroutine. The code continues along side it. That's what makes it "Co"
ok that explains a lot
So how can I make a code wait
with a coroutine
You put it in the coroutine
void Start() {
StartCoroutine(Foo());
Debug.Log("A");
}
IEnumerator Foo() {
yield return null;
Debug.Log("B");
yield return null;
Debug.Log("C");
}
This will log A, B, C
If i skipped that first yield, it would log B, A, C
But you said it works alongside the code?
correct
im finding it impossible to find a video for it. does anyone know of a video or forum that talks about adding bounds for a camera in a 3d game? so the camera cant move past a specific point on the x and z lines
id rather not have to redo all the code ive written for my current camera setup lol
then you need to code the camera to stay in a bounding box yourself
"make a code wait" is not a very correct statement. That would imply the whole game would freeze and wait for it. If you really want to do it, you can do it with Thread.Sleep. usually what you want in your game is to delay the execution of certain code. That can be achieved with timers and/or conditions in update, coroutines or async.
yes. do you know of a video or forum that can help me with this?
You will never make code in Update "wait"
Ever.
Stop trying to do that.
As we've said multiple times, if you want to do something after a delay, you need to do it in the coroutine. You can make the coroutine wait just fine.
Sunk cost fallacy.
It would probably take less time to switch to cinemachine than adding this ONE feature to your code. Let alone the next thing you will want to add that has already been done better by cinematchine.
Just food for thought. It can be fun reinventing things for sure
Ok I fixed it. You need the code before in the corutine and after
Yes. That's why you put the things you want to delay in the coroutine. So that they can be delayed
Hey all, hopefully quick question, but is the Tilemap feature just for building levels/maps and stuff or can it also be used for game logic? I'm wanting to make a scene that revolves around this 3x3 grid of squares, and I want to be able to move the individual cells around the grid and have the cells talk to each other, so something like
right_neighbor_transform = Grid.GetCell(this.x+1, this.y).transform
as a quick example off the top of my head. Is a Tilemap a good solution for this? I figured I could keep track of the cells in a dictionary of Vector2 -> Cell game object, but actually displaying the grid and having them move around is what I'm stuck on. And by move around I mean for example, swapping the top left cell with the bottom right cell. I've tried using the Grid component but I can't seem to wrap my head around it because the children I add to it just end up stacking on top of each other. Thank you!
Tilemap uses Unity's Grid class, but you don't need to use Tilemap to use it
it's basically just a world space grid that uses world coordinates
If for some reason you do want constraints on the grid, you can consider just making your own grid class.
then again, constraining the grid component isn't that much work either
I've tried using the Grid component but I can't seem to wrap my head around it because the children I add to it just end up stacking on top of each other.
I don't understand what this means.
How do I do that
scroll up to the 100 posts of people discussing timer coroutines
or just add the timer in the update loop
I have a game object with just a Grid component, and when I add children to that object they all just spawn in the same place on top of each other. I've seen Grids that automatically put children in the correct grid shape in the scene view, and I guess I just assumed that's how it worked
Although now that I think about it, that might have been a UI grid layout
how did you try to delete projectiles that went outside of the screen rect?
Added it to the start function when the projectiles are instantiated
One line of code
I’m so dumb
Thanks for the help fen you a G fr
Hi, I'm having trouble getting the tilemap.SetTile() function to work. Here is my code:
I'm serializing the Tile assets via the unity editor, and they place correctly when I place them manually using the tile palette
any ideas what im doing wrong?
where are you calling that method?
using a unity event, Ive confirmed that the function is getting called using print statements
Is there a reason why neither path is taken? Debug.Log("method reached"); if (Physics.Raycast(ray, out hit, Mathf.Infinity, ground)) { Debug.Log("raycast success"); } else { Debug.Log("raycast failure"); }
Where is that code?
Any errors popping up? That could halt code execution
it works in the god object
no errors, rest of the code works
Ill check though I guess that is the only thing that makes sense
any ideas on this?
here is my tilemap if that helps
and its attached to a grid component
I recommend putting Debug.Log("foo"); messages in every single function along the way
to narrow it down
replace foo with what is appropriate
I've confirmed the function is being called though
check for any null?
how do I do that
{
//error message
}```
right
And what executed that Event?
its not null
this invokes the event from the update loop of another game object
Can you show the console logs?
ima start a thread so these 2 things dont get mixed up
Okay, so, this is a third script that calls a function on DrawArrows which calls a function on TileSpace? Are you sure that drawArrows refers to the instance that has this function set and not a different instance of DrawArrows?
tilemap.SetTile() help
theres only 2 scripts here
Cursor (which invokes the event)
and DrawArrows (which has the function)
I uncovered a problem that I think is to blame already but thankyou
Oh, so the GetKeyDown is on Cursor? I don't know why I thought this was a third script. Can you show the full !code for Cursor?
📃 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.
its a little complicated
but when gamestate case is MOVE update calls move()
and move invokes the event draw arrows in case of the right input
I'm pretty confident that drawArrows() is being called
try this ``` // Game States
public void turnBase() {
// Cursor Movement
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
if (horizontalInput != 0 || verticalInput != 0) {
Position newPos = currentTile.position + new Position(Mathf.RoundToInt(horizontalInput), Mathf.RoundToInt(verticalInput)); ```
}
if (Input.GetKeyDown(KeyCode.S)) {
MoveCursorAndDrawArrows(new Position(0, -1));
}
if (Input.GetKeyDown(KeyCode.D)) {
MoveCursorAndDrawArrows(new Position(1, 0));
}```
Position newPos = currentTile.position + direction;
if (board.isOnGrid(newPos)) {
moveToTile(board.getTile(newPos));
drawArrows.Invoke(selectedFighter.currentTile, currentTile);
}
}
public void moveToTile(TileData tile) {
if (tile == null) {
Debug.LogError("Trying to move to a null tile.");
return;
}
Position relMovement = tile.position - currentTile.position;
if (!board.isOnGrid(tile.position)) {
Debug.LogWarning("Trying to move to a tile outside of the grid bounds.");
return;
}
transform.Translate(new Vector3(relMovement.x, relMovement.y, 0));
currentTile = tile;
}
}
}
those are just snippets
ight i figured it out lmao
total noobie mistake, I was placing it off my screen so i didnt see it 🤦♂️
ty for attempted help lol
can someone tell me why my gameobject isnt being set to active when I start dragging? I can debug.log and see that dragging is working, but the gameobject is still not being set to active?
... ^ rest of code
public void OnBeginDrag(PointerEventData eventData)
{
dragging = true;
draggedItemIcon.SetActive(true);
Debug.Log($"Begin Dragging slot: ");
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("Dragging");
}
public void OnEndDrag(PointerEventData eventData)
{
dragging = false;
Debug.Log("End Drag");
}
It's part of a hierarchy. If any of its parent GameObjects aren't active, it won't be active . . .
Locally, it is active, but not in its hierarchy . . .
its parent is "inventory" which it turned on when I press tab, I can see it if I turn it on manually but the active state doesnt change when I drag
I can see in the inspector when I drag its not even being set to active
Is the correct GameObject assigned to draggedItemIcon?
yup, I have it set to a gameobject ive assigned from dragging it into the variable
No matter what I do
Can someone who’s good with 2D layers help me I can’t get this tank to appear above the background
I’ve tried sorting layers, layer matrix, z-axis
Nothing
Its driving me insane
hard to tell what image types both are
also not really a code question
I know didn’t know where to send it
show your actual inspectors and whatnot
yea if its not coding related ur good to post it in the unity talk channel
Log the name of draggedItemIcon and log draggedItemIcon.activeInHierarchy to check that it's true . . .
Ok didn’t know my bad
I think i need to restart Unity... its not using updated code
Did you save? Did it recompile? Do you have errors in the console?
no errors, I just saved it restarting it now. it didnt print the new debug logs I just added and I changed the text for dragging and it didnt change
its still not using my updated code?
new code:
public void OnBeginDrag(PointerEventData eventData)
{
dragging = true;
draggedItemIcon.SetActive(true);
Debug.Log($"Begin Dragging slot: ");
Debug.Log(draggedItemIcon.name +draggedItemIcon.activeInHierarchy);
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("Dragging ur mom");
}
public void OnEndDrag(PointerEventData eventData)
{
dragging = false;
Debug.Log("End Drag");
}
The screenshot cuts off the rest of the console. Hard to tell from this small view . . .
one sec, I may know the issue
I had another script with drag handlers in it, this code hasnt been running...
I fail to see the connection, but as long as you got it, good . . .
I dont completely see why the other script wasnt running but this works for now xD
thxs for ur help anyways
I have a question regarding movement of a simple cylinder
when making this
wait
how to make it with the colors
How to post !code - look at the large code section (inline isn't preferred for large scripts)
📃 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;
private float playerSpeed = 2.0f;
private float jumpHeight = 1.0f;
private float gravityValue = -9.81f;
private void Start()
{
controller = gameObject.AddComponent<CharacterController>();
}
void Update()
{
groundedPlayer = controller.isGrounded;
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
controller.Move(move * Time.deltaTime * playerSpeed);
if (move != Vector3.zero)
{
gameObject.transform.forward = move;
}
// thanks google
if (Input.GetButtonDown("Jump") && groundedPlayer)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
playerVelocity.y += gravityValue * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
}
}
moving my little guy is fine
But how to make it so when the camera is attached
moving forward is based on the camera<s position
you mean camera facing direction ?
Yes
you normally rotate the player with the input of your Mouse X, that takes care of a child camera
then you use transform.forward as direction
so I did it wrong?
if (camera)
target = camera;
else
target = transform;
if we moved
target.forward = move;```
yes you're rotating with your inputs
your forward looks at your inputs
i see
Thanks
and what if
I wanted it to always look towards an object
wheter it<s moving or not
I got transform.lookAt to work (kind of)
But how can I make it so it looks at another object
I got it to work but to look at 0, 0, 0
you need references
i need more brain power
🤷♂️
I got it but how to make it keep its and not change it
is there a way to like lock it
because the rotation of the camera just goes flying
Maybe show us what you've done and what the problem is.
only call the look at once..
im confused looking at the whole thing
Pass in the other object's position
Or the other object's Transform
Would anyone have any tips on how to make characters stick to the ground when going off ramps at high speed?
I think I've found a sort of solution, but it doesn't work if the edges of the ramp and ground aren't exactly alligned
can someone please help me i have a rigged vr model right here with inverse kinematics u can see that it has hands but when i go to play the hand doesnt render the forarm also doesnt render if the camera is posisioned closer so i think its something to do with the camera unrendering things
have you tried reducing the near value of the camera?
the camera wont render things closer to it than the near clipping plane
near value?
ooo ok so just decrease that
yes.. but dont go lower than u need to
maybe, might cause problems if you go too low
.2-ish is a good value i use
also my rocky solution
i have it at 0.1
hmm i've never walked up a ramp with my body tilted like that
seems like i'd fall 😅
you don't do that? damn, now im starting to feel a tad silly walking up my ramps like that lol
hell of some calves and ankle muscles
@rocky canyon that didnt work but it def is somthing to do with the camera here i have the camera rotated straight
then if i turn it a little bit
u can see the hands actually render
it happends even in my scene view
Fixed
Create instance expects a name or type - not both.
https://docs.unity3d.com/ScriptReference/ScriptableObject.CreateInstance.html
Nevermind, you're using MS create instance
Your options would be https://learn.microsoft.com/en-us/dotnet/api/system.activator.createinstance?view=net-8.0
How acceptable is moving a rigidbody through MovePosition?
only makes sense if its kinematic and manually check collisions
it is kinematic, but can you elaborate a bit on manually checking collisions?
moveposition / kinematic movement will phase through walls / colliders unless you manually check for collisions via physics casts n such
oh, got it. Big thanks 
one more question.
for kinematic rigidbody it's better to use MovePosition or velocity?
-
MovePosition: Moves the Rigidbody to a specified position over time.
Takes into account collisions and physics interactions.(not as kinematic)- Useful for precise movement or movement based on user input.
- Provides deterministic behavior in FixedUpdate.
- May lead to smoother movement compared to directly setting velocity.
-
Velocity: Sets the velocity of the Rigidbody directly, affecting its movement in the next physics update.
- Overrides any collisions or physics interactions temporarily until the next physics update.
- Useful for continuous movement or applying forces to the Rigidbody.
- Can lead to jerky or abrupt movements if not carefully managed.
- Requires more careful handling to ensure physics interactions are properly accounted for.
alright. Thank you 
is this like gpt answer?
MovePosition does not account for collisions
it was based off of one.. but i have a markdown page that has abunch of those generic this vs that stuff
yes it does.. 🤔
other rigidbodies will collide with it, but itself just phases through colliders
moveposition is meant to be used with kinematics , it won't account for colliders
try it if you don't believe me :p
or im tripping now
no its not that i dont believe u.. i just always had thought it did
iirc the 2D Might behave differently than 3D one
hmmm, its on my todo now to fiddle with it vs velcoity
for example kinematics have velocity in 2D for some reason
ohh no, wait .. i thought it was a common one for dynamic rigidbodies as well
like people substituting it from their failed translation code
iirc the free kinematic controller uses MovePosition
the rest is casts
this is so other objects that hit it still react
hm, i got some experimenting to do now
found a post from PraetorBlue 😄
apparently i wasnt the only one that thought that 😅
whats the result
well thats less about MovePosition respecting collisions and about the actual rigidbody not wanting to be shoved in a wall. If you try to move it manually in inspector too, the rigidbody wont just allow itself to be placed in one
do note they say if its not kinematic
believe yall, lol.. gotta rewrite something real quick.. and next time im using an RB imma have to give it go.. just to say ive used it
but also straight from the docks
Moves the kinematic Rigidbody towards position.
https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
I always thought this was mainly for kinematic
b/c im a velocity = kinda guy
ya, see i think that doc could use a bit more to it
confused by this, if its not kinematic wouldn't it respect collisions with velocity and addforce
yea, https://forum.unity.com/threads/why-does-rigidbody-moveposition-ignore-collisions.1259687/ heres the post i read
i guess I never used MovePosition without kinematic so I never tried walls with dynamic
learned something new then
i never use MovePosition
need to double check cause I was having a mandela effect moment lol
im about to make a little demo thing to play around w/
the only rigidbody stuff i have is my kinematic cc ive purchased
illusion of physics
ya, i was just mistaken
seen 1 thing, thought something else was happening.. 🐰
what can you do to "await" inside coroutines except using yield return?
i ran into situation where i cant use this
really now?
what about solid walls? also 2D and 3D act different in unity
its what u said earlier
the other rigidbodies are colliding with it
and not viceversa
so use a regular async function instead of coroutine
ahhh ok
they just unclipping themselves
and thats why they appear to have bouncy material
they shuld just be pushed along with it iirc
thats why i prefer me a real RB..
and i let someone else make the kinematic ones lol
thats gonna be tough lmao, i know this but this is my last resort
gonna be hard to suggest something unless you provide more reason why u cant use coroutine then
can u make a jerryrigged while loop? and evalulate a timer inside the coroutine?
lol that sounded dumber after i said it, and it sounded pretty dumb in my head
//retrieve timezone data from s3 server
if (BuildDefine.AgentCode != "ZZZ")
{ StartCoroutine(ResourcesManager.Instance.RetrieveTimezoneFromServerFile(BuildDefine.AgentCode));
}
//Language Download And Iniitializtion
yield return LanguageDataScript.Instance.DownloadAndInitialization().AsIEnumerator();
while (LanguageDataScript.Instance.isLoading)
{
yield return null;
}```
this is the outer shell of the coroutine, my goal is to "MUST wait until RetrieveTimezoneFromServerFile finished, to the last line"
public IEnumerator RetrieveTimezoneFromServerFile(string code)
{
string ip = NetworkManager.Instance.GetResourceUrl();
Int64 time_stamp = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds();
string version_url = $"https://{ip}/Agents/{code}/sw_main.json";//agents/ccc -> sw_main.json
bool isSuccessGetFile = false;
string mainData = "";
Action<bool, string> callback = (success, data) =>
{
isSuccessGetFile = success;
mainData = data;
};
yield return GetTextResources(version_url, callback); //file obtained
if (string.IsNullOrEmpty(mainData))
{
Exception e = new Exception("WARNING! ACCOUNT NOT FOUND");
GameManager.Instance.ExceptionKey = e.ToString();
GameManager.Instance.LogOnDebug.LogException(e); //will generate error popup
if (!NetworkManager.Instance.isServerFileFirstRetrieved)
{
NetworkManager.Instance.StopAllCoroutines();
}
StopAllCoroutines();
}
else
{
// deseralize/store timezone string
TestMaintenanceData testData = JsonConvert.DeserializeObject<TestMaintenanceData>(mainData);
NetworkManager.Instance.timezoneOffset = testData.timezone;
NetworkManager.Instance.isServerFileFirstRetrieved = true;
}
yield return null;
}```
this is the coroutine
whats the current issue though with it
the problem is , GetTextResources is a server call, it grabs files from servers, it takes time
before it can retrieve files and let me check "mainData"
on outer shell, the language download is already executed
its a timing issue
You can use a UnityWebRequest inside a coroutine
it can be ~~awaited ~~yielded there
https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.SendWebRequest.html this pauses the coroutine until the request is done
how do i fix this (i get it after double clicking a script
not related to unity
https://github.com/microsoft/vscode/issues/138893
i figured out another way to do that
//retrieve timezone data from s3 server
if (BuildDefine.AgentCode != "ZZZ")
{
yield return new WaitUntil(() => ResourcesManager.Instance.RetrieveTimezoneFromServerFile(BuildDefine.AgentCode).IsCompleted);
}```
made the coroutine as Task
and uses waituntil to do it
guys how do i get out of this mode?
Ive got a script which rotates an object but I want the object to rotate around the player not itself
ty
but how could I make it follow the mouse?
Google it. You got two different views
Please use the proper channel next time