#💻┃code-beginner

1 messages · Page 68 of 1

rich adder
#

but thats getting complex i suppose

#

too many abstractions

modest dust
#

Damn, one schools teaches fun stuff like Unity, another one teaches using prehistoric systems and office

#

I guess I'm somewhere in the middle

formal escarp
#

anyways, brb

rich adder
#

im talking 2008

modest dust
#

Makes sense

formal escarp
#

i have a question and i need you guys to be brutally honest

rich adder
#

thats my forte

formal escarp
#

Is it wrong that sometimes, when im desperate i ask .ai for help or to explain me things?

#

(code speaking)

swift crag
#

I do not think it's a good idea.

rich adder
#

agreed

swift crag
#

You'll get plausible looking answers

rich adder
#

it can do more harm than good without you knowing it because of this ^

swift crag
#

but this doesn't mean you'll get valid answers

#

people with experience can notice this, but you're asking because you don't have experience!

rich adder
#

It can give you correct info , the problem is you have to tell when it is and when its not

timber tide
#

it's good for general c# questions but asking it to write you a script of game logic is not

formal escarp
timber tide
#

(it's more trained on some documentations than others and it doesn't seem to be for unity)

rich adder
#

no you should back up what you found out by simple internet search

modest dust
rich adder
#

and see if it matches what you read on AI

timber tide
#

My experience for using it with unity is it grabbing the first stackoverflow post and posting that answer

autumn tusk
#

is there a builtin function for flipping sprites vertically?

rich adder
#

rip 😦

wintry quarry
autumn tusk
rich adder
formal escarp
#

You made it sound like the web was dead 💀

rich adder
#

nah i was jk, because before AI everyone knew you go to StackOverflow 😛

#

the name itself gives it away what its for

hexed terrace
#

A beginner won't know what those three words together are ;p

rich adder
#

thast true xD 😭

autumn tusk
rich adder
#

if you get a Stack Overflow in unity You done fdup heavvy somehow 😆

autumn tusk
#

my sprite is a rigidbody2d

#

actually i should change it to a sprite

autumn tusk
#

dont need it colliding

buoyant knot
#

sprite and rigidbody2D are two totally different things

rich adder
#

I hate flipping in 2D because the pivot is still wrong direction

formal escarp
#

StackOverFlow, i think i have heard of it before but i dont know that that is.

rich adder
#

I just rotate the object 180 on Y

#

since unity is 3D

#

this way my transform.right is always correct

buoyant knot
#

flipping in 2D is very easy. But I usually change my scale, and not .flipX

hexed terrace
rich adder
hexed terrace
#

right, yeah

#

it'd come "towards" the screen as it rotates, if it's not an instant rotation

rich adder
#

yeah it would look all skewed lol

remote path
#

scale.x *-1

rich adder
#

its usually when I strictly want the 2D physics/light engine

#

otherwise i just use 3D objects with sprite renderer

#

navmesh is less of pain to deal with

remote path
#

unity gives free a* for 2d pathfinding. Not sure if they removed it

#

So you dont need navmesh

rich adder
remote path
#

gimme a sec

ancient igloo
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SeedHolder : MonoBehaviour
{
    public int seed;
    public int xPos;
    public int zPos;
    public List<GameObject> Rooms;
    public GameObject Logic;
    public GameObject newRoom;
    private bool isTriggered = false;

    private void Start()
    {
        Logic = GameObject.Find("Logic");
        Logic.GetComponent<RoomHolder>().Rooms.Add(this.gameObject);
    }

    private void OnTriggerEnter(Collider other)
    {
        //Load Room X + 1 & X - 1, & Z + 1 & Z - 1
        //Unload Rooms where X > X + 1, X < X - 1 & Z > Z + 1 & Z > Z - 1
        if (other.CompareTag("Player") && !isTriggered)
        {
            foreach (GameObject Room in Rooms)
            {
                SeedHolder seedHolder = Room.GetComponent<SeedHolder>();
                if (seedHolder.xPos - xPos > 1 || seedHolder.xPos - xPos > - 1 || 
                    seedHolder.zPos - zPos > 1 || seedHolder.xPos - zPos > - 1 )
                {
                    Destroy(this.gameObject);
                }
            }

            if (Rooms.Count < 10)
            {
                if (xPos - 1 >= 0)
                {
                    GenerateRoom(xPos - 50, zPos);
                }
                if (zPos - 1 >= 0)
                {
                    GenerateRoom(xPos, zPos- 50);
                }
                if (xPos + 1 <= 9)
                {
                    GenerateRoom(xPos + 50, zPos);
                }
                if (zPos + 1 <= 9)
                {
                    GenerateRoom(xPos, zPos + 50);
                }
            }
            isTriggered = true;
        }
        
    }

    private void GenerateRoom(int xPos, int zPos)
    {
        Vector3 rotation = new Vector3(xPos, 0, zPos);
        Instantiate(newRoom, rotation, Quaternion.identity);
    }

    private void Destroy()
    {
        Logic.GetComponent<RoomHolder>().Rooms.Remove(this.gameObject);
    }
}```
rich adder
#

navmesh is A* anyway

autumn tusk
#

ok hold up

eternal falconBOT
ancient igloo
#

Yep

#

For sure

rich adder
#

I mean a link would be preferred..

ancient igloo
#

Link to the code?

rich adder
#

yus

ancient igloo
#

I suppose I could put on git, Ill try

rich adder
swift crag
#

er, wrong reply

swift crag
ancient igloo
#

I saw

rich adder
#

so why git lol you got like 5 quick options

ancient igloo
#

like that?

rich adder
#

yea

ancient igloo
#

Just hadnt used before

#

And I have used Git

swift crag
#

you mean GitHub?

ancient igloo
#

Ye

rich adder
#

whats the question again?

ancient igloo
#

And actual Git

#

I shared the clip

swift crag
#

presumably you're talking about making a Gist on GitHub

wintry quarry
ancient igloo
#

It spawns infinite rooms

#

and crashed

swift crag
#

I suppose you could commit your work, push it to a website that hosts your git repo, and then send us a link

wintry quarry
swift crag
#

ooooor you could use a pastebin

#

which would take ten seconds

ancient igloo
#

I did

swift crag
#

oml i missed the link

ancient igloo
#

I feel like yall really giving me heck when I immediatly did the thing you asked XD

swift crag
#

my bad

autumn tusk
# autumn tusk ok hold up

so im making a 2d topdown shooter and im wondering what method of doing this would be best

im rendering the player body and player hands as two seperate objects, both of which are rigidbody2ds.

the player hands arent gonna have collision, is it worth using a dynamic sprite instead?

swift crag
#

dies internally

wintry quarry
#

there's no reason for the hands to be a Rigidbody from that description

rich adder
wintry quarry
#

not sure what "dynamic sprite" means

ancient igloo
#

Infinite spawn issue

autumn tusk
swift crag
autumn tusk
rich adder
#

oh weird, I never noticed that

wintry quarry
# autumn tusk

Rigidbodies are for physics.
Sprites are for rendering.

These are two completely unrelated concerns.

gloomy timber
#

I cannot understand and solve this error.

wintry quarry
#

TerrainManager.TerrainGeneratedHandler terrainGeneratedEvent = TerrainManager.TerrainGenerated; this line of code is nonsense

#

you can't assign an event to a delegate variable

#

as the error is saying

#

what are you trying to do here

gloomy timber
#

I tried the invoke, I tried all the usual ways

wintry quarry
#

Do you know what event means?

gloomy timber
#

I'm starting a ritual

swift crag
#

throwing random stuff at the wall won't fix your problem

wintry quarry
#

It means the delegate can ONLY be invoked from the class that owns it

#

you are trying to invoke the event from a different class

#

it doesn't work that way

#

either:

  • get rid of the event keyword
  • make a public function on TerrainManager that invokes the event and call that instead of trying to invoke the delegate directly
swift crag
#

I often do something like this:

public event System.Action Florp;
public void DoFlorp() { Florp?.Invoke(); }
gloomy timber
#

I'm posting in the beginner, don't blame me 😅

#

thanks for the improving

pastel vector
#

Hi,
I have a wierd error that I havent come across before.
I have set up a prefab and a runtimeIntilizeOnLoad on a static class so that all my necessery objects are loaded no matter what scene I use. This is all working as inteded.
However when I load a scene for a second time it seems like these cant find in the scene.
I have a simple funtion

GameObject.Find("playerParent").transform)

that is beeing called when

(SceneManager.GetActiveScene().isLoaded)

This works the first time the scene is loaded but not the second.
I have never had this problem before and therefore im thinking that the fact that I use the runtimeInilize somehow is to blame

somber wren
#

do you have any idea why this raycast doesnt detecte the ground ?

rich adder
pastel vector
#

I should also say that i can find the "playerParent" in the inspector but I still get a null refference error

somber wren
pulsar lodge
#

https://gdl.space/omewafaxov.cs https://hatebin.com/hskwioauto Could anyone help me figure out why my stat calculations are not working in my Character Class? It is only pulling the stats from the base class and not performing any calculations based on the vigor, agility, wisdom, strength, dex, and int. Thanks

somber wren
#

it work on my scene just with a plane, but not in this more detailed scene

rich adder
#

so you can see where it is

somber wren
#

did you read my code ? 😭

rich adder
#

oh the whiteline is the ray

#

i see

somber wren
#

yus

rich adder
#

do you have colliders ?

#

mesh collider

somber wren
#

yes, floors are all mesh colliders

rich adder
somber wren
#

oh, it actually detects it

supple pumice
#

guys I am starting game development right now
I followed a tutorial to make this movement script but when I try it on unity it has a visible input lag... is it normal?

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

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;

    private bool isMoving;

    private Vector2 input;
    
    private void Update()
    {
        if (!isMoving)
        {
            input.x = Input.GetAxisRaw("Horizontal");
            input.y = Input.GetAxisRaw("Vertical");

            if (input != Vector2.zero)
            {
                var targetPos = transform.position;
                targetPos.x += input.x;
                targetPos.y += input.y;

                StartCoroutine(Move(targetPos));
            }
        }
    }

    IEnumerator Move(Vector3 targetPos)
    {
        isMoving = true;
        while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
            yield return null;
        }
        transform.position = targetPos;

        isMoving = false;
    }
}```

p.s. feel free to ping me after answering
valid umbra
#

hi i have a problem. i am making multiplayer game using netcode for gameobjects. i want to share server with developers, so they can test the game. how can i let they connect to server?

keen dew
modern escarp
supple pumice
keen dew
#

Anything is possible but that's going to be a bit more difficult

rich adder
#

the NGO server is active

supple pumice
modern escarp
swift crag
onyx blaze
#

Okay \o

timber tide
pulsar lodge
timber tide
#
    public Character(CharacterBase cBase)
    {
        Base = cBase;
        //this.Level = level;
        currentHP= MaxHealth;
        currentMana= MaxMana;

        //Generate spells
        Spells = new List<Spell>();
        foreach (var spell in this.Base.LearnableSpells)
        {
            if (spell.Level <= this.Level) 
            {
                Spells.Add(new Spell(spell.Base));
            }
        }

    }

Have you debugged your values here, and that currentHP is being set to new values?

#

rather, your desired values

pulsar lodge
#

about to do that, sorry working on this inbetween projects at work lol

timber tide
#

The code looks fine honestly

pulsar lodge
#

currentHP and Maxhp are not being updated

#

samew ith mana

summer stump
pulsar lodge
solemn fractal
#

hey guys. I already managed to change the instance created color, but I am not being able to do the same with the text, any ideas?

eternal falconBOT
timber tide
pulsar lodge
timber tide
#

Yeah, you dont set your other stats after adding your scriptableobject in your constructor

#

either read directly from the SO, or set the variables in your character class as the SO base values

summer stump
solemn fractal
solemn fractal
summer stump
solemn fractal
solemn fractal
summer stump
solemn fractal
#

I am all day just to create a simple critical damage thing.. my neurons are already burned out

timber tide
rich adder
summer stump
#

Ah, text is the text COMPONENT property on OverheadDamage
So you need to do over.text.text
Poor naming, which caused confusion

timber tide
#

yeah keep those variables, but set them from the SO in the constructor

pulsar lodge
timber tide
#

You're right, if you level up and have more vigor you want those variables

#

so, technically your calc methods will look like this:

    public int MaxHealth
    {
        get { return Mathf.FloorToInt(Base.HP + ((Base.vigor + vigor) * 5)); }
    }```
#

maybe name your non-base variables like extraVigor,

solemn fractal
#

thank you a lot

timber tide
#

yee

pulsar lodge
summer stump
solemn fractal
solemn fractal
swift crag
#

won't that still give you a compile error?

#

oh nvm

#

/ and * have higher precedence

#

I was imagining it was going to try to divide a string by 2 :p

pulsar lodge
#

@timber tide Do you think it would be wise to make current values for each of my stats and then set them to = that stat, like i did with Health and Mana,

timber tide
#

depends how you want to do it

#

you can read once the SO and set values from it, or make your variables add extra values like I did above

buoyant knot
#

is that an SO?

timber tide
#

it cuts down on a step if you always read from the SO though when you deserialize everything

buoyant knot
#

it would need to be separated into a separate non-SO class

timber tide
#

it's a plain data class

pulsar lodge
#

Sorry im still pretty new, what is SO

timber tide
#

scriptable object

buoyant knot
#

scriptable object

pulsar lodge
#

ah

buoyant knot
#

is maxHP like a constant? or is it a system where it changes like in a JRPG

pulsar lodge
#

variable, not constant

#

exactly what you said

#

supposed to be a JRPG-like game.

buoyant knot
#

then i would do it like how you have, except make those properties have private set

sullen flare
#

help I dont know why my procedurally generated rooms are so small now

buoyant knot
#

you don’t want random classes being able to modify these externally willy-nikly

pulsar lodge
#

Well, i would want a class to be able to modify it when i get a level up i would think

#

but i could be thinking about this wrong

buoyant knot
#

yes.

#

with methods

#

not direct access

timber tide
#

property fields are kinda methods in a sense

buoyant knot
#

object oriented programming is inherently dangerous, so you want to really restrict access to changing things as much as possible

timber tide
#

just need to expand the logic out on them instead

swift crag
#

I also happen to be designing an RPG-y stats system right now

#

You need to draw a line between the data that changes and the data that doesn't

#

Suppose a Fighter has a base strength of 10, and also gains 2 strength per level up

buoyant knot
#

whenever you change currentHP, that would need to be coupled to checking death etc… There should be a public method for changing currentHP that handles any logic for changing chrrent HP

swift crag
#

Suppose you then update your game so that the Fighter has a base strength of 15 and gains 1 per level up

#

If you just stored the strength stat directly, your old save games would now be bogus

#

you'd have the wrong numbers

buoyant knot
#

in pokemon, you’d need to not just change HP, but change the color of an HP bar, start/stop playing near death music, change pokemon’s animation from being hurt etc

#

you don’t want external classes to just straight-ass modify currentHP

swift crag
#

not because an evil hacker will change the HP

pulsar lodge
#

so all of these should be private?

swift crag
buoyant knot
#

public int myInt {get; private set;}

swift crag
#

yeah, public getter + private setter is very useful

buoyant knot
#

thenever you allow public set, you better know wtf you are doing, because that shit can go south real fast

timber tide
#
private float currentHealth;
public float CurrentHealth
{
    get { return currentHealth; }
    set
    {
        if (value > maxHealth)
        {
            currentHealth = maxHealth;
        }
        else
        {
            currentHealth = value;
        }
    }
}```
Like something like this instead of methods is fine too.
#

I do like just making methods though

buoyant knot
#

i would make it private, and make public void ChangeCurrentHP(

timber tide
#

either way, it's exposed one way or another

#

unless you bind some delegates if you wanted

buoyant knot
#

not totally exposed. we’re separating misc crap that needs to happen a bit more

#

and if you just call currentHP = 5; that doesn’t really convey that you have more going on under the hood

swift crag
buoyant knot
#

yeah

swift crag
#

You can still have methods that directly adjust your health

#

But you want to use the right tool for the right job.

buoyant knot
#

I would also make public event Action OnHealthChanged;

#

so other things can know if something just changed

rich adder
#

this, but I typically pass the amount too

timber tide
#

delegates probably the best way if you really don't want it to be touched

pulsar lodge
#

yeah i havent really gotten all the way to that part yet, just getting my initial values set right now

timber tide
#

and set through a constructor

rich adder
#

incase they need to know for some reason

pulsar lodge
#

and values that can influnces those initial values

rich adder
#

Action<int> OnHealthChanged
or w.e

buoyant knot
#

you need to really protect it

#

i can’t stress enough how much you want to restrict that value’s exposure

timber tide
#

I wouldn't worry too much until you're set on the logic and scope

swift crag
buoyant knot
#

i have made a generic of this if you want, I think

pulsar lodge
#

sure, i would love to see it to compare

timber tide
#

Like, if you've been using unity you're forced into a dependency injection pattern anyway, which already kinda screws with these methods

#

you don't always have the privilege of using a constructor, so that removes a lot of variables you'd otherwise set as readonly.

buoyant knot
#

this does allow the set to be fully public

#

in using it, you would: public ReactiveValue<bool> myBoolean { get; private set; } = new();

#

this fully exposes the Set for anyone, but also calls the event for anything listening to go off

#

in your case, you would want something similar to this, but it would be inside of the definition of the class where you are using it

#

example (with private set):

eternal needle
stuck palm
#

how do you deal with multiple controller inputs, and how do you link an input to a player actor?

buoyant knot
#

@pulsar lodge understand?

timber tide
swift crag
#

i wouldn't say that's "depednency injection"

#

or that it forces you to use it

#

but then again, DI is literally just passing arguments to something

buoyant knot
#

dependency injection is a shitty name tbh

timber tide
#

well, it sets you up for DI which is actually convienent because pooling gameobjects is ideal

pulsar lodge
# buoyant knot <@124330927659810817> understand?

i think i do lol. Sorry i am such a noob. I've dont have a ton of experience yet and Unity feels like a whole new world to me, can be a little overwhelming to take it all in at once. School has not prepared me for this haha, most of my stuff i've done has been 1-2 class projects.

autumn timber
#

Isnt there a better way to make an animation playing from an animator to stop beside using animator.speed ?

buoyant knot
#

you might want to look into godot while you’re very new

pulsar lodge
#

unfortunately this is for a class, otherwise i probably would lol

eternal needle
solemn fractal
pulsar lodge
#

I really appreciate all the help @buoyant knot @timber tide @swift crag

swift crag
#

because you give AddTwo the numbers instead of making it make it up its own numbers

rich adder
swift crag
#

I've found it very hard to nail down any more meaningful of a definition

timber tide
eternal needle
buoyant knot
#

dependency injection is when you have A=>B, and then you change it to A=>C<=B

#

=> is depends on

rich adder
#

real DI when you do it in console apps xD

swift crag
buoyant knot
#

most dependency injection is using a base class or interface

rich adder
#

maui flashbacks

swift crag
#

the classic example of DI I always see is turning this:

public class Foo {
  public void Bar() {
    Logger logger = new ConsoleLogger();
    logger.Log("Hi");
  }
}

into this:

public class Foo {
  Logger logger;

  public void GiveLogger(Logger logger) {
    this.logger = logger;
  }

  public void Bar() {
    logger.Log("Hi");
  }
}
#

therefore DI means "give something an X instead of having it figure out its own X"

eternal needle
magic pagoda
#

so I have these "arena wall" sort of things that disappear when there are no enemies left in it, but I dont really have a way of ignoring the player in this.. any suggestions?

swift crag
#

DI is when you give something values

buoyant knot
rich adder
eternal needle
# swift crag DI is when you give something values

In unity that's probably a fair description, although I'd still argue the int example isnt DI since the script is just being used as a calculator. It is not using the "injected" values at all, doesnt even store them

#

True DI is overkill for unity imo

swift crag
wintry quarry
# magic pagoda so I have these "arena wall" sort of things that disappear when there are no ene...

OnTriggerStay is not the right thing to use here.
Use OnTriggerEnter/Exit, or a direct physics query, and keep a collection of the enemies so you know how many there are.

HashSet<Collider2D> enemies = new();

void OnTriggerEnter2D(Collider2D other) {
  if (other.CompareTag("Enemy")) {
    enemies.Add(other);
    Debug.Log($"New enemy count is {enemies.Count}");

    if (enemies.Count == 1) {
      Debug.Log("No longer empty!");
    }
  }
}

void OnTriggerExit2D(Collider2D other) {
    if (enemies.Remove(other)) {
      Debug.Log($"New enemy count is {enemies.Count}");

      if (enemies.Count == 0) {
        Debug.Log("Empty!");
      }
    }
}```
magic pagoda
swift crag
#

It is deliberately silly

#

But that's my point

rich adder
#

microsoft's di

  public static IServiceCollection AddSingleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(this IServiceCollection services)
            where TService : class
        {
            ThrowHelper.ThrowIfNull(services);

            return services.AddSingleton(typeof(TService));
        }```
😵‍💫
magic pagoda
swift crag
#

I've just never really been convinced that DI is some specific pattern or design philosophy

#

maybe this is just a matter of semantics

#

and sometimes I look at the Zenject README and my brain explodes

#

(oh my GOD it's so long)

swift crag
timber tide
#

Anyway, my example of bringing up DI was just to show that you can be stingy with access modifiers since inheriting from monos does not allow you to set otherwise private data in the constructor. You can of course set it through the inspector if it's serializable, but otherwise use plain data objects if we don't want these variables to be accessable.

swift crag
#

the spawner should tell the wall about every enemy it spawns

swift crag
#

when the spawner is done spawning enemies, it should tell the wall that it's done

#

then, when every enemy has been destroyed, the wall can disappear

magic pagoda
#

Im.. confused what-

buoyant knot
#

can we just agree public fields are bad?

eternal needle
magic pagoda
#

its- its never done unless the player destroys it-

swift crag
#

just correct me if I've made an incorrect assumption

swift crag
#

Explain to me how your game works.

magic pagoda
#

and I dont want the walls to disappear if there are enemies inside still

magic pagoda
summer stump
#

"its- its" "wha-" reads fairly dramatic
Just to explain
But yeah, hard to tell it text

magic pagoda
#

its not imo, sorry-

#

yeah theres no voice tone in text, misunderstandings happen ichishrug

swift crag
#

it sounds like how i'd write a character breathlessly stammering in confusion :p

#

anyway. explain to me how you want the game to work.

solemn fractal
#

hey guys how can I have access here to change the text? I already have access in my class to this component, but I am not being able to change the text.

magic pagoda
solemn fractal
summer stump
rich adder
solemn fractal
#

I just want to change this text

swift crag
#

'cos the field is named text

summer stump
#

Ok yeah, you're trying to get Text, but that is the legacy component. You need TMP_Text

swift crag
#

I do that a lot

solemn fractal
rich adder
#

why is bullet even caring about text

summer stump
rich adder
solid verge
#

how to reverse a game object's velocity

rich adder
solemn fractal
solemn fractal
solid verge
swift crag
#

- negates the value

#

-1 * -1 == 1

rich adder
# solemn fractal will try

its not like a copy and paste code, I was just suggesting the name would be probably more implicit what it is

swift crag
#

so whatever over is has a field called text

#

I have no idea what that code looks like

solemn fractal
#

over is just the instantiate object

swift crag
#

show us the code that defines whatever this over object is

solemn fractal
#

i managed to change the color of it

#

but not the text

solemn fractal
solid verge
#

how do i make a float be reversed

#

just

#

like one code

#

one line of code

swift crag
#

the - operator negates something

solid verge
#

so just speed-; then?

swift crag
#

no, the unary minus operator is a prefix

#

int x = -3;

#

e.g.

#

x = -x; would flip the sign of x

swift crag
#

I need to see OverHeadDamage

solid verge
#

the hell

summer stump
pulsar lodge
#

!code

eternal falconBOT
swift crag
solemn fractal
solid verge
#

all of this just a simple ping pong game

gaunt ice
#

i have said that you should use comparetag instead of ==...

solid verge
#

and i can't make the ball move

summer stump
solid verge
#
Rigidbody2D rb;
public float Speed = -1f;

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

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

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.name == "Player")
    {
        Speed = -Speed;
    }
}```
#

i tought it was the simplest i've ever done

#

didn't finish

summer stump
polar acorn
solid verge
#

yes i didn't finish yet

#

cause idk what the hell to do

#

tried ussing add force

#

it flew out

#

miles away

verbal dome
#

What do you want to do

solid verge
#

make a ball bounce off at the reversed value off of a player

#

but i can't even get it to moe

verbal dome
#

Start with the movement yeah

#

How should it move?

#

Is it one way or can it move up and down?

solid verge
#

ok

summer stump
solid verge
#

i got it to move and bounce off

#

just one question

#

how do they make it move the y axis once it hits a certain place

#

i wonder

#

or is it too difficult for me

summer stump
solid verge
#

you know the game ping pong?

verbal dome
#

Pong?

solid verge
#

the ball does not go horizontally just like that

solemn fractal
verbal dome
#

Or table tennis ping pong

#

Well i guess its the same

solid verge
#

no table tennis

#

just pong

summer stump
verbal dome
#

Vector3.Reflect is often used for bounces

swift crag
#

by default, the field will not contain anything

verbal dome
#

Or just use the built in physics and manually keep the velocity at a certain speed (magnitude)

solid verge
verbal dome
#

If you move via transform then you need to do manual collision checks

#

With CricleCast or something

solemn fractal
verbal dome
swift crag
#

I don't really understand what's going on here. Are you assigning meshProText when the OverHeadDamage component starts?

#

meshProColor will just be a color

#

and a color is a struct: it's just a value

#

if you do meshProColor = meshProText.color;, that just copies the current color into the variable

#

changing meshProColor will do nothing to the text color

#

if you need to change the text color, change the text color

summer stump
# solemn fractal

Why do you have that as [HideInInspector]?
You really don't want that
You need to assign that field, and it'll be easy via the inspector

solemn fractal
solemn fractal
swift crag
#

you still haven't shown me OverHeadDamage's code

summer stump
swift crag
#

I'm very confused.

solemn fractal
#

got it . thank you

rare rain
#

is there a way to give the argument to the OnClick() with the serialized field of the script on the same object?

wintry quarry
#

hook this up to the button ^

rare rain
#

i meant on the editor level

wintry quarry
#

sure:

public void OnButtonPress() {
  levelManager.OnSendInput(speedMultiplier);
}```
rare rain
#

im a bit confused where exactly should i put this code?

wintry quarry
#

on the Play Button script I suppose.

buoyant knot
#
        ForceGroundDisconnect = Jumping | WallJumping | Dashing | Swimming}```
That last pattern only makes sense for enum flags, right?
short hazel
#

Yes. Though with flags, the enum values that are not combined should have their values be powers of two

buoyant knot
#

just out of curiosity, is there a way to do this witout flags?

safe root
#

I'm trying to make points on a map but my CollectPoints ain't collecting points and I'm not sure why.

namespace TowerDefense
{
    public class Path : MonoBehaviour
    {
      
      [SerializeField] private List<Vector3> points = new List<Vector3>();

      void Start()
      {
        CollectPoints();
      }

      private void CollectPoints()
      {
        points = new List<Vector3>();
        Grids grid = FindObjectOfType<Grids>();

        for (int i = 0; i < transform.childCount; i++)
        {
            GameObject child = transform.GetChild(i).gameObject;
            Vector3 point = child.transform.position;

            points.Add(point);
            grid.Add(Grids.WorldToGrid(point), child);
            child.SetActive(false);
        }
      }
    
    }
}
buoyant knot
#

!code

eternal falconBOT
buoyant knot
#

to basically define (in the enum definition) that "these states are all in one category for comparison purposes"

swift crag
#

If you want to be able to use bitwise operators to combine things, then each value must have a disjoint set of bits

buoyant knot
#

or are flags just the way to go, here?

swift crag
#

or else they'll overlap and it won't make any sense

#

note that System.Flags just indicates that you intend to use the enum that way

swift crag
#

you still need to assign numbers to each value

wintry quarry
#

Grids is the one with the error - on line 31

solemn fractal
safe root
# wintry quarry Wrong script entirely

Oh whoops

namespace TowerDefense
{
    public class Grids : MonoBehaviour
    {
        private Dictionary<Vector3Int, GameObject> gameObjects = new Dictionary<Vector3Int, GameObject>();

        public bool Add(Vector3Int tileCoordinates, GameObject newgameObjects)
        {
            if (gameObjects.ContainsKey(tileCoordinates)) return false;

            gameObjects.Add(tileCoordinates, newgameObjects);
            return true;
        }
        
        public void Remove(Vector3Int tileCoordinates)
        {
            if (!gameObjects.ContainsKey(tileCoordinates)) return;

            Destroy(gameObjects[tileCoordinates]);
            gameObjects.Remove(tileCoordinates);
        }

        public static Vector3Int WorldToGrid(Vector3 worldPosition)
        {
            Grid grid = FindObjectOfType<Grid>();

            Vector3Int gridPosition = grid.WorldToCell(worldPosition);

            return gridPosition;

        }

        public static Vector3 GridToWorld(Vector3Int gridPosition)
        {
            Grid grid = FindObjectOfType<Grid>();

            Vector3 worldPosition = grid.GetCellCenterWorld(gridPosition);

            return worldPosition;
        }
    }
}
solid verge
#
float x = Random.Range(0, 2)== 0 ? -1 : 1;```
short hazel
solid verge
#

and why do they declare the random range from 0 to 2

gaunt ice
#

since max is exclusive

wintry quarry
gaunt ice
#

that means it wont return 2

buoyant knot
#

sounds good. flags they will be, then

gaunt ice
#

only 1 or 0 will be returned

wintry quarry
solid verge
#

what if it is 2

safe root
solid verge
#

oh

#

it would use 1

summer stump
short hazel
#

Random.Range(a, b) will return a number between a and b - 1

safe root
wintry quarry
#

very confusing naming you've got going on

#

also FindObjectOfType is really slow and using it constantly for things you're going to call a lot like GridToWorld is probably a bad idea

#

but you can optimize later I suppsoe

safe root
marsh sandal
safe root
silent valley
#

Hi, I'm trying to make it so if my pause menu is open, i cannot open the shop. and vise versa

gaunt ice
#

then just check if the another panel is opened

solemn fractal
#

!code

eternal falconBOT
solemn fractal
#

And here I am again with reference problems hahaha. One day I will learn. So here is the code https://paste.ofcode.org/cqfCEJJ6PfC592mUctMfCG and the prob is for the boss works perfect. But for the enemy it doesnt. I am assigning on the inspector the enemy prefab. Surely that is not correct as it is not working, and findo bject I cant as there are too many on the screen. What would be a fix for that? The prob here is that the enemy is not taking the damage so he wont die

wintry quarry
#

that's the whole point of it

#

if (other.CompareTag("BossOne")){ < You now know that other is the Boss

#

thre's no reason to be using some externally defined reference

crisp token
#

I don't get why I have to create the same structure within the initialization of that structure here

solemn fractal
wintry quarry
crisp token
#

oh nvm I just misread that

#

thanks

sour hound
#

i have an issue where my particle system shoots "blood particles" to the side instead of straight upwards when my enemy gameObject is destroyed, and i have no clue how to fix this

solemn fractal
sterile radish
#

what is a simple definition of static and what are some examples of when you would make something static?

rich adder
#

How unholy would you say this is?

var cr = Screen.currentResolution;
       currentIndexRes = Array.FindIndex(resolutions, r => r.height == cr.height && r.width == cr.width);```
short hazel
short hazel
#

It could have been beautiful, just a single Array.IndexOf(resolutions, Screen.currentResolution), but no...

rich adder
#

yeah one of those instances they just said "fkit gud enough as is"

#

oh yeah and I need 1 more refresh rate..

#

should I make a custom struct? so ugly
Array.FindIndex(resolutions, r => r.height == cr.height && r.width == cr.width && r.refreshRate == cr.refreshRate

short hazel
#

Or an extension method

rich adder
#

or make an extention method

#

ah ye

crisp token
#

does this initialize my queue with 64 false values?

final kestrel
#

https://hatebin.com/tizwaqqbqf Hey. Its me again... My script works just fine with the pointer enter and exit. I also set the selected button in the start just so I can navigate with the arrow keys. What I cannnot achieve is that I could not figure out how to start the glow coroutine i have on the key navigation.

crisp token
#

yeah, i'm just not sure if the queue will contain 64 null slots or 64 false slots like this

short hazel
cosmic dagger
short hazel
#

Each resize, it has to create a new array and copy the items over, which is a potentially expensive operation

crisp token
short hazel
#

For loop

cosmic dagger
#

create a loop . . .

crisp token
#

ok, yeah I mean that's how I would've done it just looking to make sure there was no better one line practice, trying to get more proficient ya know

#

thanks

final kestrel
short hazel
solemn fractal
#

!code

eternal falconBOT
short hazel
timber tide
# sterile radish what is a simple definition of static and what are some examples of when you wou...

Google is your friend, but for unity a good example would be making some utility classes which you can freely access without a direct reference.

ex.

public static class VectorUtility
{
    public static Vector3 CreateDirection(Vector3 startPoint, Vector3 endPoint)
    {
        Vector3 direction = endPoint- startPoint;
        direction.Normalize();

        return direction;
    }
}

public class Character : MonoBehaviour
{
  private void MoveCharacter(Vector3 startPoint, Vector3 endPoint)
  {
      //Calling this class directly by the name/type to access its methods because it's static
      Vector3 direction = VectorUtility.CreateDirection(startPoint, endPoint);
  }
}```
solemn fractal
#

Help with OnTrigger method, not being able to make work for the minions

silent valley
#

How can i get the timebetweenwaves to start once the last enemy has been killed?

fluid marten
#

Does anybody know how to make a ball movement system for VR so whenever you kick it it actually acts like a ball?

rich adder
#

stay in one channel

fluid marten
final kestrel
timber tide
final kestrel
#

Like using the arrow keys

timber tide
#

Ah, ok so yeah IPointer is mouse specific

#

or pointer specific I guess since you can get it to work with some other devices

final kestrel
#

Yes. It works fine but I just cannot make my buttons have the glow effect when im navigating with the arrow keys. I tried OnSelected method but it does not work.

#

this script is attached to my text if that matters.

sterile radish
autumn tusk
#

im trying to make this gun sprite rotate to follow the cursor but it only flips on the x axis instead of rotating

final kestrel
autumn tusk
#

this is the code

#

it was working as normal until i started getting syntax errors and now its flipping on the x axis instead of following the cursor

final kestrel
#

Hmm I did not really get what focused does. What does paused mean?

timber tide
#

And if you have multiples then you'd have a list that contains references to each of these buttons/text

#

so what your goal is to iterate over the list using the input

sick monolith
#

Does anybody know why this script is not working, I am kinda knew to this and came from UE5 wher blueprints dominate so Idk why this isnt working. Anyhow, I added this script to my player controller

eternal falconBOT
sick monolith
#

!code ```void StartDash()
{
Debug.Log("Dash started");
Vector3 mousePosition = Input.mousePosition;
Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
Vector3 dashDirection = (worldMousePosition - transform.position).normalized;

playerRigidbody.AddForce(dashDirection * dashForce, ForceMode2D.Impulse);
Invoke("DeceleratePlayer", decelerationTime);
Debug.Log("Applying force");
Debug.Log(worldMousePosition);

}```

eternal falconBOT
rich adder
#

lol your meant to read the bot msg

sterile radish
# autumn tusk this is the code

attach a rigidbody to the gun and make it kinematic and freeze the rotation on the z
then replace tf.rotation = Quaternion.AngleAxis(angle, Vector3.up); with rb.rotation = angle;
hope this helps!

sick monolith
final kestrel
rich adder
#

screenshot console window in playmode

timber tide
rich adder
sick monolith
rich adder
sick monolith
#

@rich adder

autumn tusk
#

cannot implicitly convert float to quaternion

summer stump
final kestrel
#

I can see i navigate with the arrow keys in the event manager though. Is it not what you mean?

autumn tusk
timber tide
#

there is already some ordering on the scene, but you need to grab that information and put it into a script for you to use.

rich adder
autumn tusk
#

it was working a while back but it was very impractical

final kestrel
autumn tusk
#

i might just tear down the last 45 minutes and just redo the mouse movement script from the ground up

sick monolith
timber tide
rich adder
#

wanted to see the inspector

sick monolith
#

Ok

timber tide
# final kestrel

Yeah, so you can see that you do have some ordering, but you need some script that knows that ExitButton is element 0, Settings is element 1, ect. Just so you can apply the navigational logic.

sick monolith
summer stump
rich adder
sick monolith
final kestrel
#

So i can trigger the glow?

timber tide
#

You need to know the ordering of the elements so when you press arrow key down it goes from element 0 to element 1

rich adder
#

you're missing that

#

can you screenshot your Debug print when you get them printed ? but screenshot the whole Consle window

final kestrel
#

It says so at the bottom of event system

sick monolith
#

Just a secound

sick monolith
autumn tusk
sick monolith
#

Debug events Are in that screeenshot

autumn tusk
#

only thing im wondering now

#

how do i import a variable from another script

#

i know you set the variable to public but what then

nimble blaze
#

so hello i have a very annoying thing in my game im trying to make my character fall slower like a type of glide to float to a area but i still cant figure it out i tried a tutorial but that just screw me more basically just starting the game my

timber tide
rich adder
#

your linear drag is above 0 on rigidbody2D

#

that might be cause

final kestrel
sick monolith
rich adder
sick monolith
olive lintel
#

hey guys I have a quick, somewhat obscure question that I hope someone would be able to answer. I'm currently making a keybind manager script for my game, HOWEVER! writing a reference for each individual key was kinda annoying, so I decided to write a script that takes a string I write beforehand and add it to the list of "key references" (which is a struct I made just to reference keys see which one is being pressed etc), and I noticed that the keycodes appear in Visual Studio with an integer beside them, implying to me atleast that there exists somewhere in the editor, an array with ALL of the keycodes (image included where I noticed this)

it really is fine if nobody knows because what I have now works fine, but is there a way to access keycodes using an integer for the keys index in this array? it would help me a lot. thanks for your time if you dont know anyways guys

final kestrel
sick monolith
timber tide
final kestrel
#

No

rich adder
#

does this one work? I assume it does since you got it from github

autumn tusk
#

ok when i removed some recurring movement code my player hands stopped moving with my player body

sick monolith
#

I sent the whole player controller

short hazel
rich adder
#

and they're moving the .velocity

#

so anything you do with AddForce is overwritten

sick monolith
#

OHHHHHHHHHHHHHHH

#

Im kinda stupid

noble summit
#

Hello people of Unity, I am looking to learn C# and Unity but don't know where to start, does anyone have suggestions on where to go?

nimble blaze
#

should i use force or transform for jumping?

rich adder
#

transform gives no collisions

autumn tusk
eternal falconBOT
#

:teacher: Unity Learn ↗

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

sick monolith
rich adder
#

which would require some Sort of IEnumerator(Coroutine) for a gradual decrease or use Update

#

so you can lerp the value

final kestrel
open veldt
#

Quick question gang if you load a scene async can you access gameobjects in that scene or no?

final kestrel
timber tide
summer stump
# autumn tusk i know you set the variable to public but what then

That is not really the only way. What referencing a value(variable) on another script really requires is getting a reference to the OBJECT (c# object, not necessarily unity GameObject) that HOLDS that value.
So, if you can, you can make a public field of the Type the other script is. Say it is MyScript
You would have
public MyScript script.
Not a public field for the value, but for the SCRIPT

Then you drag in the object with that script you want into the box in the inspector.
Then you can do
script.Value

You can't always just drag it in though, so I'd need to know more specifics.

Also see here for all the ways to set up references
https://unity.huh.how/programming/references

timber tide
#

why I like doing stuff myself

#

event system good for dragging though since that is a headache to get working

final kestrel
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class PlayButtonSelected : MonoBehaviour , ISelectHandler
{
    public GameObject PlayButton;

    public void OnSelect(BaseEventData eventData)
    {
        Debug.Log("Selected");
    }

    // Start is called before the first frame update
    void Start()
    {
        EventSystem.current.SetSelectedGameObject(null);
        EventSystem.current.SetSelectedGameObject(PlayButton);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
``` The script thats working on the button
olive lintel
final kestrel
rich adder
#

You can't reference Objects from one scene to another for example @open veldt

#

most of the search functions only search one scene/hierarchy

autumn tusk
open veldt
open veldt
#

👍 swag

summer stump
short hazel
#

You should find whether they're valid for the enum (not sure how), and skip them as needed

olive lintel
final kestrel
#

Thanks for your time. Appreciate it.

timber tide
#

sec fixing it lol

#

this is on a button or text

final kestrel
#

The one I successfully get the log is on button

timber tide
#

you know what, forget the update way

#

I hate it

#

If the button receives callbacks, then basically you just need to grab the text reference to apply the glow

timber tide
final kestrel
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class PlayButtonSelected : MonoBehaviour , ISelectHandler
{
    public GameObject PlayButton;
    public TextGlowOnHover textGlow;
    public Coroutine textGlowCoroutine;

    public void OnSelect(BaseEventData eventData)
    {
        Debug.Log("Selected");
        if(textGlow.glowCoroutine != null)
        {
            StopCoroutine(textGlowCoroutine);
        }
        StartCoroutine(textGlow.ChangeGlowPowerOverTime(1, .5f));
    }

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

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

I did this and it kind of works.

final kestrel
timber tide
#

Ah, ok I see what you're doing. Yeah, what you got there is the idea if ISelectHandler is working.

crisp token
#

can you not access any element from a queue?

timber tide
#

They want to use events only which is fine

final kestrel
#

I have no idea why the text glows when i put it on button though 😄

#

I dragged the text in the inspector

final kestrel
#

do you mean like arrays?

crisp token
#

like is there no get() from a queue

#

or access by index

#

you can only peek() at the first element?

final kestrel
#

I set the play button to be selected in my code. The rest is handled by the input system i believe.

crisp token
#

oh sorry I wasn't asnwering yuor question

final kestrel
#

Oh sorry my bad.

final kestrel
short hazel
# crisp token you can only peek() at the first element?

You can Dequeue() to get the first element off the queue. It's the design pattern of a queue, you can't, and shouldn't be knowing what's in the queue except for the first element.
It's like a real life queue at the supermarket for example. People arrive at the end of the queue, and people in front are processed first. First In, First Out (FIFO) collection type

timber tide
#

but if it works then it's all good

crisp token
#

I haven't learned about data structures before

short hazel
#

No it's stored contiguously in an array in the back

#

It's just that it doesn't allow you to look anywhere you want

crisp token
#

why not?

short hazel
#

It's the design pattern of the Queue

timber tide
#

optimization

final kestrel
short hazel
#

If you need to look at any element, then use a simple List or array, queues are not made for such manipulations

chilly vigil
crisp token
#

it's continuously updated

short hazel
#

Yes sure, that's one of the use cases

crisp token
#

oh wait, i'm actually so dumb, it works perfectly for what I need

#

nvm

#

Thank u

short hazel
#

Dequeue one (or more) elements each frame if there are any in the queue

#

And process them

nimble blaze
#

is there anyway of making my character move just the x axis instead of turning the y axis into 0?

#

BeeRB.velocity = Vector2.right * speed * horizontal;
}

rich adder
nimble blaze
#

BeeRB.velocity = new Vector2(1 * speed * horizontal, BeeRB.velocity.y);

rich adder
#

BeeRB.velocity = new Vector2(horizontal * speed , BeeRB.velocity.y);

nimble blaze
#

like thatt=

#

oh i got it xd

#

i dont think i even need the 1 right

#

because horizontal gives a value of 1 through -1

#

thanks you

short hazel
#

Multiplying anything by 1 does not change its value, so yep it's not necessary to have it here

silent valley
summer stump
silent valley
#

makes sense

summer stump
#

You have a check for when all enemies are killed, so that should be about the only change you need. It will call when they die, then wait for the time, then spawn them

silent valley
#

you are a legend. Something so simple was the fix.

#

Thank you

tawdry mirage
#
{
    GameObject.Destroy(waypointsAdded[waypointsAdded.Count - 1]);
    waypointsAdded.RemoveAt(waypointsAdded.Count - 1);
}```
destroyed gameobject still exists for some time, right?
summer stump
swift crag
#

also note that the c# object will continue to exist

#

so even if the unity object was instantly destroyed, it wouldn't matter at all

#

the c# object isn't actually becoming null

#

that's just a trick that anything deriving from Unity.Object pulls

rich adder
#

yeah Unity overrides != and == for Unity.Object

viral hemlock
#

Can someone plz explain to me why I’m passing through objects even though I have colliders on each object

rich adder
#

also how do you move (code)

viral hemlock
#

public void MovementPlayer()
{
// this block of code gets the left, right, up, down movement
horizontal = Input.GetAxisRaw("Horizontal");
vertical = Input.GetAxisRaw("Vertical");

if (Input.GetKey(KeyCode.LeftShift))
{
    rb2D.velocity = new Vector2(horizontal * playerSprintSpeed, vertical * playerSprintSpeed);
 
}
else
{
    rb2D.velocity = new Vector2(horizontal * playerMoveSpeed, vertical * playerMoveSpeed);
    
}

}

#

my colliders are all circle 2d

#

exept for the capsule

#

nothing was changed on them

rich adder
#

lemme see gizmos

viral hemlock
#

pardon

rich adder
#

the green edges of the colliders, do they match

#

turn on gizmos

viral hemlock
#

ok

eternal falconBOT
dry tendon
#

heyy, does anyone know wich is the best way to develop a game in realtime with two people?

viral hemlock
rich adder
dry tendon
#

to use github desktop you mean, right?

rich adder
#

thats one client sure

dry tendon
dry tendon
#

and you recommend me github or another git service?

rich adder
#

github is pretty good

dry tendon
# rich adder github is pretty good

And for example, if my game has a garden and a house, one person can edit the garden and the other the house at the same time, but until one of both people stop editing the house or the garden the oder must not edite the same thing, i'm right?

rich adder
dry tendon
#

but what if the house is over the garden on the playmode view?

#

how could i do that?

queen adder
#

what's the proper pattern to pingpong a list?All_Ally[(int)Mathf.PingPong(TurnCount, All_Ally.Count - 1)];

#

nvm that's working already

#

something else was the problem

nimble blaze
#

hello everybody can somebody borrow me their super genious head

#

so i had this problem for a bit i kinda figured it out but now i added a new mechanic and now it kinda broke my mechanic

#

if(Input.GetKey(KeyCode.Space) && BeeRB.velocity.y <= 0)
{
BeeRB.gravityScale = 0.5f;
}
else
{
BeeRB.gravityScale = startGravity;
}
//Fall Faster
if(BeeRB.velocity.y <= 0)
{
BeeRB.gravityScale = fallGravity;
}
else
{
BeeRB.gravityScale = startGravity;
}

#

so i had these two one was for gliding and the other one was for falling faster

#

if 2 methods depends on one will just one execute?

eternal falconBOT
polar acorn
#

Code runs top to bottom, one line at a time.

#

Whichever one sets gravity scale last wins

nimble blaze
#

wait so you are telling me they cannot change the same value but it is in the update method

polar acorn
#

And whichever one changes it last is the one that "wins"

#

Because that's what the gravity scale is at the end of the function

nimble blaze
#

oh ok so what could be a solution for this?

late burrow
#

how would i do unzipping files

polar acorn
rich adder
nimble blaze
#

i can just put them together in the same if let me try that because they both use the first condition

#

i will try and see

#

omg its works @polar acorn thanks a lot

gleaming arch
#

Hey guys. Im making this silly golf game, and was wondering if anyone knew how I can achieve the effect in the video of Camera parent and ball child rotation, without actually having the ball the child of the camera? I've tried applying the same rotation to the golf ball but it doesn't have the exact same effect.

#

for the camera I'm simply adding a y value to the eulerAngles

late burrow
#

i need to access Application.dataPath but access denied how do i give it path permissions

sterile radish
#

why would one use an enum when they could use an integer?

swift crag
#

which is more grokkable?

mode = 3;
mode = GameMode.Deathmatch;
#

You can also enumerate all valid values for an enum type

#

with System.Enum.GetValues

#

the compiler can also check that you've handled every valid enum value in a switch expression and warn you if you missed one

sterile radish
#

oh so they are more flexible and better understandable then right?

swift crag
#
titleText.text = mode switch {
  GameMode.Deathmatch => "Deathmatch",
  GameMode.CTF => "Capture the Flag",
};
#

if I added GameMode.TeamDeathmatch to the enum, I'd get a compiler warning

sterile radish
#

Okay, thank you so much! The examples made me understand a lot better to :)

swift crag
#

no prob (:

smoky niche
#

So RaycastHit2D.point can be used with raycasts, and I remember seeing you can also use Raycasthit2D.point[0]. Does that return the colldier you hit first?

#

Or is there no difference?

ivory bobcat
#

Point is a Vector 2 not an array of objects

#

Using the indexer operator ([]) well yield you the x or y component of the Vector 2

timber tide
#

How does this even work in 2D

ivory bobcat
ivory bobcat
timber tide
#

Ah, I guess if you have colliders overlapping it makes sense

swift crag
#

it's just like 3D

#

the raycast simply does not stop when it hits something

timber tide
#

Yeah, im just thinking how you don't really have depth, but stuff that overlaps would be the usage

slender nymph
#

you do know that you can use a direction other than Vector3.forward for a 2d raycast, right?

timber tide
#

Oh, true

smoky niche
#

Oh okay thanks!

#

So it returns the Vector2 where the ray hits the collider then

timber tide
#

For the RaycastAll? You'd get back an array of hits which you can then access to get a point in space for each.

#

People say it's not always ordered from which is hit first, but you can iterate over the array then order it yourself too.

smoky niche
#

No I meant for the normal Raycast

#

Oh that's good info thanks

timber tide
#

Point would give you the vector2

hidden path
#

How do I write a script for movement in fps I wanna use it for a bird

nimble blaze
#

hello quick question my character move with velocity but in the end of my movement my character kinda drags a little bit
hatebin.com/fuqfvwpwdv

#

i can just put the velocity to zero after the movement but i want it to decreased not completely stop so i doesnt look so robotic

slender nymph
#

what do you mean by "drags a little bit"?

#

also you need to share more of the code than that

hidden path
#

I googled it and I am not able to understand the code given there, there is no explanation how it works

nimble blaze
#

like after the velocity it still retains some velocity after that so it start moving by itself slowly

slender nymph
#

you're probably using GetAxis instead of GetAxisRaw

nimble blaze
slender nymph
#

called it

nimble blaze
#

wait so i need to just changed getrawaxis?

summer stump
nimble blaze
#

what is the differenced?

summer stump
slender nymph
#

GetAxis includes input smoothing which means your input will reduce to 0 over time after releasing the key(s)

summer stump
#

GetAxisRaw is ONLY -1, 0, or 1

slender nymph
#

of course you are also not setting velocity to 0 when there's no input anyway so it will retain it's velocity until its physics has made it stop or you start using some other input because you only apply your input when it is not 0

nimble blaze
#

well now it moves way faster and cooler but it still slides after the input

#

that is the thing i want to not make it stop completely but slowly slowly

slender nymph
#

then go back to GetAxis and remove the check for whether the input is 0

hidden path
slender nymph
#

or add more drag to your rigidbody

ivory bobcat
nimble blaze
#

well yeah the thing im trying to do, is putting some force over time

#

to neglect the amount generated after he stops

#

oh wait a moment i can just divide them because the action is on update so is gonna do that constatly

slender nymph
#

i'm guessing you missed the suggestion of adding drag to your rigidbody

nimble blaze
#

add more drag

#

let me try that

#

would it be linear or angular?

slender nymph
#

linear

nimble blaze
#

oh welp that does work

#

but it affects my y axis as well

true pasture
#

the second if statement never returns true, could someone explain why, i've tried to use context.duration before and never got it to work.

#

also I just realized invoke isn't doing what I want there but regardless I can't get the duration check to work

#

(the rest of the function works)

fierce shuttle
true pasture
#

unity events

#

on player controller component

fierce shuttle
# true pasture on player controller component

Ah, I havnt used that component to handle input, though likely what may be happening is that your function is only being called once when the input changes (for example, the first frame the key changed from not being pressed to now being pressed down) - you can confirm this by adding a Debug.Log to the start of that function, I believe there is a setting in the action map for the bind to allow it to continue receiving input, or possibly on the input controller itself, otherwise another solution would be to poll the input yourself in Update

true pasture
#

ok thanks

true pasture
chilly vigil
#

i have no idea how to make an strom circle that works because the 2017 tutorial one is broken and the 2d one i am following is from 4 years ago

inner marsh
#
{
    public Transform turret;
    public Transform turretBarrel;
    public Transform target;

    // Update is called once per frame
    void Update()
    {
        turret.LookAt(target);
        turretBarrel.LookAt(target);
    }
}
``` im trying to aim gun turrets at a target, but with the actual turrets they need to only rotate along the y axis while the rest stay null, but with this skript they rotate along the x axis as well, how would i get it to only rotate along the y axis for the turret and the x axis for the turret barrels?
summer stump
summer stump
inner marsh
#

the barrel is a child

#

so itd get pulled along

queen adder
#

i have a simple question but i've been working at it for a while now 4 some reason my unity just decides not to let me debug and i have no idea what the issue is

#

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

public class Player : MonoBehaviour
{
void Start()
{
Debug.Log("hi?");
}
}

summer stump
#

I think the barrel would be fine as you had it

inner marsh
#

yes

queen adder
#

kk

#

gms

queen adder
gaunt ice
#

have you dragged the script to the gameobject?

queen adder
#

;-;

#

no-

#

😭

#

issue solved😭

#

thank you

inner marsh
# summer stump Yeah, but trying to look at its own x and z would cause issue
{
    public Transform turret;
    public Transform turretBarrel;
    public Transform target;

    // Update is called once per frame
    void Update()
    {
        turret.LookAt(new Vector3(turret.transform.position.x, target.transform.position.y, turret.transform.position.z));
        turretBarrel.LookAt(target};
}``` the turrets are now on their sides
static cedar
summer stump
inner marsh
#

alrrr

chilly vigil
summer stump
#

Wait... you have two Updates...

#

Maybe that is why?

#

I'm gonna just put the code in my IDE and see what is up a little better

chilly vigil
hidden path
#

what does Transform.TransformDirection method do ?

eternal needle
hidden path
#

i am new to unity so i didnt know how to use docs

hidden path
summer stump
eternal needle
# hidden path i dont understand what it returns

google will lead you to the docs, you dont need to do anything in unity.
you give the method a direction in local space and it gives you that vector3 as world space. Local space means the position relative to another object, world space means its true location in the unity scene

gaunt ice
#
public            Vector3       TransformDirection(Vector3 direction);
[access modifier] <return type> <method name>
unkempt stag
#

If I have two vector3s and I want to move one so that the distance between them is N but I want to keep the angle between them the same, what's the best way to figure that?

summer stump
#

Yeah, 15 errors in that one script

chilly vigil
#

modifyed from an yt video

eternal needle
summer stump
cosmic dagger
#

local methods, FTW!

summer stump
cosmic dagger
#

damn, way to mix it up . . .

chilly vigil
#

ok here it is https://youtu.be/JuqRnsUUcho?si=b7PKrMzzoVjtvDml but he update his C# as well on video number #12

Unity 2017 - Battle Royale Series - Part 7 - Shrinking Circle!!
(Full Tutorial + Free Asset Download!)

Download the assets used in this episode here:
www.polygonpilgrimage.com/Downloads/ShrinkingCircle.zip

Thanks for watching!
Please Like and Share!

▶ Play video
hidden path
#

i wanna learn fps movement where should i learn ( i tried youtube and i cant understand anything )

summer stump
# chilly vigil ok here it is https://youtu.be/JuqRnsUUcho?si=b7PKrMzzoVjtvDml but he update his...

Yeah, I tried to go to his repo, but it doesn't even show those scripts. There was a download for a ChangeCircle script and it's just... significantly different than yours.
You've added and changed so much I'm not sure how to get back from there. There are so many fundamental errors and issues that I don't understand the reasoning behind. I'm not sure how I or anyone else can really help with that.
As hard as this is to say, and certainly to hear, I feel like... starting over may be a good idea.

Someone else may be able to help 🤷‍♂️ but there is a lot to unmodify.

For anyone else:
StormController:
https://hastebin.com/share/ufusinenis.csharp

WorldCircle:
https://hastebin.com/share/kavojolohu.csharp

chilly vigil
#

he inclues the updated c# in the decpriton of the one

summer stump
# chilly vigil he inclues the updated c# in the decpriton of the one

Yeah, I got that one too. It's just... SO different from your code.
There are so many things that just cannot be done in C# in yours. Like:

void Start()
{
    void Start()
    { }

    void Update()
    { }
}  // Start and Update should not be in ANY method.

CloseTimes[closeTimeIndex] // this value is an int, not an array (or list)

if ((int)TimeElasped > CloseTimescloseTimeIndex //missing a parentheses, missing the square brackets, and again, is an int not an array

StormCircle((float)(XRadius * (ShrinkRadiusFator * 0.01)))[1]; // this is a type, not a method, right?

NextCircleTime(); // this method doesn't exist

TimeElasped[closeTimeIndex] // this is a float, not an array

CloseTimes.count // int, not array

return -1;
CloseTimes[++closeTimeIndex]; // innaccesible because it's after a return

It's just... like nearly everything is not right

summer stump
hidden path
eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
hidden path
summer stump
hidden path
#

i know c and c# is very similar so i think its fine , is it ?

summer stump
hidden path
#

i think i should learn from the start then

#

thanks for the help mate

gaunt ice
#

Even if You know c# doesn’t mean that you know the method in unity

opal fossil
#

any tutorial on how to animate two seperate game objects to do something together?
for example, you do a special attack on an enemy that involves throwing an enemy?

crystal current
#

Hi everyone, just new here but already working on Unity for a long time I'm studying DOTS and for some reason my camera is rendering weirdly.

The blurry ones are my gameobjects that have a DOTS authoring component and the cannon doesn't have any script attached to it and it looks normal. Here's a preview of what's happening.

#

Here's how they should look like in a different angle.

I'm using URP and Entities.Graphics, maybe they are conflicting

craggy ledge
#

Hello, i was converting a movement script with the built-in character controller from this https://docs.unity3d.com/ScriptReference/CharacterController.Move.html , to a state machine from here https://www.youtube.com/watch?v=qsIiFsddGV4 . There are 2 things that i want to ask

  1. When it transitions to the jump state, it immediately go back to idle state, does anyone know where the problem is and how to fix it? i think there is a split second it is still grounded so it goes back to idle state but i don't know how to fix it without changing the abstract class
  2. There is a delay when i want to jump using the state machine version compared to the non-state machine version where it is all smooth, does anyone know what is happening?

the code is here https://gdl.space/desotukixa.m

thank you 🙏

static cedar
tepid cobalt
#

Is there a trick for deactivating objects for the pool system? Currently when my 1st spawn iteration finishes from the pool list, it refuses to start from the beginning and re-iterate.

#
    {
        if (pool.Count == 0)
        {
            Debug.Log("Pool is empty, creating a new object.");
            CreatePooledObject(); // Optionally increase the pool size
        }

        var obj = pool.Dequeue();
        ResetObjectState(obj);
        obj.SetActive(true);
        Debug.Log("Object taken from pool and activated: " + obj.name);
        return obj;
    }

    public void ReturnObjectToPool(GameObject obj)
    {
        ResetObjectState(obj);
        obj.SetActive(false);
        pool.Enqueue(obj);
        Debug.Log("Object returned to pool and deactivated: " + obj.name);
    }

    private void ResetObjectState(GameObject obj)
    {
        // Reset object state as needed
        obj.transform.position = Vector3.zero;
        obj.transform.rotation = Quaternion.identity;

        var rb = obj.GetComponent<Rigidbody>();
        if (rb != null)
        {
            rb.velocity = Vector3.zero;
            rb.angularVelocity = Vector3.zero;
        }

        // Reset any additional components or states here
        Debug.Log("Object state reset: " + obj.name);
    }```
static cedar
#

That should eliminate some switch case. If you used one.

craggy ledge
mystic oxide
#

huh? i didn't touch unity for a week... not sure what happened here

fossil drum
mystic oxide
#

hopefully nothing happened to my project

fossil drum
tepid cobalt
#

Holy crap