#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 461 of 1

night raptor
fleet grotto
#

for some reason its not showing display message option

verbal dome
boreal grotto
#

i'm making a building tool of sorts, I need to know what direction the mouse is facing. I've got it to work but I'm interested what the most efficient way to do this would be in 2d.

#

sounds a bit stupid reading it back but whatever

languid spire
boreal grotto
#

a tile

languid spire
#

then just get the direction of the mouse from the tile and check the x of it

boreal grotto
#

yes but if it's in two directions at the same time it breaks the code

languid spire
#

how can it be in 'two directions at the same time'

boreal grotto
#

like i can't check which one to build if it's facing up and left

iron wind
#

you need to provide more context, not sure what you are asking

boreal grotto
#

i just woke up the english aint englishing wlel

languid spire
boreal grotto
#

if x is more than the abs value of y then it's right, not up or down, does that make sense?

#

i showed the script to a friend and he told me it's wrong but didn't tell me how

languid spire
#

if you have a direction vector from the tile the x will always be negative or positive giving you left or right, I dont see where y comes into this

boreal grotto
languid spire
#

you've lost me completely, this is beginning to sound like an XY (excuse the pun) problem, you'll need to explain exactly what you are trying to achieve

boreal grotto
#

... that is really hard to explain for some reason

languid spire
# boreal grotto ... that is really hard to explain for some reason

this may help, it's code I use to determine the direction of joystick movement from a gamepad but the logic should be the same for you

        Direction GetDirection(Vector2 v2)
        {
            if (v2 == Vector2.zero)
            {
                // Key up
                return Direction.Origin;
            }
            Direction dir = Direction.Origin;
            bool? on = IsOn(v2.x);
            if (on.HasValue && Mathf.Abs(v2.x) >= Mathf.Abs(v2.y))
            {
                dir = on.Value ? Direction.Right : Direction.Left;
            }
            else
            {
                on = IsOn(v2.y);
                if (on.HasValue && Mathf.Abs(v2.y) >= Mathf.Abs(v2.x))
                {
                    dir = on.Value ? Direction.Backward : Direction.Forward;
                }
            }
            return dir;
        }

        bool? IsOn(float value)
        {
            float i = value;
            if (i > 0) return true;
            if (i < 0) return false;
            return null;
        }
boreal grotto
#

it's kind of similar to what i did

short hazel
#

You need to "round" the direction to the closest 90ยฐ angle (up, down, left, right), correct?

boreal grotto
#

yes

short hazel
#

Can be done with the code above, should be able to do the same logic roughly, with two dot products (up down, left right - maybe diagonally in your case) and a few if statements to know in which quadrant the direction falls in

oak elk
#

https://pastebin.com/9LtDHhWg
guys please help
i have code for generating a minecraft type chunk based on a 3d array of block data, then faces are positioned correctly but their normals and uv are scrambled and mixed up

ive narrowed it down to the generate mesh code itself and something to do with the uv array and the other arrays not matching up

#

ive been debugging for the whole day i cant fix it

covert timber
jolly temple
#

!code

eternal falconBOT
oak elk
# covert timber Looks like an UV issue, they should be in 0-1 range, try to log/debug them to se...
UV(0.00, 1.00, 0.00)
128to32
Vertex[0]: (0.00, 1.00, 0.00) (0.67, 0.20)
Vertex[1]: (1.00, 1.00, 0.00) (0.75, 0.20)
Vertex[2]: (1.00, 1.00, 1.00) (0.75, 0.40)
Vertex[3]: (0.00, 1.00, 1.00) (0.67, 0.40)

UV(1.00, 1.00, 0.00)
144to32
Vertex[4]: (1.00, 1.00, 0.00) (0.75, 0.20)
Vertex[5]: (2.00, 1.00, 0.00) (0.83, 0.20)
Vertex[6]: (2.00, 1.00, 1.00) (0.83, 0.40)
Vertex[7]: (1.00, 1.00, 1.00) (0.75, 0.40)

UV(2.00, 1.00, 0.00)
144to32
Vertex[8]: (2.00, 1.00, 0.00) (0.75, 0.20)
Vertex[9]: (3.00, 1.00, 0.00) (0.83, 0.20)
Vertex[10]: (3.00, 1.00, 1.00) (0.83, 0.40)
Vertex[11]: (2.00, 1.00, 1.00) (0.75, 0.40)

UV(3.00, 1.00, 0.00)
144to32
Vertex[12]: (3.00, 1.00, 0.00) (0.75, 0.20)
Vertex[13]: (4.00, 1.00, 0.00) (0.83, 0.20)
Vertex[14]: (4.00, 1.00, 1.00) (0.83, 0.40)
Vertex[15]: (3.00, 1.00, 1.00) (0.75, 0.40)
#

they match the position x y i have literally no fking clue why they arent working

#

im about to jump out the window

#

wait

#

if i print from the mesh it changes

#

how

#

i hate my life

#

oh wait it didnt change fm

covert timber
#

I don't know if that's the issue but it seems that you are drawing your triangles for your face like that

#

here

        // Define triangles
        triangles.Add(vertexIndex);
        triangles.Add(vertexIndex + 2);
        triangles.Add(vertexIndex + 1);
        triangles.Add(vertexIndex);
        triangles.Add(vertexIndex + 3);
        triangles.Add(vertexIndex + 2);
oak elk
#

oh wait really

wet oriole
#
//
using UnityEngine;

public class RagdollMovement : MonoBehaviour
{
    public Rigidbody hips;
    public float speed;
    public float strafespeed;
    public float jumpforce;
    bool isGrounded;

    void Start(){
        hips=GetComponent<Rigidbody>();
    }
    
    public void FixedUpadte(){
        if(Input.GetKey(KeyCode.A)){
            if(Input.GetKey(KeyCode.LeftShift)){
                hips.AddForce(hips.transform.forward * speed *1.5f);
            }
            else{
                hips.AddForce(hips.transform.forward * speed);
            }
            
        
        }
    }
}
#

my player is not showing any movement

#

the script is correct ig

oak elk
short hazel
oak elk
#

ur fixed update is mispellled

#

ye

wet oriole
#

imma kil myself

#

dude

#

sorry

covert timber
oak elk
#

i dont think its ever gonna be solved

#

this is worse than that time i used ; instead of : in a hundred line python script

#

and had no errors

toxic cove
#

Can I use this channel for like help on how to learn C#?

covert timber
#

I see you are setting uvs in AddFace but then you are overriding them line 84

#

and line 89 Rect rect = GetTileRect(textureIndex); seems to be wrong, try to use rects instead

frosty hound
eternal falconBOT
oak elk
covert timber
#

I mean that you are creating a texture atlas and its returning you rects but then you are not using rects in the uvs calculation

#

I think an easier approach would be to create the texture atlas before you create the faces, then when you create the faces, you can set the uvs to the corresponding position on the atlas

#

so you can set the uvs only once in AddFace (and no need to override them later)

oak elk
#

i have a confession
when i was first turning my array of 2d tilemaps to mesh 2 days ago i used chatgpt as a base because i had no clue how mesh generation worked
the first version of it worked perfectly fine so i just built on it so i dont know how a few parts of it actually worked

oak elk
covert timber
#

GPT is good but you have to really understand what it is doing so its easier to debug and you can adapt what it gives for your specific use case

oak elk
#

when i got rid of the entire adjusting to texture atlas part black squares started showing

i think it might be the texture changing orders when they get added to the atlas

oak elk
#

but i reap what i sow now i spend 12 hours debugging one thing

covert timber
#

yes I can understand ๐Ÿคฃ

covert timber
oak elk
#

how would ur idea work? do u mean i check what kind of blocks is in each chunk, get their texture and add it to an atlas and then uv map to them after?

ill have to learn how texture atlas work because right now im mapping to individual textures for each face of each block and then adding all to an atlas

#

yeah ill just watch a youtube guide

#

btw do you have any idea why my normals are only facing one direction?

covert timber
#

so the steps would be:

  • create the atlas
  • create the faces (4 vertices, 2 triangles)
  • set the uvs so the top left vertice match the top left of the texture on the tilemap, top right=top right, etc.. (0 to 1)
  • set normal to the direction of the face
#

(for the normals I think mesh.RecalculateNormals() could do the trick)

covert timber
oak elk
#

ah ok ill see
i tried recalculate normals but it did nothing on the mesh

#

yeah gpt did that part i just crossed my fingers and then gave up and tried fixing the uv first

oak elk
oak elk
#

wait gpt did add 4

covert timber
#

then triangles are just how you link vertices together

oak elk
#

this is too abstract for my brain

covert timber
#

so

triangles.Add(0);
triangles.Add(2);
triangles.Add(1);

triangles.Add(1);
triangles.Add(2);
triangles.Add(3);
oak elk
#

lol rip

covert timber
#

Its ok cause in your code the 1 and 2 vertices are flipped

oak elk
#

ah lol

covert timber
#

nevermind, it does 0 1 2 3 clockwise

#

so 3 and 2 are flipped

oak elk
#

i wish i could visualize it in unity

#

the mesh gets generated real time so i cant even see the uv map or stuff i just have to use mental imagery

#

why isnt 3d tilemaps built into unity its 2024

covert timber
#

you can visualize normals in rendering debugger>material>vertex attribute>Normal

oak elk
#

oh wait really

#

ah lol yeah

covert timber
#

Also you should try to make only 1 face, get it look right then you can loop to create all others

#

its easier to debug

night raptor
oak elk
#

yeah i can change the size and content of the chunk really easily by just modifying chunk size and depth

#

heres the original code that turns a 2d tilemap into a mesh plane btw

#

it had the uvs correct but after i surgically transplanted the code it broke

oak elk
#

yeah see it works even now when i copy paste it back

#

man kill me

#

lol

oak elk
#

also i dont get it
if texture can be split up into sprite tiles, why cant i directly get the sprites by resource.find
instead i need to calulate the rect myself

split dragon
#

Hi. I have a problem: I want to change the color (let it be alpha at the beginning) through a script, but this only works when the value in the slider reaches 0 (from 1 to 255, the alpha color does not change at all, and at 0 it changes immediately to 0). What's wrong here?

split dragon
summer stump
rich adder
gloomy bison
#

hi so i tried making raycasts by following a tutorial because raycasts hate me, when i use the drawWireSphere bit, it puts the wire sphere somewhere else but for him it puts it where the raycast shoots. how do i fix this?

Vector3 collision = Vector3.zero;
    public LayerMask layerMask;
    private void Update()
    {
        var ray = new Ray(this.transform.position, this.transform.forward);
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, 100, layerMask))
        {
            Debug.Log(hit.transform.gameObject);
        }
    }

    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(collision, 0.2f);
    }
#

for context it's supposed to shoot out of the spot light forwards

raw token
#

Seems like you should be assigning the raycast hit point to it

gloomy bison
#

ah yes, thank you

#

thats my dumbass not paying attention

oak elk
#

YEAHHHHHHHHHHHHHHH

#

im gonna cry

oak elk
#

heres ur name mispelled

#

because this wouldnt be possible without ur guys help lmao

#

holy shit ive been debugging for 14 hours

#

28 if u count yesterday

devout flower
#

14 hours in one day??? Holy

warm raptor
#

hello, how can I detect if a bullet fly near-by a player, I tried with a collider in trigger mode, but it doesn't work because the bullet game object is too fast, so I think I could use raycast, but as the bullet is going very fast I don't know how to make the calculation take place all along the path and not just at the ball position when updating frames. because, as you can see, since detection is based solely on frames, the bullet wouldn't detect that it had passed near a player, whereas by tracing the bullet's path, you can clearly see that it has passed near the player.

polar acorn
#

If the bullet has a rigidbody, you could enable interpolation on it so it checks along its path

eternal needle
#

Interpolation is just a visual so it moves every frame, shouldnt affect the actual collision. You could try the collision detection modes like continuous

#

Oh not sure if those work with triggers though

rich adder
#

yea

#

or thats what I remember tbh lol

brave compass
#

Alternatively, this can be done purely with math by calculating the distance between the line segment and the center of the player. If the distance is less than the radius of the detection zone, the bullet went through it.

Depending on of this is 2D or 3D, the math is a bit different, but neither require any complicated or expensive math operations. You can find examples of it online.

#

If this is 3D and the player is a capsule, you'll want to get the shortest distance between two line segments, where the player's capsule is one of those lines.

polar acorn
warm raptor
covert timber
summer notch
#

any reason i cant add audio sources in the inspector?

#

it wont let me drag and drop

rich adder
summer notch
#

it was but i unpacked it

rich adder
#

is the audio source on the same object ? show the hierarchy

summer notch
rich adder
#

which object has audiosource

summer notch
#

pixel boy

rich adder
#

I dont see it

summer notch
#

well it doesnt havbe it

#

thats what im trying to add

#

but it has a slot for it

rich adder
#

yes the slot is empty, you need to slide the component in there

summer notch
#

thats the problem

#

i cant

rich adder
#

why not

#

Add Component -> Audio Source

summer notch
#

its a on hit sound effect

raw token
#

Whatever you're dragging into that slot must be or have an Audio Source component ๐Ÿ‘€

You need to add an Audio Source component to something

rich adder
summer notch
#

oh

#

well im trying to get it to play when a bullet hits the player

rich adder
#

AudioSource is the radio, AudioClips is the music

summer notch
#

ok one sec

#

i need to change this to "AudioClip"?

rich adder
#

if you want to store the audioclip in code sure

#

this is just a Reference, not the actual component

#

it means " I want to do something with this thing"
you still need to assign it which one exactly you want to do thing on

summer notch
#

this is what i hav for it

#

im confused where i messed up

rich adder
#

well you wouldn't Play a sound without an audiosource

#

you need an AudioSource to play AudioClip from

summer notch
#

so add it as a component?

rich adder
#

yes then drop it in the slot

#

put the sound you want inside that AudioSource clip slot

summer notch
#

ok so added it the source

rich adder
#

alr

summer notch
#

then dragged the source to the hit sound

rich adder
#

I can see that

#

did you try running the code now?

summer notch
#

yes

rich adder
#

also your IDE did not look configured by the white font everywhere

summer notch
#

its still not playing but it mgith be a problem with my collision detectors now

#

IDE?

rich adder
#

yeah your code editor

raw token
#

(And this warning)

summer notch
#

im not sure but i dont have anymore time i gotta go to work

rich adder
#

check the steps ^ @summer notch

summer notch
#

i will

#

thanks for the help

silver basin
#

Does anybody know how to check velocity of my rigidbody on the x and z axis? I wrote this code, but it still changes when velocity on the y axis changes
void Update()
{

 xzVelocity = rb.velocity.magnitude - rb.velocity.y ;

if(xzVelocity > 13)
    {           
       
    //Do thing

    }
 else 
    {
    //Stop doing thing

    }
}
rich adder
#

or use sqrMagnitude as its faster then do (speedXZ * speedXZ ) >

silver basin
#

ty

muted wadi
#

does anyone know if turning two sets of wheels in opposite directions will actually result in rotation using the wheel collider? I've tried to code it so specific wheels turn in specific directions but it just propels the vehicle forward

raw token
muted wadi
#

i experimented a little more and it seems both wheels can turn independently, but when they're both turning opposite directions they barely move on ground contact and the vehicle just kind of moves back and forth slightly instead of turning

#

i also just dont understand the extremum and asymptote values which control tyre friction

#

unity documentation is pretty shit at explaining how it works. All they have there is a graph

#

thats it

native seal
#

what are your guys thoughts on additive scene loading / dealing with scene management. I'm having issues cleaning up everything from scene changes (object pools, etc) and having to subscribe to SceneManager.sceneLoaded for everyone of my DontDestroyOnLoad classes. ideas?

raw token
tranquil jackal
#

Im trying to point an object towards a target, but by splitting the pitch and yaw between two transforms
any pointers on this?

lethal bolt
#

Isnt this how its done?

raw token
lethal bolt
stable heath
#

Do you get the script from object?

raw token
# lethal bolt An object reference is required for the non-static field, method, or property 'M...

So you can't access the isGrounded field via MoveMentScript.isGrounded, because that's trying to access it as if it were static - that is, a value existing directly on the class rather than any specific instance of it.

You could make isGrounded static, but it wouldn't make a lot of sense here. The moveMentScriptScriptComponent field is initialized to that value when this MonoBehaviour is instantiated, and that happens right when you add this script to a Game Object. You don't really need to know if something is grounded at that time.

You should instead initialize this value in like Start(), from the isGrounded field on the moveMentScriptComponent reference (which is presumably already referencing a specific MoveMentScript instance).

tranquil jackal
#

no, that's not at all what's going on

tranquil jackal
#

movementScriptScriptComponent is a reference to a MovementScript, and trying to assign "isGrounded" which is likely a boolean will not work because MovementScriptScriptComponent is not a boolean

raw token
raw token
lethal bolt
#

Thanks to both (:

tranquil jackal
#

yeah that's what I want - its for a turret. the Pitch transform controls the gun moving up and down, while the yaw transform controls the gun moving side to side

raw token
rocky canyon
tranquil jackal
#

already tried that one, causes it to spin

#

a lot

rocky canyon
#

ohh.. bugger

tranquil jackal
#

i think i have an idea - I could convert the target's rotation into each transform's space, and try it that way?

rocky canyon
#

its gotta be possible tho.. u a turret functions exactly how most first person shooters are set up

#

rotating teh body left and right and the camera up and down

#

aka turret

short hazel
#

Work with directions. Compute the direction from turret to target, then split that. Don't use XYZ of positions of objects

rocky canyon
#

thats a solid way ^

stable heath
#

I have a problem with combining the same items in inventory. if work mergeItem function,source slot is discharge but doesnt change itemcount of targetslot.

#

I use scriptable object

short hazel
tranquil jackal
#

if im understanding this right: i would project the direction onto the relevant plane (since the turret won't always be pointing straight up), then rotate towards that projected direction

short hazel
#

That is also an option, with Vector3.ProjectOnPlane()

tranquil jackal
#

sick, im only asking here bc my last question got me sent here (from general) for not being complex enough

#

unless i misunderstand how the tiered channels work, should I only ask here for vector maths stuff, or was the person that responded to me just being a bit dense lmao

stable heath
short hazel
tranquil jackal
#

alrighty

rocky canyon
#

quaternions and rotations always have a tricky++ modifier

stable heath
rocky canyon
cosmic dagger
rocky canyon
#

the hostilities

cosmic dagger
#

also, if the items are the same, you don't need to check if both of them are stackable . . .

cosmic dagger
tranquil jackal
#

okay, my problem has been resolved, thank you spr2

rocky canyon
#

whoohoo! what method did u use?

tranquil jackal
#
Vector3 direction = currentTarget.rb.worldCenterOfMass - turretWeapon.transform.position;
pointer.forward = direction;
Vector3 p = Vector3.ProjectOnPlane(direction, pitch.right);
Vector3 y = Vector3.ProjectOnPlane(direction, yaw.up);
pitch.forward = p;
yaw.forward = y;
#

this be my code

cosmic dagger
tranquil jackal
#

hope that works out for you - i always preferred inheritance over composition but if it works then it works :p

#

ok i take it back, my problem has not been solved
it bugs out when placed on any surfaces not aligned with the world up

cosmic dagger
tranquil jackal
#

I might just solve my problem and make it a ball turret

native seal
#

what are your guys thoughts on additive scene loading / dealing with scene management. I'm having issues cleaning up everything from scene changes (object pools, etc) and having to subscribe to SceneManager.sceneLoaded for everyone of my DontDestroyOnLoad classes. ideas?

rocky canyon
rocky canyon
#

the 2axis part is wat gives a turret its look/feel

charred spoke
native seal
charred spoke
#

Like for example our object pool subscribes to scene unloaded and does cleanup on its objects

#

Like what you described

split dragon
#

Hi. I have a question: I have a public void Set Love(GameObject you). This void is attached to a button (OnClick). I need the void argument to be the object on which void hangs (in 1 button, the argument is 1 button, in 2 buttons, the argument is 2 buttons, etc.). Of course, I could do this manually, but I love you very much and I will get tired of doing it. Is there any way to contact through the script and assign?

native seal
#

so additive scene loading wouldn't solve it?

charred spoke
#

Im not sure I followโ€ฆ

#

If you need to reset your object pool when a scene changes then you have to know when the scene has changed. Subscribing to the scene manager events is the way

native seal
#

like holding the ui, level, etc on different scenes meaning you just unload the specific scene when needed

#

an "additive scene loading" workflow is what its called

#

not sure if its worth implementing

charred spoke
#

Sure that is great too. Not sure what it has to do with ddol object cleanup

slender sinew
#

I only use additive scenes but I dont see how that helps with the object pooling problem (for example), it would just mean you need to be more granular when you clean up your object pools

native seal
#

i guess that's true

rich adder
native seal
#

it just feels messy having if (scene == "Game") etc

slender sinew
#

well you can create some kind of abstraction for it, like I use a class associated with each scene, and it has PreSceneLoad / PostSceneLoad / PreSceneUnload / PostSceneUnload methods, and then I run my scene-specific setup / cleanup code in those methods

short hazel
split dragon
#

Pitifully. Thanks

native seal
rich adder
keen escarp
#

What do i do when my unitiy hub just gets stuck trying to open my project?

split dragon
slender sinew
# native seal so i have multiple ddol classes which each clean themselves up. Do you think it'...

if you think you need it, yeah. Nothing is "better" if you dont actually need it (to be honest I am kind of a hypocrit about this, I like to add many quality of life features).. If it's just one little spot with some gross scene checks and you dont plan on expanding on it much, then I think it's fine to leave it the way it is and focus on other things. However, yeah I think it's usually better to have something that manages scene loads / unloads rather than having to manually hook onto events and such in random classes. I don't know your codebase or the scope of your project, so it's kind of up to you to decide / experiment

rich adder
keen escarp
#

Woud love to got one week away from unity with out all my prject becoming unopenable

steep rose
#

version control is your friend with this one then

split dragon
# rich adder I mean, its valid to pass the GameObject the button is on the way you did it..

I want to change the transformation of an object by mouse (target.transform.position = new Vector2(Input.MousePosition.x, Input.MousePosition.y);), where target is the object that is assigned if I click on a certain button. Let's have 3 objects, and by clicking on 1 of them, I will change its transformation, and that method is the method of assigning target to a specific object

rich adder
#

you can in the inspector for onclick assign any gameobject you want in there

#

but this will be 1 button is always tied to the same gameobject

#

if you want to switch which object is the target you need a method to do that too

split dragon
rich adder
split dragon
#

Okey. Thanks

#

I'll just do it the old way and that's it.

short hazel
#

I guess you could have another script on the button with your own event. Hook up the button's event to that script, which raises yet another event to your target object, automatically passing the object this script is on as an argument

#

Like a relay

split dragon
rich adder
#

you only need 1 script that selects objects, then a button to run method to move or whatever

bitter ruin
#

I just want to make two objects move in the opposite direction of one another. Why is this so hard?

#

I can get Object A to mirror Object B just fine, but as soon as I try to move Object B, it instead of moving Object A, Object B just snaps back into position from Object A

bitter ruin
#

I tried attaching this script to both objects but it didn't work

polar acorn
#

Well, if both of these objects are doing this, then one of them is going to happen first

flint barn
#

Hey guys, I'm making a game that uses beat em up style maps (So sidescroller that allows you to move towards the foreground and background) but I'm having trouble understanding the best way to include collisons with objects and parts of the map that are the walls. Would Probuilder be the way to go? I was hoping there was a method where I could sort of connect the dots and wherever the lines connect, it will be unable to passthrough.

rocky canyon
#

MoveOne()
MoveOther()//using new data from One

polar acorn
#

Imagine A is at 1, 1, 1 and B is at -2, -2, -2

If A runs first, then it teleports to 2, 2, 2. Then B runs and moves to -2, -2, -2

#

If you want them to actually mirror each other's movement you need to do that when the movement occurs. Whenever one of them moves, you need to apply the opposite movement to the other one

bitter ruin
#

Right now it keeps prioritizing one over the other

polar acorn
#

You're not going to get that by having one of them teleport to the mirrored position of the other. You need to actually apply movement at the same time to both

#

If A moves left when you press left, you need to make B move right when you press left

bitter ruin
#

So for context this is meant to be a scale, like A moves down when objects are placed on it, making B move up

#

And if you move that same object to the other side of the scale, B moves down making A move up

polar acorn
#

Yeah, so, whenever you tell one of the objects to move down, you should tell the other one to move up

bitter ruin
#

Yeah is there a way to just have the physics calculate that for me?

#

Cause writing some "if" statement for this feels like I'm overcomplicating it

#

Is there no way to just say "Hey, where they go, you go opposite."

polar acorn
#

If it's just scales that weigh things based on their actual mass, I think you can do something with a configurable joint but that's beyond me, and might be something to ask in #โš›๏ธโ”ƒphysics

zenith nest
#

hey everyone, can i have some help please?

rich adder
eternal falconBOT
#

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #๐Ÿ”Žโ”ƒfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696

zenith nest
#

if im having issues with my script and animation, is this the right channel to ask in? so sorry, i dont know how to navigate discord servers at all :((

rich adder
#

do you know how to read?

steep rose
zenith nest
#

ive finished my animation tree with no issues i think, i just have no idea on how to incorporate it into my script so the walking animations occur appropriately

#

i started programming yesterday

rich adder
#

time to do !learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

steep rose
#

ah, there are many tutorials for your problem, if you truly started yesterday please !learn the engine and its quirks

#

dang

eternal falconBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

steep rose
#

he got it

#

first

zenith nest
#

thank you!

lethal bolt
#

I dont really understand the error?

polar acorn
rich adder
summer stump
#

One of the reasons var can cause issues (not trying to start anything! ๐Ÿ˜ธ ). Casting that .1 will help

short hazel
#

Avoid using var when the type on the right of the = is not clearly apparent, or if you don't have the inline type hints enabled (not sure you can have them in VS Code, VS and Rider can have them)

#

(example)

rich adder
#

indeed it does if enabled

short hazel
#

Oh good it has that, I guess it's because it uses the Visual Studio package, might spin up the same language server as VS's

rich adder
#

iirc is the C# Devkit package that does all the magic

lethal bolt
#

does anyone know how to stop the curspin when im not rotating the MouseWheel?

rich adder
#

surprisingly thats the one you need license for (just like VS)

late burrow
#

i really hate unity for not giving sleep function outside of coroutines

rich adder
short hazel
#

The more I look at the code, the worse it gets, but the use of += in the middle of line 31 here is pobablly incorrect.
As well as line 19 that does nothing

lethal bolt
#

its a place holder

#

because i want the main function first

fading mountain
#

hey guys. Which unity joint would I use to make the differrent sections of the snake in the snake game? I'm trying to use the distance joint 2d but ive never used joints before and its not working at all. this is my first project.

rich adder
#

interesting, no idea you could use joints for that game..

#

are you sure its not relative joint you need?

rich adder
fading mountain
rich adder
#

idk last time I made it I just use lots of math , thats why im interested to know if its some holygrail method i never heard of lol

#

or do you mean something less old-school like Slither.io

fading mountain
fading mountain
#

because the snake doesnt move on a grid. at least not yet

lethal bolt
rich adder
#

thats why you scroll faster you get bigger number etc.

rich adder
lethal bolt
rich adder
rich adder
lethal bolt
quick fractal
#

Would getcomponent fail if the gameobject I'm trying to.. Get, is disabled?

#

It still exists ๐Ÿ˜”

rich adder
raw token
fading mountain
west obsidian
#

with

using UnityEngine;

public class Script : MonoBehaviour
{
    public Transform body;
    Vector3 place;

    void Update()
    {
        place = body.position;
        Debug.Log(place);
    }
}

I get the error
UnassignedReferenceException: The variable body of Script has not been assigned. You probably need to assign the body variable of the Script script in the inspector.

However, it says its assigned in the inspector, and I get the correct position returned...

west obsidian
west obsidian
rich adder
#

in the hierarchy
t:Script
also naming a component , Script ๐Ÿ˜ฌ

fading mountain
rich adder
#

maybe learn how the joints work first ๐Ÿ˜… then start adventuring into doing shapes and movements

west obsidian
#

I just substituted words

rich adder
polar acorn
west obsidian
#

well I simplified, I actually have public class DynamicCamera : MonoBehaviour, place is actually notCam, and body is actually elephantCam, I just didnt want to distract from the simple error I was getting

raw token
rich adder
#

anyway just search it by that name then and see if any copies show

west obsidian
rich adder
#

either you have a copy like i said or it gets unassigned on start

fading mountain
west obsidian
#

no unassignment at start

rich adder
west obsidian
rich adder
#

on the searchbar of the hierarchy like i said already

raw token
rich adder
#

check all those objects for that script then

west obsidian
rich adder
#

BUT are they assigned

#

the error is saying no

west obsidian
#

wait

#

why do each of the objects have their own copies of the script!?

rich adder
#

idk its your project

west obsidian
#

I only added the script to the main camera wth

rich adder
#

apparently not

west obsidian
#

can I remove it?

rich adder
#

well yea..

polar acorn
rich adder
#

if you had multiple objects selected somehow when you put the script that could be a reason

west obsidian
# polar acorn Because you put them there

must have been an accident haha, I have been in the code window this entire time and only remember putting it on the camera, if I write in the document that the objects are public then drag them onto the script does that count as assignment?

#

thats how I selected them, but I only dragged my script from the asset window onto the main cam

rich adder
#

its not a "document" its a class

west obsidian
#

thanks for the help lol, I didnt know that was a thing, anyways I will def be using that debugging method in the future ๐Ÿ˜

rich adder
#

and yes thats assignment, otherwise in code its done with =

west obsidian
rich adder
#

np. there are many more hidden treasures in the manual

fading mountain
#

I have a question, would it be better to manage the segments of a snake in code or by using unity joint components?

rich adder
#

well not soo much a "lot of math" that exaggerated but you need to understand loops and stuff, maybe collection of sections

#

rigidbody seems easier if you can pull it off with joints

fading mountain
#

i would prefer to use joints since this is for a game jam but I thought maybe joints arent even used for this purpose

rich adder
#

well if its not a grid you should be good then

languid spire
rich adder
#

could work, just a bit more complex

fading mountain
#

I fixed my issue! the rigidbodies of the segments were set to kinematic instead of dynamic... chatGPT toold me that that wouldn't work

#

lol

languid spire
#

easier than joints, joints are a pain and they eat time to get them right

rich adder
brazen mortar
#

If an gameobject with components in a list<T> is destroyed, are the components removed from the list?

#

i.e. will I get a nullRefException if I try to foreach through the list

brazen mortar
#

cool thanks

#

(yes to the second question, then?)

languid spire
#

indeed

brittle veldt
#

is working with instantiating objects through using data from saved json files considered beginner or should I move to one of the lower channels to ask regarding this? ill delete this message after

brittle veldt
#

I have a json file that stores the state of a chunk in my world. At the moment, it contains the position of the chunk, the objects in that chunk, the prefab file path to each object prefab and where they are located in the world. I have no trouble with parsing this data and checked that I've retrieved this correctly.

I am trying to instantiate a prefab from my assets folder using this data and I'm seeming not able to do that

in the code below, it uses a class i've made which stores the data about each object

  • objectName (string), the name of the object (like "Cube")
  • prefabPath (string), assets folder location of the prefab (like "Assets/Resources/Cube.prefab")
  • a float list called objectPosition, this is self explanatory
foreach (ObjectData data in objectData)
        {
            Debug.Log($"Loading: {data.objectName}");
            GameObject prefab = Resources.Load<GameObject>(data.prefabPath);

            if (prefab != null)
            {
                Vector3 newPos = new Vector3(data.objectPosition[0], data.objectPosition[1], data.objectPosition[2]);
                GameObject newObj = Instantiate(prefab, newPos, Quaternion.identity);
                newObj.transform.SetParent(newChunk.transform);
            }
            else
            {
                Debug.Log($"{data.prefabPath} doesn't exist"); // This is always shown when an attempt at instantiating happens
            }

            Debug.Log($"Loaded: {data.objectName}");
        }

        Debug.Log("Chunk loaded from memory");
#

From my testing, it's like the file path I provide just doesn't exist, even though the prefab is in the correct location

languid spire
#

did you read the Resouces.Load documentation?

brittle veldt
#

yes

languid spire
#

then you should know that your path is incorrect

brittle veldt
#

why is that? what did i miss?

languid spire
#

this
"Assets/Resources/Cube.prefab")
for Resources.Load should just be
"Cube"

brittle veldt
#

i'm even more confused now

#

i tried passing data.objectName earlier and it didnt work

#

cos I read another article and thats what they did

#

i tried it now and it works

#

no idea why that was the case

#

Ok i see why now, the folder has to be called "Resources" for unity to automatically check there and grab the prefab to load

late burrow
#

but i expected other things to work while my script is sleeping

polar acorn
#

Well, you're pausing the main thread. What would you expect to happen?

#

Only one line of code can ever be running at a time

#

So it is just that script sleeping

#

which means nothing else can happen either

late burrow
#

i expected non script stuff to still work

polar acorn
#

There's no such thing as non-script stuff

#

Everything a computer does is code

late burrow
#

ok so in short

#

lua sleep

#

is much nicer

frosty hound
#

In short, it's been what, 3 years and you're still spouting nonsense?

polar acorn
#

Because lua is a script, not a program

#

The thing running your lua script has paused completely

#

waiting for it to finish

late burrow
#

during 3 years i tried make coroutines like 50 times and each time they had different kind of error

frosty hound
#

And I'm sure each of the times you've made wild inaccurate claims too.

polar acorn
#

Then you should probably have tried doing them correctly instead

brittle veldt
frosty hound
#

You haven't met Anuked, spare yourself and don't question it.

polar acorn
eternal needle
#

It's almost like an experiment, how far could one go without learning the basics of c#

languid spire
cosmic dagger
#

wait, you still can't get a coroutine running? you gotta be kidding me? ๐Ÿคฏ

steep rose
#

thats wild, ๐Ÿ˜‚

rocky gale
#
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class RollPlayer : MonoBehaviour
{
    public List<Sprite> playersToRoll;

    GameObject player;

    public int[] table =
    {
        60,
        20,
        15,
        5
    };

    int total;
    int randomNum;

    private void Start()
    {
        player = GameObject.Find("Player").gameObject;

        foreach (var weight in table)
        {
            total += weight;
        }
    }

    public void Roll()
    {
        randomNum = Random.Range(0, total);

        for (int i = 0; i < table.Length; i++)
        {
            if (randomNum <= table[i])
            {
                Debug.Log(playersToRoll[i]);
                player.GetComponent<SpriteRenderer>().sprite = playersToRoll[i].GetComponent<SpriteRenderer>().sprite;
                return;
            }
            else
            {
                randomNum -= table[i];
            }
        }
    }
}

why do i get error : NotSupportedException: Specified method is not supported. NotSupportedException: Specified method is not supported.
Unity.VisualScripting.ComponentHolderProtocol.GetComponent[T] (UnityEngine.Object uo) (at ./Library/PackageCache/com.unity.visualscripting@1.9.4/Runtime/VisualScripting.Core/Utilities/ComponentHolderProtocol.cs:70)
RollPlayer.Roll () (at Assets/RollPlayer.cs:42)

rocky gale
#

its spriterendrer

rich adder
#

no its not

rocky gale
#

wdym

#

GetComponent<SpriteRenderer>().sprite

rich adder
#

playersToRoll[i] is a sprite

rocky gale
#

oooo yea

rich adder
#

there is no such method on Sprite type

rocky gale
#

u right

#

thx

rich adder
#

hence the using Unity.VisualScripting namspace

agile summit
#

Hello. I need to make a system in which we store a String (Scenario/Explanation) + Int and String (Outcome/Result e.g +20 Money) + Int and String (Outcome 2/Result 2 e.g -20 Creativity). We need to store all 3 of those together, becuase...

We have more than 10 scenarios which we have to randomly pick from, then show it on the screen, and then update the game mechanics to the outcome values. I'm thinking to make 3 arrays with the values and I put all values in order and it should work.

Or maybe we can make separate methods for each scenario (which will result in 10+ methods, i.e 1 method for each scenario) and we return our values as a return type. But the problem in this is that the code looks really messy as one method for each scenario will clutter up the script. And I don't think we can return more than one datatype in a method.

Can anyone please suggest a way to store all 3 of the values together?

polar acorn
#

Make a class that has all the values you need, then make a list of that type

agile summit
summer notch
#

if i wanted to make a rythm game with enemies that shoot at you on beat what would be your suggested way of coding this?

#

the first thing that comes to my mind is delaying enemy bullets to when it should happen in the song but that seems lengthy

rich adder
#

find the peaks through analyzing the audio, work your way from there

summer notch
#

so im gonna have to manually code the enemies shooting with delays in timing yes?

rich adder
#

delays?

summer notch
#

like if a bass drop happens 28 seconds into the song

#

i delay the enemies bullet by 28 seconds before it instantiates

rich adder
#

doing manually means you will have to deal with all the songs etc

summer notch
#

i only plan on doing one for now just to see if its a sustainable idea later on

rich adder
#

it doesn't scale well

#

coding analyzing audio spectrum, figuring out which frequencies / pattern corresponds to what's happening in the song is always the more modular way

summer notch
#

im a bit confused

#

look at the waves in the song is what im getting

#

how im supposed to translate that into code is whats confusing me

agile summit
#

can someone please tell me what does $ mean inside a string, I've seen it alot but don't know what it does. Here is a code for example:

Debug.Log($"{stat.Key} has reached 20 or less.");

rich adder
summer notch
#

ohhh

rich adder
summer notch
rich adder
#

then you figure out which frequency belongs to what

#

short to high frequency means its most likely dropping into a beat, etc

#

its just numbers, plugin a GUI to it, play the song you start seeing what happens with those numbers, from there things will seem easier to create pattern from

summer stump
summer notch
#

so those numbers would tell me when im supposed to make the bullets spawn

#

no

rich adder
#

I have a demo of this but its on my other pc and forgot to make a repo ๐Ÿ˜› Im giving you more or less the ballpark rundown

summer stump
summer notch
#

ok lemme try to reiterate what you said

#

correct me if im wrong

#

analyze the audio

#

certain frequencys will give me different numbers

#

i take said numbers and use that to determine when the bullet is spawning

rich adder
#

a Kickdrum typically in low/mid frequencies etc.

summer notch
#

so how would i analyze the audio to find these numbers

#

and how would i use the numbers in my own code?

#

never thought this far lol

summer stump
summer notch
#

samething here

rich adder
#

this is the series I learned most of this from, stil newbie to it

summer notch
#

i think i understand

#

so on lets say i hi hat if they had a frequency of 18 for exampls

#

i make my hi hat bullets come at when 18 shows up

rich adder
#

yeah but more or less 18 could always be there just very low, its just checking how loud it is at the time

#

check the guy i sent, he explains it pretty well

#

the first 3 is theory behind it

summer notch
#

this is what the audio im using looks like

rich adder
#

thats how most audio waveforms look yes

summer notch
#

wow

#

just a bit intimidating imagining all this

rich adder
#

you have to run through it a couple of times eventually it makes more sense

obsidian granite
#

is there a builtin way to do boolean modification on rectangles? for example, difference/union/intersection?

#

the math doesn't seem like it'd be that hard, but i also got like a c in linear algebra so

#

ยฏ_(ใƒ„)_/ยฏ

#

i found a way to do it, i'm just going to join the sprites by creating a texture and writing to it.

summer notch
rich adder
summer notch
#

i am but it looks like hes using a different code

rich adder
#

where..

#

he literally named a whole video after the method i sent

#

Support me in creating tutorials by becoming a patron on my Patreon and get access to the full source code of all tutorials.
http://www.patreon.com/peerplay

A new tutorial series by Peer Play, made by Peter Olthof.

Source files download: http://www.peerplay.nl/tutorials/peerplay-AudioVisTutPart1-source.zip

Learn how to code your own music vis...

โ–ถ Play video
summer notch
#

this compare to this is what i mean

rich adder
#

those are examples in the docs

#

they arent meant to be copied every time you want to use the function

summer notch
#

my bad

rich adder
#

the unity example is very basic, just shows you more or less what its doing.
His is going to show you what each range of numbers mean

#

hopefully you did not skip the video prior to this, the theory is just as important

summer notch
#

ok i got it to work

#

im more of a hands on learner so i wanted to see what itd do from my perspective

#

thanks for the help im definetely going to use your help and his tmr when i code my first few bullets in after work

rich adder
#

alrighty

#

watch the later ones too, there is more to refine so you get specific hits or specific bullets for different sounds too

summer notch
#

for sure

#

thank you

rich adder
sour fulcrum
#

feeling really dumb, how can i convert some timer info into a 0.0 - 1.0 scale?

eg. 30f / 60f = 0.5f

summer stump
#

For a timer that increases of course

sour fulcrum
#

jesus its just division ๐Ÿ˜ญ

#

thank you so sorry

summer stump
#

No worries

dense pike
#

I need some help with animator and script

summer stump
dense pike
#

I @summer stump I need to make enemy play from idle animation to attack when in player range

strong wren
#

@jaunty crag Don't advertise outside of appropriate channels.

lethal bolt
#

How can i set a Gamobject to another gameobject in array?

#

i know its +=

eternal needle
#

The issue isnt with trying to set a gameobject here, the addition part makes no sense

lethal bolt
#

I want to get the object 0 of the array when currentBodyPart is = 0?

eternal needle
atomic yew
#

Hello everyone. I reinstalled Unity on my computer. In the past, when I clicked on the error in the console, I would reach the incorrect line of code. Now when I click on the error in the console, nothing happens. What can I do so that when I click on the error in the console, I go to the wrong line?

abstract dew
#

does anyone have any ideas on how to make a cube stick and walk on wall pretty new at this and struggling a bit (its 2D)

short hazel
eternal falconBOT
warm raptor
brave compass
warm raptor
brave compass
warm raptor
brave compass
brave compass
# warm raptor Oh yes ok, it's a capsule

Then calculating the closest distance between the capsule and the path of the bullet will be best. Otherwise, if you just compare to a single point, like the center of the capsule, bullets whizzing over their head will be reported as further away than those going past their hip.

warm raptor
brave compass
eternal needle
#

that gigantic calculation can just be ditched

warm raptor
brave compass
#

And if it was not already clear, the line segment to represent the player should be this, not the entire height of the capsule.

#

A capsule is simply a line segment with a radius, like how a sphere is a point with a radius.

split dragon
#

Hi. I have a problem: I want to move an object with the mouse cursor, but when I put this movement on it, its coordinates become very large and it goes off the screen. How do I save the coordinates of an object?

late burrow
#

finally something worked

#

async seems to work better

eternal needle
# late burrow finally something worked

well surely if you for once just properly shared a question and your code, people would actually help you make a proper coroutine. instead you insist on being vague and just complaining that it doesnt work

#

if you arent aware of how async works in unity, you'll run into issues quickly

eternal needle
split dragon
#

Thanks

short hazel
#

The second screenshot looks like it was taken from a Rect Transform, so the object is probably on a Canvas. You need to confirm that though, as well as the canvas type (screen space overlay, screen space camera, etc.)

neon ivy
#

I want to have a variable that is a static material, but it doesn't show up in the inspector so how do I fill it?

unkempt gyro
#

Who can help. There is a code that I hang on an object that can be moved by clamping the paintwork. At the same time, this object can enter through other objects (for example, the floor). How can this collision be handled?

warm raptor
#

Is their a function In C# to calculate the distance between 2 points ?

eternal needle
eternal needle
neon ivy
#

I guess I can use an SO for this. just don't wanna constantly update prefabs with a bunch of references

eternal needle
eternal needle
clever panther
#

Sorry for the stupid question, but I created a simple movement script that uses the Force-Features of the rigidbody and works fine on the normal build. But in WebGL my player very very slowly falls and my movement doesnt work at all. Is there a setting for WebGL that I'm missing?
Also as a side question, how do you stop the WebServer that is started in Unity to play the game in Browser xD?

#

Hmm, maybe I fricked up my delta-time stuff

wintry quarry
opaque idol
#

I need for a raycast to be able to detect a composite collider 2d of a tilemap whilst still in outline mode. When in polygon mode, the colliders are not perfectly straight and cause serious issues, so outline mode is required. However, outline disallows for raycast detection, so I cannot use raycasts for my desired use. How can I circumvent this issue?

clever panther
wintry quarry
#

Are you expecting to hit the "inside" of the collider instead of the edge?

#

What's the goal?

opaque idol
#

I draw a raycast every frame and check if it is detecting the ground (and give the raycast a layermask so it only detects the tilemap composite collider considered ground) and it only ever detects the ground when it is in polygon mode.

#

My understanding is that edge based colliders can't interact, so I'm trying to find a way to circumvent this.

wintry quarry
wintry quarry
opaque idol
opaque idol
wintry quarry
#

Show the code and what it draws etc

opaque idol
#
Vector2 rayOrigin = new Vector2(transform.position.x - 1.3f, transform.position.y - 1.80f);

RaycastHit2D[] bottomRaycast = Physics2D.RaycastAll(rayOrigin, -transform.up, 1, LayerMask.GetMask("Foreground"));

Debug.DrawRay(rayOrigin, -transform.up, Color.red);

if (bottomRaycast.Length == 0) {
      playerRB.AddForce(-playerRB.velocity,   ForceMode2D.Impulse);
      playerRB.AddForce(transform.up * -speed, ForceMode2D.Impulse);
}

if (letItRipTimer <= 0) {
    ResetPlayer();
}
#

it draws a line on the corner of the player's sprite directly into the ground, but detects no ground.

wintry quarry
#

Can you show a screenshot

opaque idol
#

1 sec

#

don't mind the garbage pixel art ๐Ÿ˜ญ

#

but you can see the ray in the ground and it isn't detecting it

wintry quarry
#

You need the ray to pass through the edge for it to detect

#

Start the ray a little higher up

opaque idol
#

I CAN"T EVEN SAY BRUH

#

1984

#

in any case...

#

it works ty โค๏ธ

lethal bolt
#

How to i spawn a random one of the walls? i thougth it was this easy

deft grail
#

is how you access a certain element from your array/list

dreamy haven
#

where can i go and ask for help because i cant find it the support channel

deft grail
#

this one is for code

dreamy haven
#

why is it wrong

steel kite
#
public class PlayerController : MonoBehaviour
{
    private Vector2 _movementInput;
    private Rigidbody2D _myRigidBody2D;
    private Animator animator;
    private SpriteRenderer _spriteRenderer;
    private void Awake()
    {
        _myRigidBody2D = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
        _spriteRenderer = GetComponent<SpriteRenderer>();
    }
    private void FixedUpdate()
    {
        _myRigidBody2D.velocity = _movementInput * _speed;
        animator.SetFloat("xVelocity", _myRigidBody2D.velocity.magnitude);
    }
    
    private void OnMove(InputValue inputValue)
    {
        _movementInput = inputValue.Get<Vector2>();

        if (_movementInput.x < 0 && _spriteRenderer.flipX) {
            Debug.Log("turnleft " + _spriteRenderer.flipX);
            
            animator.SetBool("turnLeft", true);
            _spriteRenderer.flipX = false;
            animator.SetBool("turnLeft", false);
            
        } else if (_movementInput.x > 0 && !_spriteRenderer.flipX) {
            Debug.Log("turnright " + _spriteRenderer.flipX);
            animator.SetBool("turnRight", true);
            _spriteRenderer.flipX = true;
            animator.SetBool("turnRight", false);
        }else {
            animator.SetBool("turnRight", false);
            animator.SetBool("turnLeft", false);
        }
    }

}

The code prints log texts, but does not change the "turnLeft" and "turnRight" Bools.

deft grail
dreamy haven
deft grail
dreamy haven
steel kite
dreamy haven
#

if you see the other 2 photos i send

deft grail
#

your missing something

deft grail
dreamy haven
steel kite
deft grail
#

so the working code works, the not working code doesnt work

deft grail
# steel kite

also your overly complicating it, unless you have specific sprite designs.
all you need to do is flip the sprite instead of using whole different animations or whatever its doing

steel kite
#

I have a turn animation. I want to play this

dreamy haven
steel kite
#

When I started walking to the right while standing facing left;

left idle -> right turn -> right walk

I want it to be like

deft grail
dreamy haven
#

is not working

willow scroll
deft grail
dreamy haven
willow scroll
deft grail
#

there is

dreamy haven
willow scroll
willow scroll
#

yey!

dreamy haven
deft grail
#

because FindObjectOfType is a method

#

you call a method by using ()

dreamy haven
#

i miss that part

lunar kelp
#

guys i think im having a problem here

neon mirage
#

Hi all! I'm following Game Maker's tutorial to build flappy. I tried my best to get the zero at where it is. But when I enter the game mode, no text showed up on the screen, the 0 just didnt appear. Help! Thanks !!

#

I'm sure the zero is in the range of the camera, I tried moving it but it never been able to show up

glossy eagle
lunar kelp
neon mirage
glossy eagle
steep rose
#

i would select it for the UI to show

neon mirage
neon mirage
steep rose
glossy eagle
steep rose
#

i didnt even notice that ๐Ÿ˜‚
that might work but they still need a camera for the canvas to render on.

glossy eagle
#

well they do have a camera already, no? Like it's the first thing in the hierarchy, so if it doesn't have unchecked the UI culling option it should render anyway I think. I might be wrong tho, haven't worked 2D in a while lol

steep rose
#

im loading in a project to see if we are correct

neon mirage
#

Thank you all youve saved my mood and my night!!

glossy eagle
steep rose
#

๐Ÿ‘

neon mirage
glossy eagle
steep rose
#

and yeah i have no idea if that affects 2D or not ๐Ÿค”

glossy eagle
#

oh okay

plain abyss
#

I have a small doubt
I am not exactly sure how can i get the "Value" of the dropdown into my "LOCBOX" Script
Can someone guide me through
I have read about get component and also tried creating a public variable but nothing seems to work

languid spire
wintry quarry
languid spire
#

He's using Text Mesh

plain abyss
rich adder
#

did you add the namespace?

#

using TMPro

languid spire
#

because you are missing a using statment

plain abyss
rich adder
stark gate
#

Hi friends! picking up unity after ages of not touching it and feel like I'm basically starting from scratch. Here's my basic pseudocode for this question:
GameStateManager (singleton):
bool toggleable
Awake():
toggleable = false
Update():
OnKeyDown(Spacebar):
toggleable = !toggleable
PlayerClass:
Start():
if(gsm.toggleable):
set color to green
else:
set color to blue
now my question comes with the update function of player class. Since my state logic is in GameStateManager, whats the best way to ensure that when my GameStateManager toggles its bool, the color toggles? Right now I'm doing something horribly messy by creating an internal toggleable bool in playerclass and essentially having two seperate toggleables but that seems prone to mistakes with desynced toggleable states

stark gate
rich adder
stark gate
#

Thank you! I'll look into it ๐Ÿ™‚

rich adder
#

the benefit of Unity event is you dont have to subscribe to event in script, unity does it for you and calls method directly

umbral rock
#

i have an issue where when i move to the right or forward my camera randomly starts spinning for no reason?

eternal falconBOT
rich adder
#

๐Ÿฅฑ

eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

rich adder
#

if its first person and camera is parented, did you lock the rigidbody

#

spinning in what way? make a video of issue

umbral rock
#

well, if i move forward the camera goes to the right

#

and if i move right the camera moves left

#

a tiny bit

rich adder
#

there is nothing that moves the camera

#

either you referenced the wrong transform or somethin

umbral rock
#

its only when i standing on the plane ground?

rich adder
#

idk dude you havent shared much detail on the actual setup or shown screenshots, just flying blind here

#

the code isnt the issue unless its placed on wrong object or referenced wrong one, I can't tel anything beyond that without seeing it..

wintry quarry
tough rampart
#

I want to drag and drop the character freely, but it does this weird thing

steep rose
rich adder
#

not psychic

tough rampart
#

I gave the "Slot" script to "Square" and "Drag" to "Root" and now the character doesn't even move

glacial stump
#

okay beginner question:

When Unity mentions a "Syntax error: ',' expected.", when it's on a line of code where there is absolutely no need for a comma, what else could it mean?

steep rose
#

show us the code

languid spire
#

the error is on a preceding line

glacial stump
#

gonna need to use the paste thingy again. bare with

languid spire
#

btw, you should be using your IDE to see these things not Unity

glacial stump
#

It's telling me it's specifically on the last string, which has one comma for the Range bit, again i've copied this directly from a tutorial

glacial stump
languid spire
rich adder
#

public float HeadWidth 0.75f;

#

is this not underlining red?

#

oh my discord just updated ๐Ÿ˜›

steep rose
#

discord updates?

rich adder
#

I mean the text didnt scroll down past their link

steep rose
#

๐Ÿ˜…

rich adder
#

so didnt see steve has replied about ide

glacial stump
#

Sorry, bare with, having to update said IDE even though i swear it updated this morning. email app being a pain. give me a sec

glacial stump
rich adder
#

follow one of the guides in !ide

languid spire
rich adder
#

โŒ› ๐Ÿค– ๐Ÿ›๏ธ

glacial stump
glacial stump
#

(this is with note I haven't actually used Unity for a good 3 years so everything's VERY likely severely out of date)

steep rose
#

to configure your !ide please use this

eternal falconBOT
rich adder
#

i guess bot is working for you..

glacial stump
#

thank you, im on it, my email just isn't getting anything to log back in which is... making this difficult for sure :/

steep rose
#

muahaha

#

the bot likes me thinksmart

steep rose
#

for unity hub prob

#

or unity website kekwait

glacial stump
#

so configuring is... setting it as the main editor? (using the VS Code one as I appear locked out of Visual Studio, my emails aren't recieving ANYTHING off of them so I can't log in)

#

oh wait

#

god it's my wifi. sorry

#

there is more to this page than it was letting on

rich adder
#

you need to login for Visual Studio ? I dont remember this

#

its been years tho

glacial stump
#

okay it begged me to log in and... now it aparrently doesn't need me to

#

oh my god i'm so confused rn, darn my wifi and darn my email

rich adder
#

login is just to sync settings n such

glacial stump
#

nope. it's logged me into my useless college account

#

from december

#

oi oi oi, it might even my PC you know, it's due for an MOT and repair

rich adder
#

fresh os

#

clears most issues

steep rose
#

im not even logged in to my VS and i can use it

glacial stump
#

??? this just crashed most of my apps what on earth

#

im dead confused

#

is this supposed to happen??

rich adder
#

yeah VS has been buggy for me lately

#

i think new update fdup some shite, are you on the latest . Make sure you update to most recent

glacial stump
#

i can only cancel that message mind - everything else was frozen

#

yea I just updated it I swear down

rich adder
#

well Allow Access for network ofc

glacial stump
#

it couldnt even let me tick that box, i couldn't allow access, I could only press cancel

#

see my dilemma? am i insane? ๐Ÿ˜ญ

rich adder
glacial stump
#

yea my issue is the entire app froze

rich adder
#

your pc is borked

glacial stump
#

yea.. might have to just give up on coding until it's fixed later this year

#

WAIT. it's working

#

okay ive asked it to update

#

if i disappear it's eaten my memory

#

like a gormet meal

rich adder
glacial stump
#

(on top of this, i've configured the IDE again)

#

no, but only because my hard drives are pretty delicate and I have a LOT of personal stuff. last time I did that I lost everything. years worth of art, music and more, and honestly it's pretty scary for me. I'd rather pay a professional to extract my stuff onto another hard drive then do it for me if im honest

#

it's kind of a fear based thing, I know its pretty silly, but I lost even a few paid for software and must have been an idiot kid and deleted the licence emails :( not long till im due money so I should be able to afford it to be done soon

#

OT but VS is almost installed

languid spire
steep rose
#

its pretty easy to do

rich adder
#

it just starts fucking up updates or apps for no good reason.

steep rose
#

i have 1 pc with windows 10 and another with arch linux, so far i havent ran into any huge problems

rich adder
#

good , windows 11 is even worse. Plagued with MS bloatware

steep rose
#

you got that right and not just bloatware, its spyware

#

im not even joking

rich adder
#

well yeah cramming copilot everywhere , yuck

#

what are they doing there

languid spire
#

both of which are real easy to eradicate

rich adder
#

windows hasn't been good since 7

languid spire
steep rose
#

they are actively trying to get rid of windows 10

#

and make you switch to 11

rich adder
#

why does my unity load so much faster on linux/mac os than windows.

steep rose
#

and when that happens im going to linux on my main machine

rich adder
rich adder
languid spire
steep rose
#

to society

steep rose
#

and steve is right, the linux kernal is insane on performance but i have to get use to it more

rich adder
steep rose
#

true but still

rich adder
#

the gui is not so bad, the only gui that comes close to me(windows like) is Mint

steep rose
#

i like arch with plasma 6 because it acts like windows

languid spire
#

If I could put an XP GUI on a Linux kernel I would and be a very happy nam

rich adder
#

pretty sure they have dozens of those lol

#

even old school win98 ones

languid spire
#

Not the original because it's still closed source

rich adder
#

i mean they got hannah montana gui, i so no reason there wouldnt be xp

steep rose
#

it doesnt have to be spot on

#

although it would be cool

languid spire
#

yes it does, that is the whole point and what is totally wrong with most Linux GUI's, they get close but not close enough

steep rose
#

they are usually like 90% close enough, i believe that would be fine

languid spire
#

nah, it has to be 100% seamless otherwise it's a waste of space

rich adder
#

who cares about the GUI I just want my apps to run fast and not chugg

steep rose
#

or mb

#

i forget

languid spire
#

GUI is what you see, if you donrt want a GUI dont install one

steep rose
#

plasma 6 is best (in my opinion)

rich adder
#

yeah but most of the time I got an app open or fullscreen

#

I dont even notice the os

steep rose
#

the only gripe I have with linux is i cant install unity hub/unity or games on arch

rich adder
#

arch is a very bare bones distro

languid spire
rich adder
#

yeah but each app has their own gui all you're seeing is native things like popup windows or other stuff like that

languid spire
steep rose
#

probably

rich adder
#

you're talking about trivial stuff like titlebars and maybe file explorer for file picker

languid spire
rich adder
#

but that contradicts "it does not have a GUI itself"

#

thats their GUI , all the OS handles is native stuff like popup window, ofc is gonna look like the native os

languid spire
rich adder
#

have you seen some apps made with windows forms lol

#

bare minimum

brazen jolt
#

I made a script (A) with like 5 values in it, and I made another script (B) where it can make gameobjects with that script but, I found there is no way to copy A and addcomponent this A to the gameobjects that's are getting made in B with the exact values I want, if I want to edit the values I need to do 1 line for each value I want to edit

brazen jolt
#

Can't I just take the A and copy paste it to add it to another gameobject without playerprefs

rich adder
#

reference A from B ? whats the problem

brazen jolt
rich adder
#

put the values in a struct or tuple and pass as many as you want

brazen jolt
#

I'll say it again

rich adder
brazen jolt
#

Just a way to copy an edited component, and paste it in another component the way I edited it u got me?

rich adder
#

why dont you explain what type of gameplay or mechanic you're going for, and what is actually happening instead compared to how you want it

#

in code?

brazen jolt
#

Yes

rich adder
#

so just copy the values over? I dont understand why you can't do that

brazen jolt
#

So I wondered

rich adder
brazen jolt
willow scroll
#

They mean they have to use their keyboard to write code

languid spire
willow scroll
#

Shift + Enter creates a new line

brazen jolt
#

GAMEOBJECT.component.thing1=5
GAMEOBJECT.component.thin2=true

rich adder
#

like I said, put them in a struct or a tuple so its easier to copy multiple ones at once

brazen jolt
#

can't I just copy a component and paste it in GAMEOBJECT

willow scroll
#

You have to get all the fields from the Type

languid spire
rich adder
#
[System.Serializable] // to edit in inspector
public struct ValuesFromA
{
    public int one;
    public int two;
    public int three;
}

public class ScriptA : MonoBehaviour
{
    public ValuesFromA ValuesFromA;
    public void SendValues(ScriptB scriptB)
    {
        scriptB.SetupValues(ValuesFromA);
    }
}
public class ScriptB : MonoBehaviour
{
    private ValuesFromA valuesFromA;
    public void SetupValues (ValuesFromA values)
    {
        valuesFromA = values;
    }
}```
willow scroll
# brazen jolt Huh I like it thanks

Another method using Reflection:

    1. Create an empty Component
    1. Get the original Componet's Type
object.GetType()
    1. Copy the fields from it
Type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
    1. Set the value for every field of the created Component
foreach (FieldInfo fieldInfo in prev.GetType().GetFields())
    fieldInfo.SetValue(...);
brazen jolt
#

Yeah man I appreciate it

muted wadi
#

if anyone here is experienced with unity wheel collider friction, please help me out. Here I'm attempting to simulate the tread behaviour of a tank with wheels. 2 sets of 8 wheels are present on both left and right sides, with the left side running at 1000 torque, and the right running at -1000 torque. With tank treads, this results in neutral turning. As in, turning on a dime. However, with my wheels, they seem to also slip down sloped surfaces while turning. The grip values make absolutely no sense. When I turn up the stiffness for the forward friction (how much force the wheels are outputting while in contact with the ground), then the tank turns. But when I turn up the stiffness on the sideways friction it simply won't turn. If i turn down the sideways friction it starts sliding down slopes. I have no idea how this works even when reading explanations.

barren shadow
#

Hello, what's the easiest way to find the world scale of an object? I know I can use Transform.localScale to get the scale relative to the parent but what about the objective scale?

barren shadow
muted wadi
#

however i think this is only accurate if your object isn't skewed

#

in which case you can use Transform.localToWorldMatrix

sand heath
#

so i got kind of a dumb question i think someone who knows math knows how to solve but I have an isometric camera and i want to move it forward back and left and right, but im not sure how to do that

#
    void MoveCamera(Vector3 position)
    {
        _transform.position += position * Time.deltaTime * _cameraSpeed;
    }

this doesn't work because the camera is tilted so just moving it wont actually move it in the correct way

steep rose
#

use global positions not local

sand heath
#

transform.position is worldspace though

#

transform.localPosition would be local

steep rose
#

transform.forward/left/right/backward is local vector3.forward/left/right/backward is global
edit: ah mistype mb

sand heath
#

there is no such thing as transform.position.forward/left/right/backward

steep rose
#

_transform.position = _transform.position + new vector3(X,Y,Z) and you can manipulate X, Y, Z to get desired affects

#

i havent tested this but it should give you what you want

sand heath
trim hedge
#

Does anyone know what's the proper way to check isGrounded for the player when using platform effetor 2d? the thing is, if I have a 3 tile height platform or something like that, when the player is jumping from below, suddenly they're in the middle of the platform and can jump again since I'm using IsTouchingLayers(platformLayer) to check if the player is grounded, does anyone know a solution?

meager gust
terse belfry
#

tilemap doesnt update

open gull
#

Hello, how can I generate different numbers without repeating them? I've seen that this is a very frequent question on various forums, but each answer is different and some are extremely complicated to understand. Here is my code:

#

My theory is that the "random range" takes the number of elements, in which case, when something is deleted from the list, the list reorganizes itself and that element ends up being occupied again, so "random.range" can take the same element again.