#💻┃code-beginner

1 messages · Page 309 of 1

polar acorn
#

Just add two strings together.

rich adder
#

just do
text = "Price " + merchantPrice

strong wren
#

i hope

#

boah i need to think of another name

polar acorn
#

You don't have to store it in a variable

strong wren
#

hmm MerchantDisplayPrice

rich adder
#

thats overkill

summer stump
south sky
#

Can someone help? The hurt animation wont play even with the correct parameters. The hurt state will be active but the animation its self wont play

strong wren
astral grail
#

thank

strong wren
polar acorn
#

so it'll start that animation every frame until the condition is no longer true

rich adder
strong wren
south sky
summer stump
polar acorn
#

or you could just not use any state

strong wren
#

this right?

strong wren
#

whilts i was tryingto do the multiplications stuff

#

i input some wrong numbers and my pc went off

rich adder
#

putting strings together should've been one of your first lines in c#

strong wren
#

yes

slender nymph
summer stump
strong wren
#

i watched a 5 hour long video on it

#

then i watched brackeys video on it

#

then game dev of brackeys

summer stump
rich adder
strong wren
summer stump
strong wren
#

and i wil not say what i inputed there

eternal needle
#

Watching other people code is pretty much nothing. Especially if you're watching brackeys then you've probably learned less than nothing

strong wren
#

alr well ima go to beed

summer stump
#

Just try an NON-video lesson

strong wren
#

but before i do i have a quick question

#

is doing like Coins per second hard?

eternal needle
#

It's like staring at the plumber fixing your bathroom, then thinking you're a plumber as well

summer stump
deft grail
strong wren
summer stump
strong wren
#

yall tought i was a troll 3 hours ago

dusk minnow
#

I need some help, how can i create such fields that i can expand like add one. I dont know What they are called so I cannot find any explain videos

dusk minnow
#

Like in the image, when i tap + it adds one more input field

strong wren
#

well now i can kinda programm

#

so i can finally say im a programmer!

#

wait a second

#

thats just a bigger nerd

#

eh its fine i dont have friends to make fun of me

eternal needle
strong wren
#

i will do as you please

slender nymph
dusk minnow
strong wren
#

well

dusk minnow
#

Thanks guys 👌🏻

strong wren
#

i just made my first Phone Game

rustic maple
summer stump
graceful spruce
#

Hey why could it be that I can't see the "AddHeroesToSlots" function when I'm using a button?

   public List<GameObject> heroesInSlots = new List<GameObject>(); // List to hold the heroes in slots

   // Method to add a list of heroes to slots
   public void AddHeroesToSlots(List<GameObject> heroes)
   {
       if (heroes.Count <= heroSlots.Count)
       {
           for (int i = 0; i < heroes.Count; i++)
           {
               heroesInSlots.Add(heroes[i]);
               heroes[i].transform.position = heroSlots[i].transform.position; // Position the hero in the slot
           }
       }
       else
       {
           Debug.LogWarning("Not enough slots to add all heroes!");
       }
   }```
deft grail
graceful spruce
#

oh

graceful spruce
soft kernel
graceful spruce
#

just GameObject itself?

deft grail
graceful spruce
#

Nima ^

soft kernel
#

does it change on button press?

graceful spruce
#

no

soft kernel
#

you can use a separate list. you don't need an argument

graceful spruce
#

👍 ty

soft kernel
#

like you did on top with public List<GameObject> heroSlots = new List<GameObject>();

#

just add another list and use that instead

graceful spruce
feral bluff
#

so im trying to make a fps game in unity but im having troubleshooting with the movement. See, everytime my character Y position goes up for a bit, the player will elevate, and i also cant move in the air, i've tried many things but none of them seem to work, here's the code:

#

`private void FixedUpdate()
{
float horizontalInput = Input.GetAxisRaw("Horizontal") * Time.deltaTime * MovementSpeed;
float verticalInput = Input.GetAxisRaw("Vertical") * Time.deltaTime * MovementSpeed;

    Vector3 cameraForward = Camera.main.transform.forward.normalized;
    Vector3 cameraRight = Camera.main.transform.right.normalized;

    cameraForward.y = 0f;
    cameraRight.y = 0f;

    Vector3 ForwardRelative = verticalInput * cameraForward;
    Vector3 RightRelative = horizontalInput * cameraRight;

    Vector3 MovementDirection = ForwardRelative + RightRelative;

    rb.velocity = new Vector3(MovementDirection.x, rb.velocity.y , MovementDirection.z).normalized * MovementSpeed; 
     /*
     Rigidbody values

     0 = ground level. a single change in the y axis up or down will make it go that way until something blocks it.
     1> =  one or more. Going up until something blocks it.
     <-1 = minus one or less. Going down until something blocks it.
     */

    Debug.Log(rb.velocity.y);

}`
eternal falconBOT
feral bluff
#

oh yeah forgot about that

deft grail
feral bluff
#

The player goes back because i placed an invisible plane on top so it goes back

#

and it happens because if it changes from cube to cube, Even if they are in the same Y level

#

or its y level goes up for a bit

summer stump
#

The issue is that you bounce off the invisible plane up top?

#

I am still confused

deft grail
feral bluff
summer stump
feral bluff
#

yeah

#

i basically dont want the player to elevate

summer stump
#

What does "two cubes in the area inside each other" mean exactly

#

Are you using gravity on the player btw?

feral bluff
deft grail
# feral bluff

are you jumping or anything? or are you literally just pressing W

feral bluff
#

i havent coded the jump function yet

teal viper
feral bluff
#

so what can i replace rb.velocity.y with? if i change it like using a number it'll either go up or down, if i use 0 it pretty much goes down slowly. but makes the player walk in solid terrain, im not really sure what to do..

deft grail
#

not the actual velocity itself anyway

feral bluff
#

it pretty much just does the same but quicker

#

it goes up then rapidly goes down

teal viper
#

Yes. The issue is the normalization, since it modifies the value on the y axis along with the rest of the vector.

deft grail
#

also i noticed one is using rb the other is Rb

#

so whats that about?

feral bluff
deft grail
feral bluff
#

well now pretty much when i removed the normalization the player walks much slower, and depending on the camera angle (I believe) it happens the same thing but MUCH faster

teal viper
# feral bluff

My previous reply was purely based on your initial code. After looking at the video I'm not sure what the issue is anymore.

deft grail
#

a good thing to test always is just make a new scene, add one plain floor and your player

#

and see what happens

feral bluff
#

alr

teal viper
feral bluff
deft grail
feral bluff
#

no on 2

#

it doesn't happen in the same cube or floor

dense walrus
#

anyone have a beginner tutorial for how to code ai for the newest version of unity?

deft grail
eternal falconBOT
dense walrus
#

enemy ai literally everything about it

deft grail
dense walrus
#

patrolling, pathfinding, shooting, etc.

dense walrus
rich adder
#

has good series on AI / Navmesh agents

dense walrus
#

k thanks

teal viper
dense walrus
#

yes

#

cant find good tutorial

teal viper
#

Define "good"

deft grail
dense walrus
#

for beginners

rich adder
#

they're all pretty much the same, they just moved some packages n buttons

dense walrus
#

even still none use the newest version of unity

rich adder
#

so what?

dense walrus
#

the one i used was very recent but still outdated so i need to find a new one

teal viper
dense walrus
#

the things he was doing i was unable to

rich adder
dense walrus
feral bluff
#

made the player's speed a lot more faster though

#

and it didnt have the issue when going fast

night raptor
dense walrus
# rich adder like what?

he went to window and selected ai but i dont have that and when i got it from the package manager it was missing some of the options he was selecting

rich adder
dense walrus
#

idk what that means

#

oh wait i know navmesh

#

ye that was the thing that was different

rich adder
teal viper
dense walrus
night raptor
summer stump
rich adder
feral bluff
rich adder
dense walrus
#

whats baking

teal viper
summer stump
dense walrus
#

ye whats that

summer stump
#

Not backing

dense walrus
#

i said baking

rich adder
#

for the agents to walk on

#

the blue thing

summer stump
rich adder
dense walrus
#

cap

dense walrus
rich adder
dense walrus
#

pathfinding

feral bluff
rich adder
#

it helps create the world for your agent

summer stump
teal viper
feral bluff
#

yeahh... Im not even sure of what to do anymore man

teal viper
deft grail
rich adder
dense walrus
#

@feral bluff i followed a good tutorial from natty gamedev on movement

dense walrus
dense walrus
rich adder
dense walrus
rich adder
#

as pointed out the difference is that now you usually bake with something like Navmesh Surface component, or volume ones..tc.

teal viper
dense walrus
#

ig ill try to still follow the tutorial and improvise

teal viper
#

Learn about the thing that changed.

rich adder
#

navmesh agents especially are the same exact code to move and assign paths

dense walrus
#

tutorial is too confusing ill come back to enemies when im more advanced

rich adder
#

all these components were "Experimental" earlier so some videos even do have these

faint osprey
#

ive got a gameobject set up with a kinematic rigidbody however when i run into it ints not moving and i dont know why

summer stump
faint osprey
#

what but that makes no sense cause if u hover over it it says controls wether or not the object is affected by physics

#

so ticking it would mean yes

rich adder
faint osprey
#

so tick for no and blank for yes

summer stump
#

Correct

faint osprey
#

thats terrible

rich adder
#

kinematic makes sense as true

#

wdym

summer stump
#

Ok 🤷‍♂️
It doesn't say select to be controlled by physics
Makes sense to me

#

Just says it controls whether it is

faint osprey
#

if i had a tick box and it said wehter or not you want ice cream you would tick for yes would u not?

summer stump
rich adder
#

" I want this to be not effected by other physics object"

summer stump
#

I simply also know what the word means

faint osprey
#

it syas controls wether physics affects it

summer stump
#

Fundamental difference in wording there

faint osprey
#

what no

rich adder
faint osprey
rich adder
#

Kinematic means Not affected

teal viper
faint osprey
#

yeah i know im not disagreeing but for someone who doesnt know the definition the wording is bad

faint osprey
teal viper
summer stump
#

Doesn't matter. Just google the word kinematic
It has a meaning outside of unity

teal viper
faint osprey
#

🤦‍♂️ no im saying that the wording is bad for people who are beginners coming into unity

deft grail
#

IsKinematic - controls if its affected by physics
this setting makes it controlled or not, so then you find out what does Kinematic do and see if you want it On or Off, simple

teal viper
faint osprey
summer stump
north kiln
#

No, you would assume that toggling it altered whether physics affected it

teal viper
north kiln
#

Luckily kinematic is also a real word

frosty lantern
#

https://gdl.space/vahicugocu.php
I'm getting a null error on the 4th line of this method when I call CreateShapeFromPolygon
The error seems to say that it's looking for a ProbuilderMesh as a parameter, so i tried calling the script differently (second screenshot) but they both give the same null error

the whole code is
https://gdl.space/ogarodalay.cs

#

both should be valid ways of calling the createpolygon method, but I still don't know why the mesh I declared and assigned a new value to the line before is returning null.

slender nymph
#

ProBuilderMesh is a MonoBehaviour. you should not be calling the constructor for a monobehaviour, in fact you probably have a warning before this error telling you that

frosty lantern
slender nymph
#

yes, that is how all MonoBehaviours and components work

lament wagon
#

does anyone have a good reference to cinemachine 3d?

#

So far I have created an empty object and placed it on my player and created cinemachine to follow and look at that empty object

#

now im struggling to calculate player movement relative to the direction the camera is facing

#

):

#

^ newbie trying to create a game

slender nymph
#

there's documentation for cinemachine pinned in #🎥┃cinemachine
but if the issue is just getting the direction the object is facing, that would be its transform.forward

#

or you can use transform.TransformDirection to convert your input from local space to world space

lament wagon
#

ty ill look into that

tough cave
#

this does work, (forward) tempRigidBodyBullet.AddForce(transform.forward * bulletSpeed, ForceMode.Impulse);
But its going on the blue line, instead of the green.

whole idol
#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class Gravity : MonoBehaviour
{
    public Rigidbody2D rb;
    private bool canJump;
    // jumpTime starts from bigger number and goes to a lower number
    // jumpTime always wants to go negative but before it goes negative if it reaches anywhere near zero we want it to stop right there
    // and not move anymore, jump will only be available if u wait for these 2 seconds to run out
    public float jumpAgainInTwoSec = 2.0f;

    public float speed = 0.0f;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        checkIfjumpPossible();

    }
    void Jump()
    {
        checkIfjumpPossible();

        if (canJump && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
        {
            rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
            jumpAgainInTwoSec = 0;
            jumpAgainInTwoSec += Time.deltaTime;


        }

    }
    // Update is called once per frame
    void Update()
    {
        Jump();
        Debug.Log("JumpTime is :" + jumpAgainInTwoSec);
        Debug.Log("canJump?:" + canJump);
        checkIfjumpPossible();

    }
    void checkIfjumpPossible()
    {
        if (jumpAgainInTwoSec == 2.0f)
        {
            canJump = true;
        }
    }
}

#

Rate my code

#

is there any way I could make this game any better?

slender nymph
#

whoops you waited 2.01 seconds to jump and now you cannot jump ever again

whole idol
#

no matter what the time is

slender nymph
#

oh wait, you never even set it to false

#

so you have several variables that serve absolutely no purpose

#

oh and can jump infinitely since those variables that serve no actual purpose in this code were really meant to prevent that

whole idol
#

isn't that automatically set to false if the condition jumpAgainInTwoSec is not 2.0f then the canJump will be false?

#

the opposite of true is false right?

slender nymph
#

how would it be set to false? you only set it to true

whole idol
#

so if its not true then what else can it be?

summer stump
#

You set it to true

whole idol
#

btw i only set the truthies cause i thought i could save up some lines of codes that way text can be shorter to paste here

#

and be readable

slender nymph
summer stump
#

And it STAYS true until set false (which never happens)

whole idol
#

i guess ill have to include a false condition here?

#

or do !JumpAgainInTwoSec == 2.0 then canJump = false

#

would that also work?

#

delcaring only the false case

slender nymph
#

please for the love of god go learn how code works

whole idol
#

to save code space?

#

ok bro chill, ill include both cases

#

btw this works too on my game lol

#

i like my code that way and it works

summer stump
#

Never ever do == with floats

whole idol
#

ok noted!

#

I will fix that

#

Added >=

#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class Gravity : MonoBehaviour
{
    public Rigidbody2D rb;
    private bool canJump;
    public float jumpAgainInTwoSec = 2.0f;

    public float speed = 0.0f;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        checkIfjumpPossible();

    }
    void Jump()
    {
        checkIfjumpPossible();

        if (canJump && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
        {
            rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
            jumpAgainInTwoSec = 0;
            jumpAgainInTwoSec += Time.deltaTime;


        }

    }
    // Update is called once per frame
    void Update()
    {
        Jump();
        Debug.Log("JumpTime is :" + jumpAgainInTwoSec);
        Debug.Log("canJump?:" + canJump);
        checkIfjumpPossible();

    }
    void checkIfjumpPossible()
    {
        if (jumpAgainInTwoSec >= 2.0f)
        {
            canJump = true;
        }
        else
        {
            canJump = false;
            jumpAgainInTwoSec += Time.deltaTime;
        }
    }
}

#

Well, that works.

#

Any recommendations on how to make it shorter or better? I guess

slender nymph
#

your 2 second jump timer is now more like 0.75 seconds

summer stump
tough cave
#

Would rename the class something more fitting for jumping, rather than gravity'. MovementController or playerJumping.

summer stump
#

Oh yeah, you are adding deltaTime in multiple places

whole idol
summer stump
whole idol
#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class playerJumping : MonoBehaviour
{
    public Rigidbody2D rb;
    private bool canJump;
    public float JumpDelay = 2.0f;
    public float speed = 0.0f;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        checkIfjumpPossible();
    }
    void Jump()
    {
        checkIfjumpPossible();

        if (canJump && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
        {
            rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
            JumpDelay = 0;
            JumpDelay += Time.deltaTime;
        }
    }
    // Update is called once per frame
    void Update()
    {
        Jump();
        Debug.Log("JumpTime is :" + JumpDelay);
        Debug.Log("canJump?:" + canJump);
        checkIfjumpPossible();
    }
    void checkIfjumpPossible()
    {
        if (JumpDelay >= 2.0f)
        {
            canJump = true;
        }
        else
        {
            canJump = false;
            JumpDelay += Time.deltaTime;
        }
    }
}

This is now my current code

#

Any further suggestions are welcome 👌

summer stump
#

Only add it once

#

Remove the one closer to the top of course

whole idol
#

I removed it

summer stump
#

Oh, the issue they meant is that you call checkIfJumpPossible twice actually

#

Just saw that

#

Once in jump and once in update

slender nymph
#

up to 3 times per frame, actually

#

or they add deltaTime up to that many times

whole idol
#

Ok, noted, Ill only call it in Update

#

and i think Ill remove the JumpDelay completelly because it makes my gameplay kinda shitty

#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class playerJumping : MonoBehaviour
{
    public Rigidbody2D rb;
    public float speed;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }
    void Jump()
    {

        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
        {
            rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
        }
    }
    // Update is called once per frame
    void Update()
    {
        Jump();
    }
}

this is now my current code

summer stump
#

Even in the air?

whole idol
#

this is a flappy bird game

frosty lantern
#

https://forum.unity.com/threads/argumentnullexception-value-cannot-be-null-parameter-name-_unity_self.1431901/

Has this bug been addressed? I get the same error when I have something selected in the hierarchy before running the game. It's not hard to work around, but it is annoying

summer stump
frosty lantern
#

is there something I can do to stop it?

whole idol
#

the only problem about this is that the bird gets exponential amount of force and just shoots up in a one-way ticket to space if you get the jump GetKeyDown triggered multiple times in one second it will eventually shoot up adding up all the accumulated force you gave it where I kinda want it to cancel out accumulated jump Added-force in case that happens so that I can have better control of my bird and not have it shoot up to the moon but rather have a more smooth flying and slow release of rigidbody jumpforce, so only when one jumpforce is done is when I wanna add the next one, which is why I added the timer in the first place, I had a big problem with this issue getting way too much jumpower if you press the jump button multiple times it adds up all the speed

summer stump
#

rb.velocity.y >= someThreshold

whole idol
frosty lantern
whole idol
#

( I haven't yet added rigidbody 2d to the pipes, or randomized the pipe positions )

#

I also want to do that later

frosty lantern
#

are you happy with the jump timing?

summer stump
whole idol
#

no this is why I made this to show you how its bad when it multiplies the speed when you press jump input multiple times

summer stump
#

Not that either

frosty lantern
#

oh it'd just be a collider trigger to lose right?

summer stump
#

Only one object requires a rigidbody for OnTriggerEnter

whole idol
#

is there any way I can take out this playerinput symbol from the screen?

#

its making it hard to see the actual bird

#

also the way the order of these layers are stacked up on top of each other it makes it look as if the wing layer is on top of the face of the bird, instead it should be underneath the player gameobject in this 2d perspective

frigid sequoia
#

I am using PlayClipAtPoint to play a small sound effect for all the stuff, but if the player (which has the audioListener) moves while the audio is played, it creates this really weird doppler effect that I don't want. Can I play this directly on the AudioListener without considering any position?

#

Is there something for that?

summer stump
frigid sequoia
summer stump
#

Just make an array or list of clips

frigid sequoia
#

I mean that if I want a shot to produce a sound when it ends, it would need to refer to the player object to produce the sound from there

summer stump
frosty lantern
#

Alright, so I am able to create the objects I need to create, I've created the meshes, and I've added a meshrenderer and meshfilter

foreach (Vector3Int move in basicHexMoves)
{
    GameObject movePoly = new GameObject("PolyMove");
    
    movePoly.transform.position += boardCoord.CubeToQuad(move);
    movePoly.transform.SetParent(transform, false);
    MeshRenderer meshRenderer = movePoly.AddComponent<MeshRenderer>();

    MeshFilter meshFilter = movePoly.AddComponent<MeshFilter>();
    ProBuilderMesh proMesh = movePoly.AddComponent<ProBuilderMesh>();
    AppendElements.CreateShapeFromPolygon(proMesh, uIPoints, 0.2f, false);
}

I just don't know how to actually connect them to get the visible object in my scene

frigid sequoia
#

I cannot even attach it to a mixer

summer stump
#

I don't understand the reticence to just do it the normal way, but yeah, I have no idea how you could do it with PlaySoundAtPoint.

An alternative is to have a soundsource object that you child to the player and move around as needed

#

People often pool these sound objects and activate then as needed

frigid sequoia
#

Cause I actually want it to be somewhat affected by distance but not this much

summer stump
#

Anything outside that limit should be an actual object with a sound source

eager spindle
#

I once made my own implementation of PlaySoundAtPoint that uses object pooling and the ability to set which audio mixer its on

frosty lantern
#

ProBuilder creates it's own MeshFilter, but the MeshRenderer isn't finding it:

    protected void InstantiateMovePoly()
    {
        for (int i = 0; i < 6; i++)
        {
            float angle = Mathf.PI / i;
            uIPoints.Add(new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)));
        }
        foreach (Vector3Int move in basicHexMoves)
        {
            GameObject movePoly = new GameObject("PolyMove");
            
            movePoly.transform.position += boardCoord.CubeToQuad(move);
            movePoly.transform.SetParent(transform, false);
            ProBuilderMesh proMesh = movePoly.AddComponent<ProBuilderMesh>();

            MeshRenderer meshRenderer = movePoly.AddComponent<MeshRenderer>();
            AppendElements.CreateShapeFromPolygon(proMesh, uIPoints, 0.2f, false);
        }
    }
frail star
#

Thank you is is exactly like i want , now I just have to alter the speed to make it look nice , I'll still peek at the tarodev video tomorrow. (Sorry didn't get that message before i left for work. so late reply)

frigid sequoia
#

Any specific reason the curve does that with no points in the middle?

charred spoke
#

The slope handles can be adjusted

frosty lantern
gaunt ice
#

A Bézier curve ( BEH-zee-ay) is a parametric curve used in computer graphics and related fields. A set of discrete "control points" defines a smooth, continuous curve by means of a formula. Usually the curve is intended to approximate a real-world shape that otherwise has no mathematical representation or whose representation is unknown or too c...

#

In geometric modelling and in computer graphics, a composite Bézier curve or Bézier spline is a spline made out of Bézier curves that is at least C0{\displaystyle C^{0}} continuous. In other words, a composite Bézier curve is a series of Bézier curves joined end to end where the last point of one curve coincides with the starting point of the ne...

frosty lantern
#

pleas

languid saffron
#

Could anyone link me a guide to temporarily disable a script?

summer stump
#

It will only disable unity methods though. Like Update

languid saffron
#

Would something like

private void OnTriggerEnter2D(Collider2D other)
{
    if (other.CompareTag("Powerup"))
    {
        {ScriptName}.enabled = false
    }
}

}

work? (im new to coding)

summer stump
#

Yeah, that would work

#

Assuming everything is set up right in the inspectors

languid saffron
#

Anything in the inspector I should look out for?

rich adder
languid saffron
languid saffron
#

object reference

rich adder
#

so you didn't assign it?

languid saffron
#

when I do public {ScriptName} script; at the top, it goes away but has me choose from limited game objects

#

or is it only game objects that have a script applied?

#

or the certain script that i want to be disabled applied to that certain game object?

topaz mortar
#

Uri u here?

languid saffron
#

So will that only disable that exact game object

#

with the script attached to it?

#

cause I want to disable more

#

for like 3 seconds

#

(over 100 game objects to be specific)

rich adder
#

what are u trying to do

languid saffron
#

disable my kill player script

#

kinda like an "invincibility" thing for a few seconds

#

my friends keep telling me to add it and i said "yeah okay ill try"

rich adder
#

instead of disabling the other objects why don't you disable the damage or whatever on player itself..

languid saffron
#

do you mean individual damage?

#

cause it insta kills

rich adder
#

so disable that part

languid saffron
#

oh alr

#

the thing is

#

it's just when it comes into collision it reloads the scene

summer stump
languid saffron
#

would i assign the script to the player or the game object itself?

#

(the game object thats supposed to disable the killplayer script)

ivory bobcat
#

The script is evaluating whether or not the other is a powerup so I'd guess you'd put this on whoever is running into the powerups

languid saffron
#

and it doesnt rlly disable the script

ivory bobcat
#

Can you post the exact code?

rich adder
ivory bobcat
#

The !code posting guidelines:

eternal falconBOT
languid saffron
#

both KillPlayer and Powerup script

rich adder
ivory bobcat
languid saffron
languid saffron
rich adder
#

i mean the Player should be checking if it hits KillPlayer script

#

but skip it if you got powerup

languid saffron
#

so i dont know much

#

anyways, ill be back later

glass ivy
rich adder
glass ivy
#

eluded me for much longer than I want to admit 😅

misty coral
#

multiplying by time.deltaTime breaks the aiming in

#

any ideas on what is wrong?

rich adder
misty coral
#

let me send video rq

#

thats how

#

but i need time.deltaTime for it to gradually go up to the aimed in position

wintry quarry
misty coral
#

wym

wintry quarry
#

you did transform.position instead of gun.transform.position

misty coral
#

when i multiply by it it breaks.

rich adder
#

nicee

#

good catch

wintry quarry
misty coral
#

huh

wintry quarry
#

or rather - it's just making that mistake visible

topaz mortar
#

string query = "SELECT * FROM `ifi-1-prod`.items WHERE playernumber = @playernumber AND itemid IN (@itemid1, @itemid2);"; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.Parameters.AddWithValue("@playernumber", playerNumber); cmd.Parameters.AddWithValue("@itemid1", scrollItemId); cmd.Parameters.AddWithValue("@itemid2", equipmentItemId);
Is there anything wrong with the way I'm creating this database call?
Chat GPT is saying something about protecting against sql injection, but I'm doing that already not?

It's suggesting I do something like this:
string query = "SELECT * FROM `ifi-1-prod`.items WHERE playernumber = @playernumber AND itemid IN ({0}, {1});"; // Dynamically formatting the query with placeholders for item IDs query = string.Format(query, "@id1", "@id2");
Is there any difference?

misty coral
#

it is still happening

wintry quarry
#

save your code

misty coral
#

i did

#

i spammed it in fact

#

to make sure

wintry quarry
#

the only other way that'd happen would be if aimHere is rapidly moving

misty coral
#

i might have other ambigious references

wintry quarry
#

Make triple sure unity picked up the changes

misty coral
#

could that mess it up

wintry quarry
#

not sure what you mean by that

misty coral
#

other transform.position instead of gun.transform.position

wintry quarry
#

Context matters

#

I can't tell you in general

misty coral
#

they are not in any way related to moving the gun what so ever

wintry quarry
#

then it sounds not related but

#

¯_(ツ)_/¯

misty coral
#

er

wintry quarry
#

It's best if you just understand the difference between those two things

#

and use the correct one in each case

misty coral
#

that is legitimately the only area where i move the gun

#

the aimHere empty is moving with my camera

#

could you suggest any work arounds??

rich adder
#

if its child maybe u want localPosition?

misty coral
#

The aimed in empty is a child of the player capsule

#

is that what you meant?

#

doesnt seem to work...

wintry quarry
#

Which object is this script on?

misty coral
#

the gun script is on the gun

#

then I have a gamObject variable that allows me to access aimedin's transform

#

i know 100% it is related to delta time

wintry quarry
#

So.. does that mean the gun script has a separate reference to ITSELF called gun?

misty coral
#

when testing it

wintry quarry
#

That's VERY odd

misty coral
#

yea i started the script a long time ago before i knew what i was doing

#

but that means that it shouldn't matter if i just do transform.position right?

wintry quarry
#

yes it shouldn't

#

but like

#

be consistent

#

use the same thing everywhere

#

otherwise it's ????? when reading the code

misty coral
#

ok

wintry quarry
#

anyway my guess is there's some other part of the script or something else entirely moving the gun

#

perhaps an Animator?

misty coral
#

have you guys ever tried something similar to what im doing and had this sort of problem?

wintry quarry
#

What you're describing doesn't make much sense unless this code is fighting some other code or component to move the object

misty coral
#

Ok I tested this

#

when I aim in

#

I multiply by time delta time

wintry quarry
#

deltaTime would then cause this because it means rather than instantly moving you move gradually which means you start to intermittently lose that fight to move the object

misty coral
#

when I aim out

#

I dont

#

and when I tested

#

hipfire or neutral stance

#

is fine

#

but aiming in sinks out of the map

#

and it goes back to neutral stance when un aimed

misty coral
#

would disabling a collider do anything

#

cuz I do do that

#

none of my otherscripts interact with the gun's position at all

wintry quarry
#

does it have a Rigidbody? Animator?

#

anything like that

misty coral
#

YES

#

it does have a rigid body

wintry quarry
#

why does it have a Rigidbody 😮

misty coral
#

so when i drop it it flops to the floor

#

is that bad?

wintry quarry
#

ok but surely when you're holding it... it should be at least set to kinematic

#

otherwise you'll be fighting that thing for positioning the object all the time

misty coral
#

yea thats probably it lemme try to fix rn

cunning rapids
#

I don't get why a gun needs a rigidbody component

rich adder
#

to drop it

cunning rapids
#

Yeah but you don't need it when you hold it

rich adder
#

yup

misty coral
#

yup it works

#

tysm

misty coral
#

I only knew I had to disable the collider

cunning rapids
# rich adder yup

Picking it up, remove it from the scene and just enable it under the player

misty coral
#

because otherwise it would fling me when pushed into objects

cunning rapids
cunning rapids
rich adder
#

I dont use camera stacking at all. I use Renderer feature

#

camera stacking is resource intensive

cunning rapids
#

If you use the same game object with the same layer, the difference in fov will be visible and ugly when it's on the floor

rich adder
#

I correct that inside the Renderer feature

cunning rapids
#

That way they can separate layers

#

Makes fixing the camera clipping much easier

cunning rapids
rich adder
cunning rapids
cunning rapids
rich adder
rich adder
cunning rapids
cunning rapids
#

Makes sense

cunning rapids
cunning rapids
#

Yeah I just searched it up, SRP exclusive

rich adder
#

camera stack sucks because shadows also don't affect the viewmodel

rich adder
#

no they don't

#

if the camera is only rendering the weapon, where do you think the shadows from world come

cunning rapids
#

I use camera stacking and the lighting works okay

rich adder
#

I never said lighting

#

the outside world will not affect view model with their shadows

cunning rapids
#

Oh yeah yeah obviously 😭

#

No I know that

rich adder
#

hence why I said its another drawback of camera stacking

cunning rapids
#

I mean my laptop sucks so it's probably a good idea I stray away from it too

#

I noticed considerable performance drops

rich adder
#

yeah having two cameras is expensive

cunning rapids
#

Are there shaders that also help eith it?

#

For stuff like BiRP

#

I don't use SRPs

rich adder
#

I stick to srp only

cunning rapids
#

Why?

rich adder
#

birp is pretty much legacy

#

its barebones, SRP has too many good features that birp dont have

cunning rapids
#

Yeah but the assets are lacking

#

There are like 4x more assets for BiRP

#

The post processing can be made up for quite easily

rich adder
#

🤷‍♂️ i barely use any external assets

cunning rapids
#

Fair enough

#

But for things like PSX-style games I haven't found any easy to use assets for stuff like texture warping for SRP

rich adder
#

again, renderer feature with shaders

#

I have a vid with it

cunning rapids
#

You can make decals for texture warping?

#

Isn't that more of a shader thing?

rich adder
#

wdym decals for texture wrapping ?

misty coral
#

Hey guys there is a weird bobbing when I jump around, any way to reduce that?

cunning rapids
#

You just said I can use the renderer feature for PSX-style graphics

misty coral
#

alr

cunning rapids
misty coral
#

it likes stutters or something

cunning rapids
#

That isn't you shooting the gun?

misty coral
#

no

#

i havent added the movement for that

rich adder
misty coral
#

when i shoot rn its does no sort of animation

cunning rapids
rich adder
cunning rapids
#

"Projector" conponent dude

cunning rapids
#

In the rigidbody

misty coral
rich adder
#

also its Birp only

cunning rapids
#

In the rigidbody

#

When you constantly move the gun next to the player, it might be jittery

misty coral
#

you mean make it interpolate or extrapolate or none?

#

making it interpolate seems to worsen the problem

cunning rapids
#

Make it interpolate

cunning rapids
misty coral
#

well it makes the overall speed slower, meaning that what I had it at before seems slower than before, thus worsening the problem

cunning rapids
#

Also, I'm a bit late to the thread, why isn't the weapon under the player parent game object once you hold it?

misty coral
#

i am unaware of the advantages of doing such things

#

hence why i am asking in coding beginner

cunning rapids
#

I feel like constantly teleporting it next to the player is unnecessary

#

When it's under the player parent game object, it always follows the player's position and orientation

#

No need to modify the script to have the gun always teleporting to the relevant position

#

Especially if you move quickly, as you mentioned

misty coral
#

interpolate did reduce the problem btw, i just upped the speed so it goes about as fast as before

cunning rapids
#

Btw @rich adder what's wrong with the method I suggested? Pick it up, remove the pickup object from the scene, enable the actual shooting object under the player (a draw animation can help with the smoothness) and if you drop it, make a new pickup object with a rigidbody in the relevant position

cunning rapids
#

Then it will need to catch up to you again

vital cargo
#

How does OnTriggerEnter2D work?, cuz mine not working

topaz mortar
versed arch
#

!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)

tacit birch
#

For the people that have purchased/used the A* Pathfinding asset (arongranberg):
How do you restrict the AI to only move in 4 directions towards the target? I have it set up for an Enemy aggro AI, but it's allowing the enemy to move diagonally, which isn't something I want since I've restricted player movement to 4-directional only

whole idol
#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.UIElements;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class playerJumping : MonoBehaviour
{
    public Rigidbody2D rb;
    public float speed;
    private bool isGoingUpwards;
    // Minimum vertical velocity thresold to consider movement. When we have this player is basically stationary in the middle
    public float velocityThreshold = 0f; 
    public float verticalVelocity;
    public float RDV; //Rotate Downwards Velocity
    //public float RUV; //Rotate Upwards Velocity ( faster )

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();

        Quaternion localRotation = gameObject.transform.localRotation;

        // Access individual local rotation values (Euler Angles)

    }
    void Jump()
    {
        float verticalVelocity = rb.velocity.y;
        RDV = verticalVelocity / 10;
        //RUV = verticalVelocity / 5;

        if (verticalVelocity > velocityThreshold)
        {
            isGoingUpwards = true;
        }
        if (verticalVelocity <  velocityThreshold)
        {
            isGoingUpwards = false;
            if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) && (isGoingUpwards == false))
            {
                rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
                transform.Rotate(new Vector3(0, 0, -RDV));

            }
            transform.Rotate(new Vector3(0, 0, RDV));

        }



    }
    // Update is called once per frame
    void Update()
    {
        Jump();
    }
}
oblique herald
#

Hiya, it's me again (seems like I have a problem every day 😅 )
Anyway, I have a inventory system on scene1, which works perfectly fine and can pick up item, select item in the ui. The problem is when I just copy and paste the entire UI to scene2 it seems to not work, I can still pick up items and open up the menu, but I no longer can select the items I've picked up. Is it not possible to just copy and paste an entire UI over a scene or is there a better way of doing it?

rare basin
rare basin
#

use Prefabs

oblique herald
#

wait prefab as in these blue thingy?

whole idol
oak island
#

Hello, anyone who has worked with Oculus lipsync here?

#

Or is there any way to get characters compatible with Oculus lipsync by default?

tender stag
#

can you see protected variables in the editor?

vital cargo
#

Why is the plus missing?

eternal needle
rare basin
vital cargo
#

Tbh

tender stag
#

between public and protected

#

and private

rare basin
#

google can xplain it to you

vital cargo
#

I don't know anymore

rare basin
#

in 2minutes

tender stag
#

private u cant access from other scripts, just the class

#

public u can

burnt vapor
#

Yeah this channel is not exactly for these type of questions

tender stag
#

and its visible in the editor

rare basin
#

just use tool called google

whole idol
#

real

tender stag
#

oh i thought it was unity talk

#

my bad

rare basin
#

still

#

google first, ask second

tender stag
#

i did

#

i want to understand more

eternal needle
whole idol
#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.UIElements;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class playerJumping : MonoBehaviour
{
    public Rigidbody2D rb;
    public float speed;
    private bool isGoingUpwards;
    // Minimum vertical velocity thresold to consider movement. When we have this player is basically stationary in the middle
    public float velocityThreshold = 0f;
    public float verticalVelocity;
    public float RDV; //Rotate Downwards Velocity
    public float RUV; //Rotate Upwards Velocity 

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        Quaternion localRotation = gameObject.transform.localRotation;
        // Access individual local rotation values (Euler Angles)
    }
    void Jump()
    {
        float verticalVelocity = rb.velocity.y;
        RDV = verticalVelocity / 10;
        RUV = verticalVelocity / 10;


        if (verticalVelocity > velocityThreshold)
        {
            isGoingUpwards = true;
            positiveSpin_LookUP();
        }
        if (verticalVelocity < velocityThreshold)
        {
            isGoingUpwards = false;
            negativeSpin_lookDownwards();

            if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) && (isGoingUpwards == false))
            {
                rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        Jump();
    }
    void positiveSpin_LookUP() 
    {
        transform.Rotate(new Vector3(0, 0, -RDV));
    }
    void negativeSpin_lookDownwards()
    {
        transform.Rotate(new Vector3(0, 0, +RUV));
    }
}
#

why is my shit only spinning towards one direction?

rare basin
#

chat gpt code?

whole idol
#

what do you mean?

#

no it's not

#

I literally changed this a thousand times to get here

burnt vapor
whole idol
#

look at my previous messages

#

yes bro

#

they are both being called

rare basin
#

how did you make sure they are?

burnt vapor
#

Did you actually confirm this by logging a message or this an assumption?

whole idol
burnt vapor
#

That doesn't matter

whole idol
#

ok imma log this actually

#

thats a good idea

rare basin
#

crazy you need to tell people to check those things

burnt vapor
#

That's the whole point of debugging, pinpoint the actual issue

whole idol
#

wdym?

burnt vapor
#

So let's see if your code is actually called in general

whole idol
#

@rare basin

burnt vapor
#

You can test this by logging inside the method or logging isGoingUpwards

whole idol
#

im doing it rn

#

They are all being called

#

lol

#

I told you this is not the problem because I can literally see the player ball spinning towards only one direction

#

the problem isnt about the methods not getting called but the way transform.Rotate(new Vector3(0, 0, -RDV)); works

#

transform.Rotate(new Vector3(0, 0, -RDV));

#

I changed this a thousand times

#

nothing works

#

I googled it

#

asked chatgpt

burnt vapor
#

How would you know? Perhaps one one method was called which causes the constant rotation

whole idol
#

asked anyone

rare basin
#

debug -RDV

whole idol
#

I did

rare basin
#

what's the value

whole idol
#

I can literally see the value being changed in the transform inspctor

#

also I can literally see the value here

rare basin
#

please do as requested

#

debug -RDV

whole idol
#
verticalVelocity```
#

Okay Imma try that

#

I also think that one is broken

burnt vapor
#

Write a debug log statement and debug both -RDV and +RUV. Place this log after you created the variables

rare basin
#

dont think

#

check

whole idol
#

Okay

#

Here's + and - RDV

burnt vapor
#

So it's always negative

#

Now log verticalVelocity

whole idol
#

ohhh I see what you're getting at

burnt vapor
#

Good job, you learned how to debug the issue

#

What is the conclusion?

whole idol
#

No conclusion, check this out

#

Vetical Velocity is positive when it's positive

#

and negative when it's negative

burnt vapor
#

So what did you do wrong?

whole idol
#

and the water here is made out of water

burnt vapor
#

You manually set the rotation to a positive/negative value, that's the issue

whole idol
#

I think its in the RUV

#

negative and positive

#

they're the same thing pretty much only one should be positive

#

and thats the issue im getting

#

it's never positive, it always thinks we're falling

burnt vapor
#

You can just use a single variable

whole idol
#

yep, tried that too

burnt vapor
#

You don't have to set it negative yourself because it already is

burnt vapor
#

You might have to switch it around depending on if the rotation is inverted but other than that you don't have to control it

whole idol
#

how did i not think of this earlier

burnt vapor
#

That's the thing I'm trying to hint at

whole idol
#

yeeeeee, thank you

#

imma try that now

#

so basically I only used one var

#
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.UIElements;
using static System.Runtime.CompilerServices.RuntimeHelpers;

public class playerJumping : MonoBehaviour
{
    public Rigidbody2D rb;
    public float speed;
    private bool isGoingUpwards;
    // Minimum vertical velocity thresold to consider movement. When we have this player is basically stationary in the middle
    public float velocityThreshold = 0f;
    public float verticalVelocity;
    //public float RDV; //Rotate Downwards Velocity
    //public float RUV; //Rotate Upwards Velocity 

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        Quaternion localRotation = gameObject.transform.localRotation;
        // Access individual local rotation values (Euler Angles)
    }
    void Jump()
    {
        float verticalVelocity = rb.velocity.y;

        Debug.Log("Vertical Velocity: " + verticalVelocity);


        if (verticalVelocity > velocityThreshold)
        {
            isGoingUpwards = true;
            positiveSpin_LookUP();
        }
        if (verticalVelocity < velocityThreshold)
        {
            isGoingUpwards = false;
            negativeSpin_lookDownwards();

            if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) && (isGoingUpwards == false))
            {
                rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        Jump();
    }

    void positiveSpin_LookUP() 
    {
        transform.Rotate(new Vector3(0, 0, verticalVelocity));
        //Debug.Log("Look up is called");
        //Debug.Log("Here's negative RDV: "+ -RDV);
    }
    void negativeSpin_lookDownwards()
    {
        transform.Rotate(new Vector3(0, 0, verticalVelocity));
        //Debug.Log("Look down is called");
        //Debug.Log("Here's positive RUV: " + +RUV);


    }
}
burnt vapor
#

Pretty much

whole idol
#

didnt even change rotation

#

tho

burnt vapor
#

You might still want to divide/multiply the velocity to have better rotation

#

It's not exactly a big number

whole idol
#

oh okay

#

where rotation?

#

😭

proven junco
#

okey does someone know why my game is fd, I can run it without any problems on my pc but when I build and run it on my laptop instead the movment gets messed up big time, like I get suuuper speed and the camera glitches

#

I've tried changing the code n stuff but nothing works

eternal needle
proven junco
#

yeah I have no clue how deltatime works, I did look into it a but bc it seems like that should be the problem

#

found a forum abt the same thing

#

and they were talking about deltatime

#

but I have no clue how that works

#

and that forum was like 14 years old

#

Cant even send my code in chat it is too long aperently

green ether
#

If speed is different depending on device/ framerate you are very likely missing some deltaTime multiplication

#

If you for example add speed in update, it will happen more often on a higher framerate > faster
On a slower device update gets called less often -> less speed

upper night
#

hey peeps! is it possible to Use unitys tree editor via a script? cant seem to find anything on the docs? looking to call it to create random trees in real time?

rocky vortex
#

im struggling with my inventory system. Im using prefabs to create the object when the player drops the item and im working on the pickup() now.
public void PickUpItem(GameObject prefab)
{
//AddToInventory(prefab); not working currently as the function requires a GearDefinition instead of GameObject
Destroy(prefab);
}

public void PickUpItem(GearDefinition prefab)
{
AddToInventory(prefab);
Destroy(prefab);
}
//ERROR FOR PICKUPITEM(GEARDEFINITION): ArgumentException: GetComponent requires that the requested component 'GearDefinition' derives from MonoBehaviour or Component or is an interface.
UnityEngine.GameObject.GetComponent[T] () (at <6c9b376c3fca40b787e8c1a2133bf243>:0)
InputManager.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/PlayerScripts/InputManager.cs:156)

When I try to add each asset item i created via the menu I created, (create asset menu... etc), into the prefab of the SampleScene, it doesnt give me the red circle saying I cant add it to that gameobject, however it doesnt get added. When I try to add it in the project window itself of the prefab, I get that red circle meaning I cant add it. Basically Im not sure how to connect between the gameobject prefab and the gear definition the inventory functions require. Why is monobehaviour necessary as the error suggests ? I need these items to be inherited from all the definitions I set for it to work.

#

also, not sure if this is considered #💻┃code-beginner or should be in general or advanced, but lmk 🙂

gaunt ice
#

show the declaration of GearDefinition, i think it is not child class of monbehaviour nor component

rocky vortex
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "Items/Gear")]

public class GearDefinition : ItemDefinition
{
    /*
     * https://forum.unity.com/threads/virtual-and-override-functions.314853/


     */
    public virtual void OnEquip(Inventory target)
    {
        Debug.Log("Equipping item: " + itemName);
    }

    public virtual void UnEquip(Inventory target)
    {
        Debug.Log("UNequipping item: " + itemName);
    }
}
#

oops lol

gaunt ice
#

ah, is this scriptable object?

rocky vortex
#

yes

#

sry, i think i forgot to mention that initially

gaunt ice
#

then reference it in serialize field

#

you cant add it as component

queen adder
#

Can someone help me turn the currency Variable in to a string. ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class gorillaWorks : MonoBehaviour
{
[Header("Currency")]
public TextMeshProUGUI currency;

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

}

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

}

}

gaunt ice
#

not turn it into string, access it .text field to get the display text

queen adder
languid spire
#

also probably should not be using TextMeshProUGUI

queen adder
#

oh ok

#

what should i use insteaD?

languid spire
#

TMP_Text

queen adder
#

ohh

rocky vortex
queen adder
#

that makes more sense...

#

I fixed it but its saying not to use the equal sign.

rocky vortex
#

im not trying to drag all equipable items as a reference through serialize fields, trying more to do it programmatically, so im not understanding the serialize field part

languid spire
gaunt ice
#

when you pick up a prefab on ground then get the scriptable object associated with it, and store it into your own inventory? i dont know how you write your inventory code

queen adder
#

I don't know whats happening or how the error is appearing?

languid spire
# queen adder

this code is correct, you have just put it in the wrong place. Move it into the Start method

queen adder
#

OHHH

rocky vortex
gaunt ice
#

prefab references the scriptable object

rocky vortex
#

via serializefield? So I should add a script to each prefab that inherits from monobehavior, have a serializefield for the gear definition, then add each definition to each prefab item via that serializefield, am I understanding correctly ?

gaunt ice
#

yes, since your gear definition is not component and you have to reference it (scriptable object) through serialize field

rocky vortex
#

perfect, ty that makes sense

queen adder
#

Yo I need help cause its saying I need a comma cause of syntax error?

rocky vortex
#

money = 100

queen adder
#

oh

#

its still there

#

the error

rare basin
#

configure your ide

queen adder
#

it is configured

rare basin
#

it is not

queen adder
rare basin
#

see what

#

screenshot your code

queen adder
rare basin
#

yup

#

it is not configured

#

!ide

eternal falconBOT
queen adder
#

its fixed

#

i don see error no mo

rare basin
#

not related to have your ide configured

queen adder
rare basin
#

no, it is not...

queen adder
rare basin
#

that's not related to have configured ide

queen adder
#

its configured

rare basin
#

your ide is not underlining errors and is not autocompleting code

queen adder
#

wait

rare basin
#

don't argue please

#

and configure your ide

queen adder
rare basin
#

jezus

#

that's NOT related

#

to have your IDE configured

queen adder
#

its configured

rare basin
#

put that public TPM_Text test1 under any variable

#

and screenshot your code

lean basin
#

How do I convert Quaternion rotation to Vector3 direction? (not euler angle)
[I thought it was](#💻┃code-beginner message) Vector3.forward*quaternionRotation
but the compiler said it can't do that.

hmm perhaps I was making stupid mistake, but I don't know what it is.

rare basin
#

you cannot multiply Vector with Quaternion types

brave compass
rare basin
#

it doesnt matter

lean basin
brave compass
#

In this case, the multiplication is non-commutative.

rare basin
#

huh, interesting

burnt vapor
#

It depends on whether the type has defined what behavior multiplication does on it with another type

#

Seems like one way it exists but not the other way

#

Which indeed is confusing but I guess there is a reason for it

keen dew
#

Matrix multiplication is non-commutative, vector * quaternion would have a different result (which would be even more confusing.) Theoretically they could have ignored "proper" maths and just swap the operands behind the scenes but who knows

static cedar
#

Vector3 * Vector3 should return a quaternion.

willow scroll
static cedar
#

Following the distributing property. And the properties of i, j and k.

willow scroll
#

What do you mean?

static cedar
#

Quaternion is complicated shit but I might get this wrong.

willow scroll
#

Well, 2 Vector3s cannot be multiplied, as there is no operator for it

#

The 2 overloads for the * operator include (Vector3, float) and (float, Vector3)

static cedar
#

There's actually a pretty good video that shows how you multiply Vector3 and end up with a quaternion.

#

Letting the x, y, z components be the i, j, k.

#

ijk = 1
ij = k
jk = I
ik = j
ii = jj = kk = -1 (I think)
Yeah I got these wrong pretty sure.

Just imagine a vector set be:
ai + bj + ck
And a, b, and c variables.

#

After simplyfing, you end up with Hamilton product which is what you also use with quaternion multiplication.

static cedar
# static cedar There's actually a pretty good video that shows how you multiply Vector3 and end...

https://youtu.be/htYh-Tq7ZBI?si=HGAPKyl_ZrBRF__1

Title is odd, "Why can't you multiply vectors" then proceeds how to multiply vectors. I found this helpful to get a basic idea on what quaternion is.

..or can you? A deceptively simple question with a complex answer – come join a mathematical journey into madness and wonder, in search of answers that might just give you a new perspective on the mathematical constructs we use in our games

Recorded at Dutch Game Day 2023, October 4th

Timestamps:
00:00 Intro
04:34 Talk Start
05:17 Anatomy of a...

▶ Play video
split dragon
#

Hi. I decided to add dictionaries to my script and looked at what they are and how to add them on the Internet. I did the same thing, but nothing works. What's wrong?

willow scroll
#

I was simply referring to Unity not having a built-in method to multiplicate Vectors, as there's no operator for it

willow scroll
spare brook
#

I have a button that closes the dropdown menu. The dropdown chooses images, gameobjects to be loaded. I want the gameobjects to be loaded when the dropdown menu is closed. (it is not loading - what should I do)

split dragon
willow scroll
split dragon
rare basin
#

you can initialize the dictioanry when declaring the variable

willow scroll
# split dragon I get it now. That's how it seems:

Yes, that's right. You can also initialize the Dictionary with the items without needing to add them via the method.

Dictionary<int, string> dict = new Dictionary<int, string>()
{
    { 1, "foo" },
    { 2, "bar" }
};

Additionally, you may also want to simplify the new()

Dictionary<int, string> dict = new() { } ...
rare basin
#

or you can just use serialized dictionaries, so they would be visible in the inspector

#

this is Dictionary<enum, Vector2> for exmaple

split dragon
#

Thank you very much. Now I understand )

scarlet skiff
#

I want it to run that code in the ground collision check only if the child named GroundCollider touches the ground and not if the other (larger) collider touchesd it, what am i doing wrong here?

willow scroll
eternal falconBOT
static cedar
willow scroll
rare basin
#

or use some editor extension assets like Odin Inspector

willow scroll
rare basin
willow scroll
rare basin
#

serialized dictionaries are life changers for me 😄

#

making the code architecture so much easier to maintain

willow scroll
#

Yes, you can also make a dictionary serializable by creating a custom Attribute

static cedar
rare basin
#

it's free and with CC0 license

burnt vapor
static cedar
burnt vapor
#

So then make it exist, the code you shared doesn't show what would make the game object

scarlet skiff
static cedar
spare brook
# burnt vapor What do you mean with loading? The gameobject does not exist?

The top left button is a button that toggles visibillity of the drop down menu (top right button). Inside the top right button, there are three options: the green image, the red image, the yellow image (originally set as false - where you cant see them). I want the user to choose an option and then click the button on the top left, which will then display the option that they have chosen

burnt vapor
#

But perhaps you want to define a variable that represents an index, and set the image under that index as active. Then you can just check using the index

willow scroll
# scarlet skiff i would rather not have to create 2 extra scripts for this simple collision, any...

Yes, you can use the Collider2D.GetContacts method, which returns the number of contacts placed in the array.
You can create an array with 2 items, as this is the amount of children your object has, but the better option will be to create an array with the childCount items.
Iterate through every contact and find the desired one by e.g. checking its tag.

private void OnTriggerEnter2D(Collider2D collision)
{
    var contacts = new ContactPoint2D[transform.childCount];
    collision.GetContacts(contacts);

    foreach (ContactPoint2D contact in contacts)
    {
        if (contact.collider.CompareTag("myCollider"))
            // ...
    }
}
static cedar
#

Real. That's sad.

split dragon
#

Okay, I'm still dumb.: How do I use TMP_Text for a dictionary?

split dragon
spare brook
green ether
split dragon
green ether
#

aight 🤷‍♂️

willow scroll
# split dragon Sadly. Thanks

The TMP_Text is abstract and thus cannot be created.
Referencing the TMP_Texts above also won't work, because of the field initializer not being able to reference a non-static field.
You'll have to either set it directly in the Inspector or add via the method, as you've done previously

burnt vapor
#

TMP does not have any implicit conversion from strings so I think you're confused

gaunt ice
#

you can use whatever you want as dict key if them have implemented GetHashCode and Equal, but the unity object hash code is unique that means you need the exact instance to get back the value.

burnt vapor
#

If you want to bind a specific TMP instance to write text to then you should find the component and not whatever this is

willow scroll
#
  • activeSelf returns true if the GameObject is active, regardless of any of its parents being active or not. This means, the GameObject may be activeSelf without being visible in the Scene
  • activeInHierarchy returns true if neither of the GameObject's parents are active. If activeInHierarchy is false, there's no way for you to see the GameObject
#

The code also deactivates the GameObject if it's already deactivated

abstract pelican
#

How can we play this up so it's not used in the update?

tough cave
#

Someone that can tell me if there's a prettier way to do this? the red ball is supposed to be a weapon that shoots randomly 1 of the 3 shapes. I want to display that shape above it in a frame (the red square). I thought maybe give every type of bullet a tag of its type/shape, and then compare its tag with bunch of if statements. but idk i really like this approach.. looks ugly idk.

  public void displayTypeOfBullet(GameObject bullet)
    {
        if (bullet.CompareTag("CubeBullet"))
        {
            hideTypeOfBullet()
            typesOfBullets[0].SetActive(true);
        } else if (bullet.CompareTag("CapsuleBullet"))
        {
            hideTypeOfBullet()
            typesOfBullets[1].SetActive(true);
        } else if (bullet.CompareTag("CylBullet"))
        {
            hideTypeOfBullet()
            typesOfBullets[2].SetActive(true);
        }
    }
    
    public void hideTypeOfBullet()
    {
        for ( int i = 0; i < typesOfBullets.Length; i++)
        {
            typesOfBullets[i].SetActive(false);
        }       
    }
wintry quarry
wintry quarry
#

make a Dictionary<BulletType, GameObject> to note which type correspnds to which thing

#

then just look it up in the dictionary

wintry quarry
#

wdym "no work"?

#

Why are you trying to get the component from your OWN GameObject here?

modest dust
wintry quarry
# abstract pelican no work

You should probably have a general Item component on the object that has things like public bool IsUsable public bool IsDroppable etc.

#

you shouldn't be checking individual item types here

abstract pelican
#

I need to make when I pick up food it shows its panel, if another item it shows another panel

modest dust
# abstract pelican no work

First you called GetComponent on inHandItem, now you changed it and call it without it, what did you expect would happen?

wintry quarry
#

btw inventory items are kind of the classic use case where people try to use inheritance and it goes wrong

#

because inheritance isn't really equipped for that

abstract pelican
#

I don't do inventory.

#

I pick up an object, food I can eat.

tough cave
wintry quarry
#

in the first sentence

#

put a script on the bullet that has some kind of BulletType field on it

abstract pelican
#

I have panels with information on what I can do with an item. Food has its own panel, items have their own.

wintry quarry
#

Yes I understand that

#

and I made my recommendation of the best approach to use

abstract pelican
#

Because of this I made such a check, but it's expensive in the update

wintry quarry
#

I don't understand why you need it in Update

#

just puit it in the code when you pick the item up

abstract pelican
wintry quarry
#

and cs public bool IsDroppable { get; }

#

that will solve your problem

abstract pelican
#

Food class

wintry quarry
#

yes

#

continue implementing it

#

Do you understand how interfaces work? You need to now implement those properties on the class.

rare basin
rare basin
#

especially with serialized dictionaries, you definitely can

abstract pelican
#

or in the interface?

wintry quarry
#

the class

abstract pelican
#

IUsable

wintry quarry
#

the class implements the interface

#

so it has to implement all the things in the interface

#

finish doing so

abstract pelican
#

okay ty

bitter walrus
#

My bullet goes fast slow fast slow, how can I fix it?

wintry quarry
#

Without seeing the code, it's hard to say any more than that

bitter walrus
wintry quarry
#

¯_(ツ)_/¯

#

Without seing the code, nobody can say

bitter walrus
#

Ama send it

wintry quarry
#

it's probably faulty in that project too. Likely an improper use of Time.deltaTime

honest haven
#

i need some help trying to get this courite to work but it does not like the void

#

but my function seems to throw a error if i remove the void

wintry quarry
#

this is like rule #1 of coroutines

bitter walrus