#💻┃code-beginner

1 messages · Page 116 of 1

lethal depot
#

i'm getting this another warning: enemyai.sensitivity is never used

wintry quarry
#

Yep just a warning saying you're not using the variable

#

Because you aren't

hoary karma
#

what's wrong?

neat bay
#

Is there a setting I can enable that allows objects to pass through eacchother but still register contacts?

languid spire
#

yes

neat bay
#

but you still need a rigidbody for that to work right?

languid spire
#

yes

neat bay
#

so how do I make the rigi body pass through objects while still registering collisions?

languid spire
#

If the collider is marked as Trigger. It will register Trigger events but will not obstruct movement of the rigidbody

neat bay
#

ohh I see

#

thank you

north kiln
merry spade
#

FIXED

I have problems with the Camera, its stuttering and lagging, I dont know from where this comes, this prototype is an early development stage so there arent many scripts that could cause that stuttering and I'm moving the Camera in Late Update

    private void Start()
    {
        isGameActive = true; // change later
        Cursor.lockState = CursorLockMode.Locked;
    }


    private void LateUpdate()
    {



        if(isGameActive)
        {
            moveCameraOnMovement();
        }

    }


    private void moveCameraOnMovement()
    {

        currentX += Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
        currentY += Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

        currentY = Mathf.Clamp(currentY, YMin, YMax);

        Vector3 Direction = new Vector3(0, 0, -distance);
        Quaternion rotation = Quaternion.Euler(-currentY, currentX, 0);
        transform.position = playertransform.position + rotation * Direction;

        transform.LookAt(playertransform.position);

    }
#

playertransform is the transform component of the player seen in the video

fluid kiln
#

if i add a script component to an item, does it trigger the "start" function when it gets added?

teal viper
merry spade
teal viper
merry spade
#

oh ok

#

Its jumping fourth and back

#

even if this is the only script in my scene

fluid kiln
# teal viper Yes, it should.
public void Start()
    {
        // Reference to this object
        myObject = gameObject;
        
        // Reference to the EnemyAI component attached to this object
        enemyAI = myObject.GetComponent<EnemyAI>();

        // Load the VFX prefab from resources
        vfx = Resources.Load<GameObject>("Starburn");

        // Load the required stats from resources
        haste = Resources.Load<Stat>("Haste");
        power = Resources.Load<Stat>("Power");
        mana = Resources.Load<LimitedStat>("Mana");

        // Set initial stats based on loaded values
        tickFrequency = 1 - haste.GetAmount() / 2000f;
        damage = 1 + power.GetAmount() * 0.1f;
        duration = baseDuration;

        // Instantiate VFX and set its parent to this object
        vfxInstance = Instantiate(vfx);
        vfxInstance.transform.SetParent(transform);

        // Start the Activate coroutine
        StartCoroutine(Activate());
    }```

Oh cause its gets attached but it doesn't seem to get the needed things
teal viper
ruby python
#

@merry spade try commenting out the LookAt line for a moment and test, I've found that sometimes LookAt causes the camera to 'flip' and produce undesirable results.

merry spade
#

should I send a video of it?

fluid kiln
#

but it doesn't take the needed things

teal viper
fluid kiln
#

well it does take the enemy ai aswell, but it doesn;t take the the scriptable objects stats nor the prefab so the issue seems to be on the "resources.Load" rows

languid spire
languid spire
#

right, so why would you expect Resources.Load to work when you are not using the correct folder structure?

fluid kiln
languid spire
#

you need to go and read the documentation

teal viper
#

The first line of the docs.

fluid kiln
#

thank you guys!

#

uhmmm it seems to be working now with the prefab but not the SO's

#

i tried like this mana = Resources.Load<LimitedStat>("ScriptableObjects/Stats/Mana.asset");
and this
mana = Resources.Load<LimitedStat>("ScriptableObjects/Stats/Mana");

#

fixed it

#

just had to use the player prefab and its statmanager component instead

neon dome
#

Anyone have the right component values for drifting wheel colliders?

deep bear
#

If I have a reference to another GameObject's button like this inside another object's script, can I get access to the button's on click function and add functionality within this script?

languid spire
#

button1.AddListener

deep bear
analog torrent
#

hello, how do i make the program give me suggestion so i don't need to write the entire line (im using visual studio code)

eternal falconBOT
woven crater
#

any tutorial on how to make an item system like one in binding of isaac / slay the spire artifact that uniquely affect the gameplay? i dont know if i should use scriptable object for this cuz the item should be different in the functionality. well except sprite/description

frosty hound
#

I would use SOs personally

woven crater
#

Thought the intended use of SOs is to create multiple instances of it

#

But each item gonna have a whole different function that change different aspects of the game

analog torrent
#

which one should i download for visual studio?

frosty hound
#

Just install it through Unity Hub, it'll auto configure it as well.

teal viper
analog torrent
#

alright.

frosty hound
woven crater
#

thank very much

stuck palm
#

When you have a collision, can you measure the speed of the collision with oncollisionenter?

jovial sandal
#

does some1 has a link to a tut where u can make a good ai i made a few but there just ret..d

eager elm
stuck palm
#

Relative to what?

eager elm
#

to each other

neat bay
#

is there a way to serialize a 2 dimensional array so it can be edited in the inspector?

teal viper
#

Not very convenient to edit

frozen sedge
#

any ideas why on earth start wave isnt being called?

#

handle picked up is called

#

i put a print in there so i know it is

neat bay
teal viper
neat bay
#

how so?

teal viper
teal viper
frozen sedge
teal viper
#

Which you can just have 2 vectors for. Or a matrix

neat bay
#

yeah, 2 wide, and just expand dwon is how I woudl imagine it

frozen sedge
#

could that be causing an issue

teal viper
neat bay
#

yeah I guess, but if its not possible then its fine

#

thanks anyway

teal viper
eager elm
frozen sedge
teal viper
eager elm
neat bay
frozen sedge
#

it errors and says this

teal viper
# frozen sedge yes

Then you probably don't have anything subscribed to it. Can you share the whole code properly?
!code

eternal falconBOT
neat bay
#

so I'm making a semi rhythm based game that includes flying and I want to be able to control at what time and speed the velocity changes with 1 array

#

it works with 2 but i just thought a 2d array would be a better way

frozen sedge
teal viper
strong wren
#

It is, but are you sure that's the same instance?

frozen sedge
#

hmm i set the instance during start

neat bay
#

Ok, thank you

eager elm
eager elm
strong wren
#

Instance of pickup. Accessing your singleton instance would throw a null before the assignment to the event

teal viper
#

Maybe share the whole script. As there are a few things unclear.

frozen sedge
#

i wil change to awake and see if that helps

eager elm
frozen sedge
#

whats called after start

#

i realized i set onpickup to null during start

#

so on enable i add an action to on pick up

#

but when starts called, it wipes that out

frozen sedge
#

i fixed it now

eager elm
teal viper
#

That's why you share the whole code...

frozen sedge
strong wren
#

Update 😛

eager elm
# frozen sedge Ah, so what comes after start

nothing comes after Start, you should use Awake() for setting up everything on itself and Start() for setting up things with other objects. If you need more control you can have 1 script that calls those setups one after another:

void Start()
{
    manager1.Setup();
    controller.Setup();
    player.Setup();
}```
jovial sandal
#

does some1 have a idea how i can make a seprate inventory for every player i am using netcode

mental gull
#
using System.Collections.Generic;
using UnityEngine;

public class jumpanim : MonoBehaviour
{
    // Start is called before the first frame update

    public Animation jumpanimation;
    public AnimationClip jump1;
    public AnimationClip jump2;
    public float timer;
    public float animno;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space)) { jumpanimation.Play(); }

        if (Input.GetKeyDown(KeyCode.Space) && jumpanimation.isPlaying)
        {
            jumpanimation.Stop();

            {
                if (timer < animno)
                { timer = timer + Time.deltaTime; }

                else
                {
                    jumpanimation.clip = jump1;
                    jumpanimation.Play();
                    jumpanimation.clip = jump2;
                }

                  
            }
    
        }

        if (jumpanimation.clip == jump1) { Debug.Log("anim2 playing"); }
    }
}

SOMEONE HELP why no anim playing but still no error

#

im rly rly new to coding

#

someone an fix it for me

strong wren
jovial sandal
#

thx

eager elm
swift crag
#

yes, the two methods are called in sequence

frigid sequoia
#

Ey, a quicky here; is there a way of like, make the player input on keyboard axis to be more smooth, and not just go almost instantly to 0 to 1?

frozen sedge
burnt vapor
swift crag
#

consider Mathf.MoveTowards / Vector2.MoveTowards

rich adder
swift crag
#
Vector2 from = Vector2.zero; // [0, 0]
Vector2 to = Vector2.right; // [1, 0]
Vector3 smooth = Vector2.MoveTowards(from, to, 0.1f); // [0.1, 0]
hallow heath
#

Hello, I am using 2023.2.3f1. when I selected gameobject in hierarchy, it reset serializefield enum property in the component. is this a bugs?

swift crag
#
current = Vector2.MoveTowards(current, input, Time.deltaTime);

this will move current towards input at a maximum rate of one unit per second

swift crag
#

Although, I guess I am on 2023.2.2f1, not 2023.2.3f1 😛

hallow heath
#

I notice this is happen if I selected multiple gameobject in hierarcy, then all enum property I've set, back to default.

swift crag
#

Do you have any custom editor code?

hallow heath
#

No

swift crag
#

That sounds like incorrect multi-object editing behavior

severe drum
#

im trying to make a dialog system for my roguelite, somethng like hades where when you enter a room event characters talk. i made a list of dialogs objects and i plan to get one dialgo randmly based on what characters are on the event. im having troube to find a way to filter my list of dilogs. like: "I want a dialog with character X and Y "

woven crater
#

can i create a copy of a scriptable object so i can modify it without effect the original?

swift crag
swift crag
woven crater
#

like this ?

swift crag
#

then you could filter all of your dialogue sets

#
dialogueSets.Where(set => set.characters.Contains(theDude));
#

(this is using LINQ)

severe drum
swift crag
swift crag
woven crater
#

its not affect weaponatt by anymean

swift crag
#

show your code

#

the whole script, ideally

severe drum
#

just the filter im trying to solve

swift crag
#

well, you'd better put some more information in dialogController

#

AllDialogsInLibrary.Where(controller => controller.characters.Contains(theDude)) will give you a sequence of every dialog controller where its characters list includes theDude

eager elm
swift crag
#

That sounds like a better idea, yes.

#

Weapon can also reference WeaponDataSO, and just store changes to that base data

#
public class Weapon {
  public WeaponDataSO definition;
  public int upgradeCount;

  public float Damage => definition.damage * (1 + upgradeCount * 0.2f);
}
#

Each upgrade adds 20% more damage

woven crater
swift crag
#

hm, but it shouldn't be happening in 2023.2.3f1

hallow heath
#

Oh thats found in 2022.3.2f1, i thought its 2023.2.3f1. Hmmm

#

i'll try in 2023.3

swift crag
#

the bug was reproduced in several editor versions

#

but it was fixed in 2023.2.0b17, which ought to mean it's not in 2023.2.3f1

hallow heath
#

It says fixed in 2023.2.0b17, but the bug still happen in 2023.2.3f1

woven crater
#

modify the copy seem to only effect the SOs object instead of instance created in weapon class

swift crag
#

Gruhlum suggested using two separate classes

#

also, you still haven't shown me your code, so I don't know what you're doing

woven crater
#

ah sorry

#

!code

eternal falconBOT
swift crag
eager elm
#

although it should be
[System.Serialize]
public class Weapon {

swift crag
#

oops

#

keyword moment

#

there we go

#

you want to separate the definition from the runtime data

woven crater
#

the seccond one is where i use the weaponatt

swift crag
#

Do you already have something assigned to the weaponatt field?

#

You're instantiating weapon in the Start method of WeaponHandle

#

and getting weaponatt in the Start method of weaponattributeHandler

#

If the second Start starts first, it'll run before you instantiate the SO in the first Start method.

#

and it'll get whatever was serialized in the weaponatt field

swift crag
#

It's also how I've done exactly this in the past (:

#

i made a game for a jam with mostly-procedurally-generated weapons

#

the base data for a weapon lived in a ScriptableObject, and then the upgrades were tracked separately

woven crater
#

ah i see the problem now. i mistake the object assign in weaponatt is the clone and yes after that fix it seem that weaponattributehandler run first and return null here

woven crater
swift crag
#

or maybe WeaponData or WeaponConfig

severe drum
swift crag
#

I see two options:

  • Weapon MonoBehaviour that references a WeaponBase ScriptableObject and holds all of the upgrade data
  • Weapon MonoBehaviour that references a WeaponConfig object, which holds the upgrade data. WeaponConfig references a WeaponBase ScriptableObject
#

The latter would make it easy to save and load weapons

#

just make WeaponConfig serializable

#

Weapon would need a method to build the weapon's visuals and reset stuff

#

which you'd call after installing a new WeaponConfig

woven crater
#

when you say Weapon class you mean Weaponhandler or create new script called Weapon?

swift crag
#

The class you've called Weaponhandler, yes

#

If it represents a weapon, name it Weapon

#

(also, you should PascalCase your class names)

#

WeaponHandler, WeaponExplosionWidget, etc.

woven crater
#

yeah i know ;w; i should start doing that from now

#

thank you much Fen

#

thats very helpful

sage cave
#

ill try to explain my problem the best i can
in a function, i have an object that i want to move smoothly to another position. the problem is that it isnt in the update function and the function runs when i press a button. ive tried my best to research but due to my lack of skills in explaining, i cant find anything.

swift crag
#

You need to set a field when you push the button

#

then, in Update, move the object if the field is set

sage cave
#

so like, a bool?

swift crag
#

yeah

sage cave
#

i was thinking of that but it just seems so... how do i say this. unpractical???

swift crag
#
private bool moving = false;
[SerializeField] Transform moveMe;
[SerializeField] Vector3 destination;

void Update() {
  if (moving) {
    moveMe.position = Vector3.MoveTowards(moveMe.position, destination, 10 * Time.deltaTime);
  }
}

public void StartMoving() {
  moving = true;
}
#

i mean, how else would you do it?

#

you need to do something over the course of several frames

#

so you need to remember something from frame to frame

#

You could also use a coroutine, which lets you write code that suspends and resumes

#

or use a library like DOTween that does roughly the same thing

sage cave
#

i hate spaghetti code and this seemed unpractical for me, so i avoided it (man i am stupid)
but thanks for telling me its fine to use it

#

i even hesitated to put it in code-general because of it

swift crag
#

"spaghetti code" happens when you have lots of weird dependencies

#

like if this class had 15 different moving variables and 6 destinations

#

and some of the variables affected each other

sage cave
#

alrightie
well thanks again and sorry in advance

#

for... being a burden???? its such a simple answer, i think i just overthink too much

swift crag
#

don't sweat it :p

#

people are here to ask and answer questions

sage cave
#

thanks a lot man God Bless and Merry late Christmas

cosmic quail
swift crag
#

that's what the bug report says, yes

#

fixed in 2022.3.14f1

#

It's possible that there was a regression in 2023.2.3f1

#

I can check that later

terse raven
#
using UnityEngine;
using UnityEngine.UI;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 20;
    int boardMoveSpeed;

    bool onBoard;

    public GameObject mainPlayerObject;
    public Rigidbody2D mainRigidbody;

    private void Start()
    {
        
    }

    private void Update()
    {
        CameraRotation();
        PlayerMove();
    }

    void CameraRotation()
    {
        Vector3 mousePos = Input.mousePosition; //get mouse position

        Vector3 objectPos = Camera.main.WorldToScreenPoint(transform.position); //change to world space
        mousePos.x = mousePos.x - objectPos.x; //Use trig and differences to find the angle to the mouse
        mousePos.y = mousePos.y - objectPos.y;

        float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg; //remember to convert to degrees
        mainPlayerObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); //set rotation
    }

    void PlayerMove()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float y = Input.GetAxisRaw("Vertical");

        Vector2 force = new Vector2(x * moveSpeed, y * moveSpeed);
        mainRigidbody.AddForce(mainRigidbody.transform.forward * force);
    }
}
#

Hi everyone I have this script and I want the player to move in the direction that they are facing

#

however I can't seem to get it working

#

In the player move function I have managed to get the x and y inputs no problem but when I try to implimnent the force with a direction the player doesnt even move at all? any thoughts?

swift crag
#

how do you know you've gotten the x and y inputscorrectly?

terse raven
#

using debug.log

swift crag
#

okay, good

terse raven
#

I still get 1, -1, 0 ect

swift crag
#

You're modifying the rotation of the player transform directly whilst also trying to use a rigidbody

#

this can cause problems: you're fighting the rigidbody

terse raven
#

So I should be rotating the rigidbody?

swift crag
#

i would suggest setting mainRigidbody.rotation instead

terse raven
#

ahhh

swift crag
#

also, that's a pretty weak force

#

well, sorta

#

one thing to check: look at the inspector for this component

#

make sure that moveSpeed is 20, not 0

terse raven
#

yes I've done that, I came across that earlier. Ill try test this

swift crag
#

that would've happened if you added the initializer after attaching the component

#

unity will remember all of the values in the inspector

#

so if you started without an initializer, the default value would've been 0

terse raven
#

I see. I've changed the playerObj to the rigidbody rotation now too. Still no luck.

swift crag
#

the other thing is that I don't really understand mainRigidbody.transform.forward * force

#

can you even multiply a Vector3 and a Vector2 like that?

#

oh, you can!

terse raven
#

apparently so. I wanted to add a force in the direction the player was facing

swift crag
#

it's just promoting the Vector2 to a Vector3

#

then multiplies each pair of elements together

#

That is not what you want

#

You want to do this:

#
transform.TransformVector(force);
terse raven
#

okay lay it on me

swift crag
#

This converts a vector from local space to world space

#

If the object isn't rotated or scaled, this will do nothing

#

If it's rotated, the resulting vector will also be rotated

terse raven
#

okay so in the add force it would be mainRigidbofy.transform.forward * TransformVector(force)?

swift crag
#

no, just transform.TransformVector(force)

#

Multiplying the vectors isn't meaningful here

#

[a, b] * [c, d] is [a*c, b*d]

terse raven
#

Ohhhhh!

swift crag
#

also, transform.TransformDirection is probably more correct

terse raven
#

that would be the forces multiplying would make the force 0

swift crag
#

that doesn't care about scale

#

If you use TransformVector, scaling up your player will make you move faster

swift crag
#

Make sure the scene view is set to "Pivot" and "Local" modes

#

and press W so that you see the arrow handles

#

The arrows show you the local axes of the selected object

#

Press X to switch to Global mode. The arrows are now world-space directions

terse raven
#

alright perfect, but for some reason my w a s d is no reversed? A and D are doing forward and backward and vise versa. I can see the arrows now too which is good

swift crag
swift crag
#

red -- X -- right
green -- Y -- up
blue -- Z -- forward

#

in 2D games, the Z axis usually points into the screen

#

so your two arrows will be red and green

#

If you move in the positive X direction in local space, you move along the red arrow

#

and if you move in the positive Y direction in local space, you move along the green arrow

terse raven
#

yes I understand

swift crag
#

So you might need to adjust how your character's graphic is rotated

#

if the character faces in the local +X direction, holding W will appear to make you strafe left

terse raven
#

OHHHHHH!

swift crag
#

in 3D, it's obvious -- the character should face forward

#

I guess people usually make a 2D character face upwards

#

like so, where the little cube is the direction you appear to be facing

#

If you set your character up like this, holding W still makes you move along the green arrow

#

so it'll look wrong

terse raven
#

Thanks so much for ur help

#

basically like a full crash course on forces and charatcers lol

swift crag
#

no prob (:

#

getting a good handle on your axes is really helpful

#

i don't have to guess-and-check very often

#

(except when trying to attach a gun to a character's hand. i always do that wrongly)

terse raven
#

anything else you'd suggest I look into as a beginner

#

like basics mechanices

#

oops

swift crag
#

too many links NOOO

#

I used to struggle to get collisions and triggers working on the first try

terse raven
#

I remeber a while back when I first touches on physics in 3D and my mind was blown with how much stuff there was which is why I've shifted into 2D for the time being.

pastel sinew
#
(In Awake())
_actions.Drone.Yaw.performed += OnYaw;
...
(called in Fixed Update)
private void Rotate()
    {
        // Adjust rotation based on input
        float rotationAmount = _rotationInput * _rotationSpeed * Time.fixedDeltaTime;
        Quaternion deltaRotation = Quaternion.Euler(Vector3.up * rotationAmount);
        _rigidbody.MoveRotation(_rigidbody.rotation * deltaRotation);
    }
...
    public void OnYaw(InputAction.CallbackContext value)
    {
        _rotationInput = value.ReadValue<float>();
        Debug.Log($"Yaw: {_rotationInput}");
    }
...

Using this setup my character object keeps spinning when I stop making new inputs. Shouldnt the Input system send 0.0 in the value at that point?

#

Not using a player input component.

slender nymph
#

if you are only subscribing to the performed event then it won't call OnYaw when you cancel the input (release the keys)

#

subscribe to the canceled event too

pastel sinew
wintry quarry
#

I find it can be cleaner simply to read the value in Update rather than using events for this kind of input handling

#

This is continuous input

pastel sinew
#

Still spinning.

queen adder
#

hi

#

when i put in my dmg overlay variable, it says "type mismatch"

#

here is my code

#

wait

#

!code

eternal falconBOT
slender nymph
queen adder
#

here is my code

rich adder
queen adder
#

ahh

rich adder
#

told you this b4

#

dont store reference types like that at least.

slender nymph
queen adder
#

well

rich adder
#

use prefab

queen adder
#

prefab?

rich adder
#

that has the panel

#

you want

#

then spawn the panel

queen adder
#

makes sense

pastel sinew
queen adder
#

thanks

rich adder
#

goodluck 🙂

slender nymph
narrow ore
#

does anybody know how to change the amount of times per second that fixedUpdate is updated?

rich adder
#

its in the physics section

pastel sinew
narrow ore
#

is there a way to do it on a script by script basis

rich adder
#

why

narrow ore
#

i'm trying to make a rhythm game

slender nymph
rich adder
#

sounds like poor design

pastel sinew
narrow ore
rich adder
#

and why you want it different for each script

#

you can also just make your own version of fixed update/ updates anyway

narrow ore
#

because if I have it set to 60 instead of 50, it'll make it way easier to subdivide seconds

rich adder
#

sure if you make a custom method, make your own tickrates

#

kinda advanced

narrow ore
#

idk how to do that unfortunately

#

yeah

#

i mean there's a reason i'm in the beginner channel

#

the extent of my knowledge is a basic understanding of C#

rich adder
#

just change it to 60 if you want 60

narrow ore
#

i'm not seeing it

#

you know what it's labeled as?

queen adder
#

so i made a new prefab and stored my image object from the scene into the asset

#

and then used said asset for the inspector's parameters

rich adder
#

iirc you can also change the Physics update rate to Update loop instead of FixedUpdate

#

at your own risk on that though

narrow ore
#

What’s the difference?

queen adder
#

however when i interact with the death cube (which calls the set health function) my damage overlay stays invisible

slender nymph
rich adder
#

that would be 32 bit color

#

Color is 0-1
Color32 0-255

queen adder
#

ohh

#

thank you

#

still invisible :(

pastel sinew
#

Works now.

#

Now Ill have to fix the Move() and Elevation().

#

Thank you @slender nymph.

rich adder
#

wait nvm

queen adder
#

here is my new code for reference

slender nymph
#

why are you increasing by a specific number like that rather than a number multiplied by deltaTime? or do you not care that those with higher framerates will increase the Health variable faster?

queen adder
#

ah, ill change that then

#

still wont fix my problem however

austere osprey
#

guys how do i fetch the sprite needed for a reference in my script?

#

like normally i would just drag it into the reference slot in my gameobject but it's a prefab

slender nymph
#

are you trying to reference something inside the scene from a prefab?

austere osprey
#

i'm trying to reference a sprite that's in my sprites folder

rich adder
wintry quarry
slender nymph
wintry quarry
#

note the difference between a Sprite and a SpriteRenderer though

austere osprey
#

oh wait

#

im stupid

#

nvm

queen adder
rich adder
queen adder
#

oh

#

ahhh the update doesnt run

#

but the function does

#

because this script is not embedded in any object

#

idk where i'd put it though

wintry quarry
#

If this is a MOnoBehaviour then it can ONLY exist on an object

#

if it's not a MonoBehaviour then it can't b e attached to an object

queen adder
#

scriptableobject

#

oh

wintry quarry
#

ScriptableObjects don't use Update

#

they are more or less data containers

queen adder
#

well this is a new conundrum

wintry quarry
#

not really

#

if you need something to run every frame

#

put a monobehaviour on a GmaeObject in the scene

#

with Update

#

it can call a function on some other object if needed

queen adder
#

can we put behaviour in particals in a particale system?

wintry quarry
#

No

rich adder
glass urchin
#

reading some decompiled code. what does int num = this.armed ? 2000 : 30; mean

#

armed is a bool

rich adder
#

if its armed then num is 2000

glass urchin
#

I see

#

thanks

rich adder
#

its just a fancy if else

swift crag
#

the name is a bit silly

#

"ternary operator" means it operates on 3 things

#

like how "binary operator" means it operates on 2 things

#

it's like calling + the binary operator or ! the unary operator

glass urchin
#

what is Object.op_Equality and Object.op_Inequality?

#

I'm seeing it in some netcode parts here and I'm not sure what it does.

rich adder
#

also this isn't the place

glass urchin
#

That's a rude way to refuse to answer.

eternal needle
eternal needle
#

Looking at decompiled code will be mostly useless for your learning as well

clear seal
#

is it possible to make a script scene replacable?

queen adder
#

use a string variable

eternal needle
green island
#

im making an multiplayer game and the player needs to instantiate something onto itself but the client cant do that so i need a funktion that gets called when a player joins and get his gameobject

rich adder
robust condor
#

What size does a "private GameObject[] enemies" have?

slender nymph
#

whatever you assign to it when you create the array

rich adder
green island
robust condor
#

@rich adder"Arrays have a fixed size that is set when they are created, while lists can grow or shrink dynamically as items are added or removed."

queen adder
#

once you make the array, you cant change the size anymore, that's all there is to it. Unlike list where you can just add stuffs later

slender nymph
narrow ore
#

does anyone know how to write a script that stores the time elapsed in seconds?

slender nymph
#

have you googled it?

narrow ore
#

yes

viral sapphire
robust condor
#

@queen adderBut I can append stuff to it and it grows

slender nymph
slender nymph
rich adder
#

Unity inspector also initializes the array for you

#

so =new is redundant when public/serializefield

robust condor
#

Okay so unity set a size of the array? Because I could most def append to it when it was public

queen adder
#

we're lost

slender nymph
#

you cannot append to an array without creating a new array with the larger size

viral sapphire
#

how do i change the resolution of the window

#

or the camera

#

im using 2d btw

rich adder
#

the camera in scene ?

viral sapphire
#

yea

rich adder
slender nymph
#

the camera's size is determined by not only the game view's resolution but also the orthographic size on the camera

robust condor
#

This is what I did for testing before changing to list and events:

public GameObject[] _NPCs { get; private set; }

protected override void Awake()
    {
        base.Awake();

        _NPCs = GameObject.FindGameObjectsWithTag(npcTag);
}

  private void LateUpdate()
    {
        _NPCs = GameObject.FindGameObjectsWithTag(npcTag);
        Debug.Log("Found NPCs: " + _NPCs.Length);
    }

And this incremented as I spawned more npcs

#

the awake returns 0 as there are no NPCs

queen adder
#

Find is making new array each time

slender nymph
#

you're also creating a lot of garbage by calling that every single frame

robust condor
#

Yeah I know it is bad, which is why I changed it

glass urchin
slender nymph
rich adder
slender nymph
glass urchin
#

legal decompiling should be discussable

rich adder
robust condor
#

@slender nymphYeah I am doing that now

slender nymph
desert elm
#

question-
how do I write a quarterion if I just want it to be 0, 0, 0?

languid spire
#

Quaternion.identity

desert elm
#

nvm

languid spire
#

which is, btw, 0,0,0,1

desert elm
#

figured a different solution out

robust condor
#

So do I need to instantiate this: public List<GameObject> _NPCs { get; private set; } ?

#

Because this is not working in Start(): _NPCs.AddRange(GameObject.FindGameObjectsWithTag("NPC"));

rich adder
#

properties are not serialized by unity

languid spire
#

declare an explicit backing field and new() that

robust condor
#

I don't know what that means

languid spire
#

so you are using properties and have no idea what they are?

slender nymph
#

you don't even need an explicit backing field unless you want to turn that into a full property. just slap an = new() on the end of that line

desert elm
robust condor
#

I don't know what " explicit backing field" means, no

rare basin
#

Then Google it?

rich adder
#

public List<GameObject> _NPCs { get; private set; } = new()

#

just do that

#

don't put _ for properties tho

dawn owl
#

why cant i do += here? how could i make it that it takes the previous value of hue and adds colorChange every time that code runs?

float newHue += hue + colorChange;
rich adder
#

you cant do += before assigning it

slender nymph
#

how would += even work there? newHue has no value until it has been assigned

languid spire
#

because you are declaring a new variable

dawn owl
#

ohh

#

i see

robust condor
#

@rich adderCan't use with tuple type

slender nymph
# dawn owl ohh

also even if it did have its default value, that would be just 0 and 0 += anything == anything so the += is still pointless

rich adder
#

where?

robust condor
rich adder
#

what ur doing i have no lcue

robust condor
#

Your code new()

rich adder
#

are u on

slender nymph
robust condor
#

Unity 2023.2.3f1

rich adder
robust condor
#

public List<GameObject> _NPCs { get; private set; } = new ();

rich adder
#

ohh the space?

slender nymph
#

that should work just fine unless you've gone and done something weird

robust condor
#

Even without space

rich adder
#

nvm im buggin lol

robust condor
#

new List<GameObject>() works tho

rich adder
#

are you sure about that unity 2023 ?

#

did you switch .net version or something

robust condor
#

Thats what it says in the editor

#

I did nothing

rich adder
#

weird

#

it should work fine, without...strange..
dont mind gray part editor does it auto

robust condor
#

Where can I see C# version?

rich adder
#

see it should be 9

languid spire
slender nymph
# robust condor Where can I see C# version?

go to Edit > Project Settings > Player > Other and find the Api Compatability Level setting in the Configuration category in there and screenshot what you see, preferably the entire Unity window with that setting visible

robust condor
#

I am still using visual studio 2017, can it be why?

languid spire
#

yes

slender nymph
#

why are you using such an old version of visual studio?

robust condor
#

Because unity was crying about visual studio code being deprecated lol

slender nymph
#

so you went and installed a 6 year old version of visual studio instead of the latest version that works perfectly fine? 🤔

robust condor
#

Gonna update it I guess

#

It was what was installed

slender nymph
#

you're like 2 major updates behind, even 2019 was installed by default with unity for the longest time

fluid kiln
#

how would you guys create an item system where items drop with randomly generated modifiers?

rich adder
robust condor
#

I donno why they would drop VSC support tho

#

Kinda sad

rich adder
#

cause its ass

fluid kiln
slender nymph
fluid kiln
rich adder
fluid kiln
rich adder
#

many ways to do something yes 😄

fluid kiln
#

not to randomly generate stats, but to define what an item is and what a modifier is

fluid kiln
rich adder
#

as long as you write proper extensible code

robust condor
#

VSC is the best editor I've used, but studio might be better for unity I guess once you learn it

fluid kiln
rich adder
#

maybe its kewl for like Web/JS

summer stump
faint agate
#

Helo can someone help me with something

faint agate
#

Im not sure how to get the drag and other options by the top left instead of it being on the play screen

rich adder
faint agate
rich adder
#

not code question

eternal needle
faint agate
# faint agate

How do I get these options to the top left like drag n stuff

#

Its stuck on the play screen

slender nymph
#

wdym by stuck on the play screen?

robust condor
#

So continuing with my npc manager I have this right now:

    private void Update()
    {
        for (int i = 0; i < _NPCs.Count; i++) {
            AIBrain AIBrain = _NPCs[i].GetComponent<AIBrain>();
            AIBrain.DoNextTask();
        }
    }

Is there a better way to call 1000+ npcs to do their thing? Should I use events on every NPC instead?

eternal needle
shrewd swift
#

tell me if im wrong

the out keyword is a way to return a value and set it in a variable ?
its useful if you want to return multiple values without using a tuple or somethign else as the return value

other question : does the out return when reaching the end of the function ? or can it return earlier if not used anymore until the end ?

example :
with out:

void Start()
{
  int enemyCount = 10;
  modifyEnemies(out enemyCount);
  // "enemyCount" is now 5
}

private void modifyEnemies(out int numberOfEnemies)
{
  numberOfEnemies = 5;
}

usual "return" way:

void Start()
{
  int enemyCount = 10;
  enemyCount = modifyEnemies();
  // "enemyCount" is now 5
}

private int modifyEnemies()
{
  return 5;
}
amber spruce
#

how do i set smth to active if its within a certain range if it isnt then i set it to false

robust condor
#

@eternal needleIn the same list? Like a tuple or what?

eternal needle
eternal needle
robust condor
#

@eternal needlepublic List<GameObject> _NPCs { get; private set; } = new ();

eternal needle
rich adder
slender nymph
robust condor
#

Will I not lose the ability to access the gameobject if I need to then?

rich adder
#

no

#

assuming its MB script

slender nymph
#

every component has a reference to its gameObject

rich adder
#

all MB scripts have gameObject / transform references of the object the script is on/belongs to

amber spruce
#

i have this for the check the range

Collider2D[] colliderArray = Physics2D.OverlapCircleAll(transform.position, ShowInteractRange, interactableLayer);
eternal needle
#

Otherwise you'll need to compare the previous and current array

amber spruce
#

alright i can figure the rest out thanks

summer stump
robust condor
#

Okay that worked, but now how do I fix this part if I am looking to add components instead? Do I need to loop through the results? _NPCs.AddRange(GameObject.FindGameObjectsWithTag(npcTag));

slender nymph
#

the best option would be to stop using FindGameObjectsWithTag

robust condor
#

I only use it in Start() tho, still bad?

#

What should I use instead?

summer stump
#

It would be better to just capture the instance when you instantiate

AIBrain prefab;

AIBrain brain = Instantiate(prefab);

_NPCs.Add(brain);

robust condor
#

But some things are already in the scene when I look for buildings I do it the same way

summer stump
robust condor
#

That will be way too many

slender nymph
#

then have them add themselves to the list at runtime

robust condor
#

Okay

stuck palm
#

how can i set the velocity of an object that has been created? i need it so an object is thrown th e same direction the player is facing

stuck palm
#

like is there a vector3.forward i can pass

slender nymph
#

get the object's transform.forward, multiply that by the desired speed and voila you now have the velocity

stuck palm
#

awesome thanks

stuck palm
#

i crashed unity

#

this crashed my unity

polar acorn
#

That loop cannot end

stuck palm
#

i thought other things would be able to run while the loop happened

#

oh well you live and learn

polar acorn
#

Literally nothing else happens until the loop ends

stuck palm
#

i see

#

well now i know thank you

rich adder
stuck palm
rich adder
steady isle
#

Can anyone link a good video to begin learning c# with

slender nymph
#

there are beginner c# courses pinned in this channel

summer stump
steady isle
#

Ok

rich adder
#

so ragdol in limb isn't doing anything for now

#

ideally Ragdoll class would just hold array of Limb

stuck palm
#

i dont need to use the action right?

rich adder
stuck palm
#

for my use case i dont think damage is necessary or the action

rich adder
#

yeah thats just for my FPS gun

stuck palm
#

i was just gonna do basically
if hit with an object faster than a given speed turn on ragdoll

rich adder
#

well Ideally you want a hit then no ?

stuck palm
#

i also dont think limbtypes is necessary for my use case either, im assuming thats for damage calculation?

rich adder
#

or are your colliders different from limbs

rich adder
stuck palm
#

i'm just gonna set up the joints

rich adder
#

yeah start with that then worry the code

stuck palm
#

is it the "character joint" component?

rich adder
#

indeed

stuck palm
#

right, i think i should make the colliders first

rich adder
#

its a painful process without the wizard 😅 but doable ofc

stuck palm
rich adder
#

I have a capsule for solid collisions and my limbs are triggers until the rigidbody is activated

#

my ray is set to ignore the solid collider

#

you dont have to do it that way ofc its for optimizations for me

stuck palm
#

its cause im using a character controller

#

so thats kinda got its own collider

rich adder
#

that would be a solid collider 🙂

stuck palm
#

yeah so i guess i'll just make colliders for the limbs now thne

rich adder
#

well regardless they need colliders

#

if they are tirgger or just solids is up to you

stuck palm
#

its hard to make changes when the colors blend in to each other 😭

rich adder
#

but CC will get in the way

#

so you have to use Layer based collision to ignore the main CC

stuck palm
#

yeah

#

thats the idea

#

shouldnt be too hard

#

i appreciate your help with this

rich adder
#

naa jus time consuming

rich adder
stuck palm
#

so the idea is, at the root have the ragdoll, each limb has a collider and limb class

#

give limb class a limb type or something

#

what then?

shadow shale
#

say i have a simple plane, i then scale it, and some function modifies the mesh and bends it/extrudes it. I would like to iterate over the new values for the vertices, but mesh.vertices doesn't change; is there an easy way to do this?

#

do i just mutiply the vertices by the scale and add position offsets if the mesh has moved?

steady isle
#

this is a rly dumb question but is vscode better than jetbrains rider for unity for coding

steady isle
stuck palm
#

helps you with code smell and just generally feels better

steady isle
#

oh ok

rich adder
steady isle
#

is free?

stuck palm
#

has direct unity integration so it has docs loaded up and stuff

stuck palm
rich adder
steady isle
#

at college or in general

stuck palm
#

to apply for github student

steady isle
#

oh bet

stuck palm
#

then you get free jetbrains products

#

you need a school ID too so

#

get that ready

steady isle
#

i aint goin throug all that im just tryna make a player than can move XD

stuck palm
#

just use VSC then

#

its not awful

steady isle
#

ok

rich adder
#

or use Visual Studio

#

which is like Rider

#

maybe a few missing features

steady isle
#

y are there so many versions of vs

rich adder
#

but close enough

rich adder
steady isle
#

dam

rich adder
#

yeah idk what they were thinking lol

stuck palm
#

@rich adder is the IDamageable class necessary for your code to work?

rich adder
#

is it necessary , no . My gun just uses that to interact with anything that has that

stuck palm
#

yeah i'll get rid of it then

rich adder
#

this way my Gun doesnt care about limbs or anything

stuck palm
#

its not necessary for my thing

rich adder
#

its still good practice to use abstractions like that

stuck palm
#

where do i apply character joints?

steady isle
rich adder
#

each limb has a joint

stuck palm
#

oh i didnt mb

#

i'll watch now

#

i was just busy getting all the limbs and colliders and rbs 😅

rich adder
potent echo
#

Hey guys, I'm making a flappy bird ripoff game and I have a bug where when the bird dies (but still manages to get through a pipe by momentum) the score still increments.

I'm trying to fix this by referencing the gameOverScreen gameobject in a script for the middle gap trigger between the pipes (which is where the score is added).

Problem is, I can't seem to properly reference the gameOverScreen gameObject in the middle pipe script, since the pipe is a prefab.

restive badger
#

If it's a prefab why don't you simply assign it in the editor

rich adder
#

because prefabs cant reference scene objects

summer stump
rich adder
#

so technically it would work
if(gameOverScreen.activeSelf) return;

#

but yeah disabling collider is prob better

#

also Logic can just hold Reference to the GameOver screen and you can also access it tat way instead of 2 Find calls

potent echo
#

i was using layers to check where the birdobject was

unborn wasp
#

hello have somone few munites to help me understand some thinks? im gonna use chat GPT too but i need help to start and understand one thing

verbal dome
rich adder
unborn wasp
rich adder
#

because it will mislead you to think something its spewing is true

#

which is a flip of the coin

#

no memes plz @potent echo

#

but yes is true

potent echo
unborn wasp
#

Ok so i want make Android aplication to randomizer image monsters from Witcher. And it was fine chat GPT generete me ok code and that was it. But now i wan to make animations of this monsters as .gif or .mp4... and its starts problem. Bcs i dont know how ask GPT to help me. And i rly dont know how to use this... what is better u think .mp4 or .gif?

summer stump
stuck palm
#

@rich adder doesnt seem to be working very well LOL

rich adder
#

just exclude the extra ones

rich adder
stuck palm
#

that screenshot rather

robust condor
#

Why does this not work:

private Home _home;
...
Home home = NPCManager.Instance.GetHomeByIndex(1);
_home = home.AddTenant(this);

NPCManager:
public Home GetHomeByIndex(int index)
{
    Home home = homes[index];
    if (home == null) return null;
    return home;
}
rich adder
verbal dome
stuck palm
rich adder
stuck palm
#

i'll make a duplicate prefab and t ry that one

rich adder
#

yea def

stuck palm
#

would the IKs in the arms be interfering?

rich adder
#

nah i also use IK

#

well

#

depends if you have the IK active

#

iirc it only works with Animator active but forgot

dry ore
#

Is this a good place to ask for some pointers to some tutorials?

stuck palm
#

it is active but i doubt thats causing the seizure

rich adder
robust condor
#

Oh derp

rich adder
unborn wasp
# verbal dome I'm a bit confused, how do you currently generate those images? Your goal is to ...

With the help of GPT chat, I created a working program that generated random images as .png files. However, I would like to change these static images to moving images that I already have prepared as both .mp4 and .gif files. But here's where I'm facing difficulties because I have no idea how to approach this... That's why I'm seeking help from someone who could assist me in understanding the basics, which I could then use to work on further modifications myself.

dry ore
# rich adder sure if its code related

I played around with unity a year or so ago and I’m looking for some tutorials for making a 2d fighting game, I just want to make sure I’m watching something up to date/good

verbal dome
rich adder
stuck palm
rich adder
#

haha nicee

unborn wasp
potent echo
verbal dome
dry ore
unborn wasp
dry ore
#

Lots of stuff I find is like 5 years old

rich adder
dry ore
rich adder
#

only the editor UI

unborn wasp
dry ore
#

I mean stuff does change like the input system

dry ore
#

Gif to png frames

stuck palm
#

@rich adder right so it fixed for a bit, but i tried something and now this is happening, any idea what might be causing it?

rich adder
summer stump
rich adder
tawdry mirage
#

does Transform.Find generate garbage?

rich adder
#

yea its slow

#

anything uses strings is slow

tawdry mirage
#

any alternatives?

rich adder
#

GetComponent

#

or Serialize the field

summer stump
stuck palm
summer stump
potent echo
rich adder
summer stump
rich adder
dry ore
#

I guess I was more so wondering if there was a good recent 2d tutorial anyone would point someone new to

potent echo
summer stump
verbal dome
# unborn wasp i have .gif files like this one

Can't you just use the video directly in unity? After converting to a compatible format if neeeded
Or use a png sequence like suggested, not sure how you would play it back then though.

stuck palm
rich adder
stuck palm
#

so now i've got the ragdolls working, how can i active and deactivate it at will?

summer stump
potent echo
#

collision.collider apparently doesnt exist when using Collider2D

rich adder
summer stump
potent echo
#

mb

summer stump
potent echo
#

Ah

verbal dome
rich adder
#

that usually overrides the physics

summer stump
stuck palm
# rich adder well do you have animator?

yeah i have an animator, but how can i disable the physics of the root entirely? if i make it kinematic it looks like the character controller movement doesnt work

rich adder
#

just make sure they are not set to collide with each other with the layer based

stuck palm
#

i think i just did it wrong the first time

rich adder
#

I start them all as Kinematic and Triggers already in unity inspector

#

having them as active rigidbodies will be awful performance if you're moving with CC

stuck palm
#

yeah fair

stuck palm
tawdry mirage
#

if i do protected static Strings strings { get; } = new Strings(); in parent class, will it create new Strings each time child class created?

stuck palm
#

i was just gonna activate the rigidbody and let the collision do its thing

verbal dome
rich adder
stuck palm
#

the game im making is like people throwing objects around

rich adder
#

or boxcast / overlapbox from the object

terse osprey
#

Why would the blood tag one not be working while the gas tank one is working

stuck palm
verbal dome
terse osprey
#

I am using an asset of the market place so I dont quite understand

rich adder
terse osprey
#

I only added the blood one, the rest was there before hand

rich adder
#

yours can work fine in your usecase tho @stuck palm

stuck palm
verbal dome
# terse osprey

If the collider is a child collider then it will check the child's tag
And ofc make sure you have the tags set up snd assigned

tawdry mirage
#

i have class Root that is parent for all other classes, and it contains static variables for gameController and similar things that need to be on the scene, they assign themselves to static fields in Root in their Awake. But now i think i will just make new static class Strings instead of putting one in Root

#

it will do similar

rich adder
tawdry mirage
#

but if it is in Root it will be prettier

terse osprey
stuck palm
verbal dome
#

@terse osprey instead of GetComponent, use collider.attachedRigidbody to get the rigidbody. This way it works if the collider is a child

terse osprey
#

I write collider.attachedRigidbody instead of component

#

or indtead of collider

verbal dome
#

Rigidbody rb = hit.attachedRigidbody

#

Instead of the line where you use getcomponent to get it

verbal dome
#

You can try using the rigidbody's gameobject if it exists. Otherwise use the collider

#

Or use GetComponentInParent instead of GetComponent

terse osprey
#

the rigid body does have a game object such as "spine" or "hips" , etc and they have the assigned tag of blood. But these rigid bodies are children of the main prefab

verbal dome
# terse osprey

Btw the GetComponent<Collider> is absolutely useless here, you are already referencing the collider (hit)

#

Start by using Debug.Log to print the hit object's names and tags

terse osprey
verbal dome
#

I would definitely name it collider or hitCollider though, to avoid confusion

stuck palm
#

this doesnt seem to be working and i dont know why, the layer mask has been set properly, and im not getting anything printed to the console

rich adder
marble turret
#

quick question, if I have a class containing several buttons, how can I make the button force a change in a button manager?

rich adder
stuck palm
#

not even the first print is showing up so its as if nothing is even colliding

verbal dome
rich adder
stuck palm
verbal dome
stuck palm
#

the big capsule around the player is the CC thing

rich adder
#

which one do you want to be message invoker?

verbal dome
#

Not sure if even kinematic rb works with CC

stuck palm
rich adder
#

so many colliders I can't tell whats happening xD

stuck palm
#

yeah 😅

#

i'll make a recording one second

marble turret
#

@rich adder thx!

verbal dome
#

Is this script for when the ragdoll is active or inactive?

rich adder
#

tryina show u how I did hit by box go flying..but my unity been stuck like this for 20 min

#

random unity bullshit.

stuck palm
#

you can see how making the cc collider a big bigger makes the collision happen though, right?

verbal dome
# stuck palm

Rigidbody probably can't use CC to detect collisions and it only works once one of the bodypart colliders hit something

rich adder
#

is box trigger?

#

which one has the script

verbal dome
rich adder
#

CC can only call OnCharacterControllerHit otherwise u need trigger

stuck palm
stuck palm
rich adder
#

record the velocity before the hit so you can tell which direction / force it was hit with

#

since it 0s out onHit

stuck palm
rain wedge
#

Could someone help with me with the onClick event for buttons?
I'm working on the 2022.3.5f1 version of unity and its onClick event for buttons ask for parameters that I'm not familiar with, such as mode and target assembly. What am I supposed to input for them.

stuck palm
#

maybe maybe

#

the object can call the collision?

#

i mean the object can call the ragdoll activate?

rich adder
rich adder
stuck palm
# rich adder both can

its just cus if u watch the video you see that the ragdoll only works once the player runs into the object

rich adder
stuck palm
# rich adder show the current code rq
 private void OnControllerColliderHit(ControllerColliderHit hit)
        {
            print("collided with " + hit.gameObject.name);
            if ((collisionLayerMask.value & 1 << hit.gameObject.layer) > 0)
            {
                print("tripping!!!!");
                ragdoll.Activate();
            }
        }
rich adder
#

well then there ya go

#

thats where the xtra params come from

#

disable debug mode

rain wedge
#

oh alright

#

thank you

rich adder
#

and why Use layers just check if object has a rigidbody and speed is High

stuck palm
stuck palm
rich adder
stuck palm
#

it will explain better

marble turret
rich adder
stuck palm
#

maybe it wasnt being hit hard enough or something

rich adder
#

lmao

stuck palm
#

sometimes it seems to teleport the player on top of the thrown object, though

#

is there a way to like

#

keep the momentum?

rich adder
#

so it goes flying backwards

opal fossil
#

is there a way to inherit animator controllers in such a way that enables the user to add additional programs? And I am not talking about animator override controller. That only allows changing animations of states

stuck palm
rich adder
stuck palm