#💻┃code-beginner

1 messages · Page 56 of 1

summer stump
#

Google "playerprefs unity".
The path is different for differen operating systems

eager elm
#

Then saving is the problem. For example you never set 'age' to anything. I recommend you dont split the ui display stuff and the generating stuff into different methods, the way you do it is gonna make you error prone.

#

and my guess is that maxStatValue is not actually set to 100 in the inspector. If you have a serialized variable than the inspector will overwrite that value and the one you have assigned in the code doesn't matter.

verbal dome
#

@silver dock Saving all the data to playerprefs in lateupdate is a bit odd too. Would be better to save only when data changes

silver dock
silver dock
eager elm
#

ah crap, UpdateUI() should be called in GenerateCharacter() and not SaveCharacterData()

queen adder
#

What's the best approach to make any world gameobject do something when they are clicked?

languid spire
queen adder
#

i tried that, idk why it wont work on non-ui

#

had to add an image and put it under a world space canvas for it to work

prisma hound
#

is the scripting for pc game dev and android game dev same and we just have to build it for android after coding in pc????

gaunt ice
#

the input handling maybe different

prisma hound
#

yes but except that????

#

i have just started unity so i dont really know anything about it

#

like are the classes and their methods same for pc and android?

gaunt ice
#

there maybe some sdk targeted for either pc or mobile, but i think you dont need to worry about this

prisma hound
#

oh

#

where can i find resources for learning unity for android?

queen adder
prisma hound
#

Tysm

wanton swallow
#

does anyone know how to make the automatic firing mode work with the new input system?

private void Start()
    {
        switch (firingMode)
        {
            case FiringMode.Auto:
                inputManager.playerControls.Shooting.Mouse1.started += _ => Shoot();
                break;

            case FiringMode.Semi:
                inputManager.playerControls.Shooting.Mouse1.started += _ => Shoot();
                break;

            case FiringMode.Burst:
                inputManager.playerControls.Shooting.Mouse1.started += _ => Invoke("BurstFire", 0);
                break;
        }
}
#

i don't know how to read if the mouse is being held and if it's being pressed

queen adder
#

aww, onmousedown doesnt work on tilemap collider 🥹

#

ig no other option than to raycast and IClickable interface

short hazel
#

Raycast, get hit point, execute tilemap.GetTile(point) to check which tile you hit

rich adder
#

think you might also need WorldToGrid

short hazel
#

Yeah, docs aren't clear on whether the point you pass to GetTile are world coords or cell coords

#

I guess they are since the method only accepts a Vector3Int

rich adder
#

yeah, I just look at Vector3Int and assume grid

queen adder
#

dont think id need to know what i hit, i just need to do something if the mouse hit any tilemap

#

anyways, what is the raycast format for making a raycast from mouse click to world pos?

rich adder
#

ohh in that case you still need WorldToGrid
raycast pos != gridpos/tilemap

queen adder
#
            Vector2 ray = mapCamera.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D[] hits = Physics2D.RaycastAll(ray, Vector2.zero, 1, LayerMask.GetMask("Ally", "Enemy"));```just copied from my other game 😅
#

havent used that viewtoray before though

rich adder
#

do note if you choose ray instead of pos you need tilemap collider

queen adder
#

this is just what i want to hit anyway

#

if i hit any of that tilemap, i want to show a menu

rich adder
#

not sure RaycastAll is really needed tbh lol

queen adder
#

rc all cause the tilemap can overlap UnityChanOops it's weird yea 😄

rich adder
#

yea i suppose

queen adder
#

shame, cant derive from collider 🥹

rich adder
#

also that switch 😬

steady isle
#

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

public class FollowPlayer : MonoBehaviour
{
public Transform player;
public Vector3 offset;
// Update is called once per frame
void Update()
{
transform.position = player.position + offset;
}
}

#

what is the error in that

rich adder
steady isle
#

wat

summer stump
# steady isle wat

If you got an error, you need to tell us what it is
How would we know?

steady isle
#

should i send code too

steady isle
rich adder
#

looks like you have a copy of this script

languid spire
#

duplicate script

steady isle
#

how to fix that

fringe pollen
summer stump
#

Delete the duplicateS

steady isle
#

i only have 3

#

different ones

summer stump
#

The error is saying you have multiple script duplicates

rich adder
steady isle
summer stump
#

Show the main assets folder too

steady isle
languid spire
#

there you go

summer stump
#

And there they are..

steady isle
#

yea i got that

#

mb

#

im so dumb

summer stump
#

Probably held control while moving them?
Which will copy move

steady isle
#

oh

#

i needa learn how to read errors😅

brazen canyon
#

Excuse me guys
Can anyone explain this fuction for me please ?
Thank you

#

Why the formula is Sqrt(jumpHeight * -3.0f * Grav) ?

timber urchin
#

player look

grim stream
#

I enabled PixelPerfect on the canvas and now my background image just stoped displaying. Why?

rich adder
brazen canyon
eager elm
eager elm
#

it's just some numbers someone threw together

#

no idea why gravity is even in there

rich adder
brazen canyon
#

I don't know

#

The guy I'm watching, he did it

rich adder
#

because Character Controllers don't have gravity, just a simple form of it

#

so you have to make custom usually

brazen canyon
#

WHATTTTT ???

rich adder
brazen canyon
queen adder
rich adder
#

always replace GetComponent wit TryGetComponent

#

unless you're doing parent or child i suppose

eager elm
#

I guess the formula is the way it is so when you set the jump height to 3 the character will always jump 3 units up, no matter how high the gravity is

brazen canyon
rich adder
queen adder
#

le trygetcomponent hits[0].transform.GetComponent<IClickable_L>()?.Left(); 😄

rich adder
queen adder
#

low budget tryget 🥹

rich adder
#

same concept

queen adder
#

u2017 dont have tryget 😭

rich adder
#

oh fr?

#

bonkers

queen adder
#

yea, been a pain from the beginning

rich adder
#

ehh make your own extension method 🧠

queen adder
#

always had to getcomp, then null check a cached var

rich adder
brazen canyon
#

What's with the Left() ?

rich adder
rich adder
brazen canyon
rich adder
queen adder
#

the ? operator looking at tryget while sipping tea

brazen canyon
steady isle
#

when i am typing my code a lot of times the thing where you click tab to autofill doesnt show up

#

why is that

rich adder
#

just incase its not there you don't get NRE (null reference exceptions)

eternal falconBOT
rich adder
#

configure it

queen adder
#

actually, why does tryget have to exist when ? can do its job?

rich adder
short hazel
#

?. cannot do its job with Unity objects

#

Doesn't check for the "destroyed but not null yet" state of them

brazen canyon
#

Welp
Sleep time
It's half past 2 am
I got a game making class tomorrow

#

I mean today moring

rich adder
#

unity cant

#

(for unity components)

queen adder
#

i dont even know what that does so ig izzfine

rich adder
#

you can use it for Coroutines for example though

short hazel
#

?., ?[], ??, and ??= yeah, these do not play well with anything deriving from UnityEngine.Object

rich adder
acoustic arch
#

so on each weapons item data it holds the weapons prefab

#

can i just instantiate the object as a child of the weapon holder and destroy whatever was being held originally to switch between weapons?

#

if so how do you instantiate as a child object

short hazel
#

Instantiate has a few overloads that take a Transform as their last argument, this is the transform that will be the parent

queen adder
#

shhh... I cant even hit the tilemapcolider```cs

    if(Input.GetMouseButtonDown(0))
    {
        Debug.Log("Clicked");
        if(!EventSystem.current.IsPointerOverGameObject())
        {
            Debug.Log("here");
            // var raycasthit = Physics2D.RaycastAll()
            Vector2 ray = camera.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D[] hits = Physics2D.RaycastAll(ray, Vector2.zero, 1, LayerMask.GetMask("Clickable"));
            switch(hits.Length)
            {
                case 0:
                    break;
                case 1:
                    Debug.Log("Clicked one");
                    hits[0].transform.GetComponent<IClickable_L>()?.Left();
                    break;

            }
        }
    }```I'm hitting a normal box colider though..
slender nymph
#

are you certain that hits.Length isn't perhaps more than 1 when you click on a tilemap collider?

#

you should also ideally be using the NonAlloc version of that method rather than allocating an array each time you click

queen adder
#

i am currently testing with normal raycast

#

not all, still not hitting it

#

im hitting other kinds of collider though

steady isle
#

when I am trying to make the score add by 1 every 1/10 of a second how can i code that (picture provided is my current code)

slender nymph
# queen adder

you need to show the current code. also why are you even using a raycast rather than OverlapPoint?

queen adder
# slender nymph you need to show the current code. also why are you even using a raycast rather ...


        if(Input.GetMouseButtonDown(0))
        {
            Debug.Log("Clicked");
            if(!EventSystem.current.IsPointerOverGameObject())
            {
                Debug.Log("here");
                // var raycasthit = Physics2D.RaycastAll()
                Vector2 ray = camera.ScreenToWorldPoint(Input.mousePosition);
                RaycastHit2D hit = Physics2D.Raycast(ray, Vector2.zero, 1, LayerMask.GetMask("Clickable"));
                if (hit.collider != null)
                {
                    Debug.Log("Clicked one");
                    hit.transform.GetComponent<IClickable_L>()?.Left();
                }
            }```
#

mb, but this is the current code

steady isle
steady isle
queen adder
#

it is continous though, it doesnt do ticks that are actually each 0.1 sec

steady isle
#

yea i see that

queen adder
#

if you wants ticks, usea coroutine

slender nymph
# queen adder

btw are you certain the colliders are where you think they are? since you've not bothered to enable gizmos we can't actually see them

steady isle
#

its still a rly long decimal

slender nymph
queen adder
slender nymph
#

while you're at it, you should print useful information instead of these practically useless "here" logs

queen adder
slender nymph
#

you're just printing the double without formatting it. so it's going to print the entire thing. and if you haven't learned about floating point inaccuracies then you should go learn about that now

queen adder
#

for 2 decimals

steady isle
#

there still is a lot of decimals and i just tryna get a whole number

queen adder
#

then F0

steady isle
#

alr

#

this what showing up

slender nymph
#

show your code

steady isle
slender nymph
#

lmao

#

you're not even using the formattedFloat. you're also formatting it before you assign to it

steady isle
#

so what should i do

queen adder
#

🥹

modest dust
#

Damn

#

Probably a programming course

queen adder
#

use the formattedstring in the line that changes the text

pseudo frigate
#

i was trying to follow along with a tutorial and they said to copy the script on the screen but dont ever show all of line 67 here:

#
    Quaternion ClampRotationAroundXAxis(Quaternion q) 
    {
        q.x /= q.w;
        q.y /= q.w;
        q.z /= q.w;
        q.w = 1f;
 
        float angleX = 2f * Mathf.Rad2Deg * Mathf.Atan
 
        angleX = Mathf.Clamp(angleX, minimumX, maximumX);
        q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleX);
        return q;
 
    }

what is likely to be the end of that? " float angleX = 2f * Mathf.Rad2Deg * Mathf.Atan"

slender nymph
#

i believe the correct answer to solving this issue is "use cinemachine"

daring tundra
#

Is there a common/known way of avoiding OnTriggerExit2D being called when a player exits out of the game while inside a trigger?

#

When I exit the game in Unity while inside a trigger, OnTriggerExit2D is called and I don't want that to happen

slender nymph
flat slate
#

!code

eternal falconBOT
flat slate
#

this is my script

steady isle
flat slate
#

but unity says that "sentences.Clear();" doesnt references an object

slender nymph
steady isle
slender nymph
#

you changed nothing functionally. all you did was move the line

modest dust
#

A programming course

slender nymph
modest dust
#

If you can't solve an issue of this level then a programming course would be best

slender nymph
modest dust
#

Because at this rate we would just end up babysitting you through every script you make

languid spire
neon sparrow
# steady isle

instead of using the ScoreFr variable you should use formattedFloat

#

also you should probably set formattedFloat after you update Scorefr

slender nymph
queen adder
#

OMG!!..... IT WAS THE RULETILE...

#

ruletile is using the sprite as collider

#

now i gotta manual these all ig

steady isle
slender nymph
#

lol no

neon sparrow
#

no

modest dust
#

Dear god

slender nymph
neon sparrow
#

read your code slowly

#

point out where you use formattedFloat

#

not where you assign it, but where you actually use it

steady isle
#

to make my variable scorefr formatted

steady isle
#

so the line where i set the text

neon sparrow
#

but where

flat slate
neon sparrow
steady isle
queen adder
#

tbh it's a "learn c#" scenario already

neon sparrow
#

but what variable are you using there

steady isle
neon sparrow
#

and you should be using...

steady isle
#

formattedFloat

neon sparrow
#

there we go

steady isle
#

but i tried it

neon sparrow
#

well try it now

#

and show what youve tried

steady isle
neon sparrow
#

ok

#

why did you change the code

#

you just need to replace one variable

short hazel
#

It's not a float, and it's not formatted lmao

polar acorn
flat slate
# slender nymph huh?

the name is working and it starts aswell from the StartDialogue but the dialogueText doesnt work either it has to start with the StartDialogue function

daring tundra
slender nymph
steady isle
polar acorn
languid spire
slender nymph
flat slate
steady isle
modest dust
# steady isle

I believe it would be faster to just take a C# course instead of guessing

slender nymph
# flat slate as you see here

if you cannot even explain what you think is supposed to be happening then i'm not going to continue to try helping you

flat slate
#

look

neon sparrow
steady isle
#

Sorry

flat slate
#

the dialogue text has to show below the "....." but it doesnt

#

and i dont know why

queen adder
#

aight... that's now the most anticlimactic debug for the month..

neon sparrow
# steady isle

in here, just replace "Score: " + scorefr; with "Score: " + formattedFloat;

#

its really not that hard

daring tundra
steady isle
neon sparrow
#

what 😭

#

its your code man

modest dust
#

Ok, that's actually getting funny now

polar acorn
#

There's nothing called that in the code

neon sparrow
slender nymph
neon sparrow
#

its his old code

#

which i have no idea why he changed

languid spire
slender nymph
modest dust
neon sparrow
#

😔

daring tundra
polar acorn
slender nymph
languid spire
daring tundra
#

but i thought that was normal since i haven't done anything weird

slender nymph
steady isle
slender nymph
steady isle
#

Ok got it

steady isle
slender nymph
#

my opinion is that you should learn c# separately from unity first. then it will be easier to learn how to use the unity engine's API

steady isle
#

Got it

#

So I’ll try learning c# without unity then thank you

sour fulcrum
#

Though it can be valuable to look at it in a Unity context for practical applications and examples of more general c# concepts

sour fulcrum
neon sparrow
steady isle
polar acorn
steady isle
polar acorn
#

formattedFloat does not exist

steady isle
#

do i gotta call it

polar acorn
#

You have nothing by that name

steady isle
slender nymph
slender nymph
#

which, again, is why you've been told to just go learn the basics

steady isle
#

ima try once more

slender nymph
sour fulcrum
#

People on this discord aren’t professionals dropping polished videos, not all help is going to be perfect and various assumptions will be implied in certain suggestions. It’s a lot harder to take suggestions at face value if you don’t understand them fundamentally

#

It’s really not easy starting to code

slender nymph
steady isle
#

i am on the website, with no help as to what to look at

#

because dropping a link is enough

slender nymph
#

go learn the basics

steady isle
#

which pinned thingy do i use

neon sparrow
#

Learn basic syntax of c#

#

Little by little youre going to put them together

polar acorn
neon sparrow
#

Then it just becomes intuition

polar acorn
#

shows you how to use, declare, and assign variables

steady isle
polar acorn
steady isle
#

so im using the dollar sign to call a variable within my statement?

slender nymph
#

you clearly missed the part where it explained what that was for

sour fulcrum
#

honestly for that specific code tutorial example the $ seems a little unnecessary ngl

slender nymph
#

string interpolation is used a lot throughout that series of courses. they should pay attention to what is being taught to them so that they understand the following courses

sour fulcrum
#

I don't disagree but at such a early stage where imo a big aspect of stuff clicking is patter recognition it is abit of a curveball considering it's specific to strings and somewhat of a shortcut to doing that.

#

I think a big moment that helps a ton in understanding code at the start is figuring out what the author gets to name themselves and what is required based on the language rules

earnest ginkgo
#

Hey can someone give me an idea of how to make a character 2d move with buttons

wintry quarry
summer stump
acoustic arch
#

can i make an object hold a prefab thats in the scene that can be changed?

#

so that if the active weapon gets swapped with another one the 2 prefabs switch with each other

steady isle
slender nymph
#

you mean like this where it even helpfully links to the documenation page for it?

steady isle
#

yea like that

#

they should have something like that

summer stump
steady isle
slender nymph
#

this is why i told you to start with the first course and do all of them. then you wouldn't miss stuff from literally the second lesson in the first course

steady isle
#

Are there any easier languages with simpler syntax

#

That can help me build up to c# cuz I’m clearly not ready

slender nymph
#

it's going to take you even longer to learn if you go and learn a completely different language first

steady isle
#

Oh

summer stump
uncut crypt
#

Is there a way to refrence these values in a script

ivory bobcat
slender nymph
#

those are the transform.localPosition localEulerAngles and localScale

uncut crypt
#

I mean how would write it in the script

uncut crypt
#

I typed the message as the other one was sent

slender nymph
daring tundra
uncut crypt
#

Is it possible to see values for a different object

slender nymph
#

what do you mean by "see values"

rich adder
#

easy: reference the other object

uncut crypt
#

Just plug in the obj name?

slender nymph
rich adder
#

eg
[SerializeField] private Transform someObject

#

ideally you use Components / Object (classes) directly instead of just Transform

#

depends what you do

uncut crypt
#

Okay

daring tundra
rich adder
#

dynamically typed :\

#

messy

slender nymph
daring tundra
#

cook a batch of metch then learn how to bake a cake

#

meth

rich adder
slender nymph
daring tundra
#

lmao

fierce shuttle
sour fulcrum
fierce shuttle
#

^ Yes, good note "instances" was the word I should have used, as its likely more relevant to what they are wanting to do

ripe oyster
#

Hi all! Having an issue here with my script (not made by me). Whenever the VRChat SDK tries to build my avatar, it comes back with these compiler errors and due to my non-existent knowledge of coding in Unity, I need help lol

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

public class FindAnimationClips : EditorWindow
{
    [SerializeField]
    private List<AnimationClip> _clips = new List<AnimationClip>();

    private void OnEnable()
    {
        var serializedObject = new SerializedObject(this);
        rootVisualElement.Add(new Button(GetAllClips) { text = "Get all clips" });
        rootVisualElement.Add(new Button(SetToLoop) { text = "Set Animations to loop" });
        rootVisualElement.Add(new Button(Unloop) { text = "Disable Animations loop" });
        rootVisualElement.Add(new PropertyField { bindingPath = nameof(_clips) });
        rootVisualElement.Bind(serializedObject);
        serializedObject.ApplyModifiedProperties();
    }

    [MenuItem("Tools/Multi-Anim Loop Toggle")]
    private static void Open() => GetWindow<FindAnimationClips>().Show();

    private void GetAllClips()
    {
        string[] guids1 = AssetDatabase.FindAssets("t:AnimationClip", null);

        foreach (string guid1 in guids1)
        {
            Debug.Log(AssetDatabase.GUIDToAssetPath(guid1));

            AnimationClip animClip = AssetDatabase.LoadAssetAtPath<AnimationClip>(AssetDatabase.GUIDToAssetPath(guid1));

            if (!_clips.Contains(animClip))
            {
                _clips.Add(animClip);
            }
        }
    }

    private void SetToLoop() => CanLoop(true);

    private void Unloop() => CanLoop(false);

    private void CanLoop(bool canLoop)
    {
        foreach (AnimationClip clip in _clips)
        {
            var settings = AnimationUtility.GetAnimationClipSettings(clip);
            settings.loopTime = canLoop;
            AnimationUtility.SetAnimationClipSettings(clip, settings);
        }
    }
}
slender nymph
#

!vrchat

eternal falconBOT
ripe oyster
#

Its not something for VRChat either. Its stopping the upload of the avatar because the script has compiler errors

slender nymph
#

then it probably needs to be put into a folder titled Editor

ripe oyster
#

Ah! Perfect6! Might I ask why that worked?

slender nymph
#

content inside an Editor folder will not be included in the build process since it will be considered part of the editor assembly

heady nimbus
#

I'm suddenly getting this error and 2 warnings that I don't recognize... I'm not positive their related to each other... Anyone familiar with these?

slender nymph
#

the error is an editor error related to some graph editor window you have open. it can typically be ignored but if it bothers you just close which ever window uses the graph editor (animator, shader graph, etc)

#

the last two logs are warnings and unless you're writing code that uses jobs or native collections you can ignore them as well

sturdy lintel
#

In my scene I have some gameObjects that are inactive due to a toggle state. I want those inactive gameObjects to also get destroyed using the method below. But this is not happening. What changes are required ??

private void DestroyOtherAxisFrames(string node)
    {
        GameObject[] axisFrames = GameObject.FindGameObjectsWithTag("AxisFrame");

        foreach (GameObject obj in axisFrames)
        {
            if (obj.name.StartsWith("AxisFrame-") && !obj.name.Equals("AxisFrame-" + node))
            {
                Destroy(obj);
            }
        }
    }```
heady nimbus
slender nymph
slender nymph
heady nimbus
#

Oh holy hell I just had a bunch of them spam when I switched to the animator window now

slender nymph
#

my dude, the animator is a graph view

#

like, it's literally one of the two examples i gave of windows that would cause that error

heady nimbus
#

Oh shit my bad, I didn't see you say the animator

queen adder
#

Starting vector, travel a given distance at a given direction, new vector. How do I calculate the new vector?

teal viper
#

PointA + direction * distance

silk night
#

Is there an easy way to freeze gameplay (like objects falling, stopping animations) without having an effect on UI / UI animations?

#

setting timeScale to 0 messes with more than just the physics stuff 😄

teal viper
#

You could set the fixed timestep to 0 I guess.

silk night
#

Oh yeah right, ill try that, thanks 😄

queen adder
teal viper
#

!code

eternal falconBOT
topaz gorge
#

now might someone know why i can save my game on my pc but on others and doesnt do anything, and i am using Application.persistentDataPath which im finding odd isnt working on other computers https://gdl.space/oqedusiziw.cs

teal viper
topaz gorge
#

No

#

which is my confusion

teal viper
#

How are you confirming that it doesn't work then?

topaz gorge
#

Ive had my friends try to make a new game on there pc's

teal viper
#

And?

topaz gorge
#

nothing

#

nothing happens

teal viper
#

How are you checking of the error was printed or not?

topaz gorge
#

I even gave them the project files to load the project

#

and still nothing

acoustic arch
topaz gorge
#

now i was thinking at first that it was maybe there anti virus deleting files but thats also not the case either

acoustic arch
teal viper
topaz gorge
#

Because it never displayed itself or in any logs?

teal viper
#

What logs are you looking at?

topaz gorge
#

i looked through everything in the built version and project and still have nothing

teal viper
#

From your friends PC?

#

That experienced the issue?

topaz gorge
#

indeed using screen share they went through all of it

#

endless something was missed im at a loss here

teal viper
#

Try removing the try catch and letting them play the new build.

topaz gorge
#

Ill give it a go and let you know

teal viper
#

Also add more verbose logs at each stage of saving/loading.

topaz gorge
#

will do

teal viper
#

You want to see how far the execution went.

topaz gorge
#

for sure

fierce shuttle
# acoustic arch i'll probably have to Destroy, the Instantiate

That may be up to how you design your game, for mine I instantiate the weapons once, make them a child then disable all of them - I then have only 1 referenced as a variable, when I want to change weapons, disable the referenced one, enable the one I want to change to, and update the reference - if you will be destroying and instantiating weapons often (for example, maybe enemies drop weapons) you could look into an object pool

To give you a general idea of my approach, it looks something like this:

public Weapon drawnGun;
public List<Weapon> allGuns;

void SpawnGuns() { ... }

public void SwapToGun(int index)
{
if(drawnGun != null) {drawnGun.Disable();}
drawnGun = allGuns[index];
drawnGun.Enable();
}

Thats not verbatim code, but a general idea, some input might call SwapToGun and pass the next/previous index to switch to, and if a weapon is already in-hand, hide it, otherwise just swap the weapons - and SpawmGuns is where all of them would get instantiated and stored in the list once, or handled by an object pool if need-be

acoustic arch
#

and then instantiating a new weapon in place of it

fierce shuttle
acoustic arch
#

well no but there's a lot of different weapons

cosmic dagger
acoustic arch
#

if i just disable it that means i have to put every prefab as a child object of the holder?

#

but only some items have prefabs (only weapons or visual items)

#

it's a 2D game that works like an RPG where you have to craft the weapons and stuff

fierce shuttle
# acoustic arch it's a 2D game that works like an RPG where you have to craft the weapons and st...

If you do not start with these weapons, then it might make sense to create them when you need them, and then keep them referenced in case the player wants to use them again at a later point in that game session, but if its a collection of weapons the player starts with, you could spawn them all initially in your "holder" and then hide all of them except for the one the player is currently trying to use - for example if you have a craftable sword, you dont have to instantiate that sword to your "holder" until the game is in a state where that sword should exist (ie: they have the materials to make it, its stored in some saved inventory, or part of some loadout, etc)

acoustic arch
#

and those disabled GameObjects become Destroyed and Instanced when being replaced by different items/weapons

#

i guess that makes sense

fierce shuttle
hybrid tapir
#

i wonder how unity does the endless grid thing that the beat saber level editors have

teal viper
#

Probably a custom shader.

hybrid tapir
#

the custom platforms creation does require it to be made with a unity project with a 2018 version of the editor cuz of all this custom stuff (including shaders)

#

like a project from the creator of the mod has all this custom stuff in it

teal viper
#

Okay

rich adder
#

just play the audio clip. what would be the use case?

silver dock
cerulean stirrup
#

i think he wants to play the audioclip through the microphone

eternal needle
silver dock
eternal needle
#

I understand that, but still that get component does nothing. You said the history log debugs meaning this is probably an issue with the tmp component. Did you try manually putting text in it and see if its visible?

silver dock
#

it just doesnt update it, cause its empty even in the inspecter

eternal needle
#

then i believe it isnt updating the correct tmpro object

#

do you have any console errors/ can you show a screenshot of the object that has HistoryLog on it?

silver dock
eternal needle
# silver dock no console errors

if its truly referencing the correct object and the debug is printing some text for loadedHistory (not an empty string), then my only other guess would be that you are calling ClearHistory() somewhere or setting the text to empty somewhere else

teal viper
#

Or referencing a prefab

eternal needle
#

true it is probably referencing a prefab

silver dock
#

there's not a single prefab in this project

teal viper
#

Then one of the things that bawsi mentioned.

#

You can use a breakpoint or Debug.Break ot examine the state of the game at that point in time.

#

See if the text changes.

supple wasp
#

How can I make this block move, scale and rotate?

gaunt ice
#

Adjust the parameters in inspector or drag it with your mouse

eternal needle
# silver dock good guess

protip if you didnt use this, you can find anything thats using your method with this button Find All References

silver dock
dry spruce
summer stump
dry spruce
#

yes

summer stump
# dry spruce yes

Ok. Well that is the only issue. Change it to TMP_Text, then drag you Score object and the Timer object into the boxes. That is it

#

Text is a legacy type of component you aren't using. So you do not want that

mystic oxide
#

can anyone explain why the function not showing on OnClick

summer stump
mystic oxide
#

it's showing on my other project, not on this.. strange

mystic oxide
summer stump
#

Got any compiler errors?

mystic oxide
#

nope

static bay
summer stump
#

Can you show the inspector again WITHOUT the dropdowns showing

#

Oh yeah huh. Multi-parameter methods aren't able to be subscribed via the inspector afaik. You have to subscribe via code
Good catch Lazy 😆

static bay
#

You can define a UnityEvent<string,string> and subscribe there.

#

But yes it's likely best to just subscribe via code and define where the parameters come from there.

#

That MainLogin class will need access to the Username and Password text fields to get their values.

mystic oxide
#

i could do it this way... but not sure its efficient/good

gaunt ice
#

Wrap the start coroutine to another method

static bay
summer stump
mystic oxide
#

something about faster, tbh idk

#

but its work on other script

#

"hello" is the function

summer stump
mystic oxide
#

ah yes

#

wait

summer stump
#

It has 0 parameters

mystic oxide
#

yea its has zero

#

dosen't work for 2 i assume

summer stump
#

Only works with 1 or 0

#

In the inspector of course

mystic oxide
#

anyway thanks! UnityChanCelebrate

summer stump
#

No worries!

silver dock
#

Is there something with this scriptable object script?
i cannot assign the items i create with it

eternal needle
eternal needle
#

in the unity project tab

#

but yea thats still a matching name

#

🤔 maybe u need to recompile or something, unless i am missing something

silver dock
fossil drum
#

Isn't he trying to add the PetData as a component?

silver dock
fossil drum
#

Yeah, you need to drag it into an Element slot

silver dock
languid spire
#

screenshot console

eternal needle
fossil drum
#

Whats the code for the PetItems list/array?

snow mural
silver dock
fossil drum
fossil drum
silver dock
fossil drum
# silver dock this?

Ah, are you adding the script instead of a scriptable object? Did you create one?

languid spire
#

wait, wait wait.
Are you trying to drag the script into there or a PetData asset you created?

silver dock
#

PetData asset

languid spire
#

show asset in project view

#

and inspector

silver dock
fossil drum
silver dock
fossil drum
sour fulcrum
#

sometimes Unity can get weird like this if you renamed the class name then the .cs file or vis versa

#

try restarting Unity, or if that doesn't work deleting the Library folder from your project folder (this just holds cached data that it will rebuild when you delete the folder and re-open the project)

silver dock
#

thanks for the help guys, fixed it

mild mortar
#

Trying to use root motion atm on my character. Noticing a weird thing on the animator tab where my values (Lateral, forward) seem to constantly be changing in the animator and causing the character's animations to kick in some times. Like walking forward without any input from me.

Anyone have any ideas where I'm going wrong?

Code is too big for discord limit apparently so I just paste linked it

https://paste.ofcode.org/ys4VBmkqy7X35msK7jJ3zT

queen adder
#

Can somebody help me with this line

Ship_Rigid.AddForce(Ship_Rigid.transform.forward * EngineForce);

It does not move the ship at all
Its in 2D, everything is set up properly

fossil drum
gaunt ice
#

set the engine force to be 100000

fossil drum
#

Oh, and it's 2D, forward is not valid in 2D. Use right or up.
Forward means it goes into the world.

queen adder
queen adder
#

Yep that fixed it

#

thanks

fossil drum
obtuse aurora
#

HELLO
I am trying to change this code from this video I found

https://www.youtube.com/watch?app=desktop&v=3sWTzMsmdx8
(it is a movement script)

I am attemting to change it from aswd keys to the arrow keys
Can I pritty please mabey have a little bit of help???

Source & game: https://github.com/Matthew-J-Spencer/Ultimate-2D-Controller
Extended source: https://www.patreon.com/tarodev

Learn how to build an amazing player controller.

This Unity character controller is built using custom physics and incorporates all the hidden tricks to make it feel amazing. 2D player controllers can be difficult to get ...

▶ Play video
#

This is the code

wintry quarry
#

Anyway you haven't explained what issue you're having

obtuse aurora
#

I would just like to try and rewrite the code but to work with just the arrow keys and not the aswd keys

#

Like a local

#

game

wintry quarry
wintry quarry
#

Go into the input manager and remove the bindings of the axes from the wasd keys

obtuse aurora
#

Well thats good

obtuse aurora
#

right i have just relized that I have no idea were that is

wintry quarry
obtuse aurora
#

Is that it

wintry quarry
#

No you're still looking at code

#

Remember when I said this has nothing to do with code

#

Stop looking at code

obtuse aurora
#

okay

dry spruce
#

Why this is happing?

wintry quarry
solar berry
#

how to make 2D animation work when timescale=0?

obtuse aurora
#

@wintry quarry

wintry quarry
#

Yep that's the input manager you found it

obtuse aurora
#

I am very pleased

#

thank you for helping me

#

praetorBlue

#

also

#

Cute cat

wintry quarry
#

Make sure you have properly assigned all references before using them

topaz mortar
#

I have a pretty complex UI with lots of different windows and elements in it
Is there a way to trigger an event on right click, no matter where that right click happens?

#

Specifically: I have a button that changes the cursor to a sell icon and then when u click an item it sells that item
But I want the cursor to change back to standard if you right click anywhere
My issue is this logic is currently on the Item, and there's plenty of places on the UI that are not items

gaunt ice
#

cant you capture input in update loop?

topaz mortar
#

yeah but it only captures it when I click on an item

#

I have like 10 different UI windows that can all be open or closed

thin sedge
#

Hi! I'm making a sort of Space Shooter type game and was wondering how I would make the enemies spawn from any direction rather than from the top only. Please reply to this message so I get notified. :)

#

I can show any material needed

topaz mortar
thin sedge
gaunt ice
#

idk what is your design but you should be able to capture any mouse input independent of any UI

thin sedge
reef patio
#

does anyone know how to create a trigger level changing script...?

reef patio
#

a object in game 3d scene, that has if you tap it with your player capsule it changes to another scene

reef patio
#

ill try it, thanks

#

ok it worked

#

thanks

#

but I need to add a spawn point for the capsule now for the next level, is it just copy capsule and paste to the next level?

#

I got it, copy and paste the capsule and add the camera to it, worked, it properly level transitions to the next of a player start in the right zone

glass crest
#

Hello, is it possible to language localize a word in which the code looks for any occurrence of that word in all strings in the game without having to go to each text that has a string and put a localization key there?

teal viper
glass crest
teal viper
# glass crest Could you explain more what do you mean by reflection? although I don't see it a...

Reflection is a feature in C#/dotnet for coding the code. Sort of meta programming. It allows you to find and manipulate existing code in the project.

No, normally the programmer doesn't go through the game text to localize it. Most decent projects, use some kind of localization system(either third party or developed for the project), that takes a key and returns a string based on the application/system language.
Programmers are only involved with writing/integrating the system. The translation and asset organization is usually done by designers or some other miscellaneous role in the team.

glass crest
teal viper
#

The point is that localization is something that is supposed to be considered at the early stages of the project.

glass crest
#

That indeed is the right thing to do

normal arrow
#

is it possible to call a function where some part of is name is a string variable ?

i have in mind something like this :

{
  MyFunctionmyString();
}```
gaunt ice
#

yes, use reflection to find the method

#

or invoke

normal arrow
#

Okay thanks i didnt know i could use invoke for that ! So i did something like this

    {
        MyOtherC#Script.instance.Invoke("MyFunction" + myString, 0);
    }```
hexed terrace
#

Use string interpolation for strings that use values, it's cheaper

($"MyFunction{myString}", 0)

fierce shuttle
#

Is it cheaper than using string.Format or string.Concat to do something similar?

charred spoke
#

Using $ is shorthand for string.Format

scarlet skiff
#

aight so im using this to make my object move around, when i just spawn in the object, it goes straigh ahead, everything is fine n dandy, but whne i play around with the rotation, then try to move... then it becoems just a bit off, dont know why tho

wintry quarry
#

Why not just use transform.forward * movementSpeed?

scarlet skiff
scarlet skiff
#

which depends on the rotation

#

note: after further testing the pivot point was off

#

so ill fix that n see

scarlet skiff
wintry quarry
#

You don't need to do trigonometry

wintry quarry
fossil drum
#

Hello,
I'm trying to make a simple 2D character controller for a platformer game. (code -> https://paste.ofcode.org/AFzVG46MF9c43xBKUJGUUb)
the code is simply supposed to provide a player that can walk on flat surfaces and jump while affected by gravity.
My problem is that I can't seem to find a way to handle diagonal collisions. If my player moves diagonally and hits an edge it gets stuck ...
I am supposed to first check for horizontal collisions, move horizontally, only then check for vertical collisions and move vertically. But still it fails to check .. can you give me some hints of what I may be doing wrong .. ?

scarlet skiff
#

but yea ill js use the .forward

#

alright so... quick question...
I had my teacher on how to copy components, since i had a newer model for my object. When he was showing me how to do it, he dragged the new model from the project folder (bottom area) straight to the layers instead of the scene, and now like i cant see the object, i cant drag it from the project folder area to make a new one, and yea uhmmm what

#

like uhmm i assume that when it was draggon into the layers it created the object

#

but i dont see it in scene

wintry quarry
#

do you mean the hierarchy?

#

just double click it in the hierarchy to see the object

#

or press F

scarlet skiff
#

doulbe clicking or pressing f is uhmm not doing anything

wintry quarry
#

try again

#

oh

#

wait

#

you're in game view

#

switch to scene view

#

this isn't a code question

scarlet skiff
#

wait nvm

#

i figured it out

#

thanks

vital sage
#

This is my first day ever actually trying to learn Unity. I'm trying to add a feature to this open source Unity 2018 project, and I'm kind of stumped. I see these components have (Script) appended to the end, but I don't see any script fields to open said "script" in Visual Studio. Am I misunderstanding what this is?

#

Are these base Unity objects just referred to as scripts?

rich adder
#

not all scripts are components

buoyant knot
#

And those components are built-in. You can write your own

vital sage
#

Ah I see, thanks y'all

#

Is there a difference between "objects" and "components"?

rich adder
#

yes GameObjects carry components

wintry quarry
#

in the epistomological sense, everything is an object

#

in the C# sense, everything is also an object

#

and then there's the UnityEngine.Object which all of these things also are

#

but in the sense that Unity has GameObjects, components are NOT GameObjects

#

they are attached to them

vital sage
#

Thank you for explaining that to me, I appreciate y'all

scarlet skiff
#

"Pivot" refers to the origin point of rotation according to the model itself, while center is calculated by unity?

#

ok so...

#

if both are wrong

#

and dont rotate in the actual middle

#

does that i gotta change the pivot point in the model?

wintry quarry
#

yes

scarlet skiff
#

could an incorrect position for the rotation point be the cause of this not working right?

(not working right = the direction isnt actually forward and is almost unpredictable)

eager elm
#

maybe you need transform.up, is your game 2d or 3d?

polar acorn
wintry quarry
#

they are not 1:1 replacements

#

as digi said if you're using Translate, you would use Vector3.forward not transform.forward

scarlet skiff
#

but yk this works now

buoyant knot
#

i have just gone cold turkey off of Translate if something has a rigidbody or any colliders

#

every time I put transform.Translate or set transform.position manually, i wind up needing to refactor it later anyway to make it work properly

scarlet skiff
#

how do i interact/see an empty

buoyant knot
#

what

scarlet skiff
#

one of those

#

that u get from "create empty"

#

nvm

wintry quarry
scarlet skiff
#

figured it out

wintry quarry
#

you interact with it just like that

scarlet skiff
#

it had spawned somewhere far away at first thus my confusion

fierce shuttle
wintry quarry
#

combine everything into one

#

and it will work fine

buoyant knot
#

you can also cast in the direction you are moving

wintry quarry
#

which is exactly what you would do when you combine everything into one cast + one move

buoyant knot
#

also, i would avoid BoxCast in favor of Cast in case you add edgeRadius in future

#

i had to refactor my BoxCasts like that before because of that

#

I assume you are doing separate casts now to check for wall floor and ceiling separately

#

I would use Cast. Cast outputs RaycastHit2D, which has a field for normal.

#

The normal tells you the angle of contact, so you can decide if you want to consider yourself grounded or on wall etc based on a single given hit

#

i currently use OnCollisionEnter/Stay to know if I’m grounded, and I’m going to be changing in future because these methods evaluate after your physics update

#

where did the other guy’s message go?

rich adder
#

probably solved it

buoyant knot
#

i think his issue isn’t code, but in the physics settings

#

let’s hope so

scarlet skiff
#

im making an thing that can throws projectiles, so i was thinking, if i make it a rigid body, and i then give it an upwards speed and a forward speed, would the gravity handle the rest?

#

like if set upward speed to 100

#

would gravity make the speed 100 - gravity * time

buoyant knot
#

gravity is a global variable

#

so you can’t give just one thing left gravity, if that is what you mean

#

but if it is a dynamic rigidbody, then you can start it with upward speed, and gravity will make it accellerate down

#

as it travels

scarlet skiff
#

no i meant if i have a speed that is taking an object up, but this object is affected by gravity, how would the speed change?

buoyant knot
#

i would use a kinematic equation to calculate the speed you need to give it, btw

scarlet skiff
#

what i am afraid if that.. like.. suire gravity will result in a speed down, but this speed wont be reduced from the speed i give to the projectile, so there will be a speed dragging the projectile down, but the upwards speed stays at 100

rich adder
buoyant knot
#

unity uses Euler integration.
Every frame, you move by deltaX = deltaTime * velocity.
And deltaVelocity = deltaTime * force / mass

scarlet skiff
#

i would NOT want:
speed up : 100
speed down: gravity

but instead want
speed up: 100 - gravity * time

buoyant knot
#

gravity is straight acceleration, so every frame, velocity += gravity * deltaTime

scarlet skiff
buoyant knot
#

if you start with a large upwards velocity, it will take many frames for gravity to completely change your direction

rich adder
buoyant knot
#

if it is a dynamic rigidbody, try rigidBody.velocity = newVelocity;

#

or myRigidbody.AddForce(additionalVelocity, ForceMode2D.Impulse);

scarlet skiff
summer nimbus
#

is there a script that combines animations at all?

rich adder
#

what that even mean

buoyant knot
#

if it has gravity, it will have velocity += gravity * deltaTime every frame

#

and there is no terminal velocity unless you program it

summer nimbus
# rich adder combines animations?

i have multiple animations that follow a sequence i would like to be able to get a script to put them one after the other and combine them into 1 animation]

buoyant knot
#

an animation is like a sequence of sprites that show in a given order (with/without looping)

summer nimbus
#

if it can turn multiple animations into one sure

buoyant knot
#

an Animator is like a finite state machine that lets you change between Animations on one gameobject

rich adder
#

Animator wont change the original keyframes or other animations

#

its just playing the clips

buoyant knot
#

scripts can tell the animator which state to go to

summer nimbus
#

i find it hard to explain things

summer nimbus
#

i would like a script where i can drag in 2 or more animations it then creates a new animation putting them in sequence

buoyant knot
#

This might be the tool to allow your script to know when one animation ends, I think

dapper lava
#

how can i check for collision but not any colission but between two specific objects

summer nimbus
#

since this is for vrchat i cannot change the animator

dapper lava
#

how can i make object have collision trigger but keep working colisions

dapper lava
#

thanks

buoyant knot
dapper lava
#

can you change object visibility in game
turn of rendering but keep everything working

rich adder
#

yes ofc

buoyant knot
scarlet skiff
#

okey thanks

dapper lava
buoyant knot
#

that way you can have a script that automatically starts one animation the moment another one ends

#

understand?

#

i’m not super familiar with doing this, but that is what that feature seems to be for

summer nimbus
#

custom scriptss cant be uploaded for vrchat so although that would work in unity it wouldnt work in vrchat

rich adder
#

this should be in
!vrchat

eternal falconBOT
rich adder
#

and its not code related

buoyant knot
#

if you can’t use code, then that cannot be a code question

slender nymph
daring tundra
#

weird that this hasnt been seen before

slender nymph
#

yeah i assume it's probably not intended. it could also be a more recently introduced bug. what version of unity are you using?

summer nimbus
daring tundra
#

unless i gotta update i havent been paying attention to that

dapper lava
#

if my prefab uses a script and i change the script in project files will the script used by prefab also change or by making a prefab all components are copied to make it functional separate object

slender nymph
wintry quarry
#

if you change the script, it changes the script

#

that would be a nightmare otherwise

buoyant knot
#

yes, if I have 5 different prefabs with a MyBehaviour component, and I edit MyBehaviour.cs, all of the prefabs just reference that new (altered) file

dapper lava
#

my wall have box collider2D and my bullet have circle collider2D with trigger
bullet.cs->

void OnTriggerEnter(Collider col){
        Destroy(gameObject);
    }

the bullet doestn disapear when it hits wall

slender nymph
#

OnTriggerEnter is for 3d colliders. you want OnTriggerEnter2D

dapper lava
#

thanks

#

and the website looks very suseful

dusky bay
final kestrel
#

Can I ask DOTween related questions here?

dapper lava
#

i need to get the script atached to the object

slender nymph
dapper lava
#

getcomponent<scriptname>()

#

and then .health

rich adder
ivory breach
#

Can anyone show me pseudocode for reloading my weapon with reserve ammo in mind?

hexed terrace
dapper lava
#

thanks

prime loom
#

Im having a weird issue. With TMP line break is not working properly i have this. In a TMP text in canvas. The info gets taken from a string list and get feed that. If i manually type the exact line then \n works as intented. But when doing it via script with the text.text = list.text its not

ivory breach
rich adder
#

ops mistyped ..anyway , same question

ivory breach
#

The number of ammunition you currently have that's not in the weapon magazine

rich adder
#

so check if magazine remaining == 0 then grab from the reserve ammo

#

or put reserve ammo in the mag

hexed terrace
#

if reserveAmmo is > clipsize, reload

#

hmm, no, doesn't need to be more than clipsize

#

more than 0

rich adder
#

if(currentammo > clipsize )
store ammo in reserve
?

hexed terrace
#

if reserveAmmo is > 0, clipsize = full, reserveAmmo - clipSize

ivory breach
#

There are three variables, ammo in magazine, magazine size and the ammo in reserve

rich adder
#

maybe clarify , are you talking about depletion or pickup/refill

ivory breach
#

Refilling the magazine based on the number of reserve ammo

#

I know if the reserve ammo is more than the magazine size, you simply refill the magazine and deduct the reserve ammo by the magazine size

rich adder
#

but depends on game, for example one of my games you can pickup individual bullets and fill mag 1 bullet at time

#

but if mag was full then goes in reserve

ivory breach
#

In other words

if (reserve ammo >= magazine size)
{
    current ammo = magazine size
    reserve ammo -= magazine size - current ammo
}
#

But I don't know the logic of what happens if the reserve ammo is less than the magazine size

#
else if (reserve ammo < magazine size)
{
    ???
}
polar acorn
#

How many in the gun and how many in reserve?

final kestrel
ivory breach
polar acorn
#

I'm not asking what your code does right now I'm asking pure math

ivory breach
#

Integers can go in negative values

summer stump
#

How do you have a negative amount of bullets?

polar acorn
ivory breach
#

In normal math, you would have 8 bullets in mag and 0 in reserve

rich adder
polar acorn
hexed terrace
ivory breach
hexed terrace
#

You cannot reload if you have 0 bullets in reserve 😄

summer stump
ivory breach
#

Oh ok

final kestrel
ivory breach
polar acorn
ivory breach
#

Add 5

final kestrel
#
transform.DOLocalJump(new Vector3(transform.localPosition.x + 8f, transform.localPosition.y - 12, transform.localPosition.z), 13, 1, .8f).SetEase(Ease.InSine);
polar acorn
ivory breach
#

Umm... None of the numbers here can change it to 0

ivory breach
#

The mag size is 12, the current ammo count is 3, and the reserve ammo count is 5, like you said earlier

polar acorn
#

Those are your building blocks. You are free to use whatever mathematical operations on those numbers

#

So, what do you do using only 12, 5, and 3 to make 5 into 0?

modest dust
#

Some advanced math going on here

ivory breach
#

This is where my brain p much short-circuits

polar acorn
#

This is very basic algebra

#

What number can you math with 5 to make 5 become 0

wooden minnow
polar acorn
#

If this is too advanced for you then you're going to have a very very bad time trying to make a game

polar acorn
#

Clamping rotation is always trouble because of the cyclical nature of degrees

wooden minnow
#

ok so what do i do

silk night
#

Store a target rotation value you clamp instead of the real current rotation

wooden minnow
#

that doesnt tell me anything

polar acorn
#

Keep your own stored value for what the degrees should be, pass them to the objects transform, and never read them back from the transform

silk night
#

Create 3 class properties: targetX, targetY, targetZ

Then you edit them on keypress, clamp them and at the end set them as the current rotation, or even better store them in one Vector3

oak mist
#

Good Afternoon. Im trying to map my little test turret to move using a controller. Left joystick moves the tank up and down, and right joystick rotates the turret left and right. My left joystick is working fine, but my right keeps being fed a value of -1 and i have no idea why. Any solution for this?

ivory breach
polar acorn
oak mist
#

I believe so, its a regular ps4 controller

#

2 on left, and 2 on right

#

i checked a mapping on reddit and followed it

#

again i could be wrong here

silk night
#

Where is the second one on the right?

wooden minnow
oak mist
#

is the guide i used

silk night
wooden minnow
#

ah ok

#

lemme try that

silk night
#

and keep the vector3 persistent as a class property

#

dont make it a local variable

wooden minnow
#

dont know what that means

#

nvm i do

silk night
#
    public class TestView : MonoBehaviour
    {
        private Vector3 _targetRotation; // <- this one
    }
oak mist
modest dust
# ivory breach Let me think a bit, then I'll come back
current += reserve; // Add all reserve to current
reserve = current - magSize; // Reserve is how much over magSize your current bullet count is
if (reserve < 0) reserve = 0; // Reserve can't be negative 
current -= reserve; // Clamp your current bullet count to max of magSize

So if you have current=3, reserve=5, magSize=12 you get
current += 5 // 8
reserve = 8 - 12 // -4
if (reserve < 0) reserve = 0 // true
current -= reserve // 8-=0 -> 8

And if you have current=11, reserve=3, magSize=12 you get
current += 3 // 14
reserve = 14 - 12 // 2
if (reserve < 0) reserve = 0 // false
current -= reserve // 14-=2 -> 12

Or just simply make a loop to increment current and decrement reserve until either current == magSize or reserve == 0

silk night
#

oh nvm, just saw the Input calls

#

I'd try other axis and if they output the values you want

oak mist
#

fair enough

#

ill try all inputs and see what happens

ivory breach
modest dust
#

Don't

quasi rose
#

Sometimes taking a step back, and writing it out, without code, can be very helpful.

slender nymph
#

oh wait, that's not entirely correct for what they are trying to do. one sec

modest dust
wooden minnow
summer stump
ivory breach
#

I'm not very good at math, and I have an assignment on the line

#

And it isn't even unity related, it's UE5

slender nymph
#
var remaining = current;
current = Math.Min(reserve, magSize);
reserve -= current - remaining;
slender nymph
ivory breach
#

True

wooden minnow
# silk night Not sure how you mean that

if my object is rotated on the Y axis when the X axis is also affected by that
instead of going something like a line it will now go diagonal because the Y axis is rotated

#

idk how to explain it

wooden minnow
#

of what

silk night
#

how it currently behaves

oak mist
#

what i might do, is take input from the third button, then add 90 degrees to the rotation (or its equivulant)

final kestrel
silk night
silk night
wooden minnow
#

how would i make it so each axis doesnt affect the other ones

silk night
#

use .localRotation

wooden minnow
#

that didnt really do anything

prime loom
wooden minnow
#

OMG ITS THE SECOND TIME I CLOSE UNITY BY ACCIDENT

silk night
wooden minnow
#

also why isnt unity giving me a warning or asking me to save when im accidentally closing it

#

this is the second time i've reset my project

hexed terrace
silk night
#

Oh you want camera dependent rotation? like if its upside down and you press left you want it to go left instead of the updside down right? idk if i explained that well 😄

wooden minnow
#

im confused

prime loom
#

we cant go and change that

hexed terrace
#

parse it

#

probably regex it to find \n and replace with <br>

prime loom
#

i even try to replace it

gaunt ice
#

why the log can display \n, it supposed to be new line character, it maybe \\n

slender nymph
#

it's probably a literal. use @"\n" in the Replace call

prime loom
#

That helped

#

What does a literal mean. And what does @ does

hexed terrace
#

\n will give you that text, it has no escape, you would do \\n in the string to escape for the \n to be accessed

slender nymph
#

@ is used for verbatim strings. which is what i actually meant when i said literal. because string literals can contain escape sequences like \n

prime loom
#

oh

#

Nice to know

#

Ty

slender nymph
#

it's likely that the original string had that escaped or that it was a verbatim string to prevent that escape sequence

heady nimbus
#

(2D) I'm instantiating several projectiles at once around the edges of an object, trying to make them "burst" out in every direction.

I have the rotations set so that the "forward" of the object should be pointing in the direction I want it to travel, but I'm not sure how to calculate that movement. What process should I use for something like this?

buoyant knot
#

first, is it kinematic or dynamic?

#

and do you just want it to go in a straight line

heady nimbus
#

I had a kinematci RB on them because I don't want them to physically interact with things, just trigger colliders. Straight light, like a burst shot

buoyant knot
#

then you have 2 options

heady nimbus
#

But I don't know if kinematic is exactly what I want/need either so I'm open to suggestions

buoyant knot
#

one is to just give the rigidbody velocity in the direction you want. that is easiest

#

despite what people will tell you, 2D kinematic rigidbodies CAN use velocity

heady nimbus
#

I did try that at one poitn but it didn't seem to be working so I probably wasn't doing it correctly. Is there something specific you need to do for kinematic then?

buoyant knot
#

this velocity gets ignored on any physics update where you issued a MovePosition command

#

first you want to basically teleport the rb to its starting point. you could try setting rigidbody.position manually

#

then set its velocity

#

if you call MovePosition after that, the target destination will get basically overwritten

heady nimbus
#

Yea, I haven't been using MovePosition for this part. Why is it necessary to set the position of the RB? I don't think I've seen that before

buoyant knot
#

because the rigidbody and transform write positions back and forth

#

rigidbodies are like a separate API

#

when the RB moves during physics step, it moves the transform and colliders with it

#

i don’t fully understand why they need to be separated like that, but they are

#

and you would need to call Physics2D.SyncTransforms to make everything immediately line up, but that has cost because we’re updating everything all at once

#

unity devs didn’t think to make an overload to just sync the one object

#

when you move rigidbody.position, it will immediately move the collider2Ds attached to it. So the .bounds and Cast calls will be correct

heady nimbus
#

Ok, at least they're moving right now, but they're just firing across the screen in the same direction, how would I calculate moving in the current "forward" direction based on rotation

buoyant knot
#

otherwise some shit won’t make sense. I could initialize an object at 0,0. Set its transform to 50,100. Then check for ground by raycasting down at the bottom of collider bounds. Well congrats, you just checked for ground at 0,0

#

is your game grid based?

heady nimbus
#

No

buoyant knot
#

you can probably use transform.up

heady nimbus
#

I'm thinking maybe it should be based on how many "nodes" I've been creating, but this is all really jsut for a boss fight

buoyant knot
#

transform.up is the vector that currently points up for that transform

#

I would define a rotation matrix by 90 degrees to rotate the vector real quick

#

for the case of 90 degrees, rotation is trivial

glacial chasm
#

Projectile is floating instead of moving forward