#💻┃code-beginner

1 messages · Page 422 of 1

tepid summit
#

i reread it

#

i am sorry for causing a ruckus

copper matrix
#

can u help me doing it cause i dont understand it tbh

fickle plume
modest dust
#

Which step don't you understand

#

There's a step by step example

sudden pilot
#

guys there is a green health bar and shield bar down of it

#

when ı change shıeld slider value it changes x scale

#

ı want to delete part and part

#

anyone knows?

ripe shard
sudden pilot
tepid summit
sudden pilot
tepid summit
#

ok

#

I have a script set up to animate a gameobject upon a mouse click, the coroutine gets called but nothing changes in the animator ```public class SwingAxe : MonoBehaviour
{
public Animator Swinger;
public bool Clicked;

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        StartCoroutine(AttackAnimation());
    }
}

IEnumerator AttackAnimation()
{
    Debug.Log("Clicked");
    yield return new WaitForSeconds(1);
    Swinger.SetBool("Attacking", true);
    new WaitForSecondsRealtime(2);
    Swinger.SetBool("Attacking", false);
}

}```

#

i have a screenshot i can send too

broken cargo
tepid summit
#

aight

#

let me test that

#

thanks man

#

that was such an easy fix

#

i kind of feel bad for asking

stray thorn
#

so i have this code that spawns cubes randomly across a certain range and sometimes it spawns 2 cubes in the same spot how do i prevent that

copper matrix
#

can i call someone who can help me via Call. I have many problems and the DeadLine is in 5h

#

like its so simple shit but i fail miserable

languid spire
stray thorn
#

yeah but how do i do that

#

is there a c# doc for lists?

languid spire
#

do you know how to make and use a List ?

stray thorn
#

not really i started unity 2 days ago

languid spire
copper matrix
#

everytime i throw a shuriken it get instantly deleted and idk why

tepid summit
#

what

stray thorn
#

cz i have to specify the type of the value in a list

#

List<int> numbers = new List<int>();

#

int or float?

languid spire
#

yes and Vector3 is a Type

rocky canyon
#

List<Vector3>

stray thorn
#

okay tysmm

copper matrix
#

looks like this

#

but when i instantiae the shuriken it gets instantly deleted

verbal dome
#

Theres a very small change that your Vector3's will be exactly the same, so rounding gives them some "spacing"

stray thorn
#

how do i round it up?

#

is there a function?

polar acorn
eternal falconBOT
verbal dome
#

You can multiply the vector before rounding if you want a spacing different than 1 unit

verbal dome
stray thorn
#

how do i check if randpos im about to add to the list is already there?

#

use occlusion culling otherwise itll start lagging when u add more objects in the future

#

its not related to ur problem btw

#

jst advice

verbal dome
languid spire
verbal dome
#

Yeah, it is using a different local list, not the list in your class

languid spire
#

and it's creating a new one every itteration

cosmic dagger
#

Yikes . . .

stray thorn
languid spire
#

you create a new one so, yes

stray thorn
#

so lke this?

languid spire
stray thorn
#

wdym?

languid spire
#

the pos at the top is not the same as the pos at the bottom

stray thorn
#

so do i remove the one at the top?

#

wait so rn i have to lists both named pos?

languid spire
#

Do you need pos outside of the Start method?

stray thorn
#

no

languid spire
#

then remove the one at the top

stray thorn
stray thorn
languid spire
stray thorn
#

wait it wouldnt work

#

all the vectors in the list are named the same thing

#

how would i check if one of them equals a certain value when all of them are the same name

languid spire
#

vectors don't have names they only have a Type and properties

stray thorn
#

isnt randpos a name?

#

vector3 randpos = new....

languid spire
#

you are comparing one instance of a Type with another instance of the same Type

stray thorn
verbal dome
languid spire
stray thorn
languid spire
#

if (pos.Contains(randpos)) { }

#

does the values of randPos exist in the list of Vector3's ?

stray thorn
#

why in gods green earth is this an error

languid spire
languid spire
#

this is why we use IDE's, hover over it and it will tell you

stray thorn
stray thorn
#

for example it said do System.Random.Range

#

that also didnt work it told me range isnt a thing

rocky canyon
#

or.. UnityEngine.Random.Range

stray thorn
#

it worked when i did UnityEngine.Random.Range

stray thorn
rocky canyon
#

u can also do using Random = UnityEngine.Random; at the top

languid spire
#

yes, you have 2 different possible Random's. System.Random or UnityEngine.Random, you must chose which one to use.
The easy option is to add
using Random = UnityEngine.Random:

rocky canyon
#

then Random.Range will just use Unity's

stray thorn
#

tyy

rocky canyon
#

try it out

stray thorn
#

like this?

rocky canyon
#

looks good to me

#

now if u hover the Random it should tell u its Unity's random

cosmic dagger
slender nymph
summer shard
#

how do i fix that

    private Vector3 lerpTowardsPosition;
    private Vector3 velocity;
    [SerializeField] private float speed;

    [SerializeField] private GameObject[] wheels;

    private void Awake() {
        lerpTowardsPosition = transform.position;
    }

    private void Update() {
        transform.position = Vector3.SmoothDamp(transform.position, lerpTowardsPosition, ref velocity, speed);

        foreach (GameObject wheel in wheels) {
            wheel.transform.localRotation = Quaternion.Euler(0, -90, velocity.magnitude);
        }
    }

    public void goToLocation(Transform newLocation) {
        //transform.position = Vector3.Lerp(transform.position, newLocation.position, 0.5f);
        lerpTowardsPosition = newLocation.position;
    }
quick ruin
#

I have an object rotating around the center during runtime, not the pivot. is there a box to check to fix

slender nymph
#

how have you confirmed that it's pivot point is not its center

quick ruin
#

first pic is pivot view second is center view

slender nymph
#

the Center tool handle position has nothing to do with how an object rotates. it shows the approximate center of the selected gameobjects

#

if i had to guess, you are probably rotating this object's parent rather than the object itself and the object is offset from the parent such that when the parent rotates it appears as if the object is rotating about its center

stiff abyss
slender nymph
#

your parameters are incorrect for your Debug.DrawRay call

stray thorn
#

how do i move a capsule using a rigidbody

tepid summit
#

im trying to make a reference to the text of an Input field, but im not sure what to call it

public InputField NameMaker;```
languid spire
stray thorn
#

yea it just tells me the options

#

when i click it dosent explain how to use them

tepid summit
tepid summit
stray thorn
languid spire
tepid summit
#

here ill give an example

#

ok

#

so it suddenly works when i try and show poeple

#

thanks unity

frosty hound
#

That wouldn't be a Unity issue, code is code.

#

You can use it wherever you want, assuming you use it correctly. Which, if it didn't work before is because you didn't use it correctly.

stray thorn
#

how do i make so i only jump when im grounded

tepid summit
#

triggers

stray thorn
#

i started 2 days ago what does that mean

languid spire
eternal falconBOT
#

:teacher: Unity Learn ↗

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

spice adder
#

hi everyone, i have a question so basically, how do i know if i need to create a new scene? for example, i am developing this game which had this 2 different scene, the shed and the backyard, the player would occasionally go back and forth between these two place to pick up items, is it better if i make these 2 in different scenes or just in 1 scene?

slender nymph
#

either option is perfectly valid, it really depends on how you want to handle it

spice adder
#

ah okay! thank you so much, i thought i was doing something wrong

halcyon dagger
#

this script is making my project being unable to build, why? Its just an util

using UnityEditor;
using UnityEngine;

public class RectTransformUpdate : MonoBehaviour
{
    [MenuItem("CONTEXT/RectTransform/Snap Anchors To Corners", priority = 50)]
    private static void Execute(MenuCommand command)
    {
        RectTransform rectTransform = command.context as RectTransform;
        RectTransform parent = rectTransform.parent as RectTransform;
        Vector2 parentSize = parent.rect.size;
        Vector2 parentMin = parent.rect.min;

        // Find corner point coordinates in parent's local space
        Vector3[] corners = new Vector3[4];
        rectTransform.GetWorldCorners(corners);
        corners[0] = parent.InverseTransformPoint(corners[0]); // Bottom left
        corners[2] = parent.InverseTransformPoint(corners[2]); // Top right

        Undo.RecordObject(rectTransform, "Anchor Modification");

        rectTransform.anchorMin = new Vector2((corners[0].x - parentMin.x) / parentSize.x, (corners[0].y - parentMin.y) / parentSize.y);
        rectTransform.anchorMax = new Vector2((corners[2].x - parentMin.x) / parentSize.x, (corners[2].y - parentMin.y) / parentSize.y);
        rectTransform.sizeDelta = Vector2.zero;
        rectTransform.anchoredPosition = Vector2.zero;
    }

    [MenuItem("CONTEXT/RectTransform/Snap Anchors To Corners", validate = true)]
    private static bool Validate(MenuCommand command)
    {
        RectTransform rectTransform = command.context as RectTransform;
        return rectTransform.parent != null && !PrefabUtility.IsPartOfImmutablePrefab(rectTransform);
    }
}
slender nymph
#

you can't use editor code in a build, put that into an Editor folder or wrap it in preprocessor directives

languid spire
halcyon dagger
#

ok so it goes into Assets/Editor ? or where do you mean

slender nymph
halcyon dagger
tepid summit
#

Hey so i'm planning to use a DDoL to keep the "user" string safe between scenes, yet I dont know where to put this DDoL. Can anyone please help

    public InputField NameMaker;

    public void NewGame()
    {
        Main.SetActive(false);
        Username.SetActive(true);
    }

    public void UserChosen()
    {
        user = NameMaker.text;
    }```
languid spire
eternal falconBOT
tepid summit
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class ButtonScript : MonoBehaviour
{

    public float NewGameCheck;
    public GameObject Main, Username;
    public string user;
    public InputField NameMaker;
    public void NewGame()
    {
        PlayerPrefs.SetFloat("NewGameCheck", 1);
        Main.SetActive(false);
        Username.SetActive(true);
    }

    public void UserChosen()
    {
        user = NameMaker.text;
    }
    public void NewUserHitPlay()
    {
        PlayerPrefs.SetString("Username", user);
    }

    public void Continue()
    {
        PlayerPrefs.SetFloat("NewGameCheck", 0);
        SceneManager.LoadScene(1);
    }
    public void ExitButton()
    {
        Application.Quit();
    }
}```
languid spire
polar acorn
tepid summit
#

sorry, i didnt think 39 lines was too many

languid spire
languid spire
tepid summit
#

obviously the user

#

but how would i type that? should i try first and post errors here

summer stump
#

You should google the method and look at the example code, which will tell you exactly how to type it

rose owl
#

I'm a complete beginner and these two errors show up, why is that?

eternal falconBOT
rich adder
#

also you're passing two positions

tepid summit
summer stump
tepid summit
#

well yea but i mean the way hes trying to do it

rich adder
summer stump
tepid summit
#

alright

summer stump
tepid summit
#

but its telling me i cant convert string into an object

rich adder
#

you can't DDOL a string

tepid summit
#

yeah so how would i attach the string to an object

rich adder
#

attach the string to an object?

#

what are you trying to do exactly

verbal dome
rich adder
#

rip

verbal dome
tepid summit
verbal dome
#

It could be one that you make

tepid summit
#

ohh

#

could i do
DontDestroyOnLoad(InputField.text);

verbal dome
#

Do you know what a component is?

tepid summit
#

yeah

#

like a CharacterController for examle

verbal dome
#

Is InputField.text a component?

tepid summit
#

i know it isnt

strong wren
#

I would start by creating a separate gameobject and component for persistent data

polar acorn
tepid summit
#

because its worht a shot

rose owl
polar acorn
slender nymph
eternal falconBOT
polar acorn
# rose owl i saw that line in a tutorial
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 170
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-07-12
tepid summit
polar acorn
obsidian shoal
verbal dome
#

I didnt watch the video, but dont multiply mouse input with deltatime

obsidian shoal
#

fixed

verbal dome
#

And make mousesens way smaller after that

obsidian shoal
verbal dome
#

Now that you dont multiply with deltatime (which is a small number) you need to account for that

#

So the sens should be made about 50-100x smaller

hallow acorn
#

hey what function should i use if i want my code to get called only at the beginning of the game and after switching the scene?

rich adder
hallow acorn
rich adder
#

idk what that means

hallow acorn
#

i wanted to setActive on my canvas to false, but it didnt work as it was still visible

rich adder
#

are you talking about a DontDestroyOnLoad object?

hallow acorn
#

what is a DontdestroyOnLoad object?

polar acorn
hallow acorn
#

it works on scene change somehow i tested it with a debug.Log

polar acorn
#

So Awake will run on scene load

rocky canyon
obsidian shoal
#

why am i unable to rotate left or right

rich adder
willow scroll
verbal dome
obsidian shoal
#

yes

#

sorry

willow scroll
#

Because the global variable is used instead of a local one

obsidian shoal
#

so change to private?

willow scroll
#

I suppose, xrot is -90 the whole time, and the mouseX just decreases it before clamping again

willow scroll
#

This means, the variable stays persistent throughout the Updates

rocky canyon
#

he sets his local transform rotation and then calls Rotate on the playerBody transform we're lookin at his head script

polar acorn
#

If you wanted to look it up that would be the term the documentation would use

obsidian shoal
willow scroll
rich adder
#

if anything a Constant is more of a global no?

willow scroll
verbal dome
rich adder
#

true static field can def be "global "

obsidian shoal
rich adder
#

the xRot looks fine being a field

#

don't think thats the issue

obsidian shoal
#

i can rotate y just not x

obsidian granite
rich adder
obsidian shoal
willow scroll
verbal dome
#

If you even have a rb

obsidian shoal
#

im just moving main cam

hallow acorn
willow scroll
#

How can you even rotate the y axis, if you're constantly setting it to 0?

obsidian granite
#

i'm working on a project that generates objects that a square bounces on. my current code generates objects correctly, but there's an issue that makes it so that an object can spawn on the intended path of the square, which makes it so that the object knocks the square off-course. what do you guys think i should do to fix this?

obsidian granite
rich adder
willow scroll
rich adder
polar acorn
hallow acorn
obsidian granite
#

i am making a software to generate one of those "bouncing cube" videos that you see on short-form content where the cube hits the wall according to music. i have my code parsing each note from a midi file and figuring out when the cube should hit a wall. the issue is, sometimes, the correct generation of the walls to the beat of the music makes an object spawn in the path of the cube previously. this is all generated before the cube even starts moving. i'm trying figure out how i can figure out where the cube will have travelled by the time it reaches a certain wall so i can prevent walls from spawning in the way of the cube's path. here's a video showing the issue. you can see in both runs, the cube is knocked off of its course because it hits an object that it was meant to hit later on. the red lines show the intended course.

#

is that better?

rich adder
hallow acorn
rich adder
# obsidian granite is that better?

not enough info just by this video. Sure we see the problem but we have no clue how you even genertate anything in the first place, (code) how can we know of any suggestions besides the "just dont spawn it there"

rich adder
rich adder
# hallow acorn no

unless you specifically told it to preserve state, aint no way it would stay enabled on its own

rich adder
#

or user error **

#

well either start showing the setup and script or we can just go in circles speculating

obsidian granite
# rich adder not enough info just by this video. Sure we see the problem but we have no clue ...

the method is like 100 lines long and nobody wants to read that. even just the relevant part is 50-ish. i'm just asking how i could store all of the locations that an object would have theoretically been if it had a certain velocity. i know i could literally just make a giant list and populate it with all of the locations, but that seems inefficient and there's likely a better option.

#

if you really want to see the code, here's the hastebin

#

no clue why it saved as java :(

forest mist
#

Which are the specializations in game programmer field?

rich adder
rich adder
obsidian granite
#

the entire thing is generated based on where it predicts the cube will be if everything goes right

hallow acorn
digital kelp
#

Why is my trait variable also being changed?

                ResourceType trait_k = new ResourceType();
                trait_k = trait;
                Debug.Log(trait.resourceAmountShallow);
                trait_k.resourceAmountShallow = 0;
                Debug.Log(trait.resourceAmountShallow);

Am I not creating a new variable trait_k and changing that one instead?
The 2 debugs print different values

rich adder
hallow acorn
# rich adder you made a singleton ?

yeah but i couldnt set it in other scripts idk why so this was the faster method which im never gonna use again and just bc i have to finish the project untill tomorrow

digital kelp
#

So they're both just referencing the same thing?

#

How can I make a new one then?

rich adder
#

they always give you a copy

digital kelp
#

There are also strings

#

if that matters

rich adder
#

should fine

digital kelp
#

But if not how would I copy a class?

rich adder
#

for example you copy the values over to new instance instead of assigning the same instance

#

or deep copy

jovial bone
#

ik this may sound stupid, but how do draw a filled circle in unity 2d

rich adder
digital kelp
#

alright, ill try

jovial bone
#

i saw a guy use a DrawCircle(vector2 pos, radius, colour)

rich adder
#

are you talking about a debug circle?

#

Gizmos.DrawSphere ?

polar acorn
#

That's not built in

jovial bone
rich adder
#

just a regular mesh?

polar acorn
jovial bone
#

i just started unity

polar acorn
#

It's probably better to just use an image

rich adder
#

so google how to draw a mesh in unity and go from there

obsidian granite
jovial bone
#

cus i am trying to create a particle fluid simulator

ionic zephyr
#

I am making a scrollable menu with different slots(which I made prefab) but the thing is that there isn´t going to be a specific number of them. These slots are the receipts the player learns throughout the game

#

how can I make this menu if I don´t know how much slots are there going to be??

rich adder
#

goodluck lol

jovial bone
rich adder
#

idk this UI stuff much
i spawn all the items in code though, each UI item has a prefab that gets spawn as child of scrollrect then added the content size fitter it automatically expands

eternal needle
ionic zephyr
#

Instantiating them?

eternal needle
#

Yes instantiate is how you spawn things

rich adder
#

var item = Instantiate(uiPrefab, theContentOfScrollRectTransform)

ionic zephyr
#

Okay, I´ll try then

#

isnt Instantiating expensive efficiency-whise?

rich adder
#

if you keep destroying and instantiate it creates garbage

#

ideally instead of destroying you recycle

#

(Object pooling)

ionic zephyr
rich adder
#

you should not worry at this UI level. How many are you really doing ?

#

realistically, this is better applied when you keep spwawning something like Bullets, enemies etc.

jovial bone
#

can you make a prefab for a circle sprite and instantiate as a draw circle

#

can that work?

rich adder
#

but idk how you would apply that to fluid sim

jovial bone
#

opikachuface

#

i see thanks

rich adder
#

are you spawning a whole bunch of small circles to simulate liquid? ig it can work that way

rich adder
#

i see. yeah thats not too bad

#

there are ways with particle system and would prob give better performance but thats way more math heavy

willow scroll
#

You could store the spawn positions in the list, and then enumerate through the whole list to look for any unwanted intersection points between the position pairs and the previous with target positions

#

But it's not going to be efficient

hallow acorn
#

i have 2 audiosources on one object and im trying to control both volumes with a slider. i made a script but how can i access both sources bc if i drag my object (where the sources are attached to) into my 2 public audiosources its 2 times the same source

rich adder
hallow acorn
rich adder
#

you literally just said

bc if i drag my object (where the sources are attached to) into my 2 public audiosources its 2 times the same source

hallow acorn
rich adder
#

pop out the inspector or lock it

#

right click the component, hit Properties

raw token
#

pop and lock it 🕺

hallow acorn
willow scroll
#

This should be better than storing them all in a List

cosmic dagger
sturdy drum
#

Apologies if this isn't the right channel for this question, but I'm wondering how I can implement a house with a door in a metroidvania, where the inside and outside of the house both occupy and show the player's location as the same spot, but going inside the house changes the map to show the inside instead of the outside. Preferably, this is all done in a single scene

cosmic dagger
cosmic dagger
raw token
#

Unity Inspector: Krunk Edition

split dragon
#

Hi. I have a question: How can I change the text, leaving it as it is now, but add another string to it.
There is a string = I love you: 0% We are doing something and 0% is changing to other numbers:
I love you: 100%
Of course, it will be possible to write letters in the inspector first, and then write +float in the script, but if the language changes?
How can I change the text by simply adding a new string, leaving the old one?

raw token
sturdy drum
cosmic dagger
eternal needle
#

You could also just have 2 different texts

raw token
# sturdy drum Unfortunately, I'm out atm and can only provide the full size map. It takes a bi...

Anything might help :P

I just couldn't quite grok what you are describing... My best interpretation is that the interior of the house is separate from the external world-space (so like rabbit hole buildings - the interior could be could like be a different size than would actually fit in the exterior as rendered), and you have a minimap of the exterior environment which displays a marker for the character on the house?

cosmic dagger
broken cargo
split dragon
eternal needle
#

What does changing the language have to do with anything?

split dragon
rich adder
cosmic dagger
rich adder
#

mate. don't crosspost

sturdy drum
#

Again, apologies for any clarity issues. The picture does take some time to fully load

craggy lava
split dragon
split dragon
rich adder
rich adder
craggy lava
rich adder
#

no clue I dont use google play

broken cargo
eternal needle
#

"Its written that way" well write it differently

sturdy drum
#

@raw token Here's a better focus, and hopefully they're easier to see

languid spire
sturdy drum
raw token
# sturdy drum <@1097950947369562187> Here's a better focus, and hopefully they're easier to se...

I'm no pro, but just spitballing: you could position you interiors in some far-flung corner of the scene (or separate scenes with additive scene loading) and have your doors keep a reference to their paired counterpart, and maybe like a flag indicating if the door is an interior or exterior door. On interaction with a door, teleport the player to the corresponding door, and if they've entered an interior set a flag on the player indicating that they are now in an interior.

Maybe use a property on the player to expose their "overworld position." If they're not in an interior, it would just return their world-space position, but if they are in an interior it could return their last known world-space position. Render their position on the minimap based on that property.

You could maybe make it all more robust by explicitly describing interiors, maybe with like a Scriptable Object asset, or a script on the interior's root object. This way the interiors could be definitively associated with specific "overworld positions," and doors/portals could inform the player about the attributes of their current interior

queen wren
#

Anybody knows what is going on here?

#

Severity Code Description Project File Line Suppression State
Error (active) CS0246 The type or namespace name 'SceneAsset' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp.Player F:\Unity\Broken Wings\Assets== Codes ==\SCK\GridManager.cs 25

#

I could get back to string or scenes ID but I like to drag and drop stuff on inspector 😁

white nest
#

any pointers on how i can get the player to rotate with the platform? i tried parenting the player movement to the platform as ive seen others suggest and it doesn't work it kinda just gets stuck when i do that.

queen wren
white nest
#

read what i just said

hallow acorn
pliant sleet
#

can i change the base scale of a sprite ? like before dragging it in the scene

#

or hierarchy

raw token
# sturdy drum Yes, I'm aware of clarity issues. That was stated above.

As an after thought, you could also actually store the interiors in the same x/y space as the exterior but at a deeper z depth. If you lined up the doors, this might let you relatively easily pull off some neat transitions within the same scene... though that might get finnicky in some situations

polar acorn
cosmic dagger
#

the code provided is from CanonMain . . .

#

but the inspector image shows Projectile . . .

glossy turtle
rose canyon
#

hey im a 3d designer and i wanted to work on a project with people for my practice so i would pretty much make u free 3d assets, which channel can i go to to advertise this?

cosmic dagger
rose canyon
polar acorn
# hallow acorn

Yes we could see that in your first images. counter is null. Where do you set counter on CanonMain?

cosmic dagger
# hallow acorn

the image you linked is from the Projectile script. make sure counter is assigned in the CanonMain script . . .

eternal needle
polar acorn
#
  1. is counter an int
  2. can an int even be null
cosmic dagger
hallow acorn
cosmic dagger
sturdy drum
cosmic dagger
#

@hallow acorn line 10 of the script you provided. that variable is not assigned . . .

hallow acorn
#

assigned it to the actual scripts and it works now

twin bolt
#

Does anyone know why my player runs faster when running diagonally, or pressing W and D or W and A? https://hastebin.com/share/masokinimo.java

polar acorn
eternal needle
# white nest 🙃

The suggestion you were given doesnt even make sense given the question. This problem isnt as easy, you need to calculate how far to actually move the object on top of platforms each time the platform moves.
You should have some way of combining movements before actually moving your player. So you would basically be adding like the movement from input and external forces (the platform). You might be able to just use the local position of where the player is on the platform to start then calculate deltas. Though I dont know an exact solution, was just trying to tell you the other one wasnt even a solution

twin bolt
white nest
raw token
# sturdy drum the Z depth is genius. Then this way, the xy is functionally the same, and the b...

I actually hadn't considered how that would affect the minimap 😅

But I definitely think it's an interesting possibility that would be fun to explore though. The tricky bits I envision are that 2D collisions don't care about z depth, so the interiors would probably need to be inactive until the player enters them, and maybe like input locked for the duration of the transition animation. The trickiest bit may be cases where an interior has multiple portals which cannot all be aligned with their overworld counterparts simultaneously

sturdy drum
raw token
stuck palm
#

private void FixedUpdate()
    {
        velocity.y += (-9.81* GameManager.Instance.deltaTime) * timeScale;
        transform.position += velocity; 

why is this going so fast? have i messed something up here

raw token
stuck palm
#

1/60

eternal needle
#

Did you debug what all the values are? Also does the velocity.y ever get set to 0 because this code shows that its only added to constantly

#

0 meaning like when its grounded

mint remnant
#

why using 2 different time variables for essentially t^2

eternal needle
#

Looks more like it's a custom time scale for this object, which itself is valid. It being 1/60 though is kinda weird

stuck palm
stuck palm
#

deltaTime is 1/60

#

sorry i miswrote

eternal needle
#

Still, have you debugged anything related to this?

stuck palm
eternal needle
#

If you arent setting it to 0 ever, what's stopping objects from accumulating velocity while standing around

stuck palm
raw token
# stuck palm deltaTime is 1/60

FixedUpdate() likely won't be executing at 1/60s intervals unless you've configured it as such, for what it's worth. But I would think that that discrepancy would slow things down instead of speeding them up

stuck palm
mint remnant
#

you are both += the velocity and also += the position

stuck palm
eternal needle
#

🤷‍♂️ if the values seem fine and you're having an issue, then you've likely not shown some code

stuck palm
eternal needle
eternal needle
stuck palm
raw token
#

Ah wait... Your change in position should be multiplied by the time

stuck palm
raw token
#

dv = a * t
dp = v * t

Both

dense matrix
#

"p" for position, while intuitive, somehow just sits wrong with me

stuck palm
dense matrix
#

I'm too physics-y based to think "momentum" there

raw token
#

hahaha yeah 😅

It's been a while since I took physics. I'm sure there's a more... appropriate symbol

#

ddisplacement? dtranslation?

dense matrix
#

What

stuck palm
dense matrix
#

I just typed "x" and

#

"dx" would be a change in position

#

(strictly, "x" should be in bold or underlined, if it's representing a vector)

#

But I'm amazed that the server moderation considered that an inexpicable phrase here

eternal needle
raw token
#

I really need to take some dedicated time to go back and study physics and calculus again, now that I actually care about it

dense matrix
#

...If needs be, I'm British

eternal needle
#

I understood what you wrote, but underlining or bolding is definitely not convention, anywhere

#

The only notation I've seen is a line above, which my upper year profs didnt even enforce because no one understood wtf he was doing anyways

dense matrix
#

I'm coming at this from a maths perspective; I'm aware other disciplines use different conventions

#

That might have caused this confusion

dense matrix
#

Btw, unrelated, and this might be a dumb question

#

but does anyone use VS Code instead of Visual Studio 20XX?

#

I have both 2019 and 2022 installed (...for some reason), but I think Code just... looks nicer? idk

raw token
#

Virtually everyone on Mac and Linux (if they're not using Rider). Some prefer it on Windows as well, but the Unity integration is a little more temperamental. I use VSCode for everything but C/C#

dense matrix
#

Is Rider another code editor?

raw token
#

Yeah! JetBrains generally has a great line of premium IDEs

dense matrix
#

Also, on Windows is there much of a difference...?

#

i.e. between Code and 20XX

craggy lava
#

No errors being thrown just not working this google play game authentication its setup right

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

dense matrix
#

(cos I have heard of people using 20XX for C/C# specifically, and Code for anything else)

raw token
#

For whatever reason, I've found that VS with C/C# projects just sort of inherently works without much fiddling or configuration, but - at least when I last tried - VSCode was a pain to get working with my C projects

dense matrix
#

So, if I'm editing C# code in Code, is it only because I have 20XX that Unity can interpret it correctly or...

raw token
#

Oh no not at all - I believe Code has pretty good C# support through extensions nowadays, and Unity did recently revamp their VSCode support. It should work independently of whether or not you have VS installed, though you may need to install the build tools separately - I'm not entirely sure

#

!ide

eternal falconBOT
dense matrix
#

Ah

raw token
#

Ah nice - the unity extension installs the toolchain

dense matrix
#

See, I'd been learning C# through Microsoft's Learn courses, and they'd been using Code for some time

#

So I'd just sticked with Code

raw token
#

Totally valid! There for a good while Unity stopped supporting their VSCode integration and the debugger stopped working... that's likely the only reason I didn't start out on Unity with VSCode. But not a problem, nowadays

dense matrix
#

I think I'd only had VS because of some file extractions and such lol

#

And like once, only to learn how to build a Razor website lol

#

okay that's one lol too many 😅

summer stump
dense matrix
#

yh I just realised that lol

#

(I've got two copies of it that's all)

raw token
#

Microsoft's become really horrible at naming things... See: their recent Game Pass changes 👀

summer stump
#

In the context it was very clear, but if you said that later, people would likely be confused haha.
All good though

summer stump
raw token
#

Oh wow I hadn't heard that 😅. That does make things all the worse

#

I guess we should also throw in VS for Mac not having any relationship with VS for Windows

#

My god Microsoft

summer stump
raw token
#

probably for the best

dense matrix
#

Sucks to be a Mac user

stiff abyss
#

Why I dont have that opion vector2

craggy lava
# dense matrix Sucks to be a Mac user

Yea it sucks to be one since i cant use VS on mac and i might need it when i am going to study data science or if i get license to jetbrains (i have macbook but i use windows to make games)

stuck palm
#

whats the math behind vector2.reflect?

dense matrix
#

It seems to take two arguments - the first being the incidence vector, the second being the normal of the surface you're reflecting against

raw token
dense matrix
#

At least, as far as I gather from the Unity Documentation

ionic zephyr
#

how can I check if a GameObject is active?

dense matrix
raw token
cosmic dagger
craggy lava
eternal needle
dense matrix
#

Yh emboldening is more common in print, for obvious reasons

craggy lava
eternal needle
# stuck palm whats the math behind vector2.reflect?

For stuff like this you should google it, youtube tutorials will draw it out. The dimension doesnt matter (2d or 3d) the concept is still the same. Websites like medium are generally extremely shit. Anyone can write an article and theres no way to really know if its accurate

waxen goblet
#

What does this mean

polar acorn
languid spire
waxen goblet
#

thank you

stuck palm
eternal needle
summer stump
thorn canyon
#

Im trying to make a zero g player controller (like outer wilds) with fully axis independent movement. I need camera lerping for the smooth feel. Heres what I tried, but when the player goes upside down, the controls are inverted.

Quaternion yAxis = Quaternion.AngleAxis(pitch, Vector3.right);
Quaternion xAxis = Quaternion.AngleAxis(yaw, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, xAxis * yAxis, drag * Time.deltaTime);```
languid spire
#

These are world space, you need to make them transform relative

thorn canyon
#

i tried doing transform.up & .right, just bugged everything out

#

heres a previous solution i had that worked, but I couldn't figure out how to lerp it. csharp //transform.Rotate(Vector3.right * Mathf.DeltaAngle(pitchOld, pitch), Space.Self); //transform.Rotate(Vector3.up * Mathf.DeltaAngle(yawOld, yaw), Space.Self);

languid spire
#

maybe the player.transform as that is what you want to be relative to

thorn canyon
#

camera controls & playermovement are in the same script for me

thorn canyon
languid spire
thorn canyon
#

yeah, zero g movement where the player moves

#

thats what i want

#

sense theres no camera clamping

languid spire
#

then why are you talking about camera lerping whilst not showing camera code

thorn canyon
#

yeah i guess its not camera code technically, but its separate from the movement so i don't know what else to call it

#

its the code im using for the players view

thorn canyon
olive lintel
#

hey guys, can anyone tell me whats going on here exactly? the last time seen float should update every frame while the target is in view, but as you can see here it is continuously set to zero. I have checked EVERY single script and none of them are doing this, and debug.logged every single time lasttimeseen is set, yet at no point is any script setting it to zero. does anyone know what might be going on? I even added the code on the right to tell me if the float its being set to is ever zero, but I'm not seeing anything in the console. Any help with this is massively appreciated.

#

I also set the targets[] array to be SerializeField to make sure absolutely NO other scripts are altering this value

#

as a matter of fact, no matter what I do setting this float value to ANYTHING, such as adding time.deltatime to it doesn't even work

#

and for some reason no matter what I do the same thing happens with the ID integer

ivory bobcat
#

Maybe you're constantly assigning it a new active target that has zero for the last time seen

olive lintel
#

so I'm completely baffled

ivory bobcat
#

I'm referring to assigning a new active target to that element in the array

polar acorn
eternal falconBOT
olive lintel
olive lintel
#

I'm also setting lastTimeSeen to Time.time here

#

(and the lastTimeSeen being passed in is also Time.time)

#

I just did it multiple times because I was starting to lose it

polar acorn
olive lintel
polar acorn
#

I have a feeling you're changing the lastTimeSeen on a copy of the activeTarget, not the original

olive lintel
#

when predicting the targets movement I forgot to return the lastTimeSeen to the returnTarget

#

dang that was all for nothing

#

sorry about that 😬 I just realised it while reading the code again

polar acorn
#

Ah that's fine, value types can sometimes be like stepping on landmines

olive lintel
#

yeah my fault I forgot that the target has to be rebuilt completely when updating its predicted movement

ivory bobcat
#

Inside the movedTarget function, you're potentially returning a new active target

#

I'm assuming this new active target would have a time of zero and if it ran every frame, the last time seen value would always be zero

vapid yew
#

I have made a sphere primitive in blender (242 verts, 480 tris) which has less tris and verts than the native Unity 3D sphere (515 verts 768 tris).

When it comes to high velocity collisions, should I opt into using a mesh collider with my custom sphere primitive as the mesh or use a sphere collider?
What is better for performance? Are there hidden downsides/overhead to using the mesh collider?

drowsy oriole
#

Based off my last problem where i had to use if one thing, else another thing on an OnTriggerEnter(), would I be able to do smth like OnTriggerEnter(Collider collider, other)? Or something like that

polar acorn
#

The sphere collider isn't "A mesh collider except that mesh is a sphere" it's a completely different thing

vapid yew
#

Can you explain why? On face value I assume that my sphere primitive is objectively better.

polar acorn
#

Because you can't get more efficient than "center and radius" which is what it uses to compute collisions

#

it's not a mesh, it's math

vapid yew
#

Okay that's perfect thanks 👍

drowsy oriole
#

Can I use 2 Colliders on an OnTriggerEnter

polar acorn
#

The one that's running it, and the one it hit

drowsy oriole
#

No, I mean can I use OnTriggerEnter(Collider collider, other)?

raw token
drowsy oriole
#

No, its a project my friend has, he has smth like that where you have collider and other

polar acorn
#

OnTriggerEnter takes a collider that this object has hit

#

All collisions occur between exactly two colliders. This one and the other one

#

There's no such thing as colliding with two other objects. That's two different collisions

raw token
#

Without seeing the code we can only speculate. If it's true that he has some method taking in multiple arguments, then I would guess it's a custom method, and not the one which is a part of the Unity API

drowsy oriole
#

private void OnTriggerEnter(Collider collider, other)

if(other.transform.CompareTag = (bannedlol))
(Ignore the bannedlol)

drowsy oriole
#

Here, gimme a sec and Ill give you the exact code

languid snow
#

hi, i found a random tutorial on youtube to make something look at the mouse. in that tutorial he sets the mouse position as this. What is screen to world point and why does he use it? I read the unity manual but i didnt understand it 😔

drowsy oriole
# polar acorn That's _very_ invalid syntax

private void OnTriggerEnter(Collider collider, other)
{
if(other.transform.CompareTag = (kickstick))

{
    StartCoroutine(TestPressCheck());
}

if (!base.enabled || !(touchTime + debounceTime < Time.time))
{
    return;
}
touchTime = Time.time;
Debug.Log("collision detected" + collider, collider);
raw token
polar acorn
drowsy oriole
#

Just tell me how I can get Collider collider and other on OnTriggerEnter

raw token
#

What do you expect other to even be??

polar acorn
# languid snow hi, i found a random tutorial on youtube to make something look at the mouse. in...

So, a position on your screen doesn't necessarily mean the same place in the world. Imagine your mouse is dead center on your screen, and you're pointing at a sign. If you spin the camera, the mouse is still dead center, but now your mouse is over a door. The screen position hasn't changed, but the world position that spot corresponds to has. This function takes a camera and checks a screen position on it, and gets back the world point that is actually over.

drowsy oriole
#

I've done this before but, only with Collider other

ivory bobcat
polar acorn
#

The thing you want to happen is fundamentally impossible and the code you've provided would not compile

raw token
drowsy oriole
#

Then, how do I fix it

polar acorn
#

A collision occurs between two and only two objects. This object, and the other one.

polar acorn
raw token
polar acorn
#

You've never specified a problem

languid snow
drowsy oriole
#

I need an other and a collider Collider, is there a substitute for that?

polar acorn
ivory bobcat
languid snow
#

oh ok

raw token
languid snow
#

thank you :D

drowsy oriole
polar acorn
#

is it the object you've collided with

raw token
polar acorn
#

or just some freaky collider that likes to sit in the corner and watch

drowsy oriole
polar acorn
drowsy oriole
#

When a collider with the tag "bannedlol" collides with the player, they get banned

#

Other is that collider

polar acorn
#

Why do you need a second parameter?

drowsy oriole
#

Idk lemme try smth

ivory bobcat
raw token
# drowsy oriole Other is that collider
void OnTriggerEnter(Collider crunchwrapSupreme) {
  if (crunchwrapSupreme.gameObject.CompareTag("bannedlol")) {
    // ...

There's one argument which is a Collider, and you change it's identifier to whatever you want. collider and other are just popular names and conventions - but the name itself does not matter, so long as you use it throughout the method body

supple garden
#

How to properly attach the weapon to the sprite? i made it the child of the sprite. Placed it on top of hand. but when i play in editor, weapon's position is changed. Im not using rigging and i dont want because i really dont know how, used the animation rigging package and 2d animation package but nothings working.

ivory bobcat
# polar acorn Why do you need a second parameter?

In the body of the code, they've likely Frankensteined random bits from the internet that addresses the object triggering the event as collider or other but did not understand that the name doesn't matter - it's referring to the same object.

polar acorn
cobalt atlas
#

So I am making a top down 3D game and I have powerups that I want to be transparent. the issue is that I want the transparency to only be for specific game objects. for example When a enemy goes through the powerup I want to see the enemy through it but I dont want to see my background through the powerup as it just looks weird. is there a easy way to fix this issue?

drowsy oriole
#

I cant do it on one collider

raw token
drowsy oriole
#

I need CompareTag

drowsy oriole
fading mountain
#

if other.tag == "example tag"

drowsy oriole
raw token
polar acorn
ivory bobcat
drowsy oriole
polar acorn
#

you don't

#

Your code is wrong for many reasons

#

That has absolutely nothing to do with the fact your variable is not named "other"

drowsy oriole
#

No Ik what im doing, ive done this before it just wont let me do it this time

raw token
polar acorn
#

This has never worked

polar acorn
#

it's not that it won't let you "this time" it's that the code you wrote is wrong

#

It was wrong

#

it will always be wrong

#

So look at the documentation

#

and use the function correctly

frosty hound
#

@drowsy oriole Use a thread so you don't flood this channel

drowsy oriole
#

I need help with collider enters

fading mountain
#

hey guys. I'm trying to implement a particle system. unfortunately when this method is called (PlayBloodEffect()) it correctly sets the position to the position of the player but it doesnt play the effect, as the Debug.Log(bloodEffect.isPlaying) returns false. how do I play my particle system?
code: https://gdl.space/litikajoma.cs

flint abyss
#

hello guys, i want to learn to make games in unity so im starting with learning c#, but i don't know where to start. so how should i? like a youtube tutorial or something?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
dim yew
#

is there something akin to a list that allows you to store things under strings rather than integers? i tried googling this like 40 times but couldn't find a way to word it

polar acorn
#

You can key them by any type, not just strings

#

It's a lookup table, give it a key, get the specified value

dim yew
#

ahhhh thank you

fading mountain
dim yew
#

will look into this

polar acorn
# fading mountain yes

Including any parent objects? If a parent of a particle system is disabled, it would also not play

fading mountain
polar acorn
fading mountain
#

but the reference is to the prefab

#

not to the instance thats in the scene

polar acorn
cobalt atlas
#

I have a top down game and I made a object transparent but I only want the transparency to be for another specific gameobject is that possible to do easily? Like have it for example when a enemy goes through a powerup it will show the enemy through it but not the lines of my ground

flint abyss
# polar acorn !learn

Im trying to find something, but that just doesn't help. I don't really want a course, like a spreadsheet or a video maybe? Because all i find is courses.

stray thorn
#

does anyone know what IEnumerator does in a script?

#

im trying to understand every part of this code idk what an IEnumertor does

fading mountain
hollow slate
#

it can be very useful.

flint abyss
#

!docs

eternal falconBOT
sour spear
#

am i correct in understanding Time.deltaTime = 1/framerate?

dense matrix
#

yes............?

dense matrix
#

iirc it's the time elapsed between the current frame and the previous frame

#

Running a Debug.Log(Time.deltaTime) in a void Update function should show you its output in real time

#

In a stable, smooth framerate, that would be 1/framerate

sour spear
#

thats what i thought but for some reason i forgot basic c#

raw token
# stray thorn im trying to understand every part of this code idk what an IEnumertor does

I want to try my hand at a really terrible high-level analogy. Bear with me 🐻

IEnumerators are like a little machine with a button and a slot. Each time you push the button, it does some work and spits something out of the slot, then goes dormant until the button is pressed once more. It repeats this until if and when it runs out of things to spit out.

The code in our methods which return an IEnumerator runs up until the point that it encounters a yield return foobar;, at which point it spits out foobar and goes dormant. The next time that the button is pressed it picks up from the next line, and again runs until the next yield return or the end of the method.

When we pass an IEnumerator to StartCoroutine(), we're handing Unity our machine so it can push the button and consume whatever it spits out. And Unity expects our machine to spit out special "yield instructions," through which we tell Unity when we would like the button to next be pressed.

yield return null will tell Unity to execute our IEnumerator again from where it left off in one frame, and the others like yield return new WaitForSeconds(2); are more self-explanatory.

This sort of logic sequence which depends on successive parts running after specific delays can totally be written in other ways, but using IEnumerators as Unity Coroutines is often a much more convenient and succinct way to accomplish it.

summer stump
dense matrix
#

Figures

#

It's more that, iirc, one value isn't tethered to the other

#

Like, deltaTime doesn't look at the Framerate for calculation

#

And similarly Framerate isn't calculated via deltaTime

#

Feel free to correct me tho...

summer stump
#

I think both "look" at a common value, which is the time taken since the last frame

young lava
#

Hi! I just had a question about good practice when it comes to using the more expensive side of operations. I know that calling GetComponent can be bad when located in a method that is called frequently, such as the update method. However, I was wondering how frequently is bad for GetComponent? For example, I have an attack that spawns 5 projectiles and I need to access a script component on each projectile when it is spawned, would this be an acceptable rate?

summer stump
#

public Projectile prefab

Projectile new = Instantiate(pPrefab);

supple garden
#

My transition for character is going well but i changed noting did everything same but my weapon is not transitioning state. I used debug log in script so issue there. Issue is in transitioning.

#

i have even made it from scratch but still its not wprking

summer stump
supple garden
summer stump
supple garden
#

I have used the same values for transitioning of character's state and that works @summer stump

summer stump
#

Ok, and the code?

supple garden
summer stump
#

Ok, and no nullReferenceException?

#

And you are sure the characterAnimator is the correct one?

supple garden
obsidian granite
#

oh in update

#

mbn

#

check to make sure the if statement is being executed, do a print inside of it

#

i'm not sure why it wouldn't be, but always good to check

supple garden
#

btw, i am also using different animator controllers. I tried to add layer but it was duplicating the weapon. so i just made anoter animator controller for it

obsidian granite
supple garden
obsidian granite
supple garden
obsidian granite
summer stump
#

That is why I asked if it is the right animator
If characterAnimator is not the one on the weapon, then of course it will not wkrk

obsidian granite
#
weaponAnimator.SetTrigger("attack");
characterAnimator.SetTrigger("attack");
#

you'll have to get a reference for both animators

#

probably easiest to just make them public fields and assign them in the inspector

#

but do it however you want

supple garden
obsidian granite
supple garden
supple garden
#

just in case you guys know, im not using avatar mask

obsidian granite
obsidian granite
supple garden
obsidian granite
obsidian granite
#

idk much abt animation

supple garden
dim yew
#

is it possible to use a dictionary to enable/disable something? i have a dictionary of spriterenderers and have no idea how to actually use them

silk night
#

and can you show us the code snippet where your dictionary is declared?

dim yew
#

disable all but one

#

sure 1 sec

silk night
#

so i guess you want to enable one selected element and disable all others, something like that? 😄

dim yew
#

yeah exactly

#

unity taking 100000 years to open sorry

silk night
#

And i guess your dictionary is Dictionary<"key", "element to disable">?

dim yew
summer stump
obsidian granite
#

speaking of dictionaries, what's the data structure that the Dictionary class implements? i don't why c# doesn't name its collections based on the data structure that it implements (i.e. a list not being called arraylist).

#

i'm assuming it's a hashmap but

#

idk maybe it's some weird form of map that i've never heard of

wintry quarry
#

And because the data structure isn't the most relevant information for the user

#

HashMap is just a Java class name BTW

obsidian granite
#

been a second since i took data structures

wintry quarry
#

Basically there are many names for what that thing is called

#

Dictionary is one of them

obsidian granite
#

i've heard unordered assosciative array, but that's too verbose for me

wintry quarry
#

Well you'll hear it a lot in C#

obsidian granite
#

i think i've only ever heard it (outside of c# ofc), in Roblox, where their data structure, "tables", have a hashtable and an array implementation at the same time. pretty cool stuff

#

but they call the hashtable implementation a dictionary

dim yew
#

is there a way to serialize a dictionary? or is there a better alternative of some sort?

wintry quarry
wintry quarry
#

Otherwise just serialize a list of key/value pair structs and populate the dictionary at runtime

#

Which btw is exactly what the serializable dictionary does.

dim yew
#

thanks i'll read into this

green ledge
#

ah. That's why, I've mostly been hearing TMap/Map/HashMap/Table/Dictionary.

#

Associative Array is literally just another term on a pool of terms for the same thing.

summer stump
green ledge
#

It's... just one of a million

#

Computer Science has a way to make one thing mean 20 million things because it seems like no one's quite sure what to call an idea.

#

If only IEEE could actually standardize computer science fully.

#

I can think of zero use cases for "Associative Array" when most people are taught Map/HashMap/Dictionary

#

If I were to even walk up to my lecturer with that, they would raise a brow at that term

#

Because it is the most verbose descriptor for something that doesn't need a verbose descriptor.

eternal needle
#

And multiple things all meaning one thing is something that just exists.. everywhere. Even in our english language

green ledge
#

I would hate to envision a world where someone writing the C# standards wrote "AssociativeArray" instead of "Dictionary" as the generic type

ivory bobcat
#

It would be the same as function and method - they are not called voids! You'd simply understand that they are the same (even the ill use of the word "void"), yet called different things. This isn't really a computer science specific issue though and there aren't twenty million different names for any one thing, tbf - a bit exaggerated.

ivory bobcat
eternal needle
#

I could see the statement "one thing means 20 million things" true is if you come from a pure software eng background instead of hands on computer science. From everyone ive asked in my area, most uni's teaching SE here focus on the theory aka drawing circles and squares and acting like you planned a whole architecture. I did CS degree but Ive done a lot of SE courses. There really are a lot of confusing terms because all of them mean nothing (yes i hate SE). In CS here though, you learn terms that actually having meaning because well you're applying them in practice and actually coding something.

green ledge
#

Computer Science is the more mathematics/concept based side

#

SEng & GProg focus on the practical

echo hamlet
#

How do i change the weight on an animation layer like this

#

In code

green ledge
#

I do get the terms and stuff though.

#

I've had to go into Comp Sci a lot independently

#

cause code-beginner would probably be someone who hasn't even gone into that realm really

echo hamlet
#

THx

#

I've already looked at that

#

How do i get the index of the layer

#

I have this

#

mask = LayerMask.NameToLayer("UpperLayer");

#

But it returns -1

eternal needle
eternal needle
echo hamlet
#

Ok

eternal needle
# green ledge cause code-beginner would probably be someone who hasn't even gone into that rea...

thats not really a reason to use non-cs terms, whatever that even means. Im truly not even sure what terms you're talking about. And this isnt "ive never seen a computer before" beginner. This is game dev beginner. If people don't have any background in cs, they often are told to go through c# basics or the learn site. Using different terms to try not confusing someone will just confuse them further when they cant find what you're talking about on google.

topaz mortar
#

Is there a way to count how many of a specific ScriptableObject I have, for example Weapon?
So I can randomly spawn one? Or should I put them in a List or something?

eternal needle
solemn bobcat
topaz mortar
eternal needle
#

🤷‍♂️ depends what you wanna use it for. I dont really see what functionality you could have where you need to find these at runtime

topaz mortar
#

I'll have one "Weapon" prefab, then several Weapon ScriptableObjects, could add new ones or remove some at times
During combat a monster will drop a weapon, which is then randomly chosen from the list of Weapon SO's and the data is put in the prefab

eternal needle
#

yea this is something id do at editor time by storing them somewhere. Also this allows you to customize what weapons can drop if thats a feature you need

topaz mortar
#

so just store them in a list? yeah kinda makes sense

solemn bobcat
eternal needle
#

Like i create a loot table SO, which holds a reference to what can drop. My enemies can take in this loot table asset. Requires more editor setup if the overall goal is just "anything can drop anything" though.

topaz mortar
#

what does your loot table look like? sounds interesting

#

I think I'll just keep it simple with a list for now though

eternal needle
topaz mortar
#

thx 🙂

#

things can seem so complicated when trying to figure it out yourself and then I come here and it turns out to be so simple lol

topaz mortar
#
if (item != null)
{
    var itemDrop = Instantiate(monsterDropPrefab);
    Item itemDropItem = itemDrop.AddComponent<Item>();
    itemDropItem = item;
}```
Does this make sense?
eternal needle
topaz mortar
#

it's because Item can be Weapon, Armor, Scroll, ... (inherited classes)

eternal needle
#

that doesnt really change anything, your code is still only adding an Item component

topaz mortar
#

I changed it to this, at least it works 🙂


var itemDrop = Instantiate(monsterDropPrefab);
Weapon itemDropItem = itemDrop.AddComponent<Weapon>();
itemDropItem.WeaponSO = LootTableWeapons[itemNumber];```
native hill
#

!code

eternal falconBOT
native hill
waxen adder
#

Toying around with rigidbody movement. Since I'm working with physics, I know that FixedUpdate becomes much more important. However, gathering inputs seem like they should still be done during simple update. As a result, I have a basic jumping script to show to see if you guys see any glaring flaws with my idea.
https://pastebin.com/Cv1517ZZ

#

Side note, this only does jumping in game, so that PlayerMovementInput being unused is something I'm already aware of

waxen adder
#

Nice!

tepid summit
willow scroll
tepid summit
tepid summit
willow scroll
tepid summit
#

and my script does have a class

native hill
#

I cnat right click so it’s hard to move around sorry

tepid summit
#

why do you have two cameras inside eachother

native hill
#

I thought it would maybe fix it

#

i don’t remember my thinking it was a while ago

tepid summit
#

ok

tepid summit
willow scroll
tepid summit
tepid summit
willow scroll
tepid summit
#

i need to save a sring to a comonent so i can DDoL the component and keep it between scenes

willow scroll
tepid summit
#

wait

#

oh my

#

i couldve done this.gameOnject this whole time

willow scroll
#

You could've even done gameObject without this this whole time

tepid summit
#

well

#

i could have

#

but wheres the fun in that

#

although

#

do i have to put the DDoL in Awake()

willow scroll
tepid summit
#

i dont need a singleton

#

i already solved it

atomic holly
#

Hi,
I develop my system of inventory so I create a list of all weapons and all charms I will have. But, Unity send me this warning :
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
Item is a ScriptableObject.

The code :

 public List<Item> Weapons = new();
 public List<Item> Charm = new();
modest dust
#

Even if Item was a MonoBehaviour, a List of MonoBehaviours is not a MonoBehaviour itself

#

Make sure the warning isn't an old one and show the entire warning

crude sphinx
#

Why does my sprinting/run code not work?

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

public class PlayerMovement : MonoBehaviour {

    public CharacterController2D controller;
    public Animator animator;

    public float walkSpeed = 40f;
    public float runSpeed = 100f;

    float horizontalMove = 0f;
    private bool jump = false;
    private bool crouch = false;
    private bool run = false;

    void Update () {

        // Jump logic
        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
            animator.SetBool("IsJumping", true);
        }

        // Sprint logic
        if (Input.GetButtonDown("Run"))
        {
            //walkSpeed = runSpeed;
            run = true;
        }
        else if (Input.GetButtonUp("Run"))
        {
            //walkSpeed = oWalkSpeed;
            run = false;
        }

        // Crouch logic
        if (Input.GetButtonDown("Crouch"))
        {
            crouch = true;
        } else if (Input.GetButtonUp("Crouch"))
        {
            crouch = false;
        }

        // Movement calculation
        if (!run)
        {
            horizontalMove = Input.GetAxis("Horizontal") * walkSpeed;
        } else
        {
            horizontalMove = Input.GetAxis("Horizontal") * runSpeed;
        }

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

    }

    public void OnLanding ()
    {
        animator.SetBool("IsJumping", false);
    }

    public void OnCrouching (bool isCrouching)
    {
        animator.SetBool("IsCrouching", isCrouching);
    }

    void FixedUpdate ()
    {
        // Move our character
        controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;
    }
} ```
atomic holly
#

And I think you need to add Time.fixedDeltaTime at the end of horizontalMove like this :

horizontalMove = Input.GetAxis("Horizontal") * walkSpeed * Time.fixedDeltaTime;
#

And why you use a bool to know if you run or not ?

#

You can use the condition of the keypressed directly for Movement calculation

crude sphinx
atomic holly
tepid summit
#

hey for some reason unity thinks this is a scenemanagement.scene, anybody know why

ivory bobcat
#

Also show the error

#

Likely it doesn't think the vector 3 position is a scene..

tepid summit
#
    public GameObject Human, Box, Spike;

    public void HumanButton()
    {
        Human = Instantiate(Human, ItemSpawner.transform.position);
    }``` CS1503    Argument 2: cannot convert from 'UnityEngine.Vector3' to 'UnityEngine.SceneManagement.Scene'
tepid summit
ivory bobcat
#

The method takes three arguments. If you're wanting to use a position as well, it's not optional to leave out rotation.

tepid summit
#

i dont want to specify rotation

#

but ill add one

eternal needle
#

do you also have a method named Instantiate? That error looks suspicious still

ripe shard
tepid summit
#

i did

burnt vapor
tepid summit
#

i dont though

#

anyway i solved it

burnt vapor
#

The only reason why it would give that error is if it knows a signature that takes scene as the first parameter. The docs are clear this isn't possible, so it was your own method

#

That, or a library

timber comet
#

!code

eternal falconBOT
tepid summit
burnt vapor
timber comet
#

Hello, as someone here suggested: i used _rb.velocity = _movementKeys.y * transform.forward + _movementKeys.x * transform.right + _rb.velocity.y * Vector3.up; for moving locally the player. While this works, it has a flow: When i press "S" the player gets launched in the air, until i stop pressing "S" (it doesn't go backwards, it only flies). Any solution for this? Here's the code: https://paste.ofcode.org/34hYuEMRDbyMi6mRpFXk7JW

worthy tundra
#

if i have a coroutine that goes something like this

IEnumerator CoroutineName()
{
     yield return new WaitForSeconds(amount);
     FunctionName();
}

and i call the coroutine while it's waiting to call FunctionName, it will restart the coroutine back from scratch right?

short hazel
#

No, it will schedule a new one

#

FunctionName() will run twice

burnt vapor
#

Right well you clearly have no interest in actually fixing it so nevermind

worthy tundra
flint abyss
#

Guys, just to make sure, C# didnt evolve over last 3 years? Im watching a tutorial and i don't want to know that something doesn't work anymore.

timber comet
#

'Cause of the new input system and stuff, i use Vector2 to take any movement key

worthy tundra
worthy tundra
timber comet
worthy tundra
short hazel
timber comet
worthy tundra
timber comet
#

I cannot just put a float there

short hazel
worthy tundra
timber comet
#

It shouldn't jump at all, but i still need some gravity

timber comet
flint abyss
short hazel
worthy tundra
timber comet
#

if i put zero there, there should be no gravity

slender nymph
worthy tundra
flint abyss
timber comet
worthy tundra