#💻┃code-beginner

1 messages · Page 190 of 1

rocky canyon
#

probably the readme thing

swift crag
#

they screwed up their TLS certificate

#

boing

storm imp
#

how come all three buttons go to the same photo?

rocky canyon
#

im gonna roll out my own splines system tho..

median ruin
#

it is a premade asset

rocky canyon
#

so ill just 86 this one while im here

wintry quarry
rocky canyon
#

b/c u probably moved the graphics

#

and the parent container has the same rect/ anchors

wintry quarry
median ruin
#

I don't know how find assembly definitions

wintry quarry
#

it's a file with a puzzle piece icon

#

.asmdef extension

swift crag
#

search for t:asmdef in the project window

#

and filter to the folder you're currently in

storm imp
wintry quarry
rocky canyon
#

i just explained it to u..

wintry quarry
#

and again what does it have to do with code?

rocky canyon
#

the parent (rect transforms) and anchors are the same..

#

u just duplicated hte same button over and over

median ruin
storm imp
rocky canyon
#

and moved the graphics

wintry quarry
wintry quarry
#

Or just move your code outside that folder entirely

rocky canyon
#

you did this.. thats why its showing the same button.. (the rect IS in the same place)

#

you only moved the stuff inside

wintry quarry
storm imp
median ruin
#

I mean, how can I add it

wintry quarry
median ruin
# wintry quarry there's a list of dependencies in the asmdef, add TMP to it
{
    "name": "fps.Game",
    "references": [
        "GUID:1826c0224c0d048b88112c79bbb0cd85"
    ],
    "includePlatforms": [],
    "excludePlatforms": [],
    "allowUnsafeCode": false,
    "overrideReferences": false,
    "precompiledReferences": [],
    "autoReferenced": true,
    "defineConstraints": [],
    "versionDefines": [],
    "noEngineReferences": false
}
wintry quarry
#

look at it in the inspector in Unity

#

not in a file editor

median ruin
#

oh I see

polar acorn
wintry quarry
rocky canyon
#

its focusing on the RECT TRANSFORM!!!... YOU moved the graphics buit didnt move the actual Object

wintry quarry
#

I'm not sure if they're saying that or if they're saynig someting about when they click the button in the game

rocky canyon
#

yea they're talking about the Focus of the window im pretty sure..

rocky canyon
#

i could be wrong.. lets listen.. 👂

wintry quarry
#

you have to show how you configured the on click listener

polar acorn
# storm imp sorry

You were told what to show and then took another screenshot that also doesn't show it

rocky canyon
#

ya, now im curious of what he means by "go to another button"

storm imp
#

click listener what's that?

wintry quarry
#

it's the first thing you would look at if you're worried about what the button is doing when you press it

wintry quarry
polar acorn
rocky canyon
#

see.. thats why i thought it was the focus / bad transform positions.. i haven't even seen a event listener

median ruin
#

Is there a way to use "OnTriggerEnter" and "OnTriggerExit" on objects that are not the parent of the script?

swift crag
#

you mean objects that the script isn't attached to?

rocky canyon
#

it trickles down the hiearchy..

rocky canyon
#

but not some other object entirely. i dont think it works that way

swift crag
#

no, it doesn't trickle down

rocky canyon
#

if it has a rigidbody and colliders it does doesnt it?

swift crag
#

Rigidbodies can receive trigger and collision events involving child colliders

rocky canyon
#

it counts as a composite colldier

#

ya, thats what im meaning

wintry quarry
median ruin
median ruin
swift crag
#

explain your actual problem

wintry quarry
swift crag
#

not your attempted solution, mind you

median ruin
wintry quarry
#

Put a script on the zone object.

median ruin
#

And. have the variables attached to the prefab

swift crag
#

i don't know what that means

rocky canyon
rocky canyon
storm imp
swift crag
#

I think you need to follow the tutorial you were linked to.

wintry quarry
wintry quarry
low path
#

have there been recent updates to the UI system or is it basically the same it's been for like 7 ish years?

wintry quarry
#

UGUI is basically unchanged

low path
#

a new new one?

wintry quarry
#

UI Toolkit is all new

low path
#

when is that from?

rocky canyon
#

when you make a button you can set up what it does when you click it straight from the inspector..
but usually you'll want to code in the behaviour in a public function from some script.. you drop the object w/ that script into the slot and pick the function (w/e u want the button to do)

median ruin
wintry quarry
#

idk maybe ~5 years ago? It's still a work in progress

swift crag
#

Explain what the problem is, Rem

#

an actual concrete issue you're having

rocky canyon
#

but yea, watch some Button Tutorials and stuff.. you wont regret it.. considering buttons is a big part of games

swift crag
#

why can't you just put a trigger collider and a component with OnTriggerEnter together?

#

what about that isn't working for you?

#

if you explain that, we can probably help you

median ruin
swift crag
#

Oh, I see.

#

Okay, so here's what you should do.

low path
#

so there was imguig, then ugui, then they made a whole new one? hopefully it's easier to use than ugui, as that was pretty convoluted...

swift crag
#

The prefab root should have most of the logic on it.

rocky canyon
# median ruin I'm not sure what you mean by that
    void OnTriggerEnter(Collider other)
    {
        // Check if the colliding object has an Enemy component
        Enemy enemy = other.GetComponent<Enemy>();

        if (enemy != null)
        {
            // Call the Damage function on the Enemy component
            enemy.Damage();
        }
    }``` i simply mean.. when unity detects a collision / trigger enter or w/e *you'll then have a reference to the thing you hit*

like in this example we take the `other` variable and check if it has an Enemy script.. and if it does we can call a function from it.. (so if you had variables or w/e you needed, you'd be able to get that stuff when the collision takes place)
swift crag
#

The collider object (which is a child) should have a component whose only job is to notify the root component about the trigger

#

Nothing else.

#

Only do this if this actually makes sense, of course

rocky canyon
#

^ and thats what i meant by keeping it simple..

wintry quarry
swift crag
#

If the prefab represents a single zone, or is fundamentally tied to a single zone, then go for it

#

If the prefab has many zones, then it doesn't really make sense to have zone configuration on the root

#

you'd have zones configuration

#

i guess :p

rocky canyon
#

designing interactions can be tricky..

#

i always take a bit of extra time to jot down what alls on the object.. and how i could keep things seperate.. like in the zone example, id probably put the trigger code on the trigger itself.. and keep it away from anything i got going on in the player..

#

but like Fen said.. its different for everyone..

swift crag
#

whiteboard it!

rocky canyon
#

facts!

scarlet skiff
median ruin
swift crag
#

talking to yourself can also be effective

spiral narwhal
#

If there is a list of a mono behavious (for example, List<Item> and Remove is used to remove an actual instance, will the actual instance be deleted or just the first element because it's the first of the type?

rocky canyon
#

lol.. RubberDuck FTW!

median ruin
swift crag
#

The first matching reference is removed from the list

polar acorn
swift crag
#

you're throwing out a post-it note, not the actual object

#

Also note that destruction is a very specific Unity concept

#

C# objects in general aren't "destroyed"

#

Once every reference to an object has been lost, the garbage collector can clean it up. That's it.

vague dirge
#

Hi, when you use transform.y for example, it uses the y world location, but I was wondering if it was possible to set manually the y attribut of a transorm
. Like if I want the transform.y the correspond to a given vector

swift crag
#

transform.y does not exist. transform.position.y does exist.

rocky canyon
polar acorn
swift crag
#

You can't set transform.position.y directly because transform.position returns a copy of the position, and modifying it would beuseless

swift crag
#

You can save transform.position in a variable, modify the variable, and store it back in transform.position

swift crag
vague dirge
swift crag
#

but AA talked about an instance being "deleted"

#

so I wanted to clarify how things can even get "deleted" in the first place

polar acorn
# median ruin why does it matter?

It's not really an issue of mattering, that's just how C# works. It clears up memory for you when nothing is still referencing something so you don't need to keep track of memory allocation

#

It's not like you can change that

spiral narwhal
#

But it would be better to yield the index of the object and use the index to delete a mono behaviour from a list, right?

median ruin
rocky canyon
swift crag
#

"yield the index of the object"

#

If you want to remove an object from a list, remove it

#

That's it

#

theList.Remove(whateverYouWantToRemove)

languid spire
#

I think he means List.RemoveAt

swift crag
#

You could indeed get the index of an object, then use that index with RemoveAt

#

it would be essentially equivalent to using Remove

spiral narwhal
#

I guess I'm concerned about whateverYouWantToRemove being of a type that Unity can't differentiate from other objects of the same type, therefore removing another object if Remove(whateverYouWantToRemove) would be called

swift crag
languid spire
swift crag
#

The list looks for the first element that equals the object you provided

polar acorn
#

Because both are the same object

swift crag
#

or your Equals method sucks

#

Every kind of object can be compared for equality (it's often just reference equality)

languid spire
#

I think we have a fundamental misunderstanding of C# here

polar acorn
polar acorn
#

Whether or not you were supposed to mark those two equal is a different matter

spiral narwhal
#

Let me share actual code because it's a bit abstract now:

 public class Bee : MonoBehaviour {
  public Apiary home;
  private void Reproduce() {
    var newBee = Instantiate(this);
    home.Add(newBee);
  }
}

So here the home has the new instance of the bee.

public class Apiary : MonoBehaviour
    {
        private readonly List<Bee> _beeStock = new();

        public void Add(Bee bee)
        {
            _beeStock.Add(bee);
        }
}

Can I now use Remove of List to remove the exact instance of Bees I want?

swift crag
#

Yes.

spiral narwhal
#

Ok :)

swift crag
#

MonoBehaviour uses reference equality (as do most reference types)

#

Reference equality is strictly based on whether two variables refer to the same object in memory

wintry quarry
spiral narwhal
#

Ok

swift crag
#

Value types are different, since they, by definition, aren't references

#

you know, I'm not actually sure how that behaves

#

i tend to implement IEquatable if I'm going to be doing anything involving equality with a struct

distant widget
#

can you help me out? in my game player has animations and when i press down shift and hold it it sets animation Run to true but when i put my finger up and dont t click anything Run stays true

#

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

public class PlayerScript : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb;
public float walk;
public Animator anim;
public float walksSpeed = 4;
public float runSpeed = 9;
public bool run;

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

}

// Update is called once per frame
void Update()
{
    walk = Input.GetAxisRaw("Horizontal");
    bool isRunning = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
    
    if (isRunning == true)
    {
        anim.SetBool("Run", true);
        
    }
    else if (isRunning == false)
    {
        anim.SetBool("Run", false);
    }

    if (walk > 0)
    {
        anim.SetBool("walk", true);
        transform.rotation = Quaternion.Euler(0, 0, 0);
    }

    else if (walk < 0)
    {
        anim.SetBool("walk", true);
        transform.rotation = Quaternion.Euler(0, 180, 0);
    }
    if (walk == 0)
    {
        anim.SetBool("walk", false);
        anim.SetBool("Run", false);
    }




    rb.velocity = new Vector2(walk * moveSpeed, rb.velocity.y);

   
    





}

}

swift crag
#

!code

eternal falconBOT
languid spire
#

!code

eternal falconBOT
eternal falconBOT
swift crag
#

dammit

#

lmao

wintry quarry
#

lmao

polar acorn
#

TRIPLE KILL

swift crag
#

please share that on a pastebin site (:

distant widget
#

okay

languid spire
#

dont check a float for equality

distant widget
#

what? i dont get it im quite new

#

oh oh

#

now i get it

languid spire
#

floats dont work well when you do ==

polar acorn
#

It is unlikely that your value will be exactly 0. Due to imprecision, it could be something like 0.000000002

distant widget
#

i checked it but it is 0

polar acorn
visual hedge
#
            yield return new WaitForSeconds(0.7f);
            //DoDamage();
            BSM.PerformList[0].choosenAttack.Activate(this, ChosenAttackTarget.GetComponent<UnitStateMachine>());
            yield return new WaitForSeconds(0.25f);

is there a way to tell to coroutine to wait until the BSM.Perf... is done executing? Or is it waiting for it by default?

swift crag
#

I don't know what that thing is

#

If Activate is a regular method, the coroutine will completely execute that method, then continue on the next line (as per usual)

polar acorn
visual hedge
languid spire
#

not true

swift crag
#

If Activate does nothing but start a coroutine, then it'll return after starting the coroutine as per usual

#

If Activate returns that Coroutine object, then you can yield return it to wait for the other coroutine to complete

languid spire
#

wait, starting the coroutine and running it until the first yield

wintry quarry
polar acorn
swift crag
visual hedge
#

thank you sir and madam

swift crag
#

Unity will go through all of them every frame, one at a time, and resume each coroutine (unless they yielded something like a WaitForSeconds that makes Unity resume them at some other time)

#

It's not concurrent programming.

spiral narwhal
#

Should MoveTowards be in Update or FixedUpdate

wintry quarry
summer stump
ivory bobcat
#

It simply moves the value of a vector3 towards another vector3.

swift crag
#

indeed: it does nothing more

#

just like Mathf.Lerp does nothing but give you a value between two points

#

(and Vector3.Lerp!)

spiral narwhal
#

I'm moving transform position to move from one position to a target

visual hedge
#

is there a way to wait till animator finished playing the desired animation?

ui.animator.Play("Attack");

So basically what I have now is that coroutine does not wait till the animation is finished and goes further. And well, yield return new WaitForSeconds() doesn't quite solve the problem since I have different attack animations for different heroes with different duration so it shall be a bit more universal approach.

swift crag
#

WaitUntil accepts a method that returns a bool and runs it until the method returns true

#

That may be useful.

#

yield return new WaitUntil(() => ui.whatever == 123); will park the coroutine until that function returns true

visual hedge
#

that's what ChatGPT suggests. Should do the job?

swift crag
#

i would advise against using the spam machine to try to learn to make games

#

If the end of that is || ui.animator.IsIntransition(0), then it will immediately end the loop if the transition takes a non-zero amount of time

#

it's cut off

#

oh, I read that backwards

visual hedge
#

ui.whatever == 123 what do you mean by 123 please?

swift crag
#

well, I'd need to see the whole line either way

swift crag
visual hedge
#
                ui.animator.Play("Attack");
                while (ui.animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1f || ui.animator.IsInTransition(0))
                {
                    yield return null;
                }

that's what chatgpt suggests
AAAAnd it doesn't get the job done

swift crag
swift crag
visual hedge
swift crag
#

You can just check if you're currently in the "Attack" state

#

That would require fewer moving parts

rare basin
#

or use enums to determine what state you are in

#

MOVE, IDLE, ATTACK

#

and make your logic based on that

swift crag
#

yes, but we have to decide when the attack is over

rare basin
#

can do via animation events for instance

swift crag
#
yield return new WaitUntil(() => !ui.animator.GetCurrentAnimatorStateInfo(0).IsName("Base.Attack"));

That should be correct. It gets the animator state info for layer 0 and asks if the current state is named "Attack"

visual hedge
swift crag
#

I presume that Play immediately changes the active state

#

ha, well there you go

#

Although, that's wrong.

#

It should be Base.Attack

summer stump
swift crag
#

ChatGPT is excellent at producing plausible, yet wrong, code

visual hedge
summer stump
#

It's ok at dialogue at least
Not GREAT but... ok

swift crag
#

It mashes words together in a way that looks correct, but isn't

polar acorn
swift crag
swift crag
#
        if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Jump"))
        {
            Debug.Log("Jumping");
        }
#

e.g.

#

from the GetCurrentAnimatorStateInfo page

spiral narwhal
#

Is there a Mathf.Approximately for Vectors?

rare basin
#

depends on what do you want to compare

#

if they match?

swift crag
#

Vector3 comparison already uses some fuzziness

#

You probably just want Vector3.Distance, though

#

with some small constant

rare basin
#

Vector3.SqrMagnitude(a - b) might work aswell for ya

swift crag
rare basin
#

could probably achieve something with Dot product

#

rly depends on what do you want to do

spiral narwhal
#

Like this?

Vector2.Distance(transform.position, _plantTarget.Value) < 0.1f
swift crag
#

Yes.

spiral narwhal
#

Gotcha, thanks

swift crag
#

== returns true if the distance is less than one hundred thousandth

#

(which helps deal with tiny math errors)

paper sable
#

hey, i get this error on line 18 NullReferenceException: Object reference not set to an instance of an object. Im trying to make something happen when i click but i get this error

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

        GameManager.input.Player.Shoot.performed += Shoot; // <- this is line 18


    }
swift crag
#

I never compare vectors for equality, since I always want a specific amount of otlerance

#

Then somerthing on line 18 is null.

vague dirge
#

How can I rotate the bean of my character controller ??

paper sable
swift crag
#

that's obviously false

#

becaues you got a NullReferenceException

#

C# doesn't throw exceptions for fun

swift crag
clear seal
#

gpt sucks

summer stump
#

If you truly believe there is nothing null in there for the object you're looking at, make sure there isn't another instance of the script somewhere

But there IS something null there

grand forge
#

can any1 tell me whats wrong its not there

paper sable
grand forge
#

in my unity code slot where it should say rigdid body

swift crag
polar acorn
swift crag
#

Now prove it.

summer stump
swift crag
#

There are a LOT of member accesses on line 18

#

GameManager.input.Player.Shoot.performed

grand forge
swift crag
summer stump
grand forge
polar acorn
swift crag
grand forge
#

so there should be a box for my ridgid body but its not there

rare basin
#

bet IDE not configured aswell

ivory bobcat
eternal falconBOT
rare basin
#

is this the console?

storm imp
rare basin
#

configure your ide @grand forge

grand forge
rare basin
eternal falconBOT
grand forge
#

where i type that then

rare basin
#

type what?

summer stump
grand forge
#

im following a turtorial to try learn the code

polar acorn
rare basin
#

you dont type anything

grand forge
#

Im so lost

rare basin
#

you configure your IDE

#

step by step

#

!ide

eternal falconBOT
summer stump
ivory bobcat
rare basin
#

chooes your code editor

#

and go through each step and configure it

#

you dont type anything

polar acorn
wintry quarry
ivory bobcat
#

Null Reference Exception errors occur when you're attempting to access a member (in your case field/property) of variable that's null.
Accessing with the dot threw the error because one or more of these are null.

storm imp
wintry quarry
#

without you showing that, it's impossible to say.

rare basin
#

then add logic that should do it after you click the button

swift crag
#

can the mechanic do anything to help you yet?

main sail
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

storm imp
# wintry quarry _you have to show what code is running when you press the button_
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TourManager : MonoBehaviour
{
    //list of sites
    public GameObject[] objSites;
    //main menu
    public GameObject canvasMainMenu;
    //should the camera move
    public bool isCameraMove = false;

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

    }

    // Update is called once per frame
    void Update()
    {
        if(isCameraMove) 
        { 
        
            if(Input.GetKeyDown(KeyCode.Escape))
            {
                ReturnToMenu();
            }


        }
    }

    public void LoadSite(int siteNumber)
    {
        //show site
        objSites[siteNumber].SetActive(true);
        //hide menu
        canvasMainMenu.SetActive(true);
        //enable the camera
        isCameraMove = true;
    }

    public void ReturnToMenu()
    {
        //show menu
        canvasMainMenu.SetActive(true);
        //hide sites
        for (int i = 0; i < objSites.Length; i++)
        {
            objSites[1].SetActive(false);

        }

        //disable the camera
        isCameraMove=false;

    }

}
wintry quarry
#

you'd have to show how your buttons are configured (which is what I've been asking for this whole time and you still haven't provided)

wintry quarry
#

You'd also have to show what you have set up in that objSites array in the inspector as well

grand forge
#

where is preferences in this thing

#

im blind so yh

#

Found it nvm

dire tartan
#

hey ive got a problem and i think i know how to fix it i just want someone who knows what they are doing to double check bassicly ive got a ragdol made up of different shapes connected with configurable joints i use its drive force to get it to be animated but an issue i have is when i turn collisions on for the hands gaps appear between the shoulder and arm if i rig the character and have the bones try to link to the model instead will that fix my problem?

clear seal
#

is this logical and technically possible?

wintry quarry
clear seal
wintry quarry
#

why is your HealthSystem variable called ballsHeld? Seems like poor name for a HealthSystem variable

wintry quarry
#

what are you trying to accomplish

clear seal
mighty falcon
#

holding balls is logical and technically possible

clear seal
#

the player needs to take a ball and then load it to the canon manually and then repeat

wintry quarry
#

yes, possible. No your code won't do that.

clear seal
mighty falcon
clear seal
ivory bobcat
clear seal
native seal
#

Is there a way to get a singleton to call its method when the scene changes? basically i want my save/load system to save then load every scene change

storm imp
polar acorn
storm imp
glossy eagle
#

Hi. One question, does anyone know how can I do like a variable where I can select multiple options please? Like when selecting a layermask, where you can select more than one at the same time

glossy eagle
#

thanks

spiral narwhal
#

Why can I not drag a Prefab that has a Script X on a ScriptableObject that demands a field X?

languid spire
#

you can

spiral narwhal
#

The arrow doesn't list the prefab

rich adder
#

the arrow?

polar acorn
spiral narwhal
#

Even in the Assets tab

polar acorn
#

Consider the intro to C# guide in the pins

spiral narwhal
rich adder
#

thats not an arrow

spiral narwhal
#

Yes the selector

#

It just says None

polar acorn
# spiral narwhal

Show the full inspector of this object and the prefab you want to drag in

rich adder
#

that thing barely works sometimes at detecting assets

spiral narwhal
#

I can't do that because it automatically closes the tab once I enter the other asset folder

rich adder
#

it pops it out into a new window

spiral narwhal
#

Right click what?

rich adder
#

the script ?

spiral narwhal
#

The prefab or the scriptable object

rich adder
#

or that ^^ lock

spiral narwhal
#

Ohhh

#

Cool

#

Thanks

rich adder
rich adder
#

if you right click even asset on Asset view

spiral narwhal
#

But just for learning: the preview bullseye or whatever cannot display prefabs?

rich adder
#

you can pop out its own inspector

languid spire
rich adder
#

idk if im doing it wrong but never does so I just drag n drop

spiral narwhal
#

Mm yes I agree. But thanks :)

storm imp
polar acorn
#

Do your other buttons have different numbers

storm imp
polar acorn
#

All of your buttons use the same number

clear seal
polar acorn
#

Wait that's literally the exact same screenshot

#

You still have button 1 selected

carmine sierra
#

why doesn't this work.. using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponSpawn : MonoBehaviour
{
public GameObject Weapon;

void OnMouseDown()
{
    Weapon.SetActive(true);
    Debug.Log("Spawned");
}

}

#

I have linked the gameobject

carmine sierra
#

but it doesn't spawn and the console doesnt write the line either

storm imp
carmine sierra
#

what does void mena

polar acorn
rich adder
polar acorn
#

Show your objSites array

clear seal
rich adder
carmine sierra
rich adder
#

cause that function needs collider

carmine sierra
#

yeah it works now thanks

#

thought it just detected off the sprite

storm imp
carmine sierra
polar acorn
rich adder
clear seal
rich adder
#

its an enum not method

clear seal
rich adder
#

there is also mouse built in Input.GetMouseDown(0)

carmine sierra
#

i deleted a duplicate camera and the consoles telling me the script is missing

#

how can i get rid of that

polar acorn
clear seal
#

is bad right?

storm imp
visual hedge
carmine sierra
polar acorn
#

@visual hedge @clear seal If you're going to just try to guess at the solution at least make it known you don't actually know the answer or you're just going to confuse the matter

rich adder
clear seal
#

so bascicly it act like a raycast touch?

visual hedge
#

oh... my bad, I haven't seen that that method is called thru button click

carmine sierra
clear seal
#

(sorry for bad english and i never tested that just saw thumbnails)

storm imp
rich adder
rich adder
polar acorn
#

I don't know what you put there

#

show it

carmine sierra
storm imp
polar acorn
polar acorn
carmine sierra
#

still dont get the difference cause couldn't both return an output

carmine sierra
#

thanks

#

so input can't be localized to clicking on a sprite

rich adder
#

void is an output

#

Input does return an output and its bool or float if you use GetAxis for example

carmine sierra
storm imp
polar acorn
carmine sierra
#

getaxis is the -1 to 1 one right

carmine sierra
#

okay but do better keyboards have better sensitivity controls?

rich adder
languid spire
#

that is something you set at the driver or OS level

rich adder
#

varies on so many things too

carmine sierra
#

like a keypress from up all the way down would have 1000 different values for a get axis or 100000 for better keyboard

languid spire
#

better, no, different key type, yes

polar acorn
#

A key is either pressed or it's not

carmine sierra
polar acorn
carmine sierra
#

is not a full press for getaxis right

#

so then getaxis is the same as raw?

polar acorn
rich adder
clear seal
#

my head

carmine sierra
#

yeah i read but couldn't half a press be a 0.5 or -0.5on the getaxis

#

while on raw it would be 1 or -1

clear seal
#

it no no wanna think :(

rich adder
#

its either pressed or not

carmine sierra
#

so how does getaxis work

storm imp
polar acorn
rich adder
#

off or on

polar acorn
carmine sierra
#

i read that

#

but doesn't that imply that there are values between 0 to 1 and 0 to -1 which would depend on how deep a key is pressed

polar acorn
#

it ramps up to 1 or -1 based on that sensitivity

carmine sierra
#

but wouldn't that depend on the keyboard

polar acorn
#

whereas GetAxisRaw does not do any smoothing

verbal dome
carmine sierra
#

how can the sensitivity be calculated digitally

polar acorn
carmine sierra
#

if its a physical movement

#

is it how long the key is pressed down

polar acorn
#

You press a key. It goes from not pressed to pressed

north kiln
#

It's an interpolation

polar acorn
#

GetAxis will smooth the value from 0 to 1 over time

north kiln
#

entirely in software (in Unity)

polar acorn
#

GetAxisRaw returns the actual state of the key, no smoothing

carmine sierra
#

oh okay so it goes to 1 if you keep it down till it can reach 1

#

rather than a tiny press

#

which would be like 0.2

rich adder
#

its mainly meant for Controller sticks/Mouse afaik

#

The meaning of this value depends on the type of input control, for example with a joystick's horizontal axis a value of 1 means the stick is pushed all the way to the right and a value of -1 means it's all the way to the left; a value of 0 means the joystick is in its neutral position.

#

keyboard key doesn't behave like that

storm imp
#

I guess I'm stuck at the moment

rich adder
polar acorn
rich adder
#

ahh misread that as array in code not obj

storm imp
potent zinc
#

I'm currently trying to check if an object is colliding with a different object the moment that it spawns, after searching on internet I can't find any way to do this. Could someone help?

polar acorn
fierce geode
#

I mean, it seems to work despite my collider moving?

rich adder
#

oh boy..

buoyant knot
#

it will jank on you if you do not do it properly

polar acorn
#

Which one are your buttons referencing

storm imp
rich adder
#

TourManager script

polar acorn
storm imp
carmine sierra
#

how would i go about stretching and rotating an objects wherever the mouse moves

#

whats the maths needed or can something easier be done

carmine sierra
#

rather than some angle calculations

carmine sierra
polar acorn
#

Half of four

rich adder
rich adder
carmine sierra
fierce geode
rich adder
storm imp
carmine sierra
#

but if it's easy i probably just need to get good and ill do it when i can

storm imp
#

I don't knew anymore

umbral marsh
#

sry for interrupting but what does this button do exactly? does it destroy the object or something else? found out after a few hours that it solves an issue i got when i toggle it off and back on, so id like to access that button by script... (not ideal i know)

fierce geode
rich adder
umbral marsh
#

if not ill be back

storm imp
polar acorn
polar acorn
#

how did you not notice there were two

#

you labeled them

storm imp
polar acorn
rich adder
#

or do you mean rotating it with the mouse axis not position?

carmine sierra
#

idk what a mouse axis is

#

but the end point of the object would be fixed

#

and it would rotate around that point

#

and only it's width would stretch

#

but i think thats what you mean by the axis#]

storm imp
rich adder
fierce geode
rich adder
carmine sierra
#

or the change in the mouse position after clicking down

native seal
#
    {
        Debug.Log("Updating experience bar: " + currentExperience + " / " + maxExperience);
        float targetFillAmount = (float)currentExperience / maxExperience;
        experienceBarText.text = $"Level: {level}";
        experienceBarSlider.value = Mathf.Lerp(experienceBarSlider.value, targetFillAmount, Time.deltaTime * 50f);
    }``` 

is there a reason my xp bar isnt updating smoothly? am I misunderstanding lerp?
carmine sierra
rich adder
#

Coroutine would be the cleanest

#

or use Dotween (very nice for UI animating)

summer stump
native seal
summer stump
#

Prime tween

rich adder
rich adder
buoyant knot
# fierce geode so... what's the correct way to rotate?

depends on your RB.
kinematic RB should use MoveRotation.
dynamic RB should only be moved by force.
Alternatively, if you want to teleport, then you need to do a physics query to see if the coast is clear, then change rigidbody.rotation

arctic ibex
#

Why cant I set rigidbody.velocity.x? Do i new to make a new vector2?

buoyant knot
#

that is the only way to exorcise the jank demons from your code

rich adder
verbal dome
arctic ibex
arctic ibex
#

aight, thanks

carmine sierra
summer stump
summer stump
fierce geode
# verbal dome Looks like you have an unwanted/incorrect collider there somewhere

I think it's due to the way I apply velocity, I multiply it by the character's rotation in order for the character to always be moving relative to the way their facing; but I'm finding that around 90 degrees along the loop in whichever axis is up is when the effects trigger. On one side of the loop, once you reach 90 degrees; the velocity's seem to reverse to force you back down and on the other side of the loop, seems any forward velocity moves the character to the left.

carmine sierra
carmine sierra
#

pressed down

summer stump
carmine sierra
#

lol i dont get it

summer stump
#

The instant the key down message is sent. The smooth interpolation begins

verbal dome
#

Are we still talking about getaxis/raw lol

carmine sierra
summer stump
#

It takes the same amount of time every time (the time can be changed via settings. But once set, it will take that amount of time). It starts the instant the key pressed event is received

#

Holding down the key will KEEP the value at one until the key is released, when the key up event is sent, and it will interpolate back down to 0

carmine sierra
#

so the time it takes to return to 0 is compared to the other times you pressed it or something?

summer stump
carmine sierra
#

okay yeah

summer stump
#

The INSTANT the key up event is received, the process begins

carmine sierra
#

so it could be useful for turning a car

#

in a game

summer stump
#

Sure. Or just moving a character so it has inertia

slender dock
#

where does this thing get called? i'm looking at LobbyUIMediator.cs from the Boss Room project ... i must have skipped over the Inject stuff when I was learning C#? :I~

limber narwhal
#

should i use internal or public for methods if i want to use methods in different scripts that are on the same gameobject?

summer stump
slender dock
#

:~I ... dang it

summer stump
median ferry
#

Does anyone know how to make a ladder work? I dont need animations just need to be able to climb up thanks

summer stump
median ferry
#

Move forward and they climb up

#

Its a 3d game

teal viper
summer stump
#

Could use raycasts or spherecasts in a similar way, and that would negate the need for checking direction

median ferry
#

Okay thank you

limber narwhal
median ferry
summer stump
median ferry
#

Yeah im sorry

#

I meant to put it in the beginner

#

Not the general code

summer stump
minor hemlock
#

I'm making a vr game and I'm going to implement a flashbanf sort of ability, but you point your hand at another player and if their in range they become flashed

#

idk how though

limber narwhal
summer stump
#

Easy enough to change when needed.
But yeah, you were right earlier

carmine sierra
#

i know i should learn myself but why doesn't this work

#

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

public class WeaponFire : MonoBehaviour
{
public float X_pullback;
public float Y_pullback;

void OnMouseDown()
{
    Vector3 originalPos =  Input.mousePosition;
    Debug.Log(originalPos);

}

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

}

eternal falconBOT
rich adder
#

what "doesn't work" mean

carmine sierra
#

input.mouseposition would save the position of the mouse right

rich adder
carmine sierra
#

yeah as i intended

rich adder
carmine sierra
spiral narwhal
#
var targetX = transform.position.x + Random.Range(-2f, 2f);
            var targetY = transform.position.y + Random.Range(-2f, 2f);

            if (targetX > CameraMovement.MAX_TOP_LEFT.x)
                targetX += Random.Range(1f, 4f);
            else if (targetX > CameraMovement.MIN_BOTTOM_RIGHT.x)
                targetX -= Random.Range(1f, 4f);

            if (targetY > CameraMovement.MAX_TOP_LEFT.y)
                targetY -= Random.Range(1f, 4f);
            else if (targetY > CameraMovement.MIN_BOTTOM_RIGHT.y)
                targetY += Random.Range(1f, 4f);

            _randomisedBuzzAroundTarget = new Vector2(targetX, targetY);

Is there a logical error? Because the constants are set up correctly, but the target still ignores the bounds

rich adder
carmine sierra
#

it is a polygon collider2d

rich adder
#

cause it sure as hell not where the script it

carmine sierra
#

ohhhh

teal viper
carmine sierra
#

cause i put it in the empty parent right

#

not the actual collider objects?

rich adder
#

right

#

it looks for the collider on itself

#

(maybe children but havent tried that)

ivory bobcat
carmine sierra
#

yeah it works now 😄

rich adder
#

but yeah like Dalphat mentions, Input.mousePosition is only Screen position

#

not world

#

big differences

carmine sierra
#

so that would mess up my code when used on different devices?

#

diff computers

rich adder
#

what no..

#

Screen Position is just the position on the pixel coordinates

#

World position is where your gameobjects live

ivory bobcat
rich adder
carmine sierra
#

so should i just make it a world position thing

rich adder
#

ScreenToWorldPoint

carmine sierra
#

thanks

rich adder
#

this changes the Screen position to world

#

obv lol

spiral narwhal
carmine sierra
#

screentoworldpoint and worldtoscreenpoint right?

rich adder
#

thats where your mouse is

carmine sierra
#

yh

rich adder
#

the gray/whiteboxes is the WORLD

#

X,Y,Z

carmine sierra
#

for 2d would both z's be the same

rich adder
#

the function transates that position in relation to the world

carmine sierra
#

so it scales it up to the screen size?

rich adder
rich adder
carmine sierra
#

i dont understand how it is different to the mouse position exactly

#

other than that it would calculate the depth in a 3d space right

#

the depth of the object being pointed at

rich adder
#

it lives on your screen, hence screen size aka Pixel Size

carmine sierra
#

yeah so for 2d could input.mousposition work fine

#

or does the screen to world world to screen thing need to be used

rich adder
#

Input.mousePosition is Pixel Coordinates

#

it has no relation to 3D or 2D

#

The bottom-left of the screen or window is at (0, 0). The top-right of the screen or window is at (Screen.width, Screen.height).

carmine sierra
#

ohh okay so it basically tracks the mouse even outside the window of the game is the issue

rich adder
#

nvm i confused myself, yes it tracks the mouse pos

carmine sierra
#

but in my case the object would always be clicked within the window and that's when I want the mouspos saved so it should be fine this time right?

rich adder
carmine sierra
#

or is there another benefit

median ferry
#

Yeah I'm so lost with making a ladder lmfao

#

Does Anyone have the time to help?

rich adder
carmine sierra
#

so thats why I should use the world coords?

rich adder
#

switch up movement to go up instead of forward with WASD

median ferry
#

Alright I'll try that

swift crag
carmine sierra
rich adder
swift crag
#

you should use the correct coordinate space because it makes zero sense to work in the wrong coordinate space

carmine sierra
#

if my object is in a windowed version of the game and clicked it would return a diff position than a windowed version in a diff area of the actual screen

swift crag
#

if I ask you what time it is and you say "34 feet", that's just plain nonsense

rich adder
#

yes thats what its for

carmine sierra
rich adder
#

the best way to get it is to Debug Values visually and see whats happening

#

use OnGUI

carmine sierra
#

if you get what im asking

rich adder
#

windowed or not , ScreenSpace is the same place

swift crag
#

they're asking about how screen space coordinates change with resolution

#

they will change, since screen space is measured in pixels

#

view space coordinates are normalized to the 0..1 range

carmine sierra
# rich adder I kinda don't know what you mean there lol

i am logging the coord when the object is clicked, if i clicked it in one space when it was in full screen then the game is windowed and taking up half the screen - the object would be a diff position on the actual screen, the mouse position logged that time would be different

#

it would be the same world position but not screen position

#

so the mous pos returned would be different

swift crag
#

Correct.

rich adder
#

the ideal thing is to be using the helper functions

carmine sierra
#

okay yeah i get it

carmine sierra
#

or is that a helper function

rich adder
#

like ScreenToWorld, WorldToScreen etc

carmine sierra
#

okay yeah

#

ill learn those then thanks

rich adder
swift crag
carmine sierra
#

can i subtract vector3s like this

swift crag
#

ah yeah, it's viewport space, not view space

rich adder
carmine sierra
#

to subtract the x and y components separately?

swift crag
#

and yeah, it's element-wise subtraction

#

which is how vector math normally works

#

* is not defined

carmine sierra
#

just wondering what games have you guys made?

swift crag
#

Vector3.Scale is used to do element-wise multiplication

rich adder
carmine sierra
#

oh yeah i don't get how scale works i put in a sprite with a certain resolution but then I can't find the resolution according to it's scale anywhere

carmine sierra
rich adder
carmine sierra
#

can you send that pls

carmine sierra
#

guarded looks cool but doesnt load

rich adder
rich adder
#

must be webgl issue ig

rancid tinsel
#

how would i find a child object with a tag at runtime?

rich adder
rancid tinsel
#

could you explain?

rich adder
#

[SerializeField] private Transform childObject

median ferry
#

Okay so i got my ladder to work

rich adder
#

you can do also transform.GetChild(indexOfchild) but its not robust

carmine sierra
#

i want to save the x and y values of poschange separately

median ferry
#

I can send an example if needed

rancid tinsel
rich adder
#

save it ina vector2 ?

rich adder
carmine sierra
rich adder
carmine sierra
#

my game is gonna be fully 2d so should i just use vector 2s

rancid tinsel
#

im trying to find a specific instance of a child of a prefab (in this case all my ground blocks will have a tree child gameobject that i only want to set active under certain conditions)

rich adder
#

both work exactly the same

carmine sierra
rancid tinsel
rich adder
carmine sierra
#

but i heard having alot of public's is bad

rich adder
#

a script ?

rich adder
carmine sierra
#

do i need to recall the variables when I want to use them?

rancid tinsel
rich adder
rich adder
carmine sierra
#

is something like this gonna work

rancid tinsel
rich adder
carmine sierra
rich adder
#

yes

#

check pins

cosmic dagger
carmine sierra
rancid tinsel
carmine sierra
#

like how I initialised the gameobject outside the methods

rich adder
#

but GetChild should suffice i suppose

#

just not solid

rancid tinsel
#

tbh your way is way easier

#

i dont see why i wouldnt do that 🤦‍♂️

rich adder
rich adder
#
SomeScriptBlock xBlock = Instantiate(blockPrefabs[0], new Vector3(j, 0, i), Quaternion.identity);
xBlock.SomeTree // do whatever with it```
#

blockPrefabs would need to be changed to SomeScriptBlock though
private SomeScriptBlock[] blockPrefabs

storm imp
#

I don't think I have an array for the button I have one for the site photos

rancid tinsel
carmine sierra
#

no errors so a private called outside all the methods can still be accessed anywhere throughout that script?

rich adder
rancid tinsel
#

i ended up just putting a script on the blocks themselves like this

#

is this not good?

rich adder
#

actually it wont work if it stars disabled..

#

scripts dont run on disabled gameobjects

rancid tinsel
#

i put it on the actual block parent though so it works

rich adder
#

gotcha

rancid tinsel
#

i tried out my map at 100x100 size and the scene view is laggy 😭

#

not surprised though

rich adder
#

do you have LOD and other optimizations setup ?

rancid tinsel
#

the map will probably be like 20x20 max

median ferry
#

My ladder works now thank you for helping @rich adder

rancid tinsel
#

oh yeah thank you navarone for helping me as well

carmine sierra
#

is that how I would call the mass value

onyx blaze
#

Hello, someone can help me?
I'm getting this error, but I don't know how to solve
I tried google, but don't works

FormatException: Input string was not in a correct format.

That's my code
int inGameItemID = int.Parse(EventSystem.current.currentSelectedGameObject.transform.GetChild(0).GetComponent<Text>().text);

I tried to show in a Debug.Log, and the result is always a number
I don't know where is the error :/
But the error are returning this line that I showed

summer stump
carmine sierra
#

Thanks

rich adder
#

you wont be able to use GetComponent there

carmine sierra
#

so get component is like a function and then the value is called with a dot after

rich adder
#

needs to run inside a method

carmine sierra
#

damn why?

#

cant save it for later

summer stump
#

Oh, yeah that's the initializer huh

summer stump
carmine sierra
#

ohh true

summer stump
carmine sierra
#

are methods built in functions

#

like getcomponent and debug.log

rich adder
summer stump
rich adder
#

these fields are created before methods are

carmine sierra
#

what's wrong with this code

rich adder
#

you cannot use something that wasnt created yet

carmine sierra
#

i see the console errors but not sure exactly what

summer stump
rich adder
eternal falconBOT
rich adder
#

I noticed before it wasnt highlighting red

summer stump
#

Make ammoMass a variable in the class, then just assign it in awake

carmine sierra
#

i need it to be public though so should I put it in start() or soemthing

rich adder
summer stump
#

public float ammoMass

void Awake() {
ammoMass =
}

native seal
#

anyone know how to stop my projectile from hitting multiple enemies that are stacked on eachother?

summer stump
carmine sierra
#

feels like this should work

#

errors are x and y_pullback and something about data types being converted

carmine sierra
#

the referenced gameobject has rb2d

summer stump
eternal falconBOT
rich adder
#

config your IDE if you want get help

carmine sierra
#

is that right

#

i cant find the devenv.exe

summer stump
rich adder
#

also this looks like Visual Studio

#

are you using vscode or visualstudio

carmine sierra
#

blue

rich adder
#

ohh

#

so follow VSCode one

#

it should not say (internal)

#

it should show the vscode version

carmine sierra
#

thanks

rich adder
carmine sierra
#

now that it does a debug does it mean its done

#

the thing still says internal though

#

yeahh and the lightbulb it works now i think

rich adder
carmine sierra
#

no it doesn't do that

#

i need to find the file they are asking for

#

also quick question can you run a build if there are errors

rich adder
carmine sierra
#

yeah cause it still says internal

rich adder
#

you dont need any files what are you talking about

#

did you click the link i've sent

carmine sierra
#

yeah

rich adder
#

the fix is there, follow the steps exactly

carmine sierra
#

okay

carmine sierra
#

it says something about restricted mode which limits the extensions so i take it off but they still don't work

rich adder
#

you did not configure it correctly im certain

spiral narwhal
#

In C# I can use return to exit a method, but if the method uses IEnumerator, how do I do that? yield return null seems to skip the frame so to speak

slender nymph
#

yield break;

spiral narwhal
#

Thank you

shell oriole
#

How do I scale the UI to fit all screens?

slender nymph
#

check the documentation pinned in #📲┃ui-ux to learn how to anchor and scale your canvas elements

shell oriole
#

where in the documentation is that?

carmine sierra
shell oriole
#

where is the specific doc

#

where it tells you that

rich adder
summer stump
shell oriole
rich adder
#

when its configured correctly ^^

carmine sierra
#

yeah

rich adder
#

I sent you the guide

summer stump
carmine sierra
#

cause i followed the page but it doesn't work

rich adder
rich adder
#

mate i did this 1000 times

#

it works fine

summer stump
carmine sierra
#

have unity extension

#

although i just installed it

#

so maybe i should restart unity?

rich adder
#

Install the unity extension, install the package , in unity select vscode . regen project files in external tools