#💻┃code-beginner

1 messages · Page 157 of 1

rare basin
#

so what's the result of Vector3.Project(Vector3.one, Vector3.zero)

#

for example?

swift crag
#

That's not a meaningful operation

#

Vector3.zero doesn't point anywhere

rare basin
#

yes sorry, Vector3.right*

#

for the 2nd one

swift crag
#

The diagonal arrow is the original vector. The vertical arrow is the result of using Project with Vector3.up

#

And the horizontal arrow is the result of using ProjectOnPlane with Vector3.up

swift crag
rare basin
#

okay i get it now

#

i somewhat always thought it is similiar to Cross product

swift crag
#

I added a plane to this imagine because its normal vector is Vector3.up

#

ProjectOnPlane flattens your vector onto a plane with the given normal vector

#

So if you add the results of Project and ProjectOnPlane up, you get the original vector back!

#

@sonic dome so, if you use those methods to split your velocity into two pieces, you can modify just the horizontal velocity, then put them back together

swift crag
#
Vector3 vertical = Vector3.Project(rb.velocity, Vector3.up);
Vector3 horizontal = Vector3.ProjectOnPlane(rb.velocity, Vector3.up);

horizontal = // do something to it here

rb.velocity = vertical + horizontal;
sonic dome
swift crag
#

If gravity goes straight down, you could also just do this

#
float yVelocity = rb.velocity.y;
Vector3 velocity = rb.velocity;
velocity = // do something
velocity.y = yVelocity;
rb.velocity = velocity;
#

Project and ProjectOnPlane work correctly for any direction

#

I think it's also a little more clear what you're actually doing

swift crag
#
Vector3.ProjectOnPlane(foo, bar) == foo - Vector3.Project(foo, bar)
#

Project, Angle, and Dot are really useful.

sonic dome
#

Oh okk ill save these SS

sonic dome
atomic sail
#

Hi guys

#

If Im planning to create a Football Management game, Unity can Help me out with that?

wintry quarry
#

Not a code question

atomic sail
#

Sorr

atomic sail
open apex
#

In this code here, how does deltatime make it so both players see the same thing?

polar acorn
#

That's not what deltatime does

open apex
#

It's the time in betweeen each frame

radiant sail
#

can anybody help me with my time.deltatime position in my code, i cant seem to figure out where to put it so that it fixes my slow camera interpolation

float mouseX = Input.GetAxis("Mouse X") * sensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity;

        mouseXSmooth = Mathf.Lerp(mouseXSmooth, mouseX, 1.0f / smoothness);
        mouseYSmooth = Mathf.Lerp(mouseYSmooth, mouseY, 1.0f / smoothness);

        rotationX -= mouseYSmooth;
        rotationX = Mathf.Clamp(rotationX, -80f, 80f);
        rotationY += mouseXSmooth;

        float moveDirectionX = Input.GetAxis("Horizontal");
        currentRotationZ = moveDirectionX * sensitivity * rotationSpeed;

        // Apply the rotation to the player's body around the y-axis
        playerBody.rotation = Quaternion.Euler(0f, rotationY, 0f);

        // Calculate smooth camera shake
        float time = Time.time * shakeSpeed;
        float smoothShakeX = Mathf.PerlinNoise(time, 0) * 2 - 1;
        float smoothShakeY = Mathf.PerlinNoise(0, time) * 2 - 1;
        float smoothShakeZ = Mathf.PerlinNoise(time, time) * 
2 - 1;

        smoothShakeX *= shakeIntensity;
        smoothShakeY *= shakeIntensity;
        smoothShakeZ *= shakeIntensity;

        // Update currentRotationZ before setting local rotation
        currentRotationZ = Mathf.Lerp(currentRotationZ, moveDirectionX * 1, Time.deltaTime * 2);

        // Set the local rotation with added camera shake
        transform.localRotation = Quaternion.Euler(rotationX + smoothShakeX, 0f + smoothShakeY, currentRotationZ + mouseXSmooth + smoothShakeZ);```
timber tide
#
public class MyClass
{
    private struct PrivateStruct1
    {
        public int camelCaseValue;
    }

    private struct PrivateStruct2
    {
        public int PascalCaseValue;
    }

    private PrivateStruct privateStruct1;
}```
Which one? I usually just do camelCase because it's still only accessible in that class, but I'm seeing conflicts with other examples.
shell sorrel
timber tide
#

hmm, alright. I've been slacking on underscore naming. That's a lot of extra effort ;p

shell sorrel
#

well great thing is, consistency matters most and this is just convention so you can adopt what ever you and the team you work with likes and stick to it

shell herald
#

an animation event is called only once for every time it plays in an animation right? also, if i want to reference an animation event in another script, how do i do that? like

once animation event in script 1 is called, something should happen in script 2

wintry quarry
#

Or fire an event in script 1 and listen in script 2

shell sorrel
#

the animation event will only call on a script on the same object as the animation

shell herald
#

how would a fired animation event look then, would it be AnimationEvent(1)? or would something else be in the parentheses

rare basin
#

you dont call animation events via code

#

but in the animation timeline

shell herald
#

yes, but like, i want to know when it is called. im a coding noob. i basically want a bool to only be true the frame the animation event is called and then be false again

rare basin
#

make 2 animation events

#

one setting this bool to true

#

second estting this bool to false

eternal falconBOT
shell herald
rare basin
#

if you want only one animation event

#

then make it in a coroutine

#
myBool = true;
yield return new WaitForEndOfFrame();
myBool = false;
shell herald
#

hmmm, ill try that

late bobcat
#

Guys i'm trying to make a mini-soccer game. I'm working on the part where if the ball hits the net it says Goal inside my console but for some reason it's not working. Here are the 2 scripts i'm working on right now. Can you help me find out what's not working? Both the net and the ball have colliders2d.
https://hatebin.com/sqccwgdpsm
https://hatebin.com/arclcpmjmu

#

I'm very new to c# and i've some experience with C if it can helps

sonic dome
#

y am i getting this error
?

ivory bobcat
languid spire
#

Impresive, you managed to obscure the code causing the error

sonic dome
languid spire
late bobcat
#

how do i do that? @languid spire

sonic dome
languid spire
remote lynx
#

OnTriggerEnter & OnTriggerExit doesnt work
code: ```cs
public class CollisionDedector : MonoBehaviour {
private readonly List<Collider> _colliders = new ();
public static CollisionDedector Instance;

private void Awake() {
    Instance = this;
}

private void OnTriggerEnter(Collider other) {
    Debug.Log("Entered");
    if (!other.CompareTag("Player")) {
        _colliders.Add(other);
        Debug.Log(_colliders);
    }
}

private void OnTriggerExit(Collider other) {
    Debug.Log("Exited");
    _colliders.Remove(other);
    Debug.Log(_colliders);

}

public bool IsColliding { get { return _colliders.FindAll(collider => !collider.CompareTag("Ground")).Count > 0;} }
public bool IsGrounded { get { return _colliders.FindAll(collider => collider.CompareTag("Ground")).Count > 0; } }

}

isTrigger is set to true in the box collider it doesnt log anything when it collides with something
#

and the thing it collides do have a collider

languid spire
remote lynx
#

is it required?

timber tide
#

triggers still require rigidbodies

late bobcat
remote lynx
open apex
#

I am trying to get make a scoreboard, I get the score to go one up, but the next time it hits something it's not going up. Isn't a function supposed to be a loop? How can I fix it?
Should I use;

{
    public int score;
    void OnCollisionEnter (Collision collisionInfo)
    {
        if (collisionInfo.collider.tag == "Obstacle")
        {
            score = +1;
        }
    }
 }
}```
?
#

This is just a raw version of the code to show my idea

late bobcat
#

@open apex if you find out how to do that bro let me know, i was trying to do that too yesterday

late bobcat
#

what? i'm for real 😄

tight cipher
#

hello

timber tide
# remote lynx ok ty

Actually, let me double check. I usually just use casting methods myself over trigger colliders but I could be wrong about this.

shell herald
#

i am super confused, why does this not work?

frosty hound
#

You need to set the position itself, you cannot update just a single axes.

#

So give your gameObject.transform.position = a new Vector3 that includes the new x position you want.

shell sorrel
#

or save position to a temp var modify x then assign it back

sonic dome
open apex
late bobcat
swift crag
#

a loop is a block of code that repeats as long as a condition is met.

#

OnCollisionEnter is invoked every time you collide with another non-trigger collider.

#

Why do you think the score is only going up once? Are you looking at the inspector for this component while the game is running?

tight cipher
#

hello, everytime i run that code while one of the slotvar isused bool is set to true , my game crash, i dont understand

open apex
swift crag
swift crag
tight cipher
swift crag
#

void is a type.

#

it's a special kind of type beacuse you aren't allowed to actually create a variable of type void

tropic fractal
#

Hello, I am new to untiy and I want to learn first person movement, is using character controller better or a rigidbody? also can u suggest a good tutorial to start? I also want animations as I have a model ready in blender.

swift crag
#

It's used to indicate that a function returns nothing.

#

private is an access modifier. It's used to control who is allowed to see a function, field, etc.

late bobcat
#

exactly as fen said, when you say "void" "int" etc before a function name you're just indicating the type of value the function should return

swift crag
#

It also happens to be the default access modifier for methods, so both Start and OnCollisionEnter2D are private.

#

Both methods return void, so neither of them returns a value

languid spire
swift crag
# tight cipher my editor closes itself

An infinite loop will freeze the editor, since the code never finshes running.

Infinite recursion can crash the editor by exhausting the memory used to remember which methods we're calling

open apex
#

so what type of value is "void"

late bobcat
#

fen G.O.A.T

swift crag
buoyant knot
#

it’s not like a real type

shell sorrel
tight cipher
shell sorrel
#

int f() returns a int void f() returns nothing

tight cipher
#

4 chances on 6

frigid sequoia
#

Guys, this is more like a technicism, but how do I check for OnCollisionEnter() but just for a specific layer of objects?

swift crag
open apex
#

so why am I not able to start a void inside a void

tight cipher
#

4 chances on 64 to return true*

late bobcat
#

so let's say your functions is like private int number() --> this returns an integer 5,6etc -->private void number() ---> This return nothings at all

shell sorrel
tight cipher
swift crag
frigid sequoia
swift crag
#
void Foo() {

}

void Bar() {

}

You can declare several methods in a class, of course. You just have to declare them one at a time.

buoyant knot
# frigid sequoia Guys, this is more like a technicism, but how do I check for OnCollisionEnter() ...
  1. OnCollisionEnter has an argument of type Collision, which contains a reference to the thing you hit. You can check the layer there.

  2. The object has a layer, and the physics system settings can be changed to automatically count 2 layers as not colliding with each other. Which makes OnCollision calls not trigger

  3. Colliders have layer override options, so you can make that specific collider not count with colliders of a specific layer.

#

If you are going to be filtering out a lot of collisions, then you want to use layer overrides or layer collision settings so these methods don’t get called in the first place

#

so you know how mario maker lets you put 100 goombas all in a little ball, touching each other? That would be 100^2/2= 5,000 collisions every frame. In this case, you would make the goombas not count collision with each other, so physics system doesn’t even call those methods 5,000 times

timber tide
# remote lynx ok ty

Ok, yeah. You need at least 1 rigidbody from either triggering object, but you can set it to Kinematic so it wouldn't be affected by physics otherwise. As for IsTrigger on the collider, only one is required and it doesn't matter who has it, but doing this also prevents OnCollision methods from triggering.

buoyant knot
#

understand?

swift crag
open apex
# shell sorrel show a example hard to say what you are talking about

I am trying to make a scoreboard

When the collision happens, the score goes up by 1 only once and the next time it collides it doesn't work anymore,
so I tried to write;

{
 OnCollisionEnter (Collision collisionInfo)
   {
    If (collisionInfo.collider.tag == "Obstacle")
       {
          score = +1;
       }
   }
}

But it says I have to define "Oncollision Enter" When I try to make it " Void OnCollisionEnter" it gives me an error.

swift crag
#

You've just created a local function

#

OnCollisionEnter is only usable inside of Update

#

Unity has no clue this thing even exists. Don't do that.

buoyant knot
#

a local function called OnCollisionEnter 😂

shell sorrel
swift crag
shell sorrel
#

so yeah dont define a function inside a other function

swift crag
frigid sequoia
buoyant knot
#

unity only sends messages to call OnCollisionEnter on collisions if you have a function called OnCollisionEnter, that takes a Collision argument, and returns void

swift crag
#

If you're having problems with the score not increasing, then you need to figure out:

  • whether OnCollisionEnter is running at all
  • whether you're hitting something with the correct tag
frigid sequoia
#

Don't really know why

timber tide
#

honestly just spherecast and use a layer mask :)

polar acorn
buoyant knot
#

Debug.Log. See what the values are for wallCollisionlayer and gameobject.Layer

polar acorn
#

Log them before the if

open apex
#

I do not understand

frigid sequoia
rich adder
#

oh jeez

swift crag
#

Are you reading what we're writing?

open apex
swift crag
polar acorn
# open apex

You have a function in your function and also a bunch of spelling errors

buoyant knot
frigid sequoia
shell sorrel
# open apex

you need to learn the basics of C# non of that is valid syntax do not put your collision function inside the update

frigid sequoia
swift crag
#

i think you need to be looking at !learn to get a handle on how C# works

eternal falconBOT
#

:teacher: Unity Learn ↗

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

swift crag
#

if so, grab .value from them

timber tide
#

To be fair it's a lot of bs reflection method binding to easy to be confused, but yeah maybe want to brush up on some c#

buoyant knot
swift crag
open apex
swift crag
#

write a method with the appropriate name and signature and unity will run it. that's it.

shell sorrel
buoyant knot
#

Layer #5 corresponds to the integer 5.
A layer mask is a 32 bit integer, where each bit corresponds to whether or not to check interaction with that layer. So a layer mask that only touches layer 5, would be layer mask 64

shell herald
#

im confused, i thought animation events are only called once. i have a single frame event in my animation and i want when it plays to add a fixed value to the position of an object. right now however, value is added many times over, even when the animation is only playing once. but if i add a debug log, it only fires once

frigid sequoia
buoyant knot
#

because that is 000…000100000

swift crag
open apex
#

thanks for the help guys 😁

#

I am gonna go back to the tutorials 😔

icy junco
#

i dont know whats the problem but i cant jump and i get and error that says NullReferenceException: Object reference not set to an instance of an object
PlayerGround.OnTriggerStay (UnityEngine.Collider other) (at Assets/Scripts/PlayerGroundCheck.cs:30)
could this be something with my groundcheck script?

buoyant knot
#

and a Layer mask that includes layers 0 and 2 would be equal to 000…00101 = 5

swift crag
#

that will combine identical log messages into one

buoyant knot
#

understand?

ivory bobcat
buoyant knot
#

this plugin has code to automatically generate a class called Layer, which contains public consts for specific layers and layer masks in your game

icy junco
ivory bobcat
icy junco
#

if...

ivory bobcat
#

I'm guessing the if-statement

frigid sequoia
buoyant knot
#

so if I have Layer 5 being terrain, then it will have Layer.TERRAIN, which is automatically 5. And Layer.TERRAIN_MASK, which is automatically 64

icy junco
ivory bobcat
#

Yeah, so playerController is null and accessing the gameObject property threw an error because playerController was null.

swift crag
buoyant knot
frigid sequoia
buoyant knot
#

then you need to go to project settings, and go define the layers that Wall can interact with

#

don’t leave that shit default

icy junco
buoyant knot
#

you will tear your hair out

#

Project Settings => Physics

#

there will be a giant matrix of checkboxes with layers

ivory bobcat
buoyant knot
#

If X and Y have a checkbox on, then they interact. Otherwise, they do not (by default) without layer overrides.

frigid sequoia
#

So just to be clear, when I am declaring variables, can I call a Layer instead of a LayerMask? Cause I don't think it lets me declare a Layer in the script, just LayerMask

swift crag
#

No, that isn't built in, unfortunately.

buoyant knot
#

no

#

Layers are ints

swift crag
#

The logic for drawing a list of layers is in there, but it isn't be applied to anything

#

I believe you can make a custom property drawer for this?

#

It came up in this server recently

buoyant knot
#

a layer mask is a bitmask

#

the different 0 and 1 directly mean like 32 separate booleans in one integer

swift crag
#

Both layer IDs and layer masks are integers. That's why it's easy to mix them up.

#

C# won't stop you from doing if (thing.layer == myMask)

#

because they're both integers, making this a completely legal comparison

frigid sequoia
buoyant knot
swift crag
swift crag
#

Checking if a thing you've collided with is on a specific layer?

buoyant knot
#

what if your layer mask has anything besides exactly one bit set 1?

frigid sequoia
#

To get the index of the layer mask as a layer???

buoyant knot
#

it could be 00010001, 1101111, 000000

swift crag
frigid sequoia
#

Dunno I am really confused XD

swift crag
#

What are you trying to accomplish?

#

I don't want to hear what thing you've tried to do to solve your problem.

buoyant knot
swift crag
#

Tell me what your problem is.

#

We're way off in the weeds here and not getting any closer to solving your actual problem

#

Explain your original problem.

buoyant knot
#

000…00111 =7 is an integer representation of a layer mask that interacts with layers 0, 1, and 2

marble barn
#

Question about "Multi-Stage Objects"

buoyant knot
#

a layer mask is alike an integer for 32 booleans, where each 0/1 corresponds to if that one layer is included in the layer mask or not

ivory bobcat
#

What was the actual issue?

frigid sequoia
#

Ok lets play it slow to make sure we are talking about the same. That think in the corner, that dropdown; those are layerMASKS, right?

swift crag
#

No.

#

Those are layers.

#

You are picking which layer the object is on

#

One, singular layer.

ivory bobcat
swift crag
#

The object is on the Character layer in this screenshot.

buoyant knot
#

this way, if I want to filter for specifically layers 1, 4, 7,8,9, 23, then I can make a single layer mask that has those bits on. Then I check vs layer mask, so I don’t need to use 7 if else if else if to check if that layer is relevant

swift crag
#

You can't be on two layers at once.

swift crag
buoyant knot
#

he doesn’t understand the difference between layer mask and layer

swift crag
#

We'll get there.

frigid sequoia
# swift crag Those are layers.

Then why the hell does it shows the Layer Dropdown when I am assigning a LayerMask variable for a script in the inspector?

swift crag
#

you're choosing which layers are included in the LayerMask.

buoyant knot
#

layer mask is 1 int that corresponds to booleans for 32 layers (some combination of those 32 layers)
a layer is just an integer for its own layer ID.

ivory bobcat
buoyant knot
#

you cannot convert a layer mask to a layer, because the layer mask could correspond to 0 layers, or multiple layers.

you can convert one layer to a single layer mask that describes just that one layer.

swift crag
frigid sequoia
swift crag
#

Are you talking about the Physics settings here?

buoyant knot
ivory bobcat
#

I think you guys are making this overly complicated..

buoyant knot
#

Layer 0 corrsponds to if the rightmost bit of a layer mask is =0 (not included), or =1 (layer 0 is included in the mask)

frigid sequoia
swift crag
sullen zealot
#

can anyone pls help me with this warning?

swift crag
#

is PlayerDataHolder just a bag of data?

#

not something that's attached to a game object?

sullen zealot
#

yes

#

iyt is

swift crag
#

If so, you could just make it a regular class.

sullen zealot
#

it is attached

shell sorrel
#

that link about bitmasks is great, it a good topic to learn about since its not just for layers or even unity. its a common programming thing

swift crag
buoyant knot
#

Monobehaviours should only be made by AddComponent

swift crag
#

in that case, just do what the warning tells you to do (:

buoyant knot
#

(accidentally replied)

timber tide
buoyant knot
late bobcat
#

Guys if i wanted to make a status in a mini-soccer game where the player would enter a kick state in which if he collides with the ball, this one gets kicked away, how should i do that? (Enter kicking state means, i press a button and player is kicking)

sonic dome
swift crag
#

The fundamental difference is..

  • An index or ID identifies a single thing
  • A mask identifies many things
late bobcat
#

wanted to make it as it is in haxball if you know the game

buoyant knot
#

idk why unity doesn’t already just have a layer enum

shell sorrel
late bobcat
#

So basicallyh in haxball you have your player, and when you press space, if you hit the ball you basically add a force to it that kicks it away.

ivory bobcat
rich adder
#

do some type of overlapscircle check if you have ball in range and use ur characters forward to kick it

late bobcat
#

well, the whole process tbh. My goal is to add that kick action or status when i press a button. I'm kinda new to C#

rich adder
#

doing it a kick only on collision will be extremly difficult to get right, I would use a quick overlapcircle to check for ball is in the range (slightly bigger than player) and use that

buoyant knot
frigid sequoia
buoyant knot
#

yes

late bobcat
buoyant knot
ivory bobcat
shell sorrel
swift crag
buoyant knot
#

that was the start of this

rich adder
#

except you call it at will

frigid sequoia
bright oxide
#

Hi, is it possible to set the cursor icon to the hand pointing up in unity?

rich adder
#

also not a code question

buoyant knot
#

it automatically generates a class for you that contains consts for the mask corresponding to just one of each specific layer

bright oxide
buoyant knot
#

like
public const int WALL = 5;
public const int WALL_MASK = 64;

shell sorrel
#

can also easily just do if (mask & (1 << layer) != 0)

rich adder
bright oxide
#

Yeah, cursor icon change to hand pointing up when hovering over an object

buoyant knot
shell sorrel
#

(1 << layer) will take a layer index and make a mask from it, then the & will tell you if the 2 things share bits or not

rich adder
swift crag
rich adder
#

@bright oxide

buoyant knot
#

0011 & 0010 = 0010, which is not zero.

swift crag
#

we're dogpiling dorito with like five copies of the same answer and I have to imagine it's extremely confusing

frigid sequoia
timber tide
#

just learn bits

bright oxide
rich adder
buoyant knot
#

because you don’t need to get into the weeds that much

frigid sequoia
polar acorn
buoyant knot
#

(layer mask & (layer mask with just the one bit on for one specific layer) > 0)
this is true => that one layer has its bit on in the mask

shell sorrel
#

you can skip over the problem for now with some utility methods from that library. but the concept of bit masking and bitwase operations is good for any programmer in any context to know

bright oxide
rocky canyon
#

😱

bright oxide
#

default hand pointing up

rocky canyon
#

bit masking.. shivers

bright oxide
rich adder
#

You have no control over that in unity.. its specific to OS .

buoyant knot
#

layer mask1 & layer mask 2 = a layer mask that only includes layers in both.
mask1 | mask2 = a layer mask that includes any layers in either mask

rocky canyon
buoyant knot
#

& and | operators work basically the same as normal AND and OR

bright oxide
buoyant knot
#

that is how you can easily manipulate the bits

frigid sequoia
# bright oxide DUDE the hand icon

Search the hand icon online; download it as sprite, set the mouse visibilty to false, place the Sprite at the mouse position. That's what I would do.

timber tide
#

Imagine if you had an item with multiple tags as: Sword, Slash, Fire, Expensive, Metal, Explosive, ect.

How would you develop the logic to check if this item contains at least a Fire tag? Most would loop through it, but with bits you can just compare them and be done.

swift crag
#

this allows you to set a custom mouse cursor.

#

Pay close attention to everything on that page. If you don't read it, the custom cursor will not work.

bright oxide
ivory bobcat
rocky canyon
rich adder
rocky canyon
#

custom cursor always feels rigid to me

rich adder
#

the only way to do it

rocky canyon
#

and i like being able to swap thru different cursors at will

timber tide
#

someone was saying that hiding the cursor and applying your own can be somewhat inaccurate

rich adder
#

there always is a delay ofc

rocky canyon
#

nah, as long as u line up the graphics to the root's center pivot

swift crag
#

It doesn't position a Sprite where the cursor is or anything like that

rich adder
#

I know that

#

they're talking about custom cursor which Im not

#

making custom cursor Software(delayed) vs Hardware (os)

rocky canyon
#

click

rich adder
#

a gameObject? blasphemy !

swift crag
#

I used Shapes to create a cursor in an RTS once

#

the problem I ran into was that drawing in AfterPostProcess with dynamic resolution scaling is broken, but drawing in BeforePostProcess means that the damn thing gets post-processed!

rich adder
#

is that a package?

swift crag
#

Yeah. It's a package for drawing nice lines, discs, etc.

rich adder
#

Oh nicee, i only knew about GL. Gotta look into shapes sounds fun

open apex
#

I have solved my problem here but I have a quesiton 🙂

The script won't accept TextMeshPro as a "text", in order to fix it I have to remove it and add a text component. But is there a way to use TextMeshPro instead of a Text component?

rich adder
rich adder
#

normally you use TextMeshProUGUI or whatever

open apex
rich adder
#

but TMP_Text is shorter and the base class that will accept any TMP variance

rich adder
open apex
ivory bobcat
swift crag
#

TMP_Text is a parent type of TextMeshPro and TextMeshProUGUI.

rich adder
#

mymyb underscore too

swift crag
#

There are differences between non-UI and UI text, but they're not relevant in most cases

#

so you can just use TMP_Text to cover both

rich adder
#

so used to IDE putting it there for me when i just type TMPT

#

xD

open apex
rocky canyon
#

i thought UGUI covered both?

polar acorn
swift crag
#

I need to name a dictionary that maps "things that make noise" to "loudness of perceived noise"

#

struggling with a name

#

intensities sounds more like a list or something

shell sorrel
swift crag
#

perceptions is closer but it's such a general name

rocky canyon
#

AudioMagnitudes

swift crag
#

and "Perception" already has a very well defined meaning

#

The values fade to 0 and get removed from the dictionary, so maybe activeNoises or something..

polar acorn
rich adder
#

bigNoisesDic

rocky canyon
#

Audio Susceptibilty

swift crag
#

causeToIntensityMap

#

since it specifically stores "causes" of perceptions

rocky canyon
#

DictionaryOfThingsThatMakeNoiseToLoudnessOfPerceivedNoise

shell sorrel
open apex
#

This is the ouput but when I put a 0 in the brackets; ToString("0") why does it become a whole number?

polar acorn
#

Yeah, when the name isn't obvious, fall back on verbosity

polar acorn
rocky canyon
#

F1 - F(x)

open apex
#

thanks

rocky canyon
#

F(number of decimal places wanted)

#

in the parenthesis

open apex
#

ok hmm

keen ember
#

heyya! tbh this is my first time coding anything beyond html so you may need to explain any errors to me very simply :,)
i'm creating a dialoguemanager by following this tutorial : https://www.youtube.com/watch?v=vY0Sk93YUhA&t=840s. however i get this error:

Assets\Scenes\Scripts\Dialogues\DialogueManager.cs(111,35): error CS0103: The name 'choice' does not exist in the current context
here is the cs file:
https://pastebin.com/P2b0v5kC

also, i'm using inkly to create a dialogue branch that goes down 3 layers of options, however the dialogue stops after the first set of options are selected. if someone could point out/fix that issue that would help tremendously :)

In this video, I show how to make a dialogue system with choices for a 2D game in Unity.

The dialogue system features Ink, which is an open source narrative scripting language for creating video game dialogue that integrates nicely with Unity.

Thank you for watching and I hope the video was helpful! 🙂

NOTE ABOUT INPUT HANDLING - If you're try...

▶ Play video
swift crag
#

You have no variable named choice.

#

Therefore, you get an error.

rich adder
#

follow the tutorial exactly

icy junco
#

what do io put in negative and positive button on scroll wheel

dusty coral
#

when i set my sword's parent as the bone it follows the bone but its not snaping to the exact position 😦

rich adder
icy junco
#

in the inputmanager?

rich adder
icy junco
rich adder
#

not sure if mouseScrollDelta is the axis

sweet flume
#

Just a question

rich adder
#

idk

#

let me google it

icy junco
#

maybe its because i had getaxisraw?

sweet flume
#

I've made a text where it show how many items you have collected but for some reason when it reached 10 it dissapears

rich adder
eternal falconBOT
rich adder
#

I just dunno how to put it in the Input manager

#

i think unity already did though with GetAxisRaw("Mouse ScrollWheel")

sweet flume
rich adder
#

read the bot message I sent

#

don't use screenshot for code

#

let alone a phone picture.

sweet flume
#

Ik I cant copy and send it rn

rich adder
#

ok do that

rich adder
sweet flume
#

Wait lemme install dc on my laptop rq

ivory bobcat
sweet flume
#

Brb

rich adder
#

if you dont want to install it

ruby python
#

!code

eternal falconBOT
sweet flume
polar acorn
rich adder
#

it diappears because it probably isn't big enough

ivory bobcat
#

I'm assuming the string is too long for the display box

sweet flume
#

just the number

rich adder
#

yup rect transform prob too small

polar acorn
# sweet flume just the number

Yeah, looks like it's just overrunning the size of the box and can't fit the number. Increase the width of your text box

sweet flume
#

so if i make it bigger it should be fine?

rich adder
edgy fox
#

is there a way in visual studio to move a whole block of code back a tab?

sweet flume
#

Ty guys

ivory bobcat
edgy fox
shell sorrel
rich adder
#

you would think microsoft would put same shortcuts from VS to VSCode

#

nope

west obsidian
#

how do I get the rotation of a vector3?

fleet willow
#

"I dont need it, Im low on cash I should buy it, dont buy it, dont buy it resist the urge, but its on sale!"

polar acorn
rich adder
buoyant knot
fleet willow
rich adder
#

and you dont know anything about fixing it

buoyant knot
#

there are many ways to represent a rotation, but at the end of the day, some sort of rotation operator/matrix is needed to rotate

ivory bobcat
polar acorn
fleet willow
#

sigh

west obsidian
timber tide
#

why you need rotation

rich adder
#

the price is cheap enough to be worth it though

west obsidian
#

like if I were to have point A be (0,0,0), point B be (0,1,0) and T be (1,1,0) then it would be as simple as removing the z coord

#

but Im rusty on rotation matrices and stuff

rich adder
#

I'm tempted of making one of these Templates myself ngl xD

west obsidian
#

I assume you do something like take the cross product to find the normal of the plane, but I dont know how to find the rotation of that normal

buoyant knot
rich adder
#

FromToRotation

buoyant knot
#

Quaternion contains methods to apply rotation operators in true 3D. But might not be needed if you are actually in true 2D

west obsidian
#

not like the shadow or anything tho

#

I want to find the local coordinates on the xy plane that goes thru the 3 points

buoyant knot
#

you can also do the math by hand. Wiki has the very simple math

west obsidian
#

ya like a1 is multiplied by the cosine of the angle

#

so there is deformation

buoyant knot
#

a projection takes only the components of the vector that would be in plane

open apex
#

Hello it's me again, I have made a code where when the player gets in touch with an obstacle and it gets replaced with another destroyed version of the player. This creates the illusion of destruction, the code works but it's faulty, it only runs once. when I drop to the game it touches the ground and after it, it won't run again. How can I make it to keep on running until the even occurs?

buoyant knot
#

it does not rotate the vector

west obsidian
buoyant knot
#

the norm will almost certainly decrease

west obsidian
buoyant knot
#

then why don’t you project it, and change the magnitude

shell sorrel
west obsidian
buoyant knot
#

project the vector onto the plane, then change the magnitude to match the original. And you need a special case where the original vector is normal

rich adder
buoyant knot
#

which you’d need anyway

west obsidian
buoyant knot
#

that’s the easiest way to do that

west obsidian
#

are you talking about the point as the vector?

#

cuz if so its already on the plane lol

buoyant knot
#

there are no points here

#

you have a 3D vector, and want it to be rotated such that it is in a 2D plane

#

what you have asked for is projection + rescale

open apex
west obsidian
#

not completely, I want to find its orientation relative to an axis

rich adder
west obsidian
#

so I guess projection works, but there is an extra step of finding the angle between it and the axis

buoyant knot
#

that has nothing to do with a 2D plane then

open apex
west obsidian
#

well my points have to do with a 2D plane, the vector is how I align my arbitrarily rotated 2D plane with a 2D plane of normal (0,1,0)

shell sorrel
west obsidian
#

I have a plane passing thru points A B C, I want to find the local coordinates of C

open apex
buoyant knot
#

idk man. once you can better articulate what you need in terms of vector/matrix operations, everything will become clear

rich adder
#

since you're destroying it

buoyant knot
ivory bobcat
open apex
#

It supposed to get destroyed only when it hits an object, when the game begins it hits the ground and the script runs and then it doesn't run again. It only runs once only (it runs when it's not supposed to)

west obsidian
#

whoops, wrong message

open apex
#

I couldn't explain myself

west obsidian
#

basis vectors

buoyant knot
#

the local coordinates of anything in 3D require 3 basis vectors to express

ivory bobcat
#

Maybe consider destroying the other object colliding with this object

rich adder
open apex
#

no

west obsidian
buoyant knot
#

vectors form a basis if they are linearly independent, and fully span the space

rich adder
buoyant knot
rich adder
buoyant knot
#

if you give me an arbitrary 2D plane, and tell me to get the local coordinates of a 3D point, I will tell you that your query makes no sense

west obsidian
#

I have 3 3D points, A B C

west obsidian
#

I want to orient them so that they are all on the same 2D plane with a normal of (0,0,1)

#

how do I do that

buoyant knot
#

still impossible

#

there are an infinite number of answers that would satisfy that

west obsidian
#

how? I did this a while back when I was making a 3D renderer

buoyant knot
#

because you still haven’t defined your new coordinate system

open apex
#

something faulty with the script

#

forget about it I will just delete it

west obsidian
buoyant knot
#

if order to change from one coordinate to a different coordinate system, you need a 3x3 matrix

west obsidian
#

Im staying in euler coords the whole time

buoyant knot
#

this 3x3 matrix effectively contains information for all 3 axes for the new coordinate system

#

wtf are euler coordinates? that isn’t relevant here

meager sentinel
#

Someone knows why my VSC ide is so buggy? It worked the last week, and now it donts

buoyant knot
#

you are doing a simple linear transformation. but you can’t do that unless it is fully defined

west obsidian
#

Im sending a desmos 3D graph of what I want

buoyant knot
#

let’s say I’m standing on the plane, and forward is my X axis

#

i can turn around

#

different x axis. still satisfies your constraints

#

different coordinates

#

therefore your question is ill posed

meager sentinel
#

Can someone help me with the VSC Ide?

#

alr did everything

#

and it dont works

ivory bobcat
#

What's the issue then? Do you get some weird error on the bottom right with VSCode about sdk?

ivory bobcat
#

Maybe you've missed a step..

meager sentinel
#

i get this tho

summer stump
#

And when you go to output?

meager sentinel
west obsidian
#

how do I transform the triangle onto the flat one, given any arbitrary points, A0 is at the origin, and B0 is downwards along the y axis

ivory bobcat
meager sentinel
keen ember
# keen ember heyya! tbh this is my first time coding anything beyond html so you may need to ...

okay, i went back and rewrote the dialoguemanager and dialoguetrigger script to a T. this new error comes up:

https://pastebin.com/z6SxWJxy - dialoguemanager
https://pastebin.com/zUfkApAY - eventsystems

Ink.Runtime.Story.Assert (System.Boolean condition, System.String message, System.Object[] formatParams) (at Assets/Ink/InkLibs/InkRuntime/Story.cs:2827)
Ink.Runtime.Story.ChooseChoiceIndex (System.Int32 choiceIdx) (at Assets/Ink/InkLibs/InkRuntime/Story.cs:1785)
DialogueManager.MakeChoice (System.Int32 choiceIndex) (at Assets/Scenes/Scripts/Dialogues/DialogueManager.cs:135)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Events.CachedInvokableCall`1[T].Invoke (System.Object[] args) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.UI.Button.Press () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnSubmit (UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:150)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.ISubmitHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:134)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)```
kind bramble
#

How do i add a AssestPostProcessor to a obejct i imported so i can add a script into that prefab?

keen ember
short perch
#

how can I sense clicks anywhere on the screen?

shell sorrel
#

depends on the input system, but could just listen for when the mouse button is pressed then its its position

short perch
shell sorrel
#

iirc it will but for more info about touces and for multitouch you got Input.touches

#

also would use GetMouseButton or GetMouseButtonDown

short perch
#

ah

low mountain
scarlet hull
#

why am i getting this error

short hazel
#

lol, pretty bad censoring job

scarlet hull
short hazel
#

Two of your assets show it

ivory bobcat
#

Maybe show the complete error?

timber tide
# west obsidian https://www.desmos.com/3d/a0ad25097b

viewspace -> clipspace -> screenspace using a projection matrix is usually how computers render 3D objects to our screens so you can research into that. As for your question, I'm still not sure what you're aiming for, as to solve that specific problem I'd just rotate until I eliminate an axis.

scarlet hull
#

UnassignedReferenceException: The variable firing of turret has not been assigned.
You probably need to assign the firing variable of the turret script in the inspector.
UnityEngine.Transform.get_position () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
turret.Shoot () (at Assets/turret.cs:47)
turret.Update () (at Assets/turret.cs:37)

ivory bobcat
#

Turret line 47

short hazel
#

Pretty self-explanatory, you haven't drag-dropped something into the "Firing" of the "Turret" script

scarlet hull
short hazel
#

It's one of the easiest messages to interpret, the longer you code, the harder they get

#

And you need to configure Visual Studio so it works with Unity

#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

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

scarlet hull
#

yeah

#

im planning to do that

short hazel
#

It's required to get help here

scarlet hull
#

sorry my bad

short hazel
#

Configure, then come back

scarlet hull
#

okay

short hazel
#

If you have any issues about it you can still post here

warm sleet
#

I have a game object, tower, that stores enemies at an array and then it shoots, but, is it possible to add detections so if there is a wall in front, or some object, it wont be able to shoot?

west obsidian
warm sleet
#

I don´t know if It´s possible to make it throught detection of the wall or something like that

short perch
#

how can I convert Input.mousePosition into a Transform?

short hazel
short hazel
summer stump
#

You can instantiate a gameobject and move it to that position though, I guess
For some reason... probably want to use an offset though for that

warm sleet
#

Wait, I think with that code you dont need to

#

how do I comment the code in discord?

ebon robin
short hazel
#

That's your interpretation

#

Might be correct, might not

#

Hence why, the real question is what should be asked here

warm sleet
#
mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();


Vector3 mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);

```
summer stump
short perch
polar acorn
warm sleet
polar acorn
short perch
#

I tried something

using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
using static UnityEngine.UIElements.UxmlAttributeDescription;

public class PlayerController : MonoBehaviour
{
    [SerializeField]
    private Transform target;
    private Vector3 clickPosition;
    public Vector3 direction;

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            target = Input.mousePosition;
            direction = target.position - clickPosition;
        }
    }
}```
#

but it's not complete

#

and it gives an error

polar acorn
short perch
polar acorn
short perch
#

I don't know

summer stump
short perch
#

oh I'm stupid

scarlet hull
#

issue here i got these 2 scripts one named turret other BULLET
https://hastebin.com/share/barehakuja.csharp - turret
https://hatebin.com/akzoqmuiff - BULLET

i want for the bullet to spawn at "firing" and follow the "target" untill it hits
but it wont move once it spawns can someone help me fix this isue

#

im not getting any errors issue is in the script

#

in bullet

#

in turret

timber tide
#

you can further debug your bullet code

#

need to figure out if it's your targeting or how you're doing the speed

polar acorn
#

Unrelated but if the literal first thing you do after instantiating a bullet is get the Bullet component from it, why not just make that prefab field of type Bullet and skip that step

timber tide
#

similar to how you're declaring your variables as transforms and gameobjects

#

you specifically want to work with the types, so you might as well reference them

scarlet hull
#

since i started this way im going to finish it like this but i will keep that inmidn for the next time

polar acorn
scarlet hull
#

aah

#

got it

timber tide
#

it's just ambiguous

#

benefit of having your fields as their specific types also makes binding stuff in the editor clearer

#

so you dont accidently bind the bullet field with a type of gun, because you instead wanted to declare the field as a gameobject

scarlet hull
#

i see

steady goblet
#

guys, trying to do a little experiment after the challenge 1 of Junior programming guide!

I did managed to create a code that doesnt give me any errors, but it just flies to the sky, can someone tell me the error?

using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;

// making the camera move along with the player
public class camera : MonoBehaviour
{
public GameObject player;
private UnityEngine.Vector3 offset = new UnityEngine.Vector3(1, 2, -3);
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void LateUpdate()
{
    transform.Translate(player.transform.position + offset * Time.deltaTime);

}

}

polar acorn
eternal falconBOT
steady goblet
polar acorn
steady goblet
#

its bc in the tutorial it places it in LateUpdate

polar acorn
steady goblet
#

after each update

polar acorn
#

Correct

#

So you're moving this object by a fixed amount every frame, after Update

scarlet hull
#

it did shoot once i dont know how

#

not really nsfw

#

only fsome pixels

timber tide
terse osprey
#

Hey, I want to write a script that removes all children that are currently active from parent

shell sorrel
scenic urchin
#

What exactly a variable being created/declared with => does? "float _var => 10"

celest citrus
#

im doing brackey's tutorial and this doesnt work for the score counter, im pretty sure its something to do with the text mesh pro but idk what to do, can someone help

scenic urchin
#

looks like a function? a variable and function at the same time? lol

tacit estuary
polar acorn
scenic urchin
#

oh wow I didn't knew c# had these

celest citrus
#

basically in the tutorial he says to add the text component to, in this case, Score Text, and i literally just cant lol

tacit estuary
polar acorn
shell sorrel
celest citrus
#

ohh ill try that thanks

buoyant knot
#

at least not one you can do with a 3x3 matrix

#

you would need a rotation operator to transform the whole plane about some defined center.

#

only then can you get the difference in position, and add the vector

shell sorrel
scenic urchin
shell sorrel
#

one of those is a function the other is a property

#

they are not the same

#

public Vector3 GetVelocity() => _rig.velocity

terse osprey
#

how can I check if a child component is active on not

shell sorrel
#

is what you want

scenic urchin
shell sorrel
#

though a property in this case would be a better choice

scenic urchin
#

I'm just a bit lost about where to use each in this kind of situation

shell sorrel
#

properties are essentially functions that look like regular field access

#

like public Vector3 Velocity => _rig.Velocity; then on access it would just be thing.Velocity

raven hill
#

Hello, how do I make one object rotate like the parent object?

summer stump
summer stump
scarlet hull
raven hill
#

I didn't realize that the object wasnt rotating just the camera

scarlet hull
#

--BULLET

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BULLET : MonoBehaviour
{

    private Transform target;
    [SerializeField] private float bulletspeed = 5f;
    [SerializeField] private Rigidbody2D rb;




    void Start()
    {
        
    }

    // Update is called once per frame
    private void FixedUpdate()

    {

        if(!target) return;
        Vector2 direction = (target.position - transform.position).normalized;
        rb.velocity = direction * bulletspeed;
    }
    public void SetTarget(Transform _target)
    {

        target = _target;
    }
    private void OnCollisionEnter2D(Collision2D other)
    {

        Destroy(gameObject);
    }



}
#

---turret

    }

    private void OnDrawGizmosSelected()
    {
        Handles.color = Color.black;
        Handles.DrawWireDisc(transform.position, transform.forward, Range);
    }

    private void FindTarget()
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, Range, Vector2.zero, 0f, enemyMask);
        if (hits.Length > 0)
        {
            target = hits[0].transform;
        }
    }

    private bool TargetIsInRange()
    {
        // Check if target is null before accessing its position
        if (target != null)
        {
            return Vector2.Distance(target.position, transform.position) <= Range;
        }

        // If target is null, it's not in range
        return false;
    }

    private void RotateTowardsTarget()
    {
        // Check if the target is null
        if (target == null)
        {
            // You may want to add additional logic here, or simply return
            return;
        }

        float angle = Mathf.Atan2(target.position.y - transform.position.y, target.position.x - transform.position.x) * Mathf.Rad2Deg - 90f;
        Quaternion targetRotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
        GunRotation.rotation = Quaternion.RotateTowards(GunRotation.rotation, targetRotation, rotationS * Time.deltaTime);
    }
}
#

i tried to fix it using chatgpt

#

but it couldnt find any errors

buoyant knot
#

I summon thee from the depths of hell. Come, Dynobot! Use !code !

eternal falconBOT
summer stump
timber tide
#

I still dont see any debug logs

terse osprey
#

Why does this not remove the child component that is active

buoyant knot
#

uhhh what

#

does SetParent work like that?

scarlet hull
#

it worked

buoyant knot
#

also that would at best try to move the child to the root of the hierarchy

buoyant knot
shell sorrel
buoyant knot
#

that would just set the i-th child to be in the root of the hierarchy

static bay
#

ya

#

bit unintuitive but meh

terse osprey
#

yes that is what I want to do, basically just unparenting the child and setting it in root

#

but I only want it to happen to the singular child that is active at the moment

buoyant knot
#

i would debug.Log to see if that line even gets called

shell sorrel
#

could break out of the loop if you just want the first one it finds

terse osprey
#

since there is only one active at the time so all active children works fine by me

#

but it doesnt unparent any at all

shell sorrel
#

also there are multiple ways to check for active

buoyant knot
#

also, if you unparent it successfully, then you will get an index our of bounds error. because you changed the list of children. So you need to break

shell sorrel
#

the one you used would return false if the object was active but its parent was not

native flicker
#

how to check whenever a player is holding down a button and do smt when the button is holded

buoyant knot
#

look up tutorials for it

static bay
native flicker
#

no, no key

#

a actual button in a gui

terse osprey
#

maybe I am just trying to do this a really stupid way but basically I have an inventory and whenever I pickup a gun it is added as a child of the inventory. I want that if I try buying a 3rd gun so above my max child limit the gun currently active is replaced by the new one

shell sorrel
native flicker
#

alr thx, i alr tried some stuff but none rl worked im prob doing smt wrong

shell sorrel
#

using IPointerDownHandler and IPointerUpHandler and a Update

static bay
shell sorrel
#

set a bool true OnPointerDown, set it false in OnPointerUp then in Update do what you want to do while the bool is true

buoyant knot
#

that is a recipe for disaster

static bay
#

^ The hierarchy is really for managing the active state of things and organization.

timber tide
#

it can work

#

unless you have an unlimited inventory then you're asking for a scene of gameobjects

#

of guns

terse osprey
#

There are a total of 5 weapons that one can get and up to two can be in the inventory at one time

#

I dont quite understand everything you guys say but ill do some research into the things you guys recommend and get it working hopefully

#

Thankyouu

polar acorn
edgy prism
#

Hello I am currently calling an idle animation in update like this

void Update()
    {
        if(!playerUnit.IsPlayingAttack && !playerUnit.IsPlayingIdle)
        {
            StartCoroutine(playerUnit.PlayIdleAnimation());
        }
    }

Im having a problem with the fact that when I want to play the attack im basically always playing the idle so it doesnt work, if I try and WaitUntil in my attack anim the update always sets it faster

buoyant knot
# timber tide it can work

don’t enable him, mao. Using parenting to effectively manage inventory, which requires a lot of querieing, size control, sorting, etc… Doing all that in hierarchy is a really terrible idea

#

Just use a list

terse osprey
#

The issue here is that I am using assets from the unity store and those work by adding a weapon as a child to have it be part of the inventory. Maybe ill try changing up the system it self

timber tide
#

well, you'd have a manager. The only difference between storing it in data vs having it on the scene is you don't need to instantiate the data onto a gameobject everytime you want to use it

hybrid tapir
#

how do you make a value in an inspector seen but like dimmed out and uneditable? i thought private and [serializefield] might do it

polar acorn
timber tide
#

so more mem vs overhead elimination, but otherwise for small amounts not really a concern.

buoyant knot
timber tide
#

oh yeah, I wouldn't deparent and stuff, but you can just get a list of all current siblings and keep pointers to them in a list

buoyant knot
#

like, sorting the list, or filtering through, or whatever… that is going to be a massive pain

buoyant knot
#

so you need to go reading the hierarchy to know the contents of the inventory

#

you need to parent, deparent to move things into or out of inventory

#

and querying or sorting the inventory is a mess

#

all this, instead of a list

timber tide
#

yeah I wouldn't care too much about how it looks on the hierarchy, you'd just read the pointers from the manager and then child them to the inventory with an Add method

buoyant knot
#

that’s what i’m getting at

timber tide
#

again, I wouldn't do this for a large inventory of stuff, but if you wanted to show your side arm equipped to your guy and your rifle (the whole load out), you might as well just keep it all on the scene

buoyant knot
#

the hierarchy exists to maintain specific relationships between gameobjects. Not to store misc gameplay information, like what is or is not in your inventory

#

imo, my limit for doing that is an inventory size of one. Where there is supposed to be a unique object parented/child

#

and even then, both will have a monobehaviour to establish and maintain the connection

kind bramble
#

How do i fix this? it wont let me add a script into a model i imported from blender.

shell sorrel
#

make a prefab from that model, then add the script in the prefab

untold saffron
#

Hello, i get the " Object reference not set to an instance of an object " error and I dont understand why, when using the following code to create floating damage text popups

polar acorn
#

There's like fifty things it could be

eternal needle
#

That's definitely a line of code

polar acorn
#

so the first step is to split that up so you can find out where the problem is

#

Well, the 0th step is getting rid of the pointless .gameObjects

untold saffron
#

i think i found that the problem is probably the GetComponent<>() part

#

but my object has a textMesh i dont understand why it returns null

eternal needle
#

70% of that line can be taken out if you directly reference the script for Instantiate

rich adder
eternal needle
#

And then you dont have to worry about keeping the same structure, where you look for a certain child

polar acorn
#

Yeah just make damageTextPrefab of type TextMeshProUGUI

#

Ah, wait, no it's in a child object

eternal needle
rich adder
#

using GameObject is kinda useuless

eternal needle
polar acorn
rich adder
#

make parent have script and prefab has the TMP reference of child, use a method on that script to do ChangeText

untold saffron
#

wait i dont understand

#

how should i do that?

rich adder
#

personally I would make these a Pool of DamageObjectsText

#

instantiating a bunch of new prefabs on each damage sounds expensive

untold saffron
#

oh okay thanks

rich adder
#

make the main script on it that controls the TMP_Text

#

everytime you get from Pooled objects set the text to new damage amount

gaunt harbor
#

Ey! Can anyone give me an idea how to make a crosshair that can detect an enemy from afar?

untold saffron
gaunt harbor
eternal falconBOT
gaunt harbor
#

And what is the code to detect when the beam is next to the enemy?

west obsidian
#

how would I find the rotation needed to point a vector in the direction of (0,-1,0)?

polar acorn
west obsidian
#

no, like if I have a unit vector (x,y,z)

#

how would I find the angles to rotate that vector so that it aligns with (0,-1,0)

gaunt harbor
rich adder
kind bramble
#

how do i fix the postion because when the codes start the objectiv is rotated and in the ground. But i fixed the Rotation but i can seem to fix the Position. Can someome help me?

eternal falconBOT
rich adder
#

also you cant make up functions and expect them to work

gaunt harbor
west obsidian
rich adder
#

also dont screenshot code next time, use the code formatting / link

kind bramble
#

ok

rich adder
eternal needle
west obsidian
#

no

#

it has to do with a transform

#

I just need to find the angle

eternal needle
#

Vector3 has a .angle method

west obsidian
#

ok, but is it on an arbitrary plane or is it euler xyz angles

eternal needle
#

UnityChanHuh wat

west obsidian
#

if I have 3 axis

#

axes

#

y is up

eternal needle
west obsidian
#

and I have some arbitrary unit vector

young smelt
#

Hey I plan on making a gameElementsManager of some sort to help make designing my game a lot easier. I want to be able to just add from my list of enemies to the scence when I right click on the heirachy window. I want to be able to just add playerElement to the list of playable characters and have it reflect on everywhere with a send of probably provided animations in it's own animation controller. I also want to implement my map generation feature. I have no idea how to start with creating it as I am used to just draging and dropping everything thing into the scence. I need help on an explanation on how to go about with starting to design it or a link to some tutorial could also help

eternal needle
#

Then take a minute to think about what you need. You asked for the angle, I gave you a method for the angle

west obsidian
#

I need 2 angles

#

2 rotations along the x and y axes

eternal needle
#

Ask it in terms of your game, not in terms of code. What are you actually trying to do in your game?

#

None of this "I want angle xyz euler this that", what is the gameplay mechanic

rich adder
#

there is probably a better solution to the problem

#

but we dont know the problem if you ask solution for Y when you're solving X

west obsidian
rich adder
#

xy problem incoming 😏

west obsidian
#

if I have 2 points, A and B, and an initial velocity v, and an arbitrary gravitational acceleration g, with gravitational vector G, then what is the velocity vector to send the object from a to b

west obsidian
#

not at all

#

gravity exists

polar acorn
#

That's the direction between two points

west obsidian
#

yes I am aware

polar acorn
timber tide
#

in before remove an axis and rotate and be done with it all

young smelt
west obsidian
#

I did the math, and figured out the equation for the trajectory in 2D

eternal needle
rich adder
#

i hate reading

west obsidian
#

since a plane can go thru any 3 points, I want to rotate the plane to 2D so I can do the trajectory calculation

west obsidian
young smelt
polar acorn
rich adder
timber tide
#

yeah, call it game manager and make it a singleton

polar acorn
#

then you can add more and more

#

until it's done

west obsidian
#

nvm Im going to a math server they can probs understand better what I need

young smelt
rich adder
#

leaving aside all the mathy shit you're trying to portray

polar acorn
rich adder
#

it sounds like that Ikr

young smelt
eternal needle
rich adder
west obsidian
polar acorn
eternal needle
west obsidian
#

alright then

#

hold on

timber tide
#

i need like 12 more credit hours for a bachelors in math but I can't be bothered. Maybe if quaternions start kicking my butt harder I'll reconsider.

eternal needle
#

Anyways it's better to ask in a unity context because there are specific methods that exist, in a math discord they may just think you are doing all steps yourself

eternal needle
dusky bay
#

mind if I put my problem in here too?

dusky bay
west obsidian
#

(oh ya, forgot to add, using unity's rotation order)

eternal needle
# west obsidian https://www.desmos.com/3d/cefa2669ea

How come you need it by individual axis? If we are talking about any vector at all then sometimes it would be the Z axis you rotate. Anyways you can get this result by doing Quaternion.LookRotation and I guess converting to the euler angles. Although theres no guarantee x and y have values while z is 0.

west obsidian
#

I dont mind, any axis works really

eternal needle
#

Working with eulers are kinda shitty in some cases

dusky bay
#

So I have this problem that's really bugging and confusing me. I made a door script where if you press F on it, it will play an animation of it closing or opening, I did this using Animator Booleans. This is used by 2 scripts, one which has the method of Opening and closing and then another Interact script which checks if I'm pressing F on something Interactable and if so, it will call the necessary function.
This is the Door Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DoorOpenFront : MonoBehaviour
{
    public bool IsOpen = false;

    public AudioSource OpenSound;
    public AudioSource CloseSound;
    public Animator animator;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void Open()
    {
        OpenSound.Play();
        animator.SetBool("Open", true);
    }

    public void Close()
    {
        CloseSound.Play();
        animator.SetBool("Open", false);
    }
}

Tell me if you want a look at the Interact script.

timber tide
#

I removed about 40 eulers methods last week and replaced all with AngleAxis if that answers some questions how much trouble I've dug with eulers

dusky bay
eternal needle
#

Oh yea AngleAxis exists too

west obsidian
# eternal needle Better to remake something now rather than continue with a suboptimal solution

considering you claim you have a math major, could you maybe see if there is a simpler approach to something after all? I have 3 points, being point A (initial pos) point B (target pos) and the gravity vector, and I want to orient all of these points in such a way that A is at the origin, and the gravity vector (normalized) is equal to Vector3.down, I just need the transformed location of point B

#

please ask away as I seem to be terrible at clarifying stuff

rich adder
#

also SS Animator states/transitions

dusky bay
dusky bay
rich adder
west obsidian
dusky bay
rich adder
#

dot product is the easiest though

eternal needle
dusky bay
west obsidian
rich adder
dusky bay
eternal needle
#

Theres also more to consider because you can launch an object at different heights and still achieve the same result. So its up to you to decide what trajectory height you want

west obsidian
west obsidian