#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 431 of 1

round plover
#

it was the only option

rich adder
round plover
#

the script

rich adder
#

right

round plover
#

but how

round plover
#

should i maybe replace "text" with the text meshpro iu thing

rich adder
#

just look what I sent you for 2 seconds

#

the solution is there

round plover
#

kk

#

tyhx

#

thx

round plover
# rich adder the solution is there

yorursolution was creating a font wich i dotn care about my problem is that i want to drag my textUI into a script i wrote wich tells me the position of my player when it moves foward and i want to drag it into scoretext but it wont let me sorry for the confusion

#

not good at explaining things

rich adder
#

how did you even remotely get that from what i sent you..

#

you're like making stuff up i swear

round plover
#

what.

#

thats what your solution wasร‰

#

creating a font asset

rich adder
#

did you scroll up to the code?

#

the direct link doesn't work well on the learn site its kinda shite

#

scroll up to the code part

steep rose
#

this seems interesting

rich adder
rich adder
round plover
#

bruh aint no way

#

how do i delete my current one

#

i made

#

ill copy what u sent me

#

nvm

rich adder
#

nothing else

#

you're overcomplicating it

#

at some point you do have to know what a TYPE and what a FIELD is so when i suggest something w /them you know what to do..

somber herald
#

I don't understand when to use time.deltaTime and when to use time.fixedDeltaTime. Currently, I'm writing a jump script using velocity and custom gravity, does the gravity force downward need to be multiplied by time.fixedDeltaTime and be in fixedUpdate? Also what about the jump force up?

devout flower
#

i'm 95% sure that gravity is in fixed updated, and jump is in a regular function without time.deltatime

somber herald
#

with velocity

rich adder
#

what

steep rose
round plover
#

@rich adder am i removing these

steep rose
#

hes using a character controller

#

prob

rich adder
steep rose
#

correct?

somber herald
#

ermm im using a rigidbody

round plover
steep rose
#

thats

#

okay

somber herald
#

is character controller better?

round plover
#

yeah nevermind it wouldnt make sense to remove it

rich adder
#

you dont want to use it on velocity no

#

MovePosition , yes

#

AddForce, no

somber herald
#

ooh can I ask why?

rich adder
#

its already waiting for the Physics frame to move velocity

somber herald
#

OHH okay

rich adder
#

which is fixed time

somber herald
#

Position isnt physics based which is why you use time.deltaTime instead?

rich adder
#

youll just end up slowing forces applied them by A lot

rich adder
#

its the time between last frame and this frame

steep rose
#

mainly so its not frame dependant

#

so you dont get extreme speeds at higher frame rate

#

slow at low

#

ect

somber herald
#

so when would I use time.fixedDeltaTIme for example?

rich adder
#

yes so take a timer for example without deltaTime ppl with faster fps would drain timer faster in update

rich adder
#

consistency

steep rose
#

legit

steep rose
#

i actually have never used fixedtimedeltatime i have zero clue why ๐Ÿ˜…

somber herald
#

Im kindaaa confused still I know that fixedDeltaTime happens over some like 60 frames and is slower but when would you use it and is it just more reliable than time.deltaTime?

rich adder
#

when you need it to go with the physics step

#

instead between frames

#

they're both consistent

#

but different

round plover
#

@rich adder what in the hell

#

that is not the position of my player!!!1๐Ÿ˜ญ

steep rose
#

what did you even do

rich adder
steep rose
#

to do that

round plover
steep rose
#

the what

#

oh

#

he

#

he led you in a correct direction

#

ngl

round plover
#

all i wanted is for that textbox to show the position of my player and now its a mess

rich adder
#

you did some other shite I have no clue about, its like you assume i have telepathy lol

fickle plume
steep rose
#

๐Ÿ˜…

steep rose
#

so you

#

followed the tutorial?

rich adder
# round plover

tell me what does have to do with "Showing Player Position"

#

cause you're making no sense

round plover
#

nthg

steep rose
#

that wont give you the player position

round plover
#

u just told me to do that

fickle plume
#

@round plover Create threads when posting images. Your posts are completely disjointed

rich adder
round plover
#

alright sir

fickle plume
#

You can reuse your old thread for this

round plover
#

its what the code showed

fickle plume
#

just link it here

steep rose
#

yeah but that wont give you the player position

rich adder
#

all you had to do was change the type lol

#

man I dont got time for this

#

goodluck

round plover
steep rose
#

ok then

queen adder
#

StatManager.instance.baseHealth -= StatManager.instance.enemyDamage;

#

is this baseheath-enemy damge or am i dumb bcs it keeps saying its nullrefrenceexeption

rich adder
trail gull
#

Whats the difference between AssetBundle.LoadFromMemory_Internal vs AssetBundle.LoadFromMemory?

wintry quarry
rich adder
#

make sure instance is assigned before you access it

#

imo you should also make itStatManager.instance.SubtractHealth(enemyDamage)
slight improvement instead accessing the instance twice like that

queen adder
queen adder
rich adder
wintry quarry
wintry quarry
steep rose
#

huh thats weird, theres no documentation for AssetBundle.LoadFromMemory_Internal unless im blind

#

im probably blind

queen adder
rich adder
#

StatManager is just a class

#

instance is null

#

at least at the time you access it

queen adder
rich adder
rich adder
queen adder
#

I typed the code in chat its red

queen adder
#

!code

eternal falconBOT
rich adder
#

I don't see any code you sent no

queen adder
#

oh well im running it in a method

steep rose
trail gull
zenith cypress
#

Generally if something has internal in the name, it's meant to not be visible to the user.

rich adder
queen adder
#
///
public void takeDamage()
{
    StatManager.instance.baseHealth -= StatManager.instance.enemyDamage    
}
rich adder
#

no context to when and how

raw token
#

Maybe share the whole script via like gdl.space?

queen adder
#

yea ill do that one sec

rich adder
#

static hell lol

#

which object has StatManager

queen adder
#

an empty object called statManager

rich adder
#

is it in the same scene as this?

queen adder
#

yes it is

summer stump
#

Why are any of those static!? ๐Ÿ˜ญ

trail gull
#

What could cause assetBundle to be null here tempStream is 100% not null, what else could it be?

queen adder
zenith cypress
#

Loaded AssetBundle object or null if failed.

summer stump
trail gull
zenith cypress
#

No I do not use them, just going off the docs LUL

trail gull
#

Great!

queen adder
zenith cypress
#

Where are you getting the bytes from? Show full function?

queen adder
summer stump
#

A serialized reference is preferred

queen adder
#

okay

rich adder
#

[SerializeField]

summer stump
rich adder
#

where DI tho ๐Ÿ˜›

#

that should be SS

#

actualy thats on par with S, you need S anyway

summer stump
zenith cypress
#

I still need to play with DI with Unity lol. It never felt good in unity for some reason

queen adder
#

so how would I fix my problem ive been at this for hours

summer stump
raw token
#

I've often heard the argument that dragging things to the inspector is more or less DI Lite

rich adder
#

doesn't have to be the DI like usual .net injection

#

that would be awkward

summer stump
#

Yeah, my main experience is zenject

#

Which was......

summer stump
fickle plume
#

I think most common criticism about DI is creating overly complicated frameworks for it. There's nothing wrong with just initializing references on instantiation by simply passing them at that time through DI method.

queen adder
rich adder
opaque aurora
#

I need help in importing the Hierarchy from the collaboration
can some one tell me how to do it ?

summer stump
summer stump
rich adder
summer stump
opaque aurora
summer stump
zenith cypress
#

I guess DI gets a little funky once you start doing instantiations, or things that are outside of the "root" structure for the game. Can't word that properly atm since it's super late haha, but things like that.

summer stump
opaque aurora
rich adder
summer stump
rich adder
summer stump
summer stump
opaque aurora
#

i am new trying to learn

queen adder
summer stump
summer stump
queen adder
#

Its still statmanager

summer stump
#

Oh wait, sorry. It was already going through the type

#

Gotta debug it like Nav said a while ago. Use some logs to see what is going on

opaque aurora
#

i fix it some way

queen adder
summer stump
rich adder
queen adder
opaque aurora
#

Do have some in YouTube making every thing clear in term of Genral info

queen adder
#

that is prob my problem becuase i have 4 NREs

summer stump
summer stump
rich adder
queen adder
#

yep

summer stump
#

It would have been good to know there were 4

opaque aurora
queen adder
summer stump
opaque aurora
summer stump
# queen adder

Have you changed the scripts since you sent them? Line 9 of the version you sent before is an int initializer

rich adder
summer stump
opaque aurora
#

i don't know laugh

queen adder
#

i have not changed them

summer stump
queen adder
#

let me resend them

summer stump
steep rose
queen adder
summer stump
#

Ohhhhhh

You cut off part of the scripts.....

#

Include EVERY SINGLE LINE

#

Good, this one looks complete

rich adder
#

yeah you can't access it in the intializer like that

#

you're assigning it in awake

summer stump
#

Yes, get rid of line 9 entirely

rich adder
#

aint no way

#

thats why error is coming from constructor method of MB

summer stump
#

If you have a singleton with the value, just access that.

queen adder
#

what is a singleton

ivory bobcat
#

What you've got with that Instance stuff

rich adder
#

singleton aka Only 1

queen adder
#

so it lets me access the variable a singleton

queen adder
summer stump
#

You should ONLY have one of each of those scripts in existence at any one point

rich adder
queen adder
rich adder
#

im aware lol

rich adder
#

google is the best tool around you teach yourself things you're not sure about

queen adder
rich adder
#

or ask for clarification + googling

queen adder
#

okay so I should be using singletons not what ever i was doing

rich adder
#

yea, thats why im suggesting it in a way to learn them a bit deeper

#

its always good to know what the tools you use do while using them

summer stump
summer stump
summer stump
# queen adder wait what

If you have a static field that is the type, and you set this to that variable, you potentially made a singleton.

queen adder
queen adder
#

I thought it was just referencing the other script so i could use the variable

rich adder
#

Singleton just means there should only be 1 of this thing

summer stump
#

public static Type Instance

^ static field

rich adder
#

static keyword already makes something the only 1 thing usually.

summer stump
#

Singleton is literally in the name. Single. You have a single one

It doesn't actually even need a static accessor field, but that is useful

rich adder
#

in unity you need to destoy another instance if somehow you have 2 of this script in the scene

summer stump
rich adder
#

Singleton is just a pattern

queen adder
summer stump
queen adder
summer stump
rich adder
#

literally..

#

explains it..

queen adder
rich adder
#

you've been told many times you have a singleton there with instance

summer stump
#

It WILL NOT WORK if there are multiple

Static means there is only one in existence basically. So the last StatManager's awake that runs will be the one referenced by Instance

queen adder
rich adder
rich adder
summer stump
rich adder
#

otherwise it makes no sense to put it in another class

queen adder
#

Okay i did that wrong I had it in multiple

#

So once i have it in there im able to reference it correct?

summer stump
#

BasePlayerPrefs.Instance will lead to that variable

It will statically access the class

rich adder
#

use this in very specific times , dont start making everything static Instance in each class

summer stump
#

For example, you should not have a static accessor to your StatManager, since you have multiple

queen adder
summer stump
queen adder
rich adder
#

instance is the one running and calling those methods

#

so you only want 1

#

Classes are just blueprints they don't do anything else

summer stump
queen adder
grave furnace
#

hi guys, can anyone help me with my top down movement script? How do i make my player stop when i release the walking button instead of keep walking a bit after i release it?

rich adder
#

when you do = this
this referes to the current Script on this object

summer stump
#

Also fix that syntax error where you set velocity

zenith cypress
#

Those are some pleasant editor colors

queen adder
summer stump
grave furnace
summer stump
rich adder
summer stump
#

Or do you want different things to have different baseHealths

grave furnace
#

thats Lunar Pink Theme

queen adder
rich adder
#

@zenith cypress got the best emojis

summer stump
#

Definitely not have a static variable

#

Just make their own with their own values

#

I mean, you could do that, but it seems so muddy to have a ton of health variables for all these different things.
Hard to extend, and gets to be a massive mess real quick

queen adder
queen adder
#

I need differnet variables for each type of helath

summer stump
#

Like an enemy has a health component, and that has a baseHealth, and a currentHealth

#

You CAN do anything you want though. It is easy enough to pivot and refactor as you go. It will happen regardless of how well you plan.

queen adder
#

but how would i acess the variables from another script though

ivory bobcat
#

Multiple instances of one script? ๐Ÿค”

ivory bobcat
summer stump
#

Serialized Reference when possible

When not, then you are instantiating. And Instantiate returns a reference

For damage based things, often you get the reference from things like OnTriggerEnter or raycasting (and other spatial queries)

queen adder
#

Okay so serialized reference

ivory bobcat
summer stump
rich adder
queen adder
queen adder
summer stump
#

GetComponent (and preferably TryGetComponent) are exactly what you want for that

queen adder
#

that is what i got currently Im gonna have to completely revamp everything

summer stump
#

You need the ``` marks at the end as well for formatting btw

queen adder
#

i fixed it

grave furnace
#

Guys i got a fast question, im watchin a tutorial and i just realized that something is worgn cause the dashCounter will never be > 0 and <= 0, right?

#

oh no

#

it reduces its value

#

would it change anything if i put this if (dashCounter <= 0) under the other if instead of inside?

somber herald
#

Whats the best way to convert the Input.GetAxisRaw to direction?

grave furnace
#

except for the variables

teal viper
summer stump
somber herald
grave furnace
#

Jake Makes Games

teal viper
grave furnace
#

but first

summer stump
grave furnace
#
using UnityEngine;
using UnityEngine.UIElements;

public class movement : MonoBehaviour
{
    [SerializeField]
    public float moveSpeed;
    public Rigidbody2D rb;
    public Vector2 moveInput;

    private float activeMovespeed;
    public float dashSpeed;

    public float dashLength = .5f, dashCooldown = 1f;

    private float dashCounter;
    private float dashCoolCounter;

    void Start()
    {
        activeMovespeed = moveSpeed;
    }
    // Update is called once per frame
    void Update()
    {
        moveInput.x = Input.GetAxisRaw("Horizontal");
        moveInput.y = Input.GetAxisRaw("Vertical");

        moveInput.Normalize();

        rb.velocity = moveInput * activeMovespeed;

        if (Input.GetKeyDown(KeyCode.Space) && (dashCoolCounter <= 0 && dashCounter <= 0))
        {
                activeMovespeed = dashSpeed;
                dashCounter = dashLength;
        }

        if (dashCounter > 0)
        {
            dashCounter -= Time.deltaTime;
            if (dashCounter <= 0)
            {
                activeMovespeed = moveSpeed;
                dashCoolCounter = dashCooldown;
            }


        }

        if (dashCoolCounter > 0){
            dashCoolCounter -= Time.deltaTime;
        }
    }
}
``` thats my actual code but i guess im missing something here
#

omg i pasted too many things

teal viper
grave furnace
teal viper
#

It's likely that that's the cause.

grave furnace
teal viper
#

Add debug logs to your code to see what's happening.

#

Or step through it with a debugger

grave furnace
#

tbh i don't have idea how to debug my code with visual studio code

#

i had issues trying to use visual studio cause i don't have 2019

#

gotta search abt it

grave furnace
#
    [SerializeField]
    public float moveSpeed;
    public Rigidbody2D rb;
    public Vector2 moveInput;

    private float activeMovespeed;
    public float dashSpeed;

    public float dashLength = .5f, dashCooldown = 1f;
    private float spinSpeed = 1f;
    private float activeSpinSpeed;
    private float dashCounter;
    private float dashCoolCounter;

    void Start()
    {
        activeMovespeed = moveSpeed;
        activeSpinSpeed = 0;
    }
    // Update is called once per frame
    void Update()
    {
        moveInput.x = Input.GetAxisRaw("Horizontal");
        moveInput.y = Input.GetAxisRaw("Vertical");
        rb.rotation += activeSpinSpeed;

        moveInput.Normalize();

        rb.velocity = moveInput * activeMovespeed;
        

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (dashCoolCounter <= 0 && dashCounter <= 0)
            {
                activeMovespeed = dashSpeed;
                dashCounter = dashLength;
                activeSpinSpeed = spinSpeed;

            }
            Debug.Log($"activespeed:{activeMovespeed} movespeed:{moveSpeed}");
        }

        if (dashCounter > 0)
        {
            dashCounter -= Time.deltaTime;

            if (dashCounter <= 0)
            {
                activeMovespeed = moveSpeed;
                dashCoolCounter = dashCooldown;
                activeSpinSpeed = 0;
            }
        }

        if (dashCoolCounter > 0)
        {
            dashCoolCounter -= Time.deltaTime;
        }
    }

He's rotating around a corner (the object is a square)

#

can i change its rotation point or whatever is that to the center of the square?

thorny hamlet
#

how to fix this bug guy pls help

rich adder
#

it isn't a bug lol

thorny hamlet
#

ok

#

thank

#

mb

grave furnace
#

oh kk

mint remnant
#

is there a way to calculate a max velocity before it's too high to miss a collision? Currently playing with dropping balls from random heights with UseGravity on and emperically finding the value to be about 29, but that might be fps dependant too

radiant frigate
#

the code that makes this thing happen is on line 75 towards the ending

#

but i shared everything in case it might be other thing causing trouble

radiant frigate
#

i need to check on what that means

#

brb

radiant frigate
rich adder
#

it skews the object

radiant frigate
#

skews?

#

and how can i make it uniform?

rich adder
# radiant frigate skews?

imagine your object is inside a cube, as you rotate it starts turn into like a trapezoid type shape

radiant frigate
#

that happens if i only rotate the z ?

rich adder
radiant frigate
#

but then i cant make it point towards the player right?

radiant frigate
#

okay wait

#

what line are you looking at?

#

75?

rich adder
#

wait

#

i just saw the code

#

i was talking about the scale

radiant frigate
#

oh

#

yeah

#

lmao

#

i rotate it via code so i can set the velocity

rich adder
radiant frigate
#

nope

#

the line below that one

#

the rotation of the parent is 0,0,0

#

so that shouldnt bother it

rich adder
#

are you talking about bulletHolder

radiant frigate
#

yes

rich adder
#

thats not rotating the bullet tho

#

wait

radiant frigate
#

in the z axis it is

rich adder
#

ops misread that

#

did you fix the scale

radiant frigate
#

what do you mean?

rich adder
radiant frigate
#

ohhhh

#

done

rich adder
#

you have to do it on the prefab

radiant frigate
#

let me try now

#

yes i did

#

okay did it and checked

#

but it still rotates on the x,y

rich adder
radiant frigate
#

in the rotation the x and y still gets modified

#

even if it shouldnt

rich adder
#

Ahh i see what you mean now.. I thought your spheres were distorting

#

just realized its 2d so it probably didn't matter

radiant frigate
#

indeed its 2d

raw token
#

On a side note, I don't understand why direction.z is in here... That's the distance to the player on the world z axis, which seems a little strange to use in a calculation for degrees, no?

bulletHolder.transform.up = Quaternion.Euler(0,0,direction.z-30+ (30*i)) * direction;

I don't think it's what's causing the problem as it's still a rotation around the z axis, but it gave me pause

rich adder
#

yeah that looks wrong

radiant frigate
#

thats the way i know in what direction he is

rich adder
#

*direction is causing the issue i think

radiant frigate
#

hmmmm, how is direction.z rotating the x,y tho?

rich adder
#

I think you can just do AngleAxis

radiant frigate
#

what does angleaxis do?

rich adder
#

try var upDirection = Quaternion.AngleAxis(direction.z - 30 + (30 * i), Vector3.forward) * direction;

radiant frigate
#

so instead of euler AngleAxis

radiant frigate
#

okay

#

nope, that didnt do the trick

raw token
#

What do you get if you log direction.z?

rich adder
radiant frigate
#

yep

radiant frigate
#

which makes sense

#

why am i even using direction.z for that?

#

when its 2d

#

what did i cook? ๐Ÿ˜ญ ๐Ÿ’€

raw token
#

My guess is that's part of the problem. You're orienting the object's y axis to a vector with a non-zero z component, so it's rotating on the x and y axis to point in a direction off of the x/y plane

#
direction.z = 0f;
// ...
bulletHolder.transform.up = Quaternion.AngleAxis(-30 + (30 * i), Vector3.forward) * direction;
rich adder
#

couldn't u just 0 out the z direction

raw token
radiant frigate
#

i do not understand

#

that is some big words

#

what does orientation the objetcยดs y axis to a vector with a non-zero z component?

#

my guess si that im trying to rotate it on the y with a -1 z

#

but i do not see how im rotating it in the y

#

because im doing that transform.up = "the math"?

raw token
# radiant frigate that is some big words

Because the player and this game object are at different z positions (which is your "depth" in a 2D game), the direction vector is not just pointing to the player on left/right (x) and up/down (y) axes, but also towards or away from the camera.

transform.up = stuff is setting the game object's rotation such that it's positive y axis is aligned with stuff, so if you assign to it a vector which is pointing towards or away from the camera, then the object is going to tilt towards or away from the camera

radiant frigate
#

okay

#

i seem to understand it now

#

and what did navarone miean with 0 out the z direction

rich adder
#

look at the code they sent

raw token
#

Before I was creating a new vector which used just the x and y components from direction and 0 for the z. Nav was suggesting to just keep using the current direction vector and set it's z component to 0f. They achieve the same thing, but mine was extra typing and extra work for the computer

radiant frigate
#

i wanted the z so it has depth, for not overlapping or clipping

#

in case you mean to set the z to 0 in the inspector

radiant frigate
raw token
rich adder
#

also you wouldn't mess with Z for rotation target in 2D

radiant frigate
#

its edited

#

i thought the direction.z = 0f;

#

was already there

#

and he meant other thing*

radiant frigate
raw token
#

womp womp ๐Ÿ˜ฆ

radiant frigate
#

wait

#

AINT NO WAY

#

I JUST USED THOSE WORDS

raw token
#

hahaha

radiant frigate
#

lmao

raw token
#

trippy

radiant frigate
#

wait

#

i think it actually solves it

#

but since i have 2 enemies i just changed 1 of them in code

#

so that could be it

#

lemme check

rich adder
#

the code should 100% work

radiant frigate
#

it does indeed work

olive galleon
#

To make a sound effects manager should I make the sound effects a publishers and subscribe to it wherever I need in order to invoke whatever method is in it? (sorry if this doesnt make sense, I just dont know how to go about it)

rich adder
#

maybe just make it a singleton

fervent abyss
#

MissingReferenceException: The object of type 'MouseButton' has been destroyed but you are still trying to access it. erm so this happens after i reload the scene... how do i bring back the references without reinstantiating

#

EventHolder.mouseButtonClicked?.Invoke(mouseButtonType); im trying to invoke an event, and in MouseButton script i subscribe to this event and start a coroutine

languid spire
#

Do you unsubscribe at all?

magic panther
#

how can I offset an object's X position relative to it's Z rotation?

fervent abyss
languid spire
#

UN subscribe ?in OnEnable?

fervent abyss
#

subscribe in onenable and unsubscribe ondisable

languid spire
#

how are you subscribing? show code

raw token
magic panther
#

no, offset by a value on the X axis, like if you extend your arm and rotate your shoulder, your hand is rotating with the shoulder but offset from it by your arm's length

#

idk how else to describe it

#

I think a drawing could do

#

moving the object or rotating it keeps the offset

#

so just local positioning relative to rotation

#

in other languages I'd use sin and cos for this, but idk how about unity objects

magic panther
iron blade
#

Hello! I'm trying to make simple 2D movement and my player can jump infinitely. I made a private bool called "isGrounded", a public LayerMask for whatIsGround, a GameObject for the groundCheck and a public float for the checkRadius, but now after all these things I do not know what to do in order to check if the player is on the ground or not. Could anyone help me?

#

nevermind, i found out

loud mango
#

why does my rb.AddForce work in the editor but not in the android build?

#

the code works right, but the it doesnt move when i play it on my phone after building

raw token
# magic panther Ping me when you have a minute

You can still use Sin and Cos in Unitylandโ„ข, but I'm still not totally clear on what you're trying to achieve...

My best interpretation is that you're trying to keep ice cream man's "shoulder" in the same place when the arm/weapon swings around?

fervent abyss
# languid spire how are you subscribing? show code
void OnEnable()
    {
        EventHolder.mouseButtonClicked += (MouseButtonType button) =>
        {
            if (button != mouseButtonType) return;
            StartCoroutine(ButtonClicked());
        };
    }

    void OnDisable()
    {
        EventHolder.mouseButtonClicked -= (MouseButtonType button) => { };
    }
```...
loud mango
random plaza
#

Heya. I'm unfortunately drawing a blank on how you can get one GameObject to create a "pointer" object to another in the world. I have an empty "Ground Point" object which I want the camera to follow, but which isn't a child of the camera, and I don't think it's wise to call GameObject.Find on every frame to locate and point at it.

#

Ideally I'd be able to create a reference to the world object so that the camera's idea of the ground point's position updates whenever it's moved instead of having to write code to continuously locate and copy its position

magic panther
random plaza
#

Anyway, short version, if any of you remember how to declare a pointer to a GameObject lmk

languid spire
loud mango
raw token
# loud mango help me with this please ๐Ÿ™

The problem you have described is not common - there is no logical reason for AddForce() to behave different in an Android build than a desktop build. There may be an issue in your code, but no one can provide feedback on that if you do not provide your code. Given that the issue is specific to a platform, you might ask in the channel specific to that platform - #๐Ÿ“ฑโ”ƒmobile. But these are quiet hours. I would not expect an immediate response

loud mango
fervent abyss
languid spire
loud mango
#

i debuged on every move and it was confirmed

#

oh, it was late and i was probably sleeping on my chair ๐Ÿ˜ญ sorry

raw token
languid spire
magic panther
raw token
serene briar
#

How do I change variables for different game objects using the same script? I want the โ€œmyMassโ€ variable of object one to be 10, and the โ€œmyMassโ€ of object two to be 5. Is there any way to do this easily? I tried a private serialized field to change them in the inspector, but it just outputs 10 twice. Iโ€™m also trying to avoid โ€œif (this.name ==โ€ฆ)โ€ because if I have a lot of objects, that would clutter my void Start.

languid spire
eternal falconBOT
serene briar
#

Alright give me a moment please

#

Sorry, it decided to suddenly work? Previously, it would show an extra debug saying 0, but now my debug is feeling okay. I donโ€™t know what happened.

languid spire
eager spindle
#

how would I store a clone of a prefab in code? I'd like to copy a prefab to instantiate later, but I'd rather not instantiate this prefab in the scene.

serene briar
languid spire
eager spindle
#

yep

radiant frigate
#

is there any way of making enemies not overlap on top of each other or go in hords that are too concentrated?

#

that are not*

languid spire
# eager spindle yep

I don't think it's possible, normally to clone I serialize/deserialize but you would still need a gameobject to deserialize to

eager spindle
#

working with someone else's code right now, they're hardcoding a prefab in the interaction system ๐Ÿคฆโ€โ™‚๏ธ I'm making it such that it changes the text in their hardcoded button so the interact system displays the name of the interact button correctly

languid spire
radiant frigate
#

could you elaborate on it a bit

#

well let me elaborate first because maybe we dont mean the same thing

radiant frigate
languid spire
#

so you are not talking about creating the enemies, just when they follow the player they all converge

radiant frigate
#

indeed

languid spire
#

so give each enemy a different speed within a range

radiant frigate
#

basically that they stop being like in left side, and more like in right side

#

but then they will still end up in the same point once all of them reach the "min distance for attacking"

#

maybe that once they reach the min distance, make them move a bit randomly to attack

#

some would still overlap but overall not that bad

#

imma try that

languid spire
radiant frigate
#

how could i make them move in a circle

#

i have thought about that but cant think of a way of coding that behaviour

languid spire
#

it's simple to get the points of a circle with radius of min distance from the player, so just use that to guide your enemies

radiant frigate
#

radius of min distance

#

yes i understand the concept

#

i will see if i find anything on how to determine those points

languid spire
#

,basic math

radiant frigate
#

i dont think that i can get each "red line" position with basic math

#

well i probably can

#

but i do not know that math

#

so i need to first learn it

languid spire
rich adder
# radiant frigate i dont think that i can get each "red line" position with basic math
 Vector3[] GetPointsAroundCircle(int numPoints, float radius)
    {
        Vector3[] points = new Vector3[numPoints];
        var angleStep = 360f / numPoints;

        for (int i = 0; i < numPoints; i++)
        {
            var angle = i * angleStep * Mathf.Deg2Rad;
            var x = Mathf.Cos(angle) * radius;
            var y = Mathf.Sin(angle) * radius;
            points[i] = new Vector3(x, y, 0);
        }
        return points;
    }```
I think..
#

been a while since

radiant frigate
#

i find it beautiful how you dont need to create 30 var for useless things

#

i guess thats the difference

#

and its also understandable math

loud sage
#

Greetings all, I am following the Unity Essentials tutorial, I'm currently on mission 4, lesson 3.5 (Collect the collectible - Destroy the collectible)
I am given the following code for the script of the relevant interaction with the gameObject:

private void OnTriggerEnter(Collider other)
{
//Destroy the collectible
Destroy(gameObject);
}

which is copied into visual studio as the tutorial instructs
however, once I go back into Unity I am given this error in the log:
"error CS0106: The Modifier 'private' is not valid for this item"

I have tried changing the method to public and even taking off that modifier alltogether, but I still get an error on that line
the script seems to be named correctly (as Collectible.cs, as instructed)
I do have a bit of programming background, just not that familiar with C# and with Unity obviously, so I'd appreciate a few pointers on what's happened here

#

I'm not sure whether it's a mistake in the tutorial, or a visual studio bug, or maybe I've written the code wrong somehow

#

I did change the collider of the gameobject to a trigger previously as the tutorial instructed

#

is this an issue where I need to declare the method in the public field and the tutorial doesn't mention it?

#

usually that's how it works in C

radiant frigate
languid spire
loud sage
languid spire
#

but where did you put it?

loud sage
languid spire
#

wrong

loud sage
#

my whole code:

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

public class Collectible : MonoBehaviour
{
public float rotationSpeed;

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

// Update is called once per frame
void Update()
{
    transform.Rotate(0, rotationSpeed, 0);

    private void OnTriggerEnter(Collider other)
    {
        //Destroy the collectible
        Destroy(gameObject);
    }
}

}

languid spire
#

yep, nested, it's in the wrong scope

loud sage
#

alright the error's gone, I had copied the method on autopilot

#

works in play mode too ๐Ÿ‘ thx

languid spire
#

lesson learned, I hope. Coding is NOT something you can do on 'autopilot'

loud sage
#

I'll try not to skip bullet points on beginners' lessons ๐Ÿซ 
I had thought the wait for a trigger would be something to be done inside the update loop, but it makes sense that it would be async

prisma ivy
#

This missing reference is eating my head, Basically this only comes sometimes, if i add some debug or something in the code and run again its not coming, also in the build its not happening, only in the editor its happening, Is there any fix for this or has any one faced this before? please help.

Error:
MissingReferenceException: The object of type 'UI_References' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.MonoBehaviour.StopCoroutine (UnityEngine.Coroutine routine) (at <2d8783c7af0442318483a199a473c55b>:0)
UI_References.SetLoadingScreen (System.Boolean status, System.String msg) (at Assets/UI_References.cs:111)
LoginManager.Init (System.Boolean isTestUser) (at Assets/LoginManager.cs:102)
GameConfigurationManager.ApplyRemoteSettings (Unity.Services.RemoteConfig.ConfigResponse configResponse) (at Assets/UI Manager/GameConfigurationManager.cs:101)
Unity.Services.RemoteConfig.ConfigManagerImpl.HandleConfigResponse (System.String configType, Unity.Services.RemoteConfig.ConfigResponse configResponse) (at ./Library/PackageCache/com.unity.remote-config-runtime@4.0.2/Runtime/ConfigManagerImpl.cs:553)
Unity.Services.RemoteConfig.ConfigManagerImpl+<>cDisplayClass46_0.<DoRequest>b0 (UnityEngine.AsyncOperation op) (at ./Library/PackageCache/com.unity.remote-config-runtime@4.0.2/Runtime/ConfigManagerImpl.cs:542)
UnityEngine.AsyncOperation.InvokeCompletionEvent () (at <2d8783c7af0442318483a199a473c55b>:0)

formal sable
#

Hey guys! I'll try to explain what I want: I have a player that the camera should be watching. But the player appears at a certain button, that is, initially he is not in the scene. I press a button and the player appears in the scene and the camera should be working and watching him.

In general, to make it convenient, we consider the camera at the GTA 5

But the problem is not with the camera itself, but that I want to assign it to a prefab that is not in the scene.

barren vapor
#

Also, don't crossposttextmessage

radiant frigate
#

if i write this Vector3[] bestPoints = new Vector3[]; im creating an array right?

#

how can i set it to a size of 0?

#

technically it wouldnt matter since i can always modify its size

#

i want it to be resizable so it only takes the vector3 that meet the criteria

keen dew
#

You can't modify an array's size. If you need that then use a List

radiant frigate
#

wasnt it the other way around? a list isnt modifiable and an array is?

keen dew
#

no

radiant frigate
#

damn

#

literally half an hour spent lol

#

glad it only was that

#

ty !

iron blade
#

Hello, why does this not work?

private void OnCollisionEnter(Collision other)
{
    if (other.gameObject.CompareTag("Coin"))
    {
        other.gameObject.SetActive(false);
    }
}```
modest dust
rare basin
#

how is that possible

#
Debug.Log("l: current pos Y: " + bsm.owner.transform.position.y);
Debug.Log("l: value to increment: " + valueToIncrement);
Debug.Log("l: destination pos Y: " + bsm.owner.transform.position.y + valueToIncrement);
#

destionation pos Y should be 8,0064[...]

modest dust
#

You're adding 8 at the end of the string

#

Take a closer look

rare basin
#

lol ok

#

ye

radiant frigate
#

hi again! im getting this error that says that the index is out of range, but when i click on it it redirects me to a line that starts a coroutine, could this be because im using a list in the coroutine?

barren vapor
#

you're summing 2 strings

#

same effect like Javascript

rare basin
#

yea i thought i twill add together

#

then print the float

#

mb

barren vapor
radiant frigate
#

okay

radiant frigate
modest dust
radiant frigate
#

stack trace?

modest dust
#

Sometimes clicking the error itself may point you to the wrong place

radiant frigate
#

thats the coroutine itself

modest dust
radiant frigate
#

it doesnt say which line

barren vapor
#

it always shows the line

radiant frigate
#

that is the full script

modest dust
#

I'd show you an example but I'm currently waiting for a train

#

If you click the error and look at the full description, there should be a couple of links pointing to different places in your code

#

The top-most one is where the error took place

radiant frigate
#

left or right?

barren vapor
radiant frigate
#

because if i left click it leads me to the code and if i right click nothing happens

modest dust
#

Left-click once

modest dust
#

on the bottom of the console there's an expandable window

#

Where the full description of the error is

radiant frigate
#

ohhhhhh

#

132

#

line 132

#

and line 80

barren vapor
#

So this
var choosenVector = bestPoints[Random.Range(0, bestPoints.Count)];

radiant frigate
#

that has to do with the return on line 132

#

yes

#

but how is that taking a number out of range?

#

isnt 0 = to the first object?

barren vapor
radiant frigate
#

maybe because its empty sometime?

barren vapor
#

Count = amount of items. So if there's 1 item, then it starts at 1.

radiant frigate
#

ohhhh

#

okay okay

modest dust
barren vapor
radiant frigate
#

it should

#

but it works

#

i worked with the max exclusive in mind

#

since b4 hand i had it being added +1

barren vapor
#

weard

radiant frigate
#

but then i remembered that (wrong btw) list work like 0=1st object so i let it be the same

#

lying

#

i dont even remember anymore

#

i just know i messed around and that its supposed to be max exclusive

winter tinsel
#

hello, im trying to instantiate an object at my rigidbodys position but just a little to the side

#

to instantiate the projectile a little to the right of the center of the rigidbody

modest dust
#

rbPos + rbTransform.right * offset

winter tinsel
#

myrigidbody.position

#
  • rigidbody.transform.right * offset?
modest dust
#

Try it out

winter tinsel
#

allright

winter tinsel
mint lodge
#

Hey guys

modest dust
winter tinsel
mint lodge
#

I have a Missile Launcher in my 2D Platformer, it works correctly, but the Missile which is only supposed to Explode upon contact with Tag Player or Ground, also explodes when it goes out of the Main Camera view

#

Does anyone know why?

modest dust
#

But it doesn't matter

winter tinsel
#

gimmie a min

barren vapor
mint lodge
barren vapor
mint lodge
#

Tried using OnBecameInvisible to force delete it when it's out of Camera View but it still Explodes()

#

Oh, I think I know what the problem is

#

I used collision.collider

#

It should be collision.gameObject.CompareTag

#

It's evaluating to 0 || 0 no matter what it collides with

stuck palm
#

what's the difference between using a return type and using an out parameter?

barren vapor
#

rubber duck concept helped once again

mint lodge
#

Thanks for being my rubber duck ๐Ÿฆ†

stuck palm
teal viper
winter tinsel
stuck palm
winter tinsel
#

its quaternion, i tried to do the same thing as the position but it didnt let me so how do i edit it?

tough phoenix
#
[SerializeField] private AudioMixer m_mixer;

[Space]

[SerializeField] private Slider m_masterSlider;
[SerializeField] private Slider m_soundFXSlider;
[SerializeField] private Slider m_musicSlider;

private void Start() => LoadValues();

public void SetMasterVolume() => SetMixerVolume("MasterVolume", m_masterSlider.value); // calling from OnValueChanged

public void SetSoundFXVolume() => SetMixerVolume("SoundFXVolume", m_soundFXSlider.value);

public void SetMusicVolume() => SetMixerVolume("MusicVolume", m_musicSlider.value);

public void SaveValues() // OnClick
{
    PlayerPrefs.SetFloat("MasterVolume", m_masterSlider.value);
    PlayerPrefs.SetFloat("SoundFXVolume", m_soundFXSlider.value);
    PlayerPrefs.SetFloat("MusicVolume", m_musicSlider.value);
}

private void LoadValues()
{
    if (!PlayerPrefs.HasKey("MasterVolume"))
    {
        return;
    }

    float volume = PlayerPrefs.GetFloat("MasterVolume");
    m_masterSlider.value = volume;

    volume = PlayerPrefs.GetFloat("SoundFXVolume");
    m_soundFXSlider.value = volume;

    volume = PlayerPrefs.GetFloat("MusicVolume");
    m_musicSlider.value = volume;
}

private void SetMixerVolume(string name, float value) => m_mixer.SetFloat(name, Mathf.Log10(value) * 20f);```
is there a better way to save the value of sliders
#

if there were more sliders here, would i write them all one by one

modest dust
stuck palm
dark cove
#

Hi guys! I'm new to this... Like all of these...

I just downloaded Unity, and I'm requested to download the editor too. Am I on track?

winter tinsel
eternal needle
winter tinsel
eternal needle
tough phoenix
#

thanks

vital yoke
#

can someone tell me what is wrong with my code, im a beginer and I really dont get why it doesnt work

slender nymph
eternal falconBOT
cosmic dagger
languid spire
#

Also, it would appear you have made absolutely no attempt to debug this code

slender nymph
#
  1. this is a code channel
  2. don't zoom your game view, it doesn't scale well
eager spindle
#

you should probably save the code(ctrl s)

arctic ibex
#

I'm trying to Lerp/Slerp a rigid body using a tutorial and its telling me "cannot implicitly convert type Quaternion to type float." The slerp thing says it wants three agruments (quaternion, quaternion, float) and I have given it three arguments (quaterion quaterion float.) I can't figure out what th eproblem is

verbal dome
arctic ibex
verbal dome
#

You'd want Mathf.LerpAngle/MoveTowardsAngle/SmoothDampAngle

arctic ibex
#

oh

#

alr thx

verbal dome
#

A more physically correct way could be to use rb.angularVelocity instead

#

Not sure if changing rotation directly can cause oddities in 2D

zenith crown
#

So im trying to make a FreeLook function for my game but im having trouble to make it reset to 0 in rotation when done freelooking

verbal dome
#

MoveTowards is not for quaternions

slender nymph
languid spire
zenith crown
#

Yeah i have no clue what im doing im js guessing my way forward

slender nymph
#

there are beginner courses pinned in this channel, and the pathways on the unity !learn site are a great way to learn how to use the engine. perhaps you should start there instead of blindly guessing

eternal falconBOT
#

:teacher: Unity Learn โ†—

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

languid spire
zenith crown
languid spire
zenith crown
#

Yeah they were more C# focused than unity focused

#

barely a unity course

eager spindle
dark cove
eager spindle
#

Nope

#

The Hub detects which device you're on and installs the correct editor

#

For now its best that you install the latest LTS version

tough phoenix
#

Inventory script has a function with 2 parameters but it doesn't appear in the editor

formal venture
#

is there any better way to write this? Like with some Mathf function or smth?

tough phoenix
#

thanks

slender nymph
eager spindle
formal venture
#

oh okay thanks

languid spire
#

but it is not better

eager spindle
#

though your current code works fine as you might want to have other functionality once your ammo in clip runs out

#

e.g. playing a click sound to signify you've run out of ammo, automatically reloading,

formal venture
radiant frigate
#

https://gdl.space/awenapajin.cs i am calculating random dots around a circle circumference that has its origin at the player , and calculating the dot product respective to the position of the enemy so i can assing places to the enemy to move, i think the dot product is somehow taking into acount the positions at the other side of the circle

#

green = player
red = enemy
blue = possible places

#

is vector2.Dot supposed to work like this or am i missing something?

zenith cypress
#

Well a dot product doesn't use positions, it uses directions. You are giving it a world position as the second value, so the offset nature of points[i] is making it act weird.

radiant frigate
#

i understand

#

ty!

#

Vector2.Dot(-direction, player.transform.position-points[i])

#

this should work?

#

okay i corrected it

#

Vector2.Dot(player.transform.position-transform.position, player.transform.position-points[i])

#

but i still have the problem with some guys

shell sorrel
#

is player.transform.position-points[i] a direction?

zenith cypress
# radiant frigate this should work?

Sure, although that just removes the player.transform.position + you have before, so you probably just want to not do that, and then pass in points[i].normalized as the second.

shell sorrel
#

like is its zero the same zero as your direction?

radiant frigate
shell sorrel
#

vector3 can be used to show a position or a direction

radiant frigate
#

but im doing player.transform.position - points[i]

#

which should give a direction

#

i think

shell sorrel
#

yes p2 - p1 gives a direction pointing from 1 to 2

radiant frigate
shell sorrel
#

though the dot product wants 2 directional vectors and returns a float that more or less tells you have similar the facing of these 2 vectors are

radiant frigate
#

yes

radiant frigate
#

i think they should be directional

shell sorrel
radiant frigate
#

how can i distinguis a directional vector from one that is a position

shell sorrel
#

well i am going with that you called it position or point

#

so assuming that is a point in space,

radiant frigate
#

yes it is

#

or it should

shell sorrel
#

ok, but what i am saying is most uses of the dot product you are going to want 2 normalized directions

radiant frigate
#

oh so i should normalize them

shell sorrel
#

oh lets step back, i mis read things

queen adder
shell sorrel
#

so used to have spaces around operators i read player.transform.position-points[i] as 1 var not 2

radiant frigate
#

ohhhh

#

no its a calculation

#

that uses 2 vectors

#

player.transform........

#

and points[i]

shell sorrel
#

yeah just me not fully paying attention, so that should work, since its comparing the play pos to current pos, with the player pos to a poiunt

#

i would normalize the vectors after subtraction though

zenith cypress
#

btw, another small thing, you don't need the -1 here Random.Range(0, bestPoints.Count - 1). Int random range is already max exclusive (if you didn't know)

zenith cypress
radiant frigate
#

yes

#

something like that

#

btw amazing name and pfp

#

lol just saw it

zenith cypress
#

If you want to play with it ^

radiant frigate
#

cool visuals

#

but i think that code is too advanced for me at the moment

zenith cypress
#

Not sure what would be too advanced about it. It's basically your code, just slight tweaks and a direction fix.

#

If you have questions about it, ask em

radiant frigate
#

what is mathf.lerp?

#

and what happens if you writeusing var _

zenith cypress
#

Lets you get a value between a and b at a certain percentage

radiant frigate
#

why that name

wintry quarry
#

linear interpolation

zenith cypress
#

lerp(0f, 2f, 0.5f) -> gives 1.0

radiant frigate
#

interesting

#

i will surely check into that

tepid cove
#

id like help leading me in the right direction, im a complete beginner at coding. i want to have "keypress combos for ability's" but im not sure how id go about creating that. for example "Z,X,C,V" being they keys and if "Z,Z,C,X" is pressed in that order you will you an ability. how would i go about doing this? or if there is a name for this kind of thing so i can search for other people implementing it and hopeful learn how to do it

zenith cypress
radiant frigate
#

oh

#

i dont know the code confuses me a bit

#

i also am a bit sleepy as one may say, so, perchance that might be the issue

#

btw what do you mean with line 41?

wintry quarry
#

if it matches, you do the move

#

if too much time passes you clear the buffer

#

it's best implemented with a State Machine

#

but if you're a complete beginner at coding, this is probably beyond your abilities at this time

#

you should probably focus on the basics for now and work up to something like this

#

it's very common for fighting games for example

radiant frigate
#

but every tutorial on yt thinks that the viewers already have x amount of expertise

#

if you had a doc that is good i would love it

#

i cant manage to find good things about that

wintry quarry
#

to be clear the state machine is just the framework on which to build this solution. It's not the solution itself.

zenith cypress
# radiant frigate btw what do you mean with line 41?

The same space being like both being proper directions, didn't know how to word that. In the image the left is the world points, the right is what line 42 is working with. Normalizing just puts them onto a 1 unit circle, and point is just a circle position already, so you don't have to offset by a world position (like you had prior) for the dot.

radiant frigate
#

im not understanding rn

#

i understand what world point is but i dont know how that would help me

zenith cypress
#

What's not achievable about it?

radiant frigate
#

since it isnt at radius distance

#

something must be off with the code

#

but i cant manage to see what it is

zenith cypress
#

Not sure what I'm looking at. The radius you had (in your code + original image) was between the player and the enemy. What is it doing vs what are you expecting it to do? I'm working with what I was given lol

radiant frigate
# radiant frigate this direction

i basically want it move to a position in the " circumference perimeter" that is close to its position ( thats why the dot product)

#

and what it does, is going to a position (sometimes not even in the perimeter) on the opposite side of the circle

#

i dont know if it makes sense what im saying

#

srry but i cant access the code now, in case its needed

ivory breach
#

Guys, is there a way I can store all elements of the materials array from a mesh renderer via code regardless of size?

frosty hound
#

Why would you need a separate collection to store them, when you have them right there?

wary sonnet
#

have anyone used Opsive universal character controller ?

wintry quarry
wary sonnet
#

I am experiencing a big amount for proccesing time because of animation and physics kind of overriding or having issues in rendering the final simulation of the character ig, it's all scripts prob that's all I know

ivory breach
wintry quarry
frosty hound
#

Might be easier to just toggle mesh renderers. Or change the materials themselves. But if you want to do it with different materials, then you can create a separate array and store them, sure.

wintry quarry
#

what's wrong with that?

wary sonnet
ivory breach
wintry quarry
#

enemyMaterials = myRenderer.materials;

#

it's really not clear what you're asking

#

Have you learned how to work with arrays and the basics of C# yet?

ivory breach
wintry quarry
#

if you don't know arrays you have a lot to learn about the basics of C# still

ivory breach
wintry quarry
#

yes...

ivory breach
#

Lemme check

wintry quarry
#

don't forget to save your code

#

also gameObject isn't necessary

ivory breach
#

Huh, it did add them

zenith cypress
#

@radiant frigate well when you wake up show some more examples to make it clearer what you want or similar. Was playing around with it and got it to do the same logic with less going on.

public Vector2 GetPointAroundCircle() {
    var playerPosition = _player.position;
    var position = transform.position;
    var distance = Vector2.Distance(position, playerPosition);
    
    // move both positions around world origin so atan2 works properly
    position -= playerPosition;
    playerPosition = Vector3.zero;
    
    // put the enemy on the circle, atan2 takes a position and gives back the radians
    // on a unit circle of where it would be on it
    var circleDirection = position - playerPosition;
    var positionOnCircleRadians = Mathf.Atan2(circleDirection.y, circleDirection.x);
    
    // get an offset to apply to the enemy's circle radians
    var angleRange = _angleRange / 2f * Mathf.Deg2Rad;
    var offsetRadians = Mathf.Lerp(-angleRange, angleRange, Random.value);
    
    // get a new offset circle position
    var positionOnCircle = new Vector2(
        Mathf.Cos(positionOnCircleRadians + offsetRadians) * distance, 
        Mathf.Sin(positionOnCircleRadians + offsetRadians) * distance
    );
    
    // take the circle position and put it back around the player
    return positionOnCircle + (Vector2)_player.position;
}
ivory breach
#

That was... a lot simpler than I expected

#

I thought I add to do the 'for' or 'foreach' loop stuff

radiant frigate
#

i dont think im in condition of checking the code

#

but if you want i can add you

grizzled island
#

i did :NumberFormatter.Format(1350)
why it returns 1K not 1.35K ?

using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;


public class NumberFormatter
{
    
    static long[] powers2 = {1000, 1000000, 1000000000, 1000000000000 };

    static char[] abbreviations = { 'K', 'M', 'B', 'T' };
        
    
        

    static public string Format(int number)
    {

        int absulute = math.abs(number);

        if (absulute < 1000)
        {
            return number.ToString();
        }
        
        float power = math.min(math.floor(math.log10(absulute) / 3), abbreviations.Length);
        int power2 = Convert.ToInt32(power - 1);

        double num = (double)absulute / powers2[power2];
        
        num = math.floor(num * 100) / 100;

        string formatted = num.ToString("0.##")  + abbreviations[power2];

        return formatted;
    }
        

    
    
}```
wintry quarry
#

attach the debugger and go through step by step, or add log statements at each step and see where things are going wrong

grizzled island
#

i did

wintry quarry
#

and what did you learn

grizzled island
#

the problem is in ToString

wintry quarry
#

how do you know that

#

what was the value of num before the ToString?

grizzled island
#

1.35

#

i returned num.ToString() and it gives 1

wintry quarry
#

because that works fine

grizzled island
#

NumberFormatter.Format(1350)

wintry quarry
#

Yes I'm aware that's what you did

#

but 1.35.ToString("0.##"); doesn't give 1

#

so num was likely not 1.35 as you said

grizzled island
#

hmm its strange

wintry quarry
#

So you need to debug your code

polar acorn
#

Curious how you expected num to be a value with decimals after using integer division

#

consider dividing by a float

wintry quarry
#

well if num is a double (which it is) that won't be integer division

#

but... really... this needs to be debugged step by step

ivory bobcat
#

Always log when you're not sure and never assume what the issue is without debugging first.

polar acorn
zenith cypress
#

math.floor also doesn't have an int overload, so it will be a float by default heheheh

wintry quarry
#

it has a double overload!

shell herald
#

i have this script for dynamic footsteps. the terrain splatmap detection works great. it is not only supposed to work with terrain but also normal gameobjects. the weird thing is, that it "prefers" the terrain. it plays the terrain sound even if a gameobject with the right layername and collider is what the player is standing on. it only works when the terrain is no longer in raycast distance and i have no idea why

https://hastebin.com/share/wecajecole.csharp

signal mango
#

There is no guarantee on the order of the array you get from RaycastAll/RaycastNonAlloc iirc

#

You have to sort it yourself if you want to treat [0] as the closest

shell herald
#

and how would i do that?

signal mango
#

Yep, straight from the docs:

grave furnace
#

(is that how you share your code on this site?)

signal mango
polar acorn
eternal falconBOT
polar acorn
polar acorn
# grave furnace

Okay, and are you sure you've set the axes Vertical and Vertical2 to different inputs?

grave furnace
#

not really, lemme check

#

xd

#

ye that was the problem

#

thanks

#

i'd never realize that lol

spark tulip
#

!code

eternal falconBOT
spark tulip
#

Friends, I'm sorry, I'm a beginner, please don't judge me. Could you please tell me why what I want to do isn't working? I created a class CarMovementService which is responsible for the calculations to be applied to the car, meaning in the main script CarLogic. Why isn't the car moving? I have a hypothesis: it might be related to the data being sent and not returned, or the rb2d is being passed as a copy and not a reference. Please help, I'm stuck.

https://gdl.space/levuleluyo.cs
https://gdl.space/ijoxawenot.cs

grave furnace
#

can't i insert my physcs material o my rigidbody2d?

polar acorn
mint lodge
#

!code