#πŸ’»β”ƒcode-beginner

1 messages Β· Page 279 of 1

polar acorn
#

Show the inspector for pointText

blissful spindle
astral falcon
#

As I thought, and what is the public variable you are trying to drag it to in your script?

polar acorn
blissful spindle
polar acorn
#

No it isn't, that's the shared parent class between both UI and 3D text

#

it works for this

#

TextMeshPro is the world text

#

TextMeshProUGUI is the UI one

#

TMP_Text is both

polar acorn
#

Not the scene

proven mirage
#

hey guys its me again and i have everything working now i just need to check if the walking points are valid whne thyere random so my solution was to create a ray cast and if it touches the cube then its valid because it can reach the point with no obstacles and basically i have this code.But when i hit play the raycats are not hitting its object and idk if its bc i hvae the direction wrong or what.Heres code

void WalkRandomly()
    {
        
        
        TimeBtwnSteps -= Time.deltaTime;
        
        if(TimeBtwnSteps <= 0)
        {
            float RandX = Random.Range(MinWalkValues.x, MaxWalkValues.x);
            float RandZ = Random.Range(MinWalkValues.z, MaxWalkValues.z);
            WalkPoint = new Vector3(transform.position.x + RandX, transform.position.y, transform.position.z + RandZ);
            TimeBtwnSteps = Random.Range(0, 5);
        }

        if(TimeBtwnSteps > 0)
        {
            float XDir = WalkPoint.x - transform.position.x;
            float ZDir = WalkPoint.z - transform.position.z;

           
            if(Physics.Raycast(WalkPoint, WalkPoint - transform.position, out ObjHit,100f, LayerMask.GetMask("Worker")))
            {
                if(ObjHit.collider == this.gameObject)
                {
                    Debug.Log("Valid Spot");
                    transform.position = Vector3.MoveTowards(transform.position, new Vector3(XDir, transform.position.y, ZDir), WalkSpeed * Time.deltaTime);

                }
            }
          
        }```
astral falcon
blissful spindle
proven mirage
#

heres ss they grey points are walk points

astral falcon
polar acorn
blissful spindle
blissful spindle
astral falcon
#

When you drag a scene object (inside the prefab hierarchy) to your prefab and you are not in prefab mode, you need to save the override to your prefab. Or better, just go into the prefab mode and link it there to avoid this πŸ™‚

blissful spindle
proven mirage
#

@astral falcon can u plz take a look at my rpob really fast since your hear and experianced coder like you should be able to determine it in a sonics pace

#

plz?

#

πŸ™‚

blissful spindle
astral falcon
proven mirage
#

i dident ena to sound rude

astral falcon
#

And for your issue, I suggest you look into debug.drawray or line and see where your raycast actually is firing to. Go from there

proven mirage
#

but i can get the right distance see

#

oh mybad

#

you said line

#

thank you

#

we got lines now

#

but how can we make that into a ray cast

#

so we can check if the point is blocked by an obstacle

#

i thoguht my raycast math was correct unless im worng

misty hedge
#

Doing anything to the capsule's or rigidbody's rotation re-introduces jitter. Just having Camera.main.transform.localRotation = Quaternion.Euler(rotX, rotY, 0); reduces jitter, but it doesn't entirely eliminate it. Super weird

proven mirage
#

k i think i got it

#

now we need to multiply it by - number

acoustic sun
#

Is there a way to reset the scene into its defalt view? For some reason, I am unable to move the scene view with my mouse

rocky canyon
#

top right Layout

#

ur in Iso view

rich adder
#

I think that <- symbol means Prospective

#

3 lines same length, would be ortho

wintry quarry
#

yes - they are in "Left" view though

#

I don't recall if that locks the scene camera though, i don't think it does

rocky canyon
#

yeap, just reset the layout

rich adder
#

yeah true maybe its locked

rocky canyon
#

thats what i thought when i seen Left

#

but if that was ur last Iso view.. it sticks around

#

so, not enough of a clue

rich adder
#

iirc if you hold right click you should still be able to rotat it no ?

#

I don't have unity open atm

rocky canyon
#

ya, it goes back to perspective

#

so not sure.. his lock icon isnt locked.. and the 2D button isn't highlighted

#

so maybe a bug?

rich adder
#

time to restart unity πŸ˜›

swift crag
#

i've had situations where middle-mouse dragging doesn't work until I left click in the scene view to focus it

#

but I presume they're left-clicking with the hand tool here.

rocky canyon
#

longer its open the longer it takes to recompile / draw

primal burrow
#

!cs

eternal falconBOT
cobalt schooner
#

why am i getting the "Can't add script component 'movecam' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." error even though my class name and file name are exactly the same?

swift crag
#

well, do you haver any compile errors?

cobalt schooner
#

im not sure, how can i check

swift crag
#

by looking at the console

cobalt schooner
#

looks like it

swift crag
#

well there you go

#

fix those

#

is your code editor highlighting these errors?

#

if not, it needs to be configured correctly

cobalt schooner
#

i think so

#

wait nvm i dont think it is

#

no... it is highlighting them

#

but i dont see anything wrong with them

swift crag
#

share your code.

#

!code

eternal falconBOT
cobalt schooner
wintry quarry
#

Also...

#

You need to pay closer attention when you copy things

#

you are simply copying incorrectly

cobalt schooner
#

hmm alright

languid spire
#

Also remember C# is case sensitive

cobalt schooner
#

yeah i already had problems with that but i got them figured out im pretty sure

languid spire
#

no you didn't

cobalt schooner
#

well the ones that i had at the start

#

these are new errors lol

languid spire
#

update is not the same as Update

cobalt schooner
#

the tutorial that i was following did it with a lowercase u for some reason

languid spire
#

find a better tutorial

cobalt schooner
#

yeah that sound like a good idea

astral falcon
#

I suggest the unity tutorials from learn.unity.com . They are quite good to understand the basics about how unity is working

maiden yarrow
cobalt schooner
#

thanks

languid spire
maiden yarrow
languid spire
maiden yarrow
astral falcon
#

Documentation > any tutorial out there

maiden yarrow
#

should have done that😭

#

thanks

#

idk I never had to read libraries when I did coding

eternal needle
languid spire
astral falcon
#

If you just rely on others peoples knowledge about something instead of the guys invented that something, you just adapt to their faults

maiden yarrow
#

never thought it was something to actually sit down and read

#

thanks a bunch

astral falcon
#

everyone did watch tutorials. I even do it today to get the hang of like a new system introduced, but then still going over to the docs, see waht I can do with it. Test, play around and run into errors to understand the dos and donts.

languid spire
astral falcon
cobalt schooner
# polar acorn Show it

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.

If this tutorial has helped you in any way, I would really appreciate...

β–Ά Play video
maiden yarrow
#

I guess it depends on the book

polar acorn
cobalt schooner
#

playercam

maiden yarrow
astral falcon
#

? What a suggestion πŸ˜„

polar acorn
# cobalt schooner playercam
Number of times it wasn't exactly like the tutorial: 153
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-3-28```
verbal dome
#

I was waiting for that

cobalt schooner
#

im 100% sure he used a small u one time, maybe it was another script or smth

polar acorn
cobalt schooner
#

well then im tripping idk

#

maybe i just thought that it was lowercase since most is lowercase

#

idk

polar acorn
astral falcon
# cobalt schooner idk

Whatever, just pay more attention and do not rely on tutorials about how to write proper code

polar acorn
#

Best to know the syntax yourself so even if you end up as one of the unlucky 5 where the tutorial itself is wrong you know what to look out for

cobalt schooner
#

well idk how to start learning coding since it seems like there is unlimited stuff to learn

modest dust
astral falcon
polar acorn
cobalt schooner
#

alright thank you all for your suggestions and help, i'll go figure stuff out now😁

frigid sequoia
#

If... I want to do like a... stackeable effect? Let's say I want the player to gain X buff after killing an enemy for Y secs and I want it to be able to stack up to Z times. How do I do this? Through Coroutines? I would love to have control of if gaining a new stack does reset the duration for previous stacks or not with a bool if possible

astral falcon
# frigid sequoia If... I want to do like a... stackeable effect? Let's say I want the player to g...

Sounds like you could use a tick system or just seconds to reduce like a counter on every effect. It should not really matter, if you have an effect once or 10x if you just manage them with a constant tick. So you start the effect on tick 0, the next same effect on tick 2, and they all could last for 3 ticks, on tick 3 two would be active and on tick 4, only the second would run cause the first ran out. If you want them to reset any of the same kind, you could try to check for the same effect in your active effect list and reset all of the same kind if you set the "bool" of your effect to do so.

ruby python
#

!code

eternal falconBOT
astral falcon
ruby python
#

Hi all,

Sooooo, more maths issues. I'm trying to get a 'shield' system working, but having a bugger of a time figuring out my coroutine so that the shield effect fades

IEnumerator ShieldFade()
{
    while(currentShieldVisibility > minShieldVisibility)
    {
        currentShieldVisibility -= Time.deltaTime * shieldFadeSpeed;
        playerMaterial.SetFloat("_Shield_Visibility", currentShieldVisibility);
    }
    if(currentShieldVisibility < minShieldVisibility)
    {
        currentShieldVisibility = minShieldVisibility;
    }

    yield return null;
}

Any ideas where I'm going wrong please? (the shield 'coming on' is outside of the coroutine, this is just the 'fade out' part.

astral falcon
polar acorn
ruby python
#

Yeah.

ruby python
faint fulcrum
#

Hi, I am having a problem with Unity's Random, every time I run my game it always produces the same results. Not sure whether I am misunderstanding how to use random. ```

[Range(0f, 1f)]
public float wormChance;
[Range(0f, 1f)]
public float zombieChance;
[Range(0f, 1f)]
public float spiderBeetleChance;
[Range(0f, 1f)]
public float crawlerChance;
[Range(0f, 1f)]
public float spiderChance;


private void Start()
{
    InvokeRepeating(nameof(SpawnEnemy), 1f, spawnRate);
}

private void SpawnEnemy()
{
    GameObject enemyPrefab = enemyPrefabs[Random.Range(0, enemyPrefabs.Length)];
    float random = Random.value;
    if (random < wormChance)
    {
        enemyPrefab = wormPrefab;
        Debug.Log("Worm");
    }
    else if (random < zombieChance)
    {
        enemyPrefab = zombiePrefab;
        Debug.Log("Zombie");
    }
    else if (random < spiderBeetleChance)
    {
        enemyPrefab = spiderBeetlePrefab;
        Debug.Log("SpiderBeetle");
    }
    else if (random < crawlerChance)
    {
        enemyPrefab = crawlerPrefab;
        Debug.Log("Crawler");
    }
    else if (random < crawlerChance)
    {
        enemyPrefab = spiderPrefab;
        Debug.Log("Spider");
    }

    Vector2 position = new Vector2();
    position.x = Random.Range(spawnArea.bounds.min.x, spawnArea.bounds.max.x);
    position.y = Random.Range(spawnArea.bounds.min.y, spawnArea.bounds.max.y);

    Quaternion rotation = Quaternion.identity;

    Instantiate(enemyPrefab, position, rotation);
}

}

eternal falconBOT
faint fulcrum
#
using System.Collections.Generic;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    public float spawnRate;

    public Collider2D spawnArea;

    public GameObject[] enemyPrefabs;

    public GameObject wormPrefab;
    public GameObject zombiePrefab;
    public GameObject spiderBeetlePrefab;
    public GameObject crawlerPrefab;
    public GameObject spiderPrefab;

    [Range(0f, 1f)]
    public float wormChance;
    [Range(0f, 1f)]
    public float zombieChance;
    [Range(0f, 1f)]
    public float spiderBeetleChance;
    [Range(0f, 1f)]
    public float crawlerChance;
    [Range(0f, 1f)]
    public float spiderChance;


    private void Start()
    {
        InvokeRepeating(nameof(SpawnEnemy), 1f, spawnRate);
    }

    private void SpawnEnemy()
    {
        GameObject enemyPrefab = enemyPrefabs[Random.Range(0, enemyPrefabs.Length)];
        float random = Random.value;
        if (random < wormChance)
        {
            enemyPrefab = wormPrefab;
            Debug.Log("Worm");
        }
        else if (random < zombieChance)
        {
            enemyPrefab = zombiePrefab;
            Debug.Log("Zombie");
        }
        else if (random < spiderBeetleChance)
        {
            enemyPrefab = spiderBeetlePrefab;
            Debug.Log("SpiderBeetle");
        }
        else if (random < crawlerChance)
        {
            enemyPrefab = crawlerPrefab;
            Debug.Log("Crawler");
        }
        else if (random < crawlerChance)
        {
            enemyPrefab = spiderPrefab;
            Debug.Log("Spider");
        }

        Vector2 position = new Vector2();
        position.x = Random.Range(spawnArea.bounds.min.x, spawnArea.bounds.max.x);
        position.y = Random.Range(spawnArea.bounds.min.y, spawnArea.bounds.max.y);

        Quaternion rotation = Quaternion.identity;

        Instantiate(enemyPrefab, position, rotation);
    }
}```
polar acorn
faint fulcrum
#

sorry, new to this lol

polar acorn
faint fulcrum
#

both

#

i can provide screenshot

#

it only spawns 2 of the 5 prefabs, and they are always in the same positions

#

the "crawler" always spawns at the top middle, and the "zombie" always spawns on the top right

#

none of the others ever spawn

polar acorn
# faint fulcrum both

Have you tried logging random and seeing if the number you roll ends up any different?

faint fulcrum
#

I think i did

#

but i will try again

#

where should i log it?

polar acorn
#

Right after you roll it

#

See if you get a different number each time

harsh vault
#

Is there a way to sense tiles through tags in unity? Trying to figure out how to do footsteps on 2D side scroller tiles

faint fulcrum
#

same number each time

astral falcon
faint fulcrum
#

0.91 and 0.44

#

they get logged alternately

#

I think 0.91 corresponds to the crawler and 0.44 to the zombie

astral falcon
#

you could try resetting the random.seed to get a new number

polar acorn
#

I wonder if Invoke might be somehow be like, running the code a single time and re-executing it each time, which means the random seeds are the same.

opaque kettle
#

hey, do any of you guys know why my seeker from the a* pathfinding assets sometimes tries to pathfind through obstacles?

polar acorn
#

Generally, Invoke should be avoided for several reasons, and if it futzes with random that's another one

#

Try a coroutine instead

faint fulcrum
#

How should i run it on a regular interval then?

#

ah ok

#

will test now

#

thanks

astral falcon
#

Its called initstate now

polar acorn
#

Start a coroutine that runs SpawnEnemy, then waits for spawnRate seconds, then starts another copy of itself

swift crag
#

Ooh I wonder if this is The Bug

polar acorn
swift crag
#

Is this a URP project by any chance

polar acorn
#

What is The Bugℒ️

faint fulcrum
harsh vault
#

Basically I want the footstep sounds to change when the player is on a different tile sprite. Idk how to implement it though

swift elbow
swift crag
#

Some of URP's post-processing code calls Random.InitState and winds up giving you a completely predictable random state

#

It sounds like the bug has been fixed, though

#

What version of Unity are you using?

polar acorn
faint fulcrum
#

2022.3.18f1

swift crag
#

Check if you have an update for the URP package in your package manager. Should be fine in that unity version.

astral falcon
#

And seems like you were right about the invoke taking the same function when repeating, digiholic. It will not regenerate any random.seed and just take the seed it was started with

faint fulcrum
polar acorn
faint fulcrum
#

Just changed the code to use coroutines and same result

#

still predicatable

polar acorn
astral falcon
#

the random seed usually updates on every millisecond just by design, but if you like temporarily store that function in that invocation, you cant access the "new" seed. Not sure if thtas a bug or a feature πŸ˜„

polar acorn
astral falcon
faint fulcrum
astral falcon
#

ye, show the code

faint fulcrum
# polar acorn What's the coroutine code look like?
{
    StartCoroutine(nameof(SpawnEnemy));
}

private IEnumerator SpawnEnemy()
{
    GameObject enemyPrefab = enemyPrefabs[Random.Range(0, enemyPrefabs.Length)];
    float random = Random.value;
    Debug.Log(random);
    if (random < wormChance)
    {
        enemyPrefab = wormPrefab;
        Debug.Log("Worm");
    }
    else if (random < zombieChance)
    {
        enemyPrefab = zombiePrefab;
        Debug.Log("Zombie");
    }
    else if (random < spiderBeetleChance)
    {
        enemyPrefab = spiderBeetlePrefab;
        Debug.Log("SpiderBeetle");
    }
    else if (random < crawlerChance)
    {
        enemyPrefab = crawlerPrefab;
        Debug.Log("Crawler");
    }
    else if (random < crawlerChance)
    {
        enemyPrefab = spiderPrefab;
        Debug.Log("Spider");
    }

    Vector2 position = new Vector2();
    position.x = Random.Range(spawnArea.bounds.min.x, spawnArea.bounds.max.x);
    position.y = Random.Range(spawnArea.bounds.min.y, spawnArea.bounds.max.y);

    Quaternion rotation = Quaternion.identity;

    Instantiate(enemyPrefab, position, rotation);

    yield return new WaitForSeconds(spawnRate);

    StartCoroutine(nameof(SpawnEnemy));
}```
polar acorn
astral falcon
#

I am not quite sure you are running into the same issue as with invocation here as you start it from within itself

faint fulcrum
swift crag
#

so to make sure: you currently aren't mucking with Random.InitState, correct?

faint fulcrum
#

correct

astral falcon
#

you can try to set that initstate to a new value based on the current time for example

swift crag
#

and you don't happen to be using splines?

#

i also found a bug with a specific spline component a while ago

#

that vanished from the Atlassian bug tracker page so I have no idea what happened to that report

faint fulcrum
#

dont know what a spline is lol]

astral falcon
#

can you try Random.InitState(System.DateTime.Now.Millisecond);

faint fulcrum
#

should this go in the coroutine?

astral falcon
#

yep, just at the start

swift crag
faint fulcrum
#

but it is still mroe predicatable than should be

faint fulcrum
#

It now looks like this

#

some enemies still spawn one the same position

#

and are the same type

#

eg in bottom left

#

two black enemies on same position

swift crag
#

well, since you're seeding with the current time, that will happen if two or more enemies spawn at once

faint fulcrum
#

they dont spawn at once

#

they spawn a second apart

astral falcon
#

do you get the exact same number on those two?

faint fulcrum
#

yes

polar acorn
#

If multiple things start the coroutine at the same time, each "tick" of it will sync up between them

#

Since before, when the seed was fixed, you had two different numbers, I'm pretty sure you have two spawners

faint fulcrum
#

i only have one spawner in the scene

#

and enemies are only spawned one at a time, for each time the coroutine is run

astral falcon
#

I guess milliseconds is not the best to be used here, as every second could have the same millisecond returned if you run the spawnrate at a second span. Whats your spawnrate set to?

#

can you just get rid of milliseconds and use .Now?

faint fulcrum
#

spawnrate is 1

#

good popint

astral falcon
#

thought so.

#

yeah, try to alter the spawnrate and also use .Now. that should get some more randomness in it

faint fulcrum
#

what is syntax for just now

astral falcon
#

just remove .milliseconds

faint fulcrum
#

after getting rid of milliseconds it doesnt like it

astral falcon
#

oh, whats the error?

faint fulcrum
#

Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'System.DateTime' to 'int' Assembly-CSharp C:\Users\Mark\TopDownTest\Assets_Scripts\SpawningScripts\EnemySpawner.cs 38 Active

astral falcon
#

Try System.DateTime.Ticks

faint fulcrum
#

nope

astral falcon
#

Now.Ticks, sorry

#

System.DateTime.Now.Ticks

faint fulcrum
#

Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'long' to 'int' Assembly-CSharp C:\Users\Mark\TopDownTest\Assets_Scripts\SpawningScripts\EnemySpawner.cs 38 Active

faint fulcrum
astral falcon
#

oh its long, right. hm, lets read the docs πŸ˜„

swift crag
#

okay, I see that URP 14.0.9's changelog acknowledges the fix

#

Use local random state for post-processing.

astral falcon
faint fulcrum
#

like how/

astral falcon
#

Random.InitState((int)System.DateTime.Now.Ticks);

faint fulcrum
#

thanks

astral falcon
#

Might fail too, just fiddeling around in discord right now πŸ˜„

short hazel
#

Ticks is probably a huge value (one that surpasses the max value of int) so be aware that this will make it loop back around to negative values, or the cast will blatantly fail, not sure which

faint fulcrum
#

it works now

#

thanks so much guys

harsh vault
#

Yoooo no way I actually figured out how to use a raycast and tags to get it to play on certain sprites

faint fulcrum
#

all the logs are different

astral falcon
short hazel
#

It's way bigger than an int (638472563476759027) at the time I got its value, so yep it loops back to negatives, but doesn't throw a cast exception

#

So you're most likely safe in terms of getting duplicate values on different runs

faint fulcrum
#

ok

#

cheers everyone

swift crag
#

we've bumped into another bug in a unity package or in some other code you're using

hazy crypt
#

hey guys, just a real small thing here, im trying to get the name of the current scene. After some looking, I think im meant to be using Scene.name to get this, but Im getting literally no options for the Scene struct

#

I have declared "Using UnityEngine.SceneManagement" at the top of the script

#

I know yall hate screenshots but it best demonstrates what I mean here

muted wadi
#

is the start position minus the end position divided by 2 the midpoint?

hazy crypt
hazy crypt
astral falcon
swift sedge
muted wadi
#

i see

#

thanks

astral falcon
#

dont subtract it. You just get false results

hazy crypt
#

Thats how i think about it

astral falcon
#

yep, good explanation

swift sedge
#

I would do a thorough read on mathematical vectors

hazy crypt
#

Oh hell yeah, vectors are very sexy once youre invested in game dev

muted wadi
#

nah i know about vectors but im just horrid at maths so whenever i do a calculation and it doesn't work i cry

swift sedge
hazy crypt
#

I use Brilliant, the learning app, quite often

swift sedge
#

think about how the Lerp function was made

#

or bezier curves

hazy crypt
muted wadi
swift sedge
#

and random is just made by a bunch of numbers stuck together

hazy crypt
#

I made my own b spline script once in a agme engine that only had basic calculations

#

One of my proudest moments

swift sedge
#

inverse kinematics are sick

hazy crypt
#

Not relevant to this channel anymore though and I dont wanna be told off

#

fair thougj

tender stag
#

can someone just point me in the right direction?

#

i wanna make my own scroll rect

#

but a really simple one

#

which just uses scrolling

#

no dragging or scrollbars or anything else

polar acorn
#

Why make your own?

astral falcon
#

You can just delete those objects (sliders etc) and they are gone

polar acorn
#

Why reinvent the wheel?

tender stag
#

for my inventory system

#

messes everything up

#

since scroll rect uses the same thing

#

trust me i tried everything

#

overriding the scroll rect OnBeginDrag etc

swift sedge
#

how do you think other games managed to pull it off?

tender stag
#

or didnt use OnDrag interfaces

astral falcon
#

and what will it listen to?

tender stag
#

for inventory system

astral falcon
#

how you know if you drag the rect if not us ing ondrag or similar

tender stag
#

i just wannt use scrolling

#

on the mouse

#

to move content up and down

muted wadi
tender stag
#

so it doesnt go above or beyond its bounds

#

thats it

muted wadi
#

my issue was half the problem, the other half was misunderstanding the bezier

hazy crypt
hazy crypt
astral falcon
hazy crypt
#

Im not sure what youre trying to achieve but that seems like one solution

tender stag
#

too complicated and breaks other things

hazy crypt
#

Thast not so good

tender stag
#

i just wanna make a simple script which moves content up or down

#

depending on scrollSensivity

#

and so it doesnt go above or below where it can

#

we dont have to get into the detail why

#

i tried everything trust

tender stag
astral falcon
#

Well, sounds like you being kinda prejudiced about whats possible and whats not. Just cause you cant figure it out, doesnt mean, its not possible and more robust if you do it right with the builtin components. Can you explain exactly, what the user should be able to do with your scrolling inventory and the items in it?

swift sedge
tender stag
#

all i want is the player to be able to scrolldown this list

#

no dragging

#

no scrollbars

#

not anything excesive

astral falcon
#

Then its just some math you gotta do to get the size of the rect, the anchoredposition in relation to the screen and the overlapping so you know, what your min and max values are where you can lerp to with your mousewheel adding or subtracting

#

you got a mask image, thats your like 100% value. And the underlying content, which is your actual size to compare against. if its 120% for example, you can lerp between -20% on top or 0 to be at default position. kinda like that

tender stag
#

yeah i get what u mean

astral falcon
#

it will still be a pain in the b to do that and make it feel smooth with all that inertia and easing I guess. but ye, that should do the trick

swift sedge
#

would clamping work as well?

#

setting the position to be between min and max

muted wadi
#

is it possible to only use the top half of a Random.insideUnitCircle?

astral falcon
muted wadi
#

i tried something similar and it didn't work

polar acorn
#

If it's in the top half, it'll be unchanged. If it's in the bottom half, it'll mirror it to the top

tender stag
#

now i just need to clamp it

muted wadi
polar acorn
astral falcon
muted wadi
#
{
    startPos = transform.position;
    endPos = master.targetLock.position;
    midPoint = (startPos + endPos) / 2;

    randomDir = Random.insideUnitCircle * 12;
    curvePoint = randomDir += midPoint;
}``` this is what im doing right now, how would i set the y value?
polar acorn
#

Set the y component's value to the absolute value of the y component

swift sedge
muted wadi
#

oh

polar acorn
muted wadi
#

so i would abs randomDir after it gets random?

polar acorn
#

The y component

#

Unless you also want it to only be in the front half as well

astral falcon
muted wadi
#

wait im lost

#

how do I abs the y component

astral falcon
#

Mathf.Abs(y)

muted wadi
#

oh right

frank forge
#

How would you move a game object without explicitly changing its transform value? I need the object to still collide with colliders but it just passes right through them if I change the transform

polar acorn
muted wadi
#

ok i think i got it, thanks guys

astral falcon
tender stag
#

i have no idea how to clamp it tho

#

like the anchorpoints etc

astral falcon
#

anchoredPosition needs to be clamped to fit the mask overlap of your content. test around with values, you will get there

muted wadi
astral falcon
swift crag
#

It's that you're leaving the physics system in the dark.

fair steeple
#

Hey, I'm learning the new input system. I'm trying to get an "OnKeyUp" thing going on butI can't sue the event "cancelled". It does print "OnDownwards" but not "DownwardsUp"

    private void OnEnable()
    {
        playerInput.actions["Downwards"].performed += OnDownwards;
    }

    private void OnDisable()
    {
        playerInput.actions["Downwards"].performed -= OnDownwards;
    }
    public void OnDownwards(InputAction.CallbackContext context)
    {
        print("OnDownwards");
        if (context.canceled)
        {
            print("DownwardsUP");
        }
    }
swift crag
#
rigidbody.position = whatever;

This tells the rigidbody that it needs to move to that position in the next physics update

swift crag
swift crag
#

you only subscribed to performed

fair steeple
#

I see

#

I'm new to events

#

Thanks

fair steeple
swift crag
#

note that setting rigidbody.position is teleporting it -- it doesn't try to handle collisions between the original position and the new position

#

rigidbody.MovePosition(whatever) will ask it to move to the destination as if it just had a very high velocity

swift elbow
swift crag
#

Also, if you have Interpolate enabled on the rigidbody, setting the transform's position might not even work at all

#

Interpolate causes it to set the transform's position every frame

#

It doesn't expect you to have messed with the position, so it just ignores whatever the current position is

muted wadi
astral falcon
#

Something to be discussed elsewhere I guess πŸ˜„

muted wadi
#

yeah, interesting topic though

tender stag
#

i clamped the max up position

#

how can i clamp the lower one now?

#

calculate the maxScrollDownPosition i mean

astral falcon
#

You can only scroll up from the beginning, right? Like in terms of the rect, it can only go up when it sits on default

tender stag
#

what do you mean

astral falcon
#

If you look at your rect of your content. you can only move it up from start, right? youcant move it down cause there is no content. so if you scroll it up by lets say 100px, you can also scroll it back down 100px, not further. Not sure you get what I mean

tender stag
#

i put this targetPosition.y = Mathf.Max(targetPosition.y, maxScrollUpPosition);

#

just to show u

summer stump
tender stag
#

i cant have the orange going higher than red

astral falcon
#

Than you have to check the difference of your mask height and your content height

tender stag
#

so literally just that

muted wadi
tender stag
#

viewport is this

summer stump
swift elbow
#

@summer stump did you block me? 😭 what did i do 😭

tender stag
#

lmao

summer stump
muted wadi
#

there's nothing below planck?

summer stump
#

According to our current understanding of quantum physics

swift crag
#

something something 11-dimensional manifolds

summer stump
swift crag
#

i am a reformed string theory fan

#

anyway, scripting:

swift elbow
muted wadi
tender stag
#

@swift crag sorry to budge in, but u know ui pretty well, how do i get the position of the red dot?

#

its using strech

swift crag
#

I'm not that great at calculating that stuff via script. I should really figure it out already

#

RectTransform.rect is the shape of the RectTransform

astral falcon
swift crag
#

(in its own local space)

swift crag
#

rect transforms do not have minimum or preferred sized

astral falcon
swift crag
# swift crag (in its own local space)

I suppose you'd want to use Rect.NormalizedToPoint to get the local-space position of the bottom-center of the rect, then use transform.TransformPoint to turn that into a world-space position

#

you'd ask for the point at [0.5, 1]

astral falcon
#

world space position? For what? He just wants to get the local y position and the height to clamp the y position to its height within the viewport rect

swift crag
#

ah, I interpreted "position" as being in world space by default

muted wadi
#

how can i make it so that when the player clicks, a thing happens, but when they hold, a different thing happens? Currently both things are happening even if they click or hold.

astral falcon
muted wadi
muted wadi
# rich adder use a timer

is that really the most efficient way? I was really hoping there was something else i was overlooking

astral falcon
muted wadi
#

input.getkeydown

rich adder
astral falcon
muted wadi
#

is the new input system just that weird sphere with a thunderbolt in it as the icon?

#

because i've seen it before and i've heard how complicated it is

astral falcon
#

Wth? I dont know the icon of it πŸ˜„

#

Well, if you wanna stick to the old one, you might use a timer as navarone said

muted wadi
#

guess i will. I hate using timers so much, they're so messy

astral falcon
#

as well as code is with the old input system πŸ˜„

muted wadi
#

daily struggle

rich adder
muted wadi
#

alright downloading the new input system, it better blow my socks off

muted wadi
acoustic sun
rocky canyon
#

top right corner (Layout) button

acoustic sun
acoustic sun
rocky canyon
#

its not hiding, its as top right as u can go w/o being on the close/maximize buttons

#

click it and go to Reset Layout.. that will reset all the windows

acoustic sun
#

Okay. Thank you so much for the tip

hazy crypt
#

Hey guys, a quick one, do playerPrefs get reset when reloading the scene they were set in?

#

If they dont then I got some bug finding to do lol

short hazel
#

They don't, unless you explicitly do so via code

rocky canyon
#

once u set the value, its there

hazy crypt
#

Damn that complicates things

#

Okay let me show you guys what im doing

polar acorn
#

Not resetting is kind of their entire job

hazy crypt
#
// check and set player PB, change personal best text to reflect new records
        if (PlayerPrefs.GetFloat(levelName + "PB") < finalTimerTime && raceEnd == true)
        {
            PlayerPrefs.SetFloat(levelName + "PB", finalTimerTime);
            personalBestText.text = ("New Personal Best!");
        }
        else
        {
            personalBestText.text = ("Personal Best");
        }
#

Im making an arcade racer

#

I want to store the personal best time between attempts and im reloading the scene for my "quick restart" function as im assuming thats the best way to do it.

#

So im comparing the previous PB to the current run finish time, then updating it ifs lower. thats the intent

short hazel
#

Your PB condition looks backwards, it should save a timer that is lower than the saved one, not the inverse

#

Unless the longer you take, the better it is

hazy crypt
#

No youre correct

#

Ill change it now

#

It was overwriting either way previously though, maybe that wont happen once changed

#

Yeah I just got a 5s time and it got overwritten by a 6s time

#

Ill do some investigating

queen adder
#

begginer here. how can I stop the player from moving when touching something, it rotates forward or backward

#

2d

#

for example I make a coin and when i touch it I can make the player rotate

muted wadi
#

how would i create a circle of positions equal distance from each other along the edge?

#

is there a math function that lets me do that?

eternal needle
#

that math is in degrees, but you will need to use radians for mathf.sin

quartz mural
#

hi im making a pokemon game and all was going well but now my encoutner pokemon oes not work anymore

quartz mural
swift elbow
ember tangle
#

Why do I access a GameObjects layer with gameObject.layer instead of this.layer?

swift elbow
swift elbow
timber tide
#

if it's inside of the same gameobject's script you can just use layer right it's part of GO not obj

#

ah, actually you do need to reference gameobject still

ember tangle
#

I thought that 'this' was used to target an instance of the object

#

but I think I understand what you guys are saying

#

instance of script vs instance of GameObject right?

timber tide
#

this is useful for when you are inside of a method where you declared similar reference names, but 'this' keyword will always point the the current instance's member scope

eternal needle
ember tangle
#

thanks!

queen adder
#

how to send the code

#

properly

ember tangle
swift elbow
eternal falconBOT
muted wadi
#

is it not possible to start a coroutine from getComponent?

rich adder
muted wadi
#

oh yeah that works too

#

but how come coroutines dont start from getComponent?

#

am i doing it wrong?

rich adder
#

Wdym they don’t start form GetComponent

eternal needle
#

GetComponent is a function, to get a component. you can then start a coroutine however you like

muted wadi
#
{
    fb.GetComponent<FireballBehaviour>().HomingAttack(targetLock);
}``` doing this doesn't work for me
rich adder
#

That’s not how you start coroutiens that’s why

muted wadi
#

i get no errors but it also just doesn't work

rich adder
#

Nothing to do with getcomponent

muted wadi
#

how would i start it from getComponent?

#

seems much more convenient

eternal needle
rich adder
#

Because there is no syntax error

eternal needle
#

look at the docs on fb it should be telling you something

queen adder
#
 void Update()
 {
     kretnja();

 }

 public void kretnja()
 {
     if (Input.GetKey(KeyCode.RightArrow) == true)
     {
         igrac.velocity = Vector2.right * speed;
     }

     
     


     if (Input.GetKey(KeyCode.LeftArrow) == true)
     {
         igrac.velocity = Vector2.left * speed;

     }
     


     if (Input.GetKeyDown(KeyCode.UpArrow) == true && Grounded)
     {
         igrac.velocity = Vector2.up * JumpStrength;

     }
rich adder
#

You’re just not calling it with the startcoroutine

muted wadi
slender nymph
rich adder
#

It’s more of a pain starting coroutine from another class

#

Just called the public method that will startCoroutine

muted wadi
rich adder
#

Cause then you also have to pass the MB

#

Yes

queen adder
muted wadi
#

alright i'll just make a method for it

rich adder
#

You need fb.getComponent<FireWhatevrr>().StartCoroutine(fb. getComponent<FireWhatevrr>() .HomingAttack())
or whatever

summer stump
# muted wadi

() is required unless you do it as a string (which you should not)

swift elbow
muted wadi
quartz mural
summer stump
quartz mural
#

one thing i dont understand

#

ive set the game objects

#

to their sprites

#

in the inspector

queen adder
swift elbow
quartz mural
lavish bay
#

hey yall, I'm having an issue with an animator controller where it's advancing through a clip despite not having a criteria to do so. could i get something to check it out?

quartz mural
#

the trainer sprite doesnt come up?

lavish bay
#

here's a short vid of my situation. I have a clip where something holds being hidden, one where it animates to being visible, another where it holds visible, and another where it disappears again. I have the two hold states set to have no exit time and only triggers for leaving the state. However, when I play back, it exits from disappeared anyway

queen adder
#

also one thing, if I jump and hold left or right arrow to move to the side, I start gliding in the air and fall very slowly, how can I change that? I want to make my character be able to move in the air but for a very short time. I just want to limit the horizontal movement while in air. @swift elbow

swift elbow
quartz mural
#

oh fixed it

queen adder
rocky canyon
#

add linear drag to stop it from gliding

#

may want to dampen the velocity towards 0 when not giving inputs

#

not sure.. can also turn up the gravity scale to fall faster

queen adder
#

yes, but the thing is it stops falling as soon as I press right arrow to move right, I mean it falls but very very slowly

rocky canyon
#

should fall the same speed if ur only giving it force in the right direction.. sounds like you might be adding forces elsewhere..

swift crag
#

I'm guessing you're changing the Y velocity when you move from side to side.

#

Notably, if you set your velocity to Vector3.right * moveInput * moveSpeed, you're going to completely lose your Y velocity

#

Each physics update will move you down slightly because gravity accelerates you a tiny bit

stuck palm
#
public IEnumerator StunInPlace(float stunLength, float shake_strength)
    {
        stunlocked = true;
        Vector2 originalPosition = armature.position;
        float elapsedTime = 0.0f;

        while (elapsedTime < stunLength)
        {
            float shakeStrength = Mathf.Lerp(shake_strength, 0f, elapsedTime / 1f);
            Vector2 randomDirection = Random.insideUnitCircle * shakeStrength;
            armature.position = originalPosition + randomDirection;

            elapsedTime += Time.deltaTime;
            yield return null;
        }
        armature.position = Vector2.zero;
        stunlocked = false;
    }

why isnt the armature transform moving?

swift crag
#

is armature animated?

queen adder
#
public class movement : MonoBehaviour

    
    

{
    
    
    
    
    public Rigidbody2D igrac;


    public float speed = 5;
    public float JumpStrength = 5f;
    public bool Grounded = true;
    

    



   

    



    // Start is called before the first frame update


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

    }

    public void kretnja()
    {
        if (Input.GetKey(KeyCode.RightArrow) == true)
        {
            igrac.velocity = Vector2.right * speed;
        }

        
        


        if (Input.GetKey(KeyCode.LeftArrow) == true)
        {
            igrac.velocity = Vector2.left * speed;

        }
        


        if (Input.GetKeyDown(KeyCode.UpArrow) == true && Grounded)
        {
            igrac.velocity = Vector2.up * JumpStrength;

        }
stuck palm
#

armature is the root object of the armature

queen adder
stuck palm
#

@swift crag scratch that it is animated LOL

swift crag
#

that'll do it

stuck palm
#

its got a default position

#

nothing else

swift crag
#

and remember that the presence of any animation state having an animation clip that sets the position will mean the animator always writes to the position

#

even if you've never been to that state yet

stuck palm
swift crag
#

You can also modify the position in LateUpdate.

#

You'd just add to the position every frame the shaking is happening

#

since the animator will be resetting the position every frame

stuck palm
rocky canyon
#

if(stunlocked){shake();}

stuck palm
swift crag
#

there's no convenient way to do that with coroutines

#

I've made my own "coroutines" before

stuck palm
#

so i dont think i'll be breaking anything

swift crag
#

literally just making a list of IEnumerator and calling MoveNext on them all at the right moment

tender stag
stuck palm
#

what is the enumerator class anyway?

tender stag
#

and if i dont gray it out, i cant move the scrollbar or scroll down with the mouse
only one of them works at the same time

swift crag
#

They get turned into a class that stores all of the information needed to remember where you are in the method

#

An IEnumerator represents something you can enumerate over

#

An IEnumerable is something that can give you an IEnumerator

#

(so you can enumerate over it many times)

#

IEnumerator is non-generic, so it just gives you a sequence of objects

#

(that's why you can yield return all kinds of stuff from a coroutine method)

#

IEnumerator<T> is the generic version, which provides a specific kind of object

#

and IEnumerable<T> is something that can give you an IEnumerator<T>

#

List<T> is a very common example of something that is IEnumerable<T>

#
foreach (var what in list) { Debug.Log(what); }
#

you could've also done

#
IEnumerator<int> enumerator = list.GetEnumerator();

while (enumerator.MoveNext()) {
  Debug.Log(enumerator.Current);
}
#

Unity uses IEnumerators to implement coroutines.

tender stag
swift crag
#

You call a method that returns IEnumerator and pass the result to StartCoroutine

swift crag
#

if the current value is something special, like an instance of WaitForSeconds, it can do different things

#

but if you discount that, then coroutines are pretty much just...

List<IEnumerator> coroutines;

void Update() {
  coroutines.RemoveAll(coroutine => !coroutine.MoveNext());
}

public void StartCoroutine(IEnumerator coroutine) {
  if (coroutine.MoveNext())
    coroutines.Add(coroutine);
}
#

(unity immediately calls MoveNext on the enumerator you give it)

stuck palm
#

thats pretty cool

#

thanks for the easily digestible info πŸ˜„

swift crag
#

When you call an IEnumerator method, it does absolutely nothing

#

I used to think it ran until the first yield

#

it does not! but if you pass it to StartCoroutine, then it'll get MoveNext() called on it immediately

tender stag
#

how can i detect if a scrollbar is being held

#

i tried placing an event trigger on the handle with OnPointerDown and OnPointerUp and calling a method which sets a bool either true or false

#

but having an event trigger component on the handle messes with the scrollbar and doesnt allow me to scroll at all

dense mica
#

Howdy folks. I usually develop and debug with MS VS 2022. But since updating to 2022.3 my 2D projects are taking much longer to connect the debugger to, and hitting breakpoints takes 5-10 seconds where everything just freezes. Before I go scorched earth on this computer, does anyone have tips for how to get things working well again?

amber spruce
#

hey so how exactly would i have it so i call a function and i have it return a value so for example i want it when i attack a enemy it will trigger their damage function and if they die it will return a bool saying true that way i can store how many kills the player has

rocky canyon
#
//example code
public bool TakeDamage(int damageAmount)
{
    health -= damageAmount;
    if (health <= 0)
    {
        Die();
        return true;
    }
    return false;
}```
summer stump
rocky canyon
#

ya, not knowing his setup i did bare basics.. id probably have a manager where i pass in the enemy and return his health maybe.. but my enemy scripts usually take care of their own stuff if they die.. they would tell a gamemanager about it instead of my attack knowing bout it

potent nymph
#

I have the following HLSL code for a custom function in shader graph, which works perfectly fine (basically just the sample texture 2D node at the moment)

#ifndef BIOMES
#define BIOMES

void Biomes_float(UnityTexture2D Tex, UnitySamplerState SS, float2 UV, out float4 Out) {
    Out = SAMPLE_TEXTURE2D(Tex, SS, UV);
}

#endif
#

however, UnityTexture2D and UnitySamplerState are not defined types, so my code editor is complaining

#

Cannot resolve type: 'UnityTexture2D'

slender nymph
potent nymph
#

is this not a beginner question?

slender nymph
#

it's a shader question

potent nymph
#

I understand that it's for a shader, but my question is about how to resolve the type error. I'll repost the question regardless

north kiln
#

To be clear, shader programming is different to general coding in Unity, which is why it's not really suited to this channel

torn marlin
#

Does OnTriggerEnter work with character controller?

#

thats why im asking bro @slender nymph

#

I tried it

slender nymph
#

well if you tried it then you should have seen that it does, in fact, work

torn marlin
#

No it does not

slender nymph
#

then you've set something up incorrectly

torn marlin
#

see, my player is controlled charactercontroller, im trying to make a checkpoint system and attached a checkpoint script to the checkpoint object with isTrigger turned

swift elbow
#

does your player have a collider?

torn marlin
#

Yes

slender nymph
#

the CC is a collider

#

and is also what will produce the OnTriggerEnter message

#

what have you actually done to check whether OnTriggerEnter is being called

torn marlin
#

Debug.Log()

#

In the collision condition

slender nymph
#

show your code

torn marlin
#

ok

slender nymph
#

and both objects involved in the trigger overlap

torn marlin
#

!code ```public class Checkpoint : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Player")
{
Debug.Log("Checkpoint set");
GameManager.Instance.SetCheckpoint(transform.position);
}
}
}

slender nymph
#

well for starters, you aren't actually confirming that OnTriggerEnter is being called with that log. and you should also be using the CompareTag method rather than string equality to check tags

torn marlin
#

nvm it works now

#

thanks

quick kelp
#

hey been messing around with fmod and im trying to play a sound for every time the player selects a slot
realized after implementing a debug.log that the sound constantly plays cause its in the void update
ive tried a few thing but at this point i need some advice https://hastebin.com/share/ipugagejom.csharp

slender nymph
#

instead of manually checking for a selected object, you could instead implement the ISelectHandler interface on some component on those selectable objects and just play the sound when an object is selected

wintry quarry
wintry quarry
#

That's the better way ^
A simple if statement here would have worked too:

if (selectedGameObject != null && _selected != selectedGameObject) {
  _selected = selectedGameObject;
  // play sound here
}
hidden geyser
#

Hi, I'm currently trying to create an inventory system, but I'm encountering a problem. When I try to initialise the inventory, the boxes for the items instantiate but their parent is not defined because "the definition of the parent of a transformation that resides in a Prefab Asset is disabled to avoid data corruption" and I don't understand why I can't define this parent.

ItemUi (boxes for the items) might being instantiate in the panel "Items"

Can someone help me ? I added some pictures and a few code snippets

slender nymph
#

if your contentPanel variable in UI_InventoryPage refers to a prefab that won't work, you need to assign a scene object as the parent

hidden geyser
#

Content panel is part of a prefab. I already tried to assign a empty gameObject as the parent but it didn't work, I had the same console error

slender nymph
#

Content panel is part of a prefab.
well there's the issue. it must be an object in the scene. is it perhaps part of the same object that your UI_InventoryPage component is part of?

wintry quarry
#

Also, Instantiate allows the parent to be passed in directly to the Instantiate call. Setting the parent during instantiation is the best way for UI elements to get proper layout.

brave wharf
#

Hey guys! Im trying to have my enemies respawn if the player has to respawn as well and having a bit of trouble. Heres a few screenshots of the code im using. Any help will be much appreciated!

wintry quarry
#

!code

eternal falconBOT
hidden geyser
hidden geyser
slender nymph
#

okay and does the InventoryController object have a reference to that UI_InventoryPage prefab, or does it reference the one in the scene? if the former, that's the problem

wintry quarry
wintry quarry
#

You are calling InitializeInventoryUi on your prefab reference

#

you need to actually instantiate the prefab, then call InitializeInventoryUI on the instance

#

alternatively, if InventoryController is supposed to reference the copy already in the scene, it needs to actually refernece that copy, not the prefab itself

brave wharf
#

Sorry about that! Well i have it so when the player dies, the game fades to black and the player respawns at a checkpoint. However any enemies that were defeated before the death stay defeated, and im trying to find a way to have them respawn as well. Ive tried giving them the player tag and creating a new enemy tag to get them to respawn but to no avail.

wintry quarry
hidden geyser
brave wharf
wintry quarry
brave wharf
#

Oh okay! And then how would i make them respawn? Thats where ive been having a bit of a problem

wintry quarry
#

that depends on what "respawn" means for you

#

presumably just set them active and set their positions back to their spawn positions

#

basically - reset everything that needs to be reset.

brave wharf
#

Oh gotcha. Ill give that a try along with the list. Thanks!

unborn hound
#

Hey yall, I'm working on a movement system for my first VR game in unity. It's physics based for a number of reasons, and I need to use the AddForce method on the player rigidbody to get the movement I want.
So far I've got pretty much everything settled until I add more features, but there's this one problem that's been bugging me.
When the player is on the ground, a high velocity naturally slows due to friction, but in the air its velocity is almost unchanging. I want players to have a small amount of control in the air to help them land where they want, but I also don't want them to speed up their horizontal movement too much while falling. The code I ended up with to try and solve this would theoretically allow the player to use the joystick on their controller to increase or slow their movement if below a certain speed, and only slow their movement, but not increase it if above that speed.
Of course, I wouldn't be here if it worked so I'd appreciate some advice on what I need to change to allow it to work correctly.

{
    Body.AddForce(newForce, ForceMode.Acceleration);
}```
CurrentSpeed and XZSpeed are Vector2's, and XZSpeed is the x and z components of the newForce Vector3
twilit pilot
wintry quarry
#

You need to account for direction

twilit pilot
#

how so?

wintry quarry
#

full force should be allowed if it would slow the player down

#

as per the question

twilit pilot
#

yeah, it would fall within the clamp if so

wintry quarry
#

Basically you will need to use vector projections

#

You can't do 3.

#

if you do 3. then external forces can't accelerate you past the max velocity either

#

though I guess it's not clear if that's a requirement or not.

unborn hound
#

yes the max velocity isn't a hard limit

#

it's a limit to the player increasing it further

wintry quarry
#

yeah. I actually have an asset in progress to do exactly this, it's not quite ready yet though.

unborn hound
#

i had a method previously that did that but it would slow the player down if you attempted to move forward past the max velocity which isn't ideal

wintry quarry
#

the math is actually quite annoying

unborn hound
#

dang, i thought itd be simpler lol

#

can anyone explain why (CurrentSpeed + XZSpeed).magnitude < CurrentSpeed.magnitude
doesn't work though?

#

im fairly new to vector math stuff lol

wintry quarry
#

well it's unclear what those things are

twilit pilot
unborn hound
wintry quarry
#

well for one, simply adding XZSpeed is not the same as Body.AddForce(newForce, ForceMode.Acceleration);

#

it would have to be + XZSpeed * Time.fixedDeltaTime

#

they would be equivalent if you use ForceMode.VelocityChange

unborn hound
#

wait that makes so much sense, it would only be equivalent if i used foremode velocity change

#

yeah

#

well let me test that rq deynai's method didn't work tho i prob did it wrong

#

yeah that worked perfectly actually, i cant increase my forward velocity past a certain point but can slow down midair

#

thanks for the help yall

warped sorrel
#
        transform.position.x += 5;

why is this not allowed

wintry quarry
#

so modifying the x on the copy would do nothing

#

rather than do nothing and make you frustrated, it gives you an error

#

You can do transform.position += Vector3.right * 5; for the same effect

#

or transform.position += new Vector3(5, 0, 0);

warped sorrel
#

if it returns a copy, how does that mutate anything?

wintry quarry
#

this is what position looks like in Transform:

public Vector3 position {
  get {
    return _internalPosition;
  }
  set {
    _internalPosition = value;
  }
}```
#

transform.position += is calling the SETTER.

#

transfrom.position.x is calling the GETTER

rare basin
wintry quarry
#

it's C#

rare basin
#

not what i said

#

can't unity override it, as many things?

wintry quarry
#

no

#

Unity uses C# largely unmodified

#

it can't change the rules of the C# language

rare basin
#

i see

wintry quarry
#

What they can do is stuff like they did recently with Rigidbody2D

rare basin
#

can you make some extension methods though?

#

to easily modify just the x for example?

#

transform.position.SetX(5)?

wintry quarry
#

so you can do for example myRigidbody2D.velocityX += 5;

warped sorrel
wintry quarry
slender nymph
wintry quarry
#

I use something like that in my code often

warped sorrel
#

are they just trying to force some opinion about how to do OOP on me by making x only gettable and not settable

wintry quarry
#

they would have to make transform.positionX as a property

rare basin
rare basin
#

can't they make the same for transform.positionX?

wintry quarry
wintry quarry
rare basin
#

alright i get it now

wintry quarry
rare basin
#

so basically when modifying the velocityX, the setter of that property is changing the actual velocity vector?

warped sorrel
#

just an annoying conceptual hurdle for my students. transform.position.x += 5 would be significantly easier for them to understand.

twilit pilot
wintry quarry
rare basin
#

i see

#

interesting stuff

#

thank you!

rare basin
#

especially the GetRandom() is used very often by me

#

instead of doing the Random.Range(0, arrayLength)

twilit pilot
fossil tree
#

hi how can i make a raycast for instanciate a object at the end of the raycast i want the ray as made by the position of my mouse

exotic hazel
#

guys i just dont usestand how i fix this error

#

This is the code

slender nymph
#

which is line 117 of CraftingSystem.cs

exotic hazel
slender nymph
#

then AxeReq1 is null

exotic hazel
#

so nothing is assigned on axereq1?

slender nymph
#

correct

exotic hazel
slender nymph
#

Text is not the same as a TMP_Text component

exotic hazel
#

that text is completely different

slender nymph
#

then show that object and the Text component on it

exotic hazel
#

oh it has textmeshpro

#

theres also a couple more problems im facing like earlier if i pressed C my inventory was opening but now nothin happens is it cus of this error? that my inventory is no longer opening

slender nymph
#

exceptions will stop the execution of the method they happen in so anything later than your error would not have executed

#

also you should consider using a better way to get a reference to those TMP_Text objects instead of chaining transform.Find calls

exotic hazel
#

i hope it works now

#

cus im getting like 4 problems i hope its cus of this

slender nymph
#

make sure you are also addressing your errors starting with the earliest in the console and not just the latest. typically the earlier ones are the cause of the later ones

exotic hazel
#

im still facing 1 problem but i can fix it ik why it is caused

rare basin
#

and dont use find("") please

#

this is terrible code architecture

oblique sandal
#

Hey guys, been stuck on this for too long... Doing my first unity project for a uni assignment and I can't figure out why my ball is constantly spinning in the z axis when it makes a collision, not sure if im missing something?

It has a regular sphere collider, default rigidbody, and a character controller. I have a camera following it with cinemachine but isn't related as bug still persists when disabled fully

This is the script for movement + the small part I have added for collisions which will be used for jumping, im completely lost? anyone have any idea what could be causing it?

https://gyazo.com/cfb96530fc20e1634d0038cbe8709568

unborn moon
#

!code

eternal falconBOT
oblique sandal
#

void Update()
{
    Movement();
    //Jumping();
}


//double jump prevention
private void OnCollisionEnter(Collision collision)
{
    Debug.Log("Collision!");
    Debug.Log(collision.gameObject.name);
    if (collision.gameObject.tag == "Ground")
    {
        isOnGround = true;
        Debug.Log("isonground true");
    }
}

void Movement()
{
    float Horizontal = Input.GetAxis("Horizontal");
    float Vertical = Input.GetAxis("Vertical");
    Vector3 movementDirection = new Vector3(Horizontal, 0.0f, Vertical);
    float magnitude = movementDirection.magnitude;
    movementDirection = Quaternion.AngleAxis(cameraTransform.rotation.eulerAngles.y, Vector3.up) * movementDirection; //movement adjustment based on camera
    movementDirection.Normalize(); //diagonal control - stops diagnonal being way faster
    controller.SimpleMove(speed * movementDirection * magnitude); //character controller movement


}

pine umbra
pine umbra
frigid sequoia
eternal needle
# pine umbra why is it terrible?

It's slow, it's fragile because it relies on you setting the name correctly in inspector and in script, and then relies on you never changing the names. One accidental change to 1 string or you accidentally name something the same as the object you're trying to find and the game breaks

oblique sandal
subtle sage
#

Anyone can help me with this? I can play the game with the Unity "Play Button" but I can't build it

oblique sandal
teal viper
teal viper
# subtle sage but why

Because you don't want your users to download a whole editor to play the game🀨

subtle sage
#

and how do I fix it

teal viper
#

Don't use editor API in the build.

#

If it's only needed for editing time, wrap it in a preprocessor define.

subtle sage
#

how do I remove editor api in the build?

teal viper
subtle sage
#

"wrap it in a preprocessor define."
Im new to this and I don't know what that means

frigid sequoia
oblique sandal
teal viper
#

Surely you understand at least something. It's mostly English.

subtle sage
teal viper
#

So you know how to read errors?

subtle sage
# teal viper So you know how to read errors?

I see this "Assets\LogicScript.cs(5,19): error CS0234: The type or namespace name 'SceneManagement' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)"

#

pobably I can't

cobalt schooner
#

im getting this error "Assets\Scripts\InputManager.cs(23,15): error CS1061: 'PlayerMotor' does not contain a definition for 'ProcessMove' and no accessible extension method 'ProcessMove' accepting a first argument of type 'PlayerMotor' could be found (are you missing a using directive or an assembly reference?)
" and idk whats wrong i have been searching for like 30 min now. Here's the scripts

teal viper
subtle sage
#

idk

teal viper
subtle sage
#

Logic Script

#

line 5 char 19?

teal viper
#

Good. The numbers following it are line number and character number in the file.

subtle sage
#

line five: using UnityEditor.SceneManagement;

teal viper
#

Yes. Does it say anything about editor?

subtle sage
#

ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

#

but how do I remove it without braking the code?

teal viper
#

There's no way to use editor API in the build. It's like asking "how do I break laws of physics"?
The answer is don't break them in the first place.

vast vessel
#

Any shorter way to write this ?
n==2 || n==7 || n==x

teal viper
#

Whatever you're doing there, you probably don't need the editor API there.

teal viper
teal viper
# subtle sage

EditorSceneManager. How did you come to using it in the first place?πŸ˜…

subtle sage
#

SceneManager didnt exist

teal viper
#

I'm sure there's no single tutorial that suggests using it.

teal viper
#

But you decided to use a namespace that you shouldn't use instead.

subtle sage
#

so how do I replace / fix it?

vast vessel
teal viper
subtle sage
#

πŸ”΄ Get bonus content by supporting Game Maker’s Toolkit - https://gamemakerstoolkit.com/support/ πŸ”΄

Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then gi...

β–Ά Play video
vast vessel
teal viper
subtle sage
#

Wait

#

ok

#

I have it

fiery plume
#

Is there a way to detect spikes in a music track? like if DB >= 90 ??

teal viper
#

Not unless you use some low level API I think.

exotic hazel
#

When i clitched this button. I got this error.idk how i fix it tho ik what it means.

languid spire
exotic hazel
#

wait the button is null?

languid spire
#

yes, read the code it cannot be anything else

exotic hazel
#

oh ok let me check

#

this is why i should have never used find to get the button

#

its so hard to find the error

languid spire
#

indeed also why you should try to understand every line of code you write and not use copy/paste for code you do not

exotic hazel
#

i never copy paste code even if im provided the code i first watch the whole video and then try to write it again myself

#

i cant copu it either if i want to cus the game they are making in the video and the game im making are similar but not the same

#

i did find the problem

#

i gave the wrong path while using find

honest haven
#

what does this mean

languid spire
burnt vapor
burnt vapor
# honest haven what does this mean

You added code that caused a stack overflow, and this usually means recursive code that never ended in the same frame, or you simply put too much work in the current frame. Share what you added that caused this.

cobalt schooner
#

im getting this error "Assets\Scripts\InputManager.cs(23,15): error CS1061: 'PlayerMotor' does not contain a definition for 'ProcessMove' and no accessible extension method 'ProcessMove' accepting a first argument of type 'PlayerMotor' could be found (are you missing a using directive or an assembly reference?)
" and idk whats wrong i have been searching for like 30 min now. Here's the scriptsv

exotic hazel
#

im still getting the same error.The axe blueprint isnt supposed to be none

eternal falconBOT
exotic hazel
#

i think i got it

cobalt schooner
exotic hazel
#

if this works i dont know any reason why it wasnt working before but

languid spire
cobalt schooner
exotic hazel
#

it still isnt working

#

lemme try logging

tropic marten
#

is someone able to guide me on how to use the Player Input Manager correctly?
I can spawn my player prefab correctly when 2 controllers are attached, but want to make sure these are correctly identified as Player 1 and Player 2 to be able to use this reference for the scoring later on

#

irgnore me, worked it out πŸ™‚

final kestrel
#

Can I subscribe as many methods I want to a single event? In the same class?

#

I mean player class subscribes 3 of its methods to an event

summer stump
#

3 is nothing, yes you can

final kestrel
#

all right thanks a lot.

late bobcat
polar acorn
late bobcat
polar acorn
late bobcat
#

it's weird, objectpooler looks fine too tbh

#

idk what's causing that, now i'm getting a nullreferenceException after i restarted unity

static bay
idle maple
#

I'm not sure what chat would be appropriate for this but I'm getting this error and I have no idea what could be causing it, I already tried deleting literaly every object in my scene and it still shows up

#

does anyone know what could be causing this?

wintry quarry
#

as for the rest - looking at the full stack trace may shed some light

late bobcat
idle maple
timid hinge
#

I made a game that consists of randomly generating dungeons through corridors, having a playerroom (room where the player spawns) and fightpitroom (room where there are enemies to defeat) and I would like to add something to the game so that the playerroom room, the items do not change location, how can i do that?

wintry quarry
timid hinge
#

i create a procedural dungeon generator

wintry quarry
timid hinge
wintry quarry
#

Are you asking how to generate the same dungeon multiple times?

timid hinge
#

no, im asking how to dont change the place of the itens on the playerroom

static bay
#

Actually, never mind.

late bobcat
wintry quarry
late bobcat
#

as far as i know

timid hinge
#

to be exacly equal when i generate the rooms

static bay
#

Mb.

late bobcat
#

yeye ik but that's just me wanting to understand every line of code

timid hinge
late bobcat
#

πŸ˜„

#

dw about it

timid hinge
#

this is the playerroom that have the player object and the prefab placer that have the prefab to the itens spawned on the dungeon

wintry quarry
# timid hinge

I don't really know what this screenshot is supposed to tell me. I don't know how your game works. All I can say if you want the player room in the same place is, write your code to put it in the same place.

As for items I have no idea how items work in your game

timid hinge
#

but where can i change that code do put in the same place ?

modest sluice
timid hinge
#

the playerroom code its a part of a system responsible for generating rooms in a game environment, placing items and enemies within those rooms, and spawning a player at the center of each generated room.
and the prefab placer provides functionality to place items and enemies within the game environment, handling instantiation both during gameplay and in the Unity editor environment.

queen adder
#

hi im new to unity and i am whenever i upload a decent photo for my 2d game it looks horrendus ingame, i have disabled the filters and messed around with import settings and cant figure out why? other games dont have this issue so there has to be a solution but i cant find it

late bobcat
#

@queen adder share a screenshot of what's happening

queen adder
#

heres the photo side by side, the ingame is the best i could get it to look after 1 hour of tweaking random settings i have no idea what do lol

#

both same image just one is lower quality

late bobcat
#

can you take a screen of the settings?

queen adder
#

import?

late bobcat
#

ye

queen adder
#

yes no problem

late bobcat
#

that's not pixel art, you can try trilinear or bilinear i think.

#

on the filter move if you haven't already tried

queen adder
#

yeah unfortunately this does not do much to help, i think its something to do with aliasing idk tho

late bobcat
#

have you tried with different images?