#💻┃code-beginner

1 messages · Page 34 of 1

fossil tree
#

ok i gonna try that

#

tysm

#

have nice day

gaunt ice
#

no, your array is in forms of [][], you need to access it through arr[i][j]

rich adder
#

ObjectArray[index].Objects[somenidex]

candid oyster
#

thanks!

rotund hull
#

how can i transform then into grid points

#

or positions

gaunt ice
#

i forgot the first array is array of struct

modest dust
rich adder
candid oyster
#

Yay, its working

modest dust
# rotund hull how can i transform then into grid points

If a background is 10x10 and at position (0,0) is the center of one of the backgrounds then at (0,5) you'd have two background touching each other. From (0,5) up to (0,15) is the second background and so on. Now do the math

candid oyster
#

Now I dont have to link up my 2d array individually with my game objects.

turbid marsh
#

Can anyone explain in clear language what this is? Main() in c#

timber tide
#

Entry point

gaunt ice
#

entry point to the program
but you wont see it in unity

rotund hull
modest dust
# rotund hull alrightly i will try that in code

To get the actual size of the background in world space look at pixels per unit in your texture import settings. If the background is 10 x 10 px and you have 100 px per unit then in world space your background is 0.1 x 0.1 units

gaunt ice
#

c# is case sensitive

modest dust
#

scratch best programming language

#

idk why even bother with unity

polar acorn
#

It's simple: Rigidbody exists. RigidBody does not. These are different words. Use the proper names for things

#

Then keep doing them until that is no longer the case

modest dust
#

good luck then

rotund hull
#

the idea

modest dust
rotund hull
modest dust
#

If your background is 1x1 unit and (0,0) is the center of the background with (0,0) coords then anything between position (-0,5 , -0.5) up to (0.5 , 0.5) is considered to be within the (0,0) coords
the background on the right with coords (1,0) would have it's center at (1,0) and anything within the range from (0.5 , -0.5) up to (1.5 , 0.5) would be considered to be within the (1,0) coords and so on

next hound
#

On Opening Visual Studio 2022 community version i get this error : StreamJsonRpc.ConnectionLostException:
The JSON-RPC connection with remote party was lost before the request could complete.

i just installed VS with workspace as unity and this happens...
Image

#

feel free to ping

modest dust
#

If the grid size is 1 like in the example above and camPos is -0.4 on the x axis then you'd have a result of 0.1, resulting in 0
if the camPos is -0.6 on x axis then you'd get a -1 as a result and so on

rich adder
# next hound

hard to say from this alone, did you use the Visual Studio Installer.

next hound
#

yes

rich adder
#

hmm

#

possibly Firewall issues

#

or your internet

next hound
#

hmm

ivory bobcat
#

Maybe try running visual studio as administrator

green copper
#

am I missing something obvious? I renamed the variable from m_thrust to thrustMain, and since that change all the force applications just stopped applying

#

changing the names back did not work the rigidbody just refuses to move

frosty hound
#

Check the inspector to make sure the values are assigned.

green copper
#

the particle emitters continue to turn on and off so the functions are definitely running

frosty hound
#

You shouldn't be giving default values to public fields in code, as it's overridden by the inspector.

green copper
#

Removed public keyword, function still does not apply force

frosty hound
#

Are there errors in your console when you run?

swift crag
#

An exception in the AddForce call would stop downThrustersOn() from running

#

I suspect the problem is coming from something else you changed at the same time.

green copper
#

No errors, two warnings but only in the VS console, not the unity one

polar acorn
#

No errors while running the game either?

swift crag
#

Can you share the rest of the script?

#

and yes, the important part would be while running

modest dust
#

Is the rigidbody kinematic or dynamic

green copper
#

yes, no errors while running

#

isKinematic is unchecked

#

copying the whole script, what's the tool to make it pastable?

swift crag
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

green copper
#

I remember there's a tool I'm supposed to use

swift crag
#

your rigidbody doesn't happen to have a mass of a bajillion, does it

green copper
#

if relevant, the issue started happening when I renamed the thrust values, and hooked up the left and right thrusters to the function after I finished tweaking the size and placement

swift crag
#

i think the default is just 1

green copper
#

started

#

my bad

swift crag
#

ah

green copper
#

started happening/stopped working brain bug

#

mass is 50

#

but that's intentional and it was working before then

polar acorn
#

Log thrustMain before you call add force

swift crag
#

well, it's now private and is never assigned

#

so i am very confident in its value

polar acorn
#

It'd also show that the code is reaching Add force at all

swift crag
#

the thruster particles are working

#

unless all of the particle systems are incorrectly assigned or something, I guess

#

I would still go ahead and throw in a log

green copper
swift crag
#

when you eliminate the impossible, etc. etc.

green copper
swift crag
#

are you sure you aren't just flying into the floor or something

green copper
#

ship starts the scene in the middle of the space, gravity is lowered so there's a good few seconds in contact with nothing

#

none of the forces, linerar or torque, apply in that time

swift crag
#

your acceleration is going to be very small..

#

20 force on a 50kg object

#

i'd just set the force really big and see what happens

green copper
#

Gravity is one third

#

tried with 2000 and no effect

swift crag
#

okay, probably not that, then

#

Everything about your code looks like it should work fine.

modest dust
#

If so then that wouldn't change the value

swift crag
#

hopefully that meant "tried it just now with 2000"

green copper
#

I tried with 2000, then back to 20, then back to 2000 and it worked

#

?????

swift crag
#

did you actually recompile after changing the number

green copper
#

yes, both times

next hound
green copper
#

though humans are fallible yada yada but I'm fairly sure I compiled it

next hound
swift crag
#

make sure to catch the entire rigidbody

rich adder
#

which one are you launching

green copper
next hound
next hound
rich adder
#

particularly about the logs/reinstall

swift crag
# green copper

How does it behave when using a huge force value? does it barely accelerate, or does it immediately smash into a wall?

#

I'm wondering if you had the wrong constraints

green copper
swift crag
#

Which object is the joint component on?

green copper
#

the thruster block so when I copied it it maintained the joint and I didn't need to recreate it

swift crag
#

I wonder if you were getting a bad interaction between the rigidbodies (through that fixed joint)

#

I've only used joints a few times before

green copper
#

with a thrust of 200f the ship has a thrust just barely too light to lift it, falls very slowly while thrusting at full

swift crag
#

that's an acceleration of around 4m/s^2

#

reasonably close to gravity at 1/3 strength

green copper
#

a thrust of 1000f is roughly how it performed before the issue

swift crag
#

you said that this happened after setting up the side thrusters. did this involve changing anything about the ship's setup?

#

I would deactivate those thruster objects see how it's behaving.

green copper
#

had the same thought and just finished test

#

no change

#

ship still requires 1000f thrust to mimic 20f from before

swift crag
#

that's a factor of 50. are you sure you didn't change anything about how you apply force to the ship?

#

because a factor of 50 is what you'd get if you switched from AddForce(..., ForceMode.Impulse) to AddForce(...)

#

the default physics timestep is 0.02, or 50Hz

#

50 is also the mass of the ship, conveniently

#

so you also could have previously been adding to the velocity instead of adding a force

#

or using ForceMode.Acceleration

green copper
#

The only things I did were rename the variables and add the side thruster particle emitters

#

I renamed the variables by right clicking them at the reclaration and using Visual Studio's "rename" feature

swift crag
#

a force of 20 newtons on a 50kg ship would never make it accelerate more than 0.4 m/s

#

which is very slow. not nearly enough to beat gravity.

green copper
#

the strange thing is, in the first testing

#

when every rigidbody was the same weight

#

the thrusters were too heavy and made the handling screwy and bottom-heavy

#

upping the mass fixed it

#

and I did have to up the thrust to compensate

#

but not to this degree

swift crag
#

and did you do that by changing m_Thrust in the inspector?

green copper
#

no, I did so in the script

cosmic plover
#

I'm watching and waiting. I want to ask a question but unsure if I should.

swift crag
#

just go ahead.

green copper
#

I used the inspector to refine it while running to find the right number, but to make the final change I stopped the simulation and edited the script and restarted it

swift crag
#

Editing the script would have had zero effect if it was a serialized field.

#

The field initializer's value gets clobbered when unity restores all of the serialized fields on the object.

green copper
#

So I was experiencing a wierd bug/mistake before that made things work, and that wierdness stopped working

swift crag
#

I feel like you just lost track of your values. Without version control, we can't really confirm what used to be there.

cosmic plover
#

I don't think this is a beginner question but I wanted to ask it here because it's pretty active. I want to edit multiple terrains through script without having a seam like you can in the editor with a brush.

#

So is there an easy way to do that?

swift crag
#

It gathers data from one or more Terrains into a single texture

#

you can then paint on that texture

cosmic plover
#

I'd like to see an example of how to do this. I've tried it already and I didn't understand it.

swift crag
#

I have a (somewhat messy) example from a game I haven't worked on in a bit

#

I used Graphics.Blit to copy from the source texture to the destination texture. I think I modified a sample shader for that "Terrain Add" material

#

wait, that's not the right one.

#

oh, it was. i haven't touched this in a minute 😛

#

This is all pretty old and messy. I'd rather find something else for you to look at.

cosmic plover
#

I can use the built in shaders though right? For set height or something like that?

swift crag
#

Yeah, I bet so

cosmic plover
#

The hidden ones

swift crag
#

I was using this to "stamp" the terrain with a texture

#

It draws on both the splatmap and the heightmap

cosmic plover
#

I just want to modify the height and then smooth it out.

swift crag
#

If you want to do multiple modifications, you'll need to "ping pong" between two different render textures

#

since you can't blit from a texture to itself

#

Ah, here's a little example.

#

Note that TerrainTools was in an experimental namespace in older versions of unity

#

but it should be largely the same

oblique torrent
#

is there a workaround to not being able to use System.Numerics BitOperations

#

im making a chess engine and my self written GetLSB function is soo much slower than BitOperations.TrailingZeroCount

swift crag
#

Why can't you use it?

#

too new?

#

ah, yeah, doesn't show up

oblique torrent
#

yeah

#

replacing my self written GetLSB and GetMSB increased speed by more than 200% 😪

swift crag
#

this may be helpful

#

you'd need to use these inside of Bursted code, I suspect

#

I think I messed with using these at one point

#

Looks like I didn't keep any code using them though

oblique torrent
#

hm

#

Unity.Mathematics has a tzcnt

#

hopefully its fast enough lol

charred spoke
#

It should be

#

Im using it in my rendering code and it hasn’t been a problem

swift crag
#

I presume that it'd still be faster if you could Burst the mathematics calls

#

but see how it performs, yeah

#

I'm fuzzy on what goes on there.

charred spoke
#

You can burst anything from unity.mathematics

ruby python
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

swift crag
charred spoke
#

Well considering that its bit shifting magic pretty fast

swift crag
#

and, vitally, I don't think it's going to be using those x86 intrinsics

#

but I'm just spitballing

#

i guess my conclusion is to tryitandsee

oblique torrent
#

idk what bursting is ill look into that later 🤣

#

havent even opened unity yet just been working in c# alone

swift crag
#

Burst lets Unity compile a subset of C# down to native code

oblique torrent
#

gonna transfer it all later

oblique torrent
#

so do i just burst compile certain parts of code

charred spoke
#

[BurstCompile] is magic

ruby python
#

Hi all, end of a long day and my brain is failing me.

Could someone help me out a little with this little piece of maths? 😦

  float hitDistance = hit.distance;
  hitDistance = -hitDistance;
  dustKickParticleRate = hitDistance * 335f;

Basically I have a raycast pointing straight down, as I hit the 'limit' of the ray I'm setting the particle rate of a vfx graph, what I'm trying to do is invert the distance number so that I can use the distance to drive the amount of particles emitted (lower the further away from the ground).

#

If that makes any kind of sense. lol.

charred spoke
#

static methods and anything that isnt a native object can be bursted

swift crag
#

1 / x is very steep for x values near zero, though

visual venture
#

How do I input movement code?

ruby python
swift crag
#

6 / distance would give you a value between 1 and 0.5

#

you could clamp this to keep it reasonable

ruby python
#

right okay, well I need to go between 0 and 2000 particles.

swift crag
#

you can do a few multiplications and divisions, or just use the lerp methods

ruby python
#

Sorry, honesly my brain has really given up on me now, been doing fluid simulations all day. Think I'm a bit math'ed out. lol.

swift crag
#
float t = Mathf.InverseLerp(nearDistance, farDistance, hitDistance); 
float rate = Mathf.Lerp(maxRate, 0, t);
#

this would be a linear interpolation instead of 1/x

swift crag
eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

visual venture
toxic cloak
#

Is instantiating an object is better or seting it to active and inactive is normaly?

swift crag
#

I don't understand what that means.

swift crag
#

If there's only going to be one copy of something, activating and deactivating it can make a lot of sense

#

like if there's a door that disappears after you find a key

#

Instantiation makes sense when you could have a varying number of something

#

you instantiate a bullet

polar acorn
#

The term for this is "Object Pooling"

ruby python
#

If you're going to be instantiating a lot, look at object pooling.

toxic cloak
#

i mean in my case i have a single coin in a single platform so which will be better instantiating or setting it to active

polar acorn
toxic cloak
#

Yep Thanks All

arctic ridge
#

Hi there, i was wondering how to change a variable in the middle of the same script? For example, i have a variable set to 5, that i want to be reduced by one every second. My main idea is this:
While( timer => 1)
wait(1)
timer = timer - 1

fallen snow
#

hey I'm getting this error and idk where it is in my code can someone point it out (I have no clue ab code)

swift crag
eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

swift crag
#

that way, it'll highlight errors for you.

#

That looks like Visual Studio to me.

visual venture
swift crag
visual venture
polar acorn
swift crag
#

If you have zero idea what's going on, then you should really be following a tutorial.

visual venture
swift crag
#

that is the code editor.

#

notably, it is not part of Unity

summer stump
visual venture
swift crag
#

The tutorial may not explicitly talk about how to install and use a code editor.

visual venture
#

Ah it was like this.

wary sable
#

how would you go about checking (by script) if an animator controller has a specific blend tree?

swift crag
fallen snow
swift crag
fallen snow
swift crag
#

Click the "Visual Studio" link that matches how you installed the editor.

#

they both take you to the same page, but if you used the Hub, it skips a few steps

polar acorn
eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

fossil tree
#

hi, how can i edit a toogle in the script like how i put a if for

#

like if the toogle is on that make a thing

#

sry im french its hard to explain xddd

fallen snow
#

I configured my IDE and it seems like it's working, I fixed an error

#

but now I have an warning

#

Idk what this means ngl I have no idea about code

fossil tree
#

warning are normal

fallen snow
#

alright

fossil tree
#

if that run that good

#

XDD

polar acorn
wary sable
#

you have a semicolon after an if statment

#

nothing within your brackets will run with that there

polar acorn
#

This if statement has nothing in it. It does nothing at all

fallen snow
#

ok!

swift crag
#

; terminates a statement

fallen snow
#

yay fixed that

#

now I need to make it so it actually works

#

rather than crashing

swift crag
#

Assuming you are talking about the Unity UI toggle.

fossil tree
#

yes ty

polar acorn
#

Ah, Fen beat me to it

fossil tree
#

the thing i search is like the onclick of the event trigge

#

r

timid prawn
#

hey! Im new, can someone answer 1 question?

swift crag
timid prawn
#

ok x) mb, I found an interesting project on the internet that I wanted to explore to understand how it works a bit. I downloaded it as a Unity package, and everything was imported correctly, but the scene remains empty. I just wanted to know if this is normal. 😊

summer stump
swift crag
#

The package may include some scene assets.

#

search t:Scene in the Project window to show all scenes in the project

fallen snow
#

I'm trying to make it so that when this script is attrached to an object, upon collision it only hurts objects tagged with "Player" but rn it doesn't hurt anything at all. anyone can help? this is like reading another language ngl

fossil tree
timid prawn
#

ok I check!! thx a lot @swift crag sorry if my question seems idiot Im learning by myself

polar acorn
fallen snow
#

that's what I'm trying to do

#

😭

polar acorn
fallen snow
#

AA how

polar acorn
#

You have the collider of it as a parameter

#

Colliders have a .gameObject

wary sable
#

gameObject.ComparTag() refers to itself, just like using .this in plain c#

fallen snow
#

if (gameObject.CompareTag("Player")) so I swap compare tag to gameObject?

wary sable
#

when using OnTriggerEnter, the local var you create (in this case collisionData) is the refrence to the other object

#

so if you are trying to check to see if the other object is the player you will want to use that local var, not gameObject

fallen snow
#

I know very VERY little code I can barely understand

wary sable
#

all good, just remember that gameObject is referring to whatever game object the script is attached to

#

so if you have this script on a cube, calling gameObject will give you a refrence to said cube

fallen snow
#

so like if (gameObject.collisionData("Player")) is correct?

buoyant knot
#

no

polar acorn
#

Use the collider instead of this

wary sable
#

no, you dont need to refrence gameObject at all here

fallen snow
#

I want to attach this script to enemy projectiles and I don't want it to hurt the enemy firing it

#

what is this

#

oh

buoyant knot
#

gameObject gives an object of type GameObject.
CompareTag is a method in the gameObject class. CompareTag takes a string as an argument (input).
When you call gameObject.CompareTag(“myString”), it calls this function. It compare’s gameObject’s tag with “myString” and returns true (if they are the same) or false if they are not.

swift crag
eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

fallen snow
#

I'mma try write in pseudocode

like
if (object colliding with is tagged "player")
{damage that object}

buoyant knot
#

before you write pseudocode, you must learn to actual code

fallen snow
polar acorn
fallen snow
#

I have like no time to learn code I need to get this in 😭

timid prawn
#

U had right, there is 4 t:scene! thx, Im trying to open them haha! @swift crag

fallen snow
#

samething in my head

#

that

#

how do I write that in C#

wary sable
#

so this is attached to a projectile, then you want to check if the thing its touching is the player correct?
Then you need to compare the tag "player" to the player object, not the bullet. gameObject.compare is checking the tag of the bullet not the player...

To refrence the object you are colliding with, you use the var you created in OnTriggerEnter(otherobject)
that "otherObject" is anything that enters the collider of the bullet. you want to compare the tag of that

buoyant knot
#

bro, you need to learn. we aren’t here to write code for you

polar acorn
#

So, you chain those together with . just like you do with 's in English

#

So, get the collider's gameObject's tag

fallen snow
buoyant knot
#

when you use left.right, the program looks in the class of left’s type for a method/field/property named by right

timid prawn
#

it's so hard to download a project damn

wary sable
fallen snow
# wary sable how were you trying to check before?

basically before as long as it collided with something it modified the hp. but I want to make it so only on colliding with the player it does this, bc otherwise the enemy shoots itself when the projectile collider and their own collider merge

wary sable
fallen snow
#

ok! I'll take an SC of the original script I am attempting to modify

wary sable
#

so how would you try and check if the object with a health script is the player?

polar acorn
# fallen snow

So, notice how the first line has you calling GetComponent on the collider's gameObject.

fallen snow
#

Idk 😭 I want it so the modify health part only works if the object is player

polar acorn
#

So, how might you instead call CompareTag on the collider's gameObject

fallen snow
#

OHHH

wary sable
fallen snow
#

I know it's just Idk how to write it bc I know nothing about coding 😭

#

where's the getcomponent part? 😭

wary sable
#

its in your sc

fallen snow
#

does it literally say GetComponent?

#

bc I'm blind and

#

yeah

wary sable
#

all good

fallen snow
#

OO PFOUND IT

polar acorn
fallen snow
#

idk what to do now

polar acorn
polar acorn
#

At no point did anyone say that should change

wary sable
#

so on that line you are storing the 'HealthSystemAttribute' of whatever object your bullet is colliding with as 'healthScript'. Notice that you get the 'HealthSystemAttribute' from a gameObject... That gameObject is whatever you collided with and its saved as 'colliderData'. using .CompareTag() how would you compare the tag of that colliderData?

fallen snow
#

I don't knoww :(

polar acorn
# fallen snow I don't knoww :(

You need to realize that code isn't magic. All of the words in each line mean something as much as they do in the sentence you're reading right now

#

You already know how to call a function on an object

fallen snow
polar acorn
#

So now you need to call a different component

fallen snow
#

I don'ttt

#

even

swift crag
#

yes you do. you've done it repeatedly.

polar acorn
#

The very first line of your code

#

Is you calling GetComponent<HealthSystemAttribute>() on the collider's gameObject

fallen snow
#

I didn't write it! I'm trying to modify code from unity playground

polar acorn
#

So you can read it

fallen snow
#

all I'm asking it how to get a working if statement bc I d k syntax.

like

#

this if statement does nothing

polar acorn
#

is that what you want

fallen snow
#

no I want it to compare tag on the object it's colliding with

swift crag
#

then you'd better not call CompareTag on gameObject.

wary sable
#

ok, then what is the object that you are colliding with?

fallen snow
#

so the enemy which tracks me fires at me

polar acorn
fallen snow
#

and this script is attached to the hostile projectile

fallen snow
polar acorn
#

the same way you are calling GetComponent on that object

fallen snow
#

I've been asking how to do that

#

I know that's what I've been trying to do

polar acorn
fallen snow
#

omg omg omg facepalming I literally can't understand you though

swift crag
#

your code already calls a method on the game object you're colliding with.

polar acorn
fallen snow
#

calls a method?

swift crag
#

if you have literally no idea what any of these words mean then you really need to just learn properly. !learn

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

fallen snow
#

do I put it in there

wary sable
polar acorn
#

What is the first line of the function

fallen snow
fallen snow
polar acorn
fallen snow
#

Where's dilly he explained it easier 😭

polar acorn
#

because if you literally do not know what words mean how are we supposed to help

swift crag
#

that is my point. you shouldn't be trying to do this specific task when you don't know what any of the words mean yet.

fallen snow
#

this isn't a situation I should or want to be in

polar acorn
swift crag
#

sounds like you need to ask your lecturer for another copy of those files.

polar acorn
#

There's an intro to C# guide pinned in this channel

polar acorn
fallen snow
#

not yet

polar acorn
#

best get crackin'

fallen snow
#

ok so

#

you guys know the solution pretty much

polar acorn
fallen snow
#

not asking you to

#

just asking you to explain in a way

#

that's easier for a literal novice

queen adder
polar acorn
fallen snow
#

my adhd ass cannot communicate with you

polar acorn
fallen snow
#

I cannot focus on what you're saying at all

swift crag
#

You know nothing about programming, so it's impossible to explain the solution to you without just giving you working code.

#

That's the problem.

#

You need at least a basic grasp of what these things mean

#

what it means when you see foo.bar.Baz() in a script

fallen snow
#

Hey I've come pretty far just by interpreting the code I'm attempting to modify

#

I get it in pseudocode not in C#

ashen ferry
#

comfort wtf is ur og discord tag kekW

polar acorn
fallen snow
#

desolate bruh

#

if you think that's translating pseudocode idk what to say

polar acorn
#

In english, you would say "Mandy's Wagon". In C# you would say Mandy.Wagon

#

You have the collider of the object you hit, it's a paremeter to your function

fallen snow
#

so like compareTag.collider

polar acorn
#

So, how would you get that collider's gameObject

swift crag
#

foo.bar tries to retrieve something named bar from a variable named foo.

polar acorn
#

Is that what you want

wary sable
#
  //how could you use theObjectThatHitMe??
}```
fallen snow
#

I want to get the bullet to initiate the modifyhealth action upon colliding with an object tagged as "player"

polar acorn
fallen snow
#

Collider.GameObject("Player")

#

but that's not mentioning a tag

polar acorn
wary sable
#

to check something like that you need to call a method / function

polar acorn
#

So call that function on the collider's gameObject

fallen snow
#

If collider's gameobject's comparetag is ("player")

#

something like that?

wary sable
#

yes

polar acorn
fallen snow
#

collider.gameobject.comparetag("Player")

polar acorn
fallen snow
#

ok ok ok ok uhhh

#

what name did I give it

#

collider2d?

wary sable
#

you know the answer to the question I asked, just read through the statments

polar acorn
#

You're already using the name in several places

#

including calling GetComponent on it

#

Or you can look up what a "Function Parameter" is

#

and see where you did that in your code

fallen snow
polar acorn
wary sable
fallen snow
#

wait so colliderData.gameObject.CompareTag("player")?

#

0 errorsif I use that

polar acorn
queen adder
#

does anyone know how to transfer a project from desktop to a macbook

golden ermine
#

Why am I getting this error on line 53?

polar acorn
polar acorn
golden ermine
#

oh ahoot i didnt see haha

queen adder
fallen snow
#

IT WORKS

#

I need to test more

#

to make sure

golden ermine
#

here, why am i getting error on line 53

fallen snow
#

IT FLIPPING WOOOOOORKKSSSSS

polar acorn
#

It's kind of confusing but don't use those, use an actual == null instead

short hazel
#

Seems like it's a custom EventHandler, by the signature

polar acorn
#

Oh, actually, you're right technically it's all on line 53

#

So aimGunEndPointtransform could also be null

golden ermine
#

yea im following this guy

#

he did that and no error

rich adder
#

codemonkey code ?

golden ermine
#

yeah

wintry quarry
rich adder
#

codemonkey has bad tuts although he says "its clean code"

short hazel
#

Because code monkey

wintry quarry
#

ah yeah codemonkey - that explains it

short hazel
#

Action<OnShootEventArgs>, the cleaner alternative since you never actually use the object sender parameter of an EventHandler

wintry quarry
#

If OnShootEventArgs is a class, not a struct, it's still not great

#

if it's a struct then fine

golden ermine
polar acorn
short hazel
#

hmmm

uncut dune
#

this piece of code somehow isnt working

rich adder
#

thats a big ass chain lol

wintry quarry
# golden ermine

This is kinda cringe in Unity, just letting you know. it will work fine for the tutorial, but it's a lot of GC for no reason

uncut dune
golden ermine
wintry quarry
rich adder
wintry quarry
polar acorn
wintry quarry
#

you only needed to figure out why aimGunEndPointTransform was null

rich adder
wintry quarry
#

The ?. was completely fine for an event

#

put the code back how it was

#

and fix your null reference

polar acorn
#

Yes, I didn't know what type it was because you didn't show the full code

uncut dune
# wintry quarry define "isn't working"

basically it checks if the enemy is worth more then the current currency available, and if it is less then the room it should start spawning from or more then the room it should stop spawning from and rolls another enemy if so

#

but now that I look at it

#

there is 2 conflictions

wintry quarry
#

what was it actually doing

golden ermine
wintry quarry
uncut dune
rich adder
#

I bet its using transform.Find

uncut dune
#

I think its this bc these 2 can never be true at the same time

polar acorn
# golden ermine

Now that whole if statement isn't necessary, just get rid of it

golden ermine
wintry quarry
polar acorn
#

and find out why aimGunEndPointTransform is null

rich adder
golden ermine
rich adder
#

god transform.Find is so ugly

#

CleanCode my butt

short hazel
#

Drag-drop. Direct reference

uncut dune
#

but those 2 last ones

#

are never true at the same time

wintry quarry
#

Yeah regardless of what kind of script it is and what it should be doing, you need to break that line of code into something understandable

uncut dune
#

maybe this will work

short hazel
wintry quarry
golden ermine
#

like this?

rich adder
#

doing Find is ugly af

#

assign them inside inspector

uncut dune
rich adder
wintry quarry
# uncut dune ok thank will do
var randomEnemy = enemyPool[random];
int enemyRoom = randomEnemy.SpawnableFromRoom;
if (enemyRoom < RoomNumber || enemyRoom > RoomNumber)```
#

now the if statement is so much easier to read

#

it's very clear that if (enemyRoom < RoomNumber && enemyRoom > RoomNumber) is impossible
do note that it's quite possible for you to get an infinite loop with this though.

golden ermine
#

but that wont fix this on 54

uncut dune
#

they are different

rich adder
#

in the inspector

golden ermine
#

i did

polar acorn
golden ermine
#

do i still need this?

uncut dune
#

and I just figured I shouldve put || in all of them

rich adder
#

i did say get rid of find

wintry quarry
uncut dune
#

I'll get less performance

#

Im only using them once

golden ermine
wintry quarry
polar acorn
wintry quarry
#

intermediate variables are never worse and are usually better performance wise

#

think of it this way: the variable exists whether you name it or not.

wintry quarry
#

by naming it you get to reuse them and therefore avoid extra calculations

uncut dune
#

so its like calling a new variable everytime?

#

if I dont name them

wintry quarry
#

every time you write enemyPool[random]; it has to call the indexer function on the array

#

that's not free

#

it's faster to save it in a variable and reuse that variable. Local variables often don't even have to be written to memory

#

they can just live in CPU registers, which is the fastest thing possible basically

uncut dune
#

does it update?

#

or saves to the current random value

wintry quarry
#

no nothing updates

#

in this image you're using the same random twice though

#

random isn't changing

arctic maple
#

hi! currently trying to build our project game.
right now we have a main menu scene and a cutscene scene. when we load the cutscene scene, the entire game freezes for a moment and then nothing happens. no crash. no errors. this only happens with the cutscene scene. nothing visually changes either.
attaching a debugger gives no error message, and neither does player.log. the game otherwise works completely flawlessly in editor mode.
the last message in player.log says: [ALLOC_PROFILER] Peak usage frame count: [32.0 MB-64.0 MB]: 2943 frames Requested Block Size 16.0 MB Peak Block count 3 Peak Allocated memory 33.5 MB Peak Large allocation bytes 0 B [ALLOC_PROFILER_BUCKET] Large Block size 4.0 MB Used Block count 1 Peak Allocated bytes 76.4 KB ##utp:{"type":"MemoryLeaks","version":2,"phase":"Immediate","time":1697574917439,"processId":4928,"allocatedMemory":279875,"memoryLabels":[{"Default":-128},{"Thread":432},{"Manager":9506},{"GfxDevice":72},{"GfxThread":2112},{"Serialization":508},{"String":181},{"HashMap":1536},{"Utility":263624},{"PoolAlloc":112},{"VR":1696},{"Subsystems":96},{"CoreBusinessMetrics":128}]}
but i don't really know if it's relevant.
would appreciate any help i could get :]

swift crag
#

do the build settings include the cutscene in the scene list?

wintry quarry
acoustic arch
#

my colliders look weird when the player runs into them constantly

uncut dune
acoustic arch
wintry quarry
#

between the 3 array accesses it's the same

acoustic arch
uncut dune
wintry quarry
wintry quarry
uncut dune
wintry quarry
# uncut dune yah I'll try implementing it the best I can

for example:

var enemy = enemyPool[random];
while (enemy.EnemyWorth > currentWalletSize || enemy.SpawnableFromRoom < RoomNumber || enemy.NotSpawnableFromRoom > RoomNumber) {
  random = Random.Range(0, enemyPool.Length);
  enemy = enemyPool[random];
}```
#

this only does enemyPool[random] once per loop iteration rather than 3 times

arctic maple
uncut dune
#

now I know my while loop is running

#

cuz its crashing unity

#

progress

acoustic arch
#

movement.x is horizontal input

crude prawn
#

does anyone know a workaround in this? im trying to make so the camera follows the player but only in the x axis

arctic maple
#

@wintry quarry this would be the other thing.

polar acorn
wintry quarry
wintry quarry
#

when you unpause and continue does it stay at that same location?

#

Or does it switch to other locations?

wintry quarry
crude prawn
#

Thank you

wintry quarry
crude prawn
#

with cinemachine right

violet topaz
#

im trying to get the camera to follow the player but i dont know how to assign the player to the cam ```cs
public class CameraFollow : MonoBehaviour
{
[SerializeField] private Vector3 offset;
[SerializeField] private float damping;

public Transform target;

private Vector3 vel = Vector3.zero;


private void FixedUpdate()
{
    Vector3 targetPosition = target.position + offset;
    targetPosition.z = transform.position.z;

    transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref vel, damping);
}

}```

arctic maple
# wintry quarry Or does it switch to other locations?

it just stays like that and actually ends up crashing after a while now
doesn't crash without a debugger connected either.
worth noting that the background audio is playing on loop the whole time.
what i'm doing is pressing a button that just loads another scene. that function works fine since other scences load without a hitch. just the cutscene scene that ends up doing nothing.

wintry quarry
wintry quarry
crude prawn
wintry quarry
wintry quarry
crude prawn
#

hmm ill give it another go

heavy saddle
#

Hi sorry I created the particles for the effect of the weapons that string of code I have to inseries to be able to give the input that every time I shoot it starts the effect

heavy saddle
#

Thanks

frank light
#
        if (Input.GetButtonDown("Jump") && characterController.isGrounded)
        {
            characterController.velocity = new Vector3(characterController.velocity.x, jumpHeight, characterController.velocity.z);
        }
    }
}

the characterController.velocity gives me this, what am i doing wrong?

swift crag
#

You can't assign to it.

#

call Move() to move the controller

#

Move takes a distance and moves by that much

green copper
#

Is there an easy way to smooth this motion out?

tough lagoon
swift crag
#

You're moving by 0.5 meters every frame

#

That will be very fast

#

and also framerate-dependent

#

You should multiply that vector by Time.deltaTime so that you move at 0.5 meters per second, instead of 0.5 meters per frame

green copper
#

that smoothed it out a ton, thanks

swift crag
#

you need to explain your problem.

#

i can guess what it is, but i've been wrong before (:

mossy arrow
#

the spawning is not in the right place idk why

#

it is spawning way to high or way to low

swift crag
#

okay, so i was wrong

#

i was guessing your problem was that you were going through walls

swift crag
#

since the script uses transform.position.y to compute where it's going to spawn the pipe

#

What is this component attached to?

mossy arrow
#

what component

#

the pipe?

swift crag
#

No. The PipeSpawnScript component.

mossy arrow
#

I dont get it (im bad at coding)

summer stump
rich adder
swift crag
#

you attached it to a game object somewhere.

#

I want to see that object.

swift crag
#

Switch to the scene view.

#

Where is this object?

mossy arrow
swift crag
#

press W so we can see some arrow gizmos

rich adder
#

might wanna fix this too

swift crag
#

that looks reasonable enough

#

Height Offset is set to 10, though

#

That looks like it'll be way more than one screen height's worth

#

Perhaps you need a smaller number.

mossy arrow
#

wait im so lost

#

what do i do rn?

swift crag
#

Change Height Offset to a small number.

#

See how it looks.

#

I think your height offset is way too large.

#

Do this in the inspector.

mossy arrow
#

5?

swift crag
mossy arrow
#

ok

#

lets see

#

did not work

swift crag
#

Show me the inspector for the pipe spawner again.

swift crag
#

Okay. It looks pretty even now.

swift crag
#

Notice how, in the prefab view, the gap between them isn't at the center?

#

It's above and to the right of the center.

mossy arrow
#

how do i fix that

swift crag
# mossy arrow

notice how the pipes are all at about the same height now. they're just too high on average.

swift crag
#

I don't know what the pipe prefab looks like

#

Does it have two sprite renderers for the two halves?

#

If so, move their objects.

mossy arrow
#

like this?

swift crag
#

surely you have moved objects around before

#

ah, you deleted the post

#

Show me the hierarchy window for this prefab.

#

I need to see every object.

mossy arrow
swift crag
#

That is not the prefab.

#

I need to see the hierarchy window while you are editing the pipe prefab.

mossy arrow
#

this?

rich adder
# mossy arrow

you have to move the white ones where the circle was. Use move tool you'll see where it is

swift crag
#

That is not the hierarchy window.

#

Double click the Pipe prefab to start editing it.

#

Screenshot the hierarchy window.

swift crag
# mossy arrow

this is the hierarchy window, but you were not editing the Pipe prefab.

mossy arrow
#

this one?

swift crag
#

That is not the hierarchy window.

#

Do you not understand what the Hierarchy window is?

mossy arrow
#

nope

swift crag
#

It is the window named "Hierarchy". You sent me a screenshot of it a minute ago.

mossy arrow
swift crag
#

It shows every object in the scene or in the prefab you're currently editing.

mossy arrow
#

this?

swift crag
#

Yes.

formal escarp
#

i have a question.

swift crag
#

Move Top Pipe and Bottom Pipe.

formal escarp
#

i have a project on unity, how do i make it so every time i press "R" the level restarts?

swift crag
#

when you click on "Pipe", that will select the prefab's root. That's where the prefab's "center" is.

#

Move the pipes so that the gap between them is around that center.

swift crag
mossy arrow
#

wait so what do i do rn

swift crag
#
void Update() {
  if (Input.GetKeyDown(KeyCode.R)) {
    SceneManager.LoadScene("someScene");
  }
}
#

note that SceneManager is in the UnityEngine.SceneManagement namespace. You will need to include using UnityEngine.SceneManagement; at the top of the script.

mossy arrow
#

so what do i do?

formal escarp
#

alrighty. thanks Fen.

#

you the goat.

swift crag
#

The gap between them is not at the center right now

#

Click on "Pipe" and look where the arrows appear in the scene view. That's the center of the prefab.

mossy arrow
#

where do i move them

swift crag
#

Do not move them around in the hierarchy. Move them around in the scene view.

#

like, change their positions

mossy arrow
#

ohhhh

#

do i move down or up?

swift crag
#

Click on "Pipe".

#

Screenshot the scene view.

mossy arrow
summer stump
mossy arrow
#

ye

summer stump
#

Move them there...

swift crag
#

Press W so that you can see some arrows instead of that tiny circle.

mossy arrow
#

w is not wokring

swift crag
#

Click the four-arrow button.

mossy arrow
#

done

#

now?

rich adder
#

scroll up

mossy arrow
summer stump
rich adder
#

still didn't click the 4 arrows

mossy arrow
swift crag
#

you did not click the button. you are still in "Rect Tool" mode

#

please do what I ask you to

mossy arrow
#

bro what W

#

i did press it

rich adder
#

just click it forget W just click it..

swift crag
#

I asked you to click on this button.

mossy arrow
swift crag
#

Good.

#

You will now see arrows in the scene view.

mossy arrow
#

yes

swift crag
#

Click on Pipe. The arrows are the center of the prefab.

rich adder
#

did your teacher in school have to show you how to hold a pencil 😆

swift crag
#

Click on Top Pipe. Move it so that it's a little above where the arrows were.

#

Do the same thing with Bottom Pipe.

#

All of the pipes are appearing way too high because the center of the prefab is not where the gap is.

#

You need to move the gap to the center of the prefab.

mossy arrow
#

i do not see a

#

dot

swift crag
#

That's because the dot appeared when you were in "Rect Tool" mode.

#

You switched out of that mode.

swift crag
# mossy arrow

Assuming you currently have "Pipe" selected, this is correct.

#

They will now appear correctly.

mossy arrow
#

the dot is running away from me

#

what did i say

#

im trying to come to it

#

can someone help me?

rich adder
#

perhaps clarify whats wrong

summer stump
swift crag
#

AH

#

See this?

#

Switch that from "Center" to "Pivot"

#

Center tries to put the arrows at the "center" of the object

#

this is often misleading

#

er, not local

#

from "center" to "pivot"

#

my bad

mossy arrow
#

BRO IT IS RUNNING AWAY!

swift crag
#

whatever the rect tool is doing doesn't really matter

mossy arrow
#

how do i fix this!

swift crag
#

Ignore the rect tool. Leave it on "Move Tool".

polar acorn
#

This seems to be doing exactly what is expected

mossy arrow
#

so what do i do

swift crag
swift crag
polar acorn
swift crag
mossy arrow
lusty socket
#

Hi im making a 2d sprite game and added code for an overhead checker, just wondering what to create in the scene to put this in and work

swift crag
mossy arrow
#

done

lusty socket
#

🙂

swift crag
#

now fix the positions of the pipes

#

you should see that the arrows now no longer between the two pipes.

mossy arrow
#

the pipe is running away from me

swift crag
#

Select "Top Pipe".

polar acorn
swift crag
#

If you select "Pipe", you will be moving the entire prefab around.

mossy arrow
#

do i move one at a time?

swift crag
#

You can select both at once if you want to.

hexed terrace
#

Why is so much space being taken up in here with non-code basic beginner stuff

swift crag
#

yes, I was just typing that, actually

hexed terrace
#

-> thread

swift crag
#

this is not remotely a code problem and we should've moved it a long time ago

hexed terrace
mossy arrow
swift crag
#

Doesn't matter.

#

This is no longer a code problem.

lusty socket
swift crag
#

I would use Physics2D.CheckBox to test if there's anything above the player.

#

wait, wrong name...

#

2D and 3D are just different enough to trip you up

#

This method will check if there is a collider inside the box.

#

If you set the layer mask to only include the level's layer, then the query will ignore everything that isn't the level.

#

perhaps...

#
Collider2D hit = Physics2D.OverlapBox(player.transform.position, Vector2.one * 0.2f, 0, LayerMask.GetMask("Level");

bool canUncrouch = hit != null;
#

This is probably not the correct point to check, though.

#

it'll probably be at your feet.

#

I'd add an empty object to the player where you want the "head check" to be centered at

#

then just use its position.

#

Maybe like this.

#

This is basically identical to a "ground check".

lusty socket
#

@swift crag Could you check my code please im getting the error Parameter Crouch does not exist after completing my code for the crouch and ive no idea why. thankyou

swift crag
#

if you show me your code, perhaps!

lusty socket
#

whats the website to create a code url sorry?

swift crag
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

frank light
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class CharacterControllerMovement : MonoBehaviour
{
    public Rigidbody rb;

    private CharacterController characterController;
    private const float YHeight = 1.58f;

    public float speed = 650f;
    public float jumpHeight = 5f;

    void Start()
    {
        characterController = GetComponent<CharacterController>();
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        // Get the player's input.
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");

        // Create a movement vector based on the player's input.
        Vector3 movementVector = new Vector3(horizontalInput, 0, verticalInput);

        // Move the GameObject using the Character Controller component.
        characterController.SimpleMove(movementVector * Time.deltaTime * speed);

        if (Input.GetKeyDown(KeyCode.Space) && characterController.isGrounded)
        {
            // Debug.Log('jumped');

            rb.velocity = new Vector3(0, 10, 0);
        }
    }
}

can anyone see what i am doing wrong with the jumping part of this script, it doesn't do anything.

crystal cipher
#

I made a daily reward system

polar acorn
#

Don't.

timber tide
#

Smells of gpt

polar acorn
frank light
#

so would it better to do movement through rigidbody or charactercontroller?

lusty socket
polar acorn
swift crag
#

Use a CharacterController if you want to directly control movement.
Use Rigidbody if you want the player to be affected by other physics objects.

frank light
#

sorry for asking a question in a help channnel Fen

swift crag
#

Of course, you can also just use a kinematic Rigidbody if you really want.

#

It's fine to make mistakes. I'm just commenting that it's an unusual setup.

polar acorn
#

it's the attempting to have two different movement controllers

swift crag
#

CharacterController is used for non-physical movement. All it does is make sure that you don't go through walls.

timber tide
#

rigidbody-light

lusty socket
polar acorn
lusty socket
#

ohhhh no i completewly forgot to do that. thankyou sorry i was just being extremely dumb

swift crag
#

zap

#

You won't get a compile error becauase C# has no idea about which animator parameters do and don't exist

#

As long as you pass a string, it's happy

livid jacinth
#

ok i was asking about it yesterday but this is still bothering me, I have a prefab with a script that has an array on it, when I try to change the size of the array using the inspector, the array disappears completely and I'm getting this wall of text pop up in the console. Nothing sticks out to me as the cause for it to happen, can someone take a look to see if you can figure it out?

swift crag
#

i'm randomly getting that too

#

i have a lot of nested lists in my inspector

#

what unity version?

#

I am on 2022.3.10f1 at the moment (the 2022 LTS)

livid jacinth
#

I was on that one, then I updated to 2022.3.11f1 and it's still happening

swift crag
#

I mostly just get error spam when any non-transform component is being inspected

#

in a way that doesn't make stuff actually disappear from the inspector

livid jacinth
#

It was working perfectly fine until I tried to see if I could have nested arrays in the script and that's when it blew up

swift crag
#

but I have definitely seen that one a few times..

livid jacinth
#

yeah i've noticed if I click off the prefab and then go back to it, the array is still there and fine

#

It would just be nice for it to not throw a fit when I want to do it the convenient way

swift crag
#

I have had some trouble cross-referencing the error with the code that unity publishes

#

all of the versions in the changelog are alpha versions

livid jacinth
#

if i try to click on any of the scripts in the error it just comes up with nothing

swift crag
#

yeah, because the actual source isn't on your disk

livid jacinth
#

oooooh

wary sable
swift crag
#

It looks like you can override the behaviours that are used by individual states.

#

notice how you can add behaviours to the layers

#

not just the individual states

wary sable
#

ahhh

#

thank you!

swift crag
#

ah, but that's not quite it

#

You can override behaviours (and motions) for a specific state

valid finch
#

I thought entering Playmode reset everything in your program.. like hitting the power switch for a game. I have some stuff that is being stored with don't destroy on load.. and It is persisting.. How the hell do I reset my scene to the default??

swift crag
#

So if you overrode the behaviours for a specific state, the "Effective" method would give you the override

#

not the state's original behaviours

wary sable
#

ok, that makes a lot more sense. Not really useful for what I'm trying to do but good to have an answer.

#

Thanks 😄

swift crag
valid finch
#

Is there a way to reset everything in your scene within unity? I always thought exiting playmode reset everything to default values and positions. Weird

swift crag
#

It generally should, unless you're doing some Bad Stuff

#

I think instantiating inside OnDestroy is "bad stuff"

#

I think you'll get a console warning if you do that

valid finch
#

Alright.. yeah. That was weird.. it was keeping the xValue I was storing.. even after closing

lusty socket
#

Can anyone tell me place to go to ask for help with animations in unity?

valid finch
swift crag
lusty socket
#

Can anyone help with my crouching, assuming its a coding issue as the speed isnt slowed down when pressing c and the animation doesnt play either, i dont know what you would want to see for help so ive attatched my code below, thanks

swift crag
#

use Debug.Log to check if your code is running at all

lusty socket
#

the running and jumping are all working, just the crouching

swift crag
#

Cool. But how do you know your crouching code is even running?

lusty socket
swift crag
#

I don't know what you did, so I can't really tell you anything.

#

I did notice, though, that crouchPressed is never set anywhere in your code

lusty socket
#

what can i tell you to help out just to give you a better idea