#💻┃code-beginner

1 messages · Page 315 of 1

vocal marlin
#

especially timers

willow scroll
#

If it collides, what then?

vocal marlin
#

by not working do you mean it just isn't doing anything?

abstract finch
vocal marlin
#

have you used a Debug to see if that part of code is being reached?

long tiger
willow scroll
vocal marlin
eternal needle
#

By the way you can also just construct the rotation once then just keep rotating the vector. Basically store the rotated vector and keep rotating it, rather than adjusting the quaternion and rotating the initial

willow scroll
abstract finch
#
    {
        while (true)
        {
            float anglesChecked = 0;
            while (anglesChecked < 360)
            {
                Quaternion axisRotation = Quaternion.AngleAxis(anglesChecked, Vector3.up);
                Debug.DrawRay(transform.position, axisRotation * startDirection, Color.red);
                //transform.rotation = axisRotation;
                anglesChecked += _angleStepSpeed * Time.deltaTime;
                yield return null;
            }
        }
    }```
Heres the code. I just do 360 from the angle in a coroutine. (In the real code theres no coroutine)
long tiger
vocal marlin
long tiger
#

wait i think I found the issue

long tiger
abstract finch
long tiger
willow scroll
#

I'm sure it can be done with math

vocal marlin
eternal needle
abstract finch
#

noted, right now im having trouble getting it to do a radial check in the direction i want which is upwards. At the moment it goes around.

eternal needle
eternal needle
eternal needle
# willow scroll There most definitely is

Well goodluck trying to solve that purely with math, having no knowledge of the colliders around. Unless you want to manually calculate which area is free based off each part of a non primitive collider

willow scroll
#

Also, "having no knowledge" about the colliders around is entirely false

#

Simply use SphereCast with the suitable radius

abstract finch
#

some monsters in games have a quick side step move, its basically that

#

except in this case the enemy isnt limited being grounded it can go up or down

eternal needle
eternal needle
abstract finch
#

yea im using that

#

im just trying to figure out how i can make this ray move along a different direction but i can try on my own

willow scroll
eternal needle
#

And if you try to deal with those cases, itll sure as hell be more expensive than doing like 8 raycasts.

abstract finch
#

my game is simple and uses simple structures that are square if the first check fails i place a cooldown on it regardless

#

why does unity allow me to do Quaternion * Vector3 but not the other way around?

eternal needle
gaunt ice
#

A*B!=B*A
matrix multiplication is non commutative

eternal needle
#

Ah discord formatting. It italicized my message lol

silent prism
#

hey guys i want to set the time of my animation to the float value in the script how can i do this

sullen rock
#

Hey, sorry for reposting, feels like my question got a little burried, so Im asking again https://gdl.space/tacapodabe.cs

Script #2 creates a texture and applies it, but when I try to get textureCoords from the raycast in script #1 it always returns (0,0). Can anybody help me figure out why?

modern mesa
#

hello

#

i have a maths project and i have to visualize a spherical triangle

abstract finch
# eternal needle Ah discord formatting. It italicized my message lol
    {
        float anglesChecked = 0;
        Vector3 axisV3 = Vector3.forward;
        while (anglesChecked < 360)
        {
            Quaternion axisRotation = Quaternion.AngleAxis(anglesChecked, axisV3);
            Vector3 direction = axisRotation * startDirection;
            if (!Physics.Raycast(pos, direction, checkLength, obstacleMask))
            {
                return direction; // Found Direction 
            }
            anglesChecked++;
        }
        Debug.LogError("Failed To Find Clear Path");
        return Vector3.zero;
    }```
Heres the final function
modern mesa
#

the teacher allowed help of ai and stuff so ive been using chatgpt to help me

#

void DrawCurvedLine(Vector3 startPoint, Vector3 endPoint, int pointCount)
{
GameObject lineObject = new GameObject("CurvedLine");
LineRenderer lineRenderer = lineObject.AddComponent<LineRenderer>();
lineRenderer.startWidth = 0.1f;
lineRenderer.endWidth = 0.1f;
lineRenderer.positionCount = pointCount;

    Vector3[] points = new Vector3[pointCount];
    for (int i = 0; i < pointCount; i++)
    {
        float t = i / (float)(pointCount - 1);
        points[i] = Vector3.Slerp(startPoint, endPoint, t); // Adjust for sphere radius
    }
   
    lineRenderer.SetPositions(points);
}
#

but this code doesnt work as i want

#

it creates a curved line between two points i selected on the sphere but the line is inverted and the lines cull

eternal needle
eternal needle
sullen rock
#

Toggling convex off fixed it it seems

onyx tusk
#

how 2 make 2d buttons dynammically?

deft grail
hazy minnow
#
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class DinoJumpScript : MonoBehaviour
{
    public bool grounded;
    public float speed;
    public Rigidbody2D myrigidbody2D;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) == true && grounded == true)
        {
            myrigidbody2D.velocity = Vector2.up * speed;
        }
    }
}
``` ```using System.Collections;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;

public class onGroundScript : MonoBehaviour
{   
    public DinoJumpScript script;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == 3)
        {
            script.grounded = true;
        }
    }
}
``` Why the player can still jump ?
onyx tusk
slender nymph
hazy minnow
#

What is the correct way to do a ground check

slender nymph
#

physics queries like a raycast, overlapcircle, etc are preferred over physics messages

hazy minnow
#

ok

onyx tusk
#

how 2 make 2d buttons dynammically?

slender nymph
deft grail
slender nymph
#

what you replied was not actually an answer to the question that was asked

#

they were not asking how you planned to implement that feature since, you know, that was the whole basis of your question. they were asking what you were actually trying to achieve so that an answer could be provided

onyx tusk
slender nymph
#

just saying "2d buttons dynamically" doesn't actually say anything

deft grail
slender nymph
#

didn't you know gr4ss, they want to create it on runtime

slender nymph
# onyx tusk creating on runtime?

if you cannot describe what you are actually trying to do then you will not be able to get help since nobody knows what you are struggling to accomplish

deft grail
onyx tusk
onyx tusk
#

& can i through it use gameObject.GetComponent<Button>()?

deft grail
#

or just instantiate of type Button, then you dont need to GetComponent

safe ingot
#

Hello, please advise what is the best way to implement multiplayer, if I want to implement a game in which the game state will be stored on the server, are there any tools?

green ether
#

I am using Mirror and it took me months to learn the basics and hook everything up to steamworks etc aswell

slender nymph
slender nymph
#

well last time i checked jmonkeyengine is not the unity engine

safe ingot
slender nymph
#

there isn't just a magical "make a multiplayer game" feature in Unity. you need to research the available networking frameworks, choose the one that best fits your needs, then learn how to use that framework

scarlet skiff
#

I feel like now that i know more about coroutines i feel like Invoke is kinda useless, except maybe for when you have a very simple method. But other than that, the fact that you have to input the function as a string of its name for invoke, disallowing you from using method with parameters, just makes invoke useless, or am i missing something?

safe ingot
#

a lot of uselles information and service where you can create sh1ty multiplayer clone with juts sync

#

Is there really no option to create a headless server and override methods? onjoin onquit sendmessage etc

slender nymph
slender nymph
safe ingot
green ether
#

As far as Im aware

safe ingot
slender nymph
#

you can create a headless server for unity. that doesn't mean you still don't need to choose a fucking networking solution that has the capabilities to do what you want

#

there are dozens of networking solutions you can choose from, you need to research them to find the one that best fits your needs. otherwise you need to do it yourself

#

we couldn't possibly know what is wrong with that little info. please see #854851968446365696 for what to include when asking for help

safe ingot
#

@slender nymph what do you mean by network solution

slender nymph
#

i mean a framework that does the networking for you because there is no built in multiplayer functionality in the unity engine. if you'd bothered to do any research about this, you'd know that

safe ingot
slender nymph
#

it's pretty clear that you didn't

safe ingot
# slender nymph it's pretty clear that you didn't

It’s obvious that I came here to ask people who have experience so that they could give me advice, and not just write blah blah blah you’re a s*cker and don’t look at the Internet for "Networj solution"

slender nymph
#

alright, this conversation is pointless. i'm going to block you now. good luck with your fruitless attempt at doing multiplayer since you clearly have no idea what is required for that

safe ingot
ocean dove
#

Imagine calling 360 (or 36 or idk how many) raycasts

safe ingot
slender nymph
#

this isn't godot where a single raycast allocates like 600 bytes

ocean dove
#

How is 360 raycasts not expensive

#

That's probably about -0.5 to -2ms cpu

slender nymph
#

have you done any profiling to determine if it is in fact expensive? or are you just assuming that big number == big performance hit

ocean dove
#

Trust me I have

#

even shooting 256 raycasts takes a big hit on perfomance

slender nymph
soft kernel
#

I had about 80 enemies, each sending about 8 raycasts every frame trying to find player

#

didn't see any performance issue

ocean dove
#

Oh what, I'm supposed to magically pull out code that I removed and or heavily edited to improve perfomance?

soft kernel
#

https://youtu.be/Xd4UhJufTx4?si=tmE9j7anPh8o90-U
you can watch this to get better idea

Find what common Unity optomizations truly make a difference. In this video I go over a bunch of interesting optimization tips as well and give you my recommendations on each.

Keep your code running fast with as little garbage allocation as possible by learning from these important concepts.

Benchmarks (let me know if you get weird results!):...

▶ Play video
slender nymph
ocean dove
#

I'm not planning on finding the code

#

It's already gone

#

and I won't bother proving you as I saw your previous argument

soft kernel
ocean dove
#

You went so quick from telliong someone to search up networking solutions to blocking them

slender nymph
ocean dove
soft kernel
#

rigidbody

slender nymph
soft kernel
#

and it was HDRP

ocean dove
#

Finding directions using your solution is understandable

#

So you target high spec devices

soft kernel
#

they were zombies so I didn't need smart path finding

soft kernel
ocean dove
#

I target low end so I have to optimize my code haard

#

I tried doing raycast culling and it was a horrible idea for me

soft kernel
#

what are you using raycast for

ocean dove
#

as I mentioned, culling. But that code is long gone as even on 256 raycasts the accuracy was bad and the fps was even more horrible than it was without it

#

I think I got like -50 fps just from rays on a for loop

#

Doing huge amounts off of raycasts should be done asynchronously in order to split the amount of rays that are shot out over a larger amount of time which should theoretically improve perfomance

#

which I have not done and it went horribly wrong

soft kernel
#

why using rays for culling

ocean dove
#

Physics culliong is slow

#

Trigger culling is way faster and I could replace my other system for cullingn with it

#

The best part about trigger culling is that it's just a trigger and objects have ontriggerenter and ontriggerexit methods in em

#

It's the fastest range and the best culling method if you don't want to have large floors disappear as the default camera cull spheres tend do to that

soft kernel
#

are you sure the problem is with the rays it self and not the thing you do with that info?

#

in pc, I don't think sending 300 rays would take more then 1ms. how slow can a low end device be?

slender nymph
#

the expense probably came with either not using non alloc versions of queries that return multiple results, or whatever you were doing with the results

soft kernel
slender nymph
#

the garbage is going to be the biggest performance hit when the GC runs

#

but i can test what is faster real quick

soft kernel
#

but in a longer gameplay time

#

what I mean is the result would be even faster for a short test

vernal bone
#

Need help.
Trying to make a moving platform, and as internet said, easiest way to make player move with platform is to set platform as player's parent.

Everything works fine, but when i exit the "play" while player agent still on platform, editor gives an error:
"Cannot set the parent of the GameObject while activating or deactivating the parent GameObject"

What can i do with this?

slender nymph
soft kernel
vernal bone
slender nymph
slender nymph
naive pawn
#

i mean it Enter is called when you press play so i guess it kinda makes sense...

vernal bone
slender nymph
#

yep. there's a Physics2D setting to prevent callbacksOnDisable just note that it affects everything, so that would include if you wanted to disable some object and get an OnXXXExit2D response at runtime too

vernal bone
slender nymph
#

unity told me that was "as designed" when i reported it as a bug a few months ago

ember oasis
#

how do I change the order in layer of a canvas button

slender nymph
#

UI draws based on order in hierarchy, move the object further down in the hierarchy to draw it on top of objects that are higher in the hierarchy

slender nymph
#

well there's only one object on the canvas there so naturally its hierarchy order won't matter since that only affects how the UI draws

#

if you want to change how your ui appears with your world space objects then it depends on your canvas settings

ember oasis
#

no but like

#

its behind the background

slender nymph
#

this is not a code question btw
but again, it depends on your canvas settings

wanton canyon
#

so Im trying to make it so that you can pick up and throw slimes in my game. issue: the slimes have this giant WanderAI script that is a state machine controlling how they move, and it seems to reset their position to before you throw it. Im just at a loss on how to fix 😅 script for WanderAI: https://pastebin.com/hGYR6U9m I can also share the scripts that pick up/drop items as well if needed

slender nymph
#

if you're going to use pastebin, can you at least select the language so there's syntax highlighting instead of just a giant grey blob of text

tawny bolt
slender nymph
#

be more specific than "not working"

ember oasis
#

wouldn't it make more sense to have the dash inside of the movement script

tawny bolt
#

it does this when i press dash dosent increase my speed

slender nymph
#

welp paste.ofcode isn't working for me right now so i can't even view the code 🤷‍♂️

ember oasis
#

same here

tawny bolt
#

can i send you the code directly ?

slender nymph
#

no, just paste it to a different site

tawny bolt
#

ok

slender nymph
#

okay so for starters, your SpeedControl method limits the movement speed

tawny bolt
#

wdym where do i limit the speed can you highlight

slender nymph
#

your SpeedControl method

tawny bolt
#

how do i fix it ?>

#

// limit velocity if needed
if (flatVel.magnitude > moveSpeed)
{
Vector3 limitedVel = flatVel.normalized * moveSpeed;
rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z);
}

#

this is where i limit my speed

#

how do i make a limit of 20 except of 10

ember oasis
#

could someone post tutorial videos on how to create a pursuer ai that will chase you down

green ether
#

Is it possible to set one Objects RectTranstform on the canvas to the same position as another objects if that other Object is in a Grid LayoutGroup?

#

The object I wanna move is on the same canvas but outside of the layout group

wintry quarry
tawny bolt
#

what is limit ?

#

an int ?

young fossil
#

Hi. So I've got a couple of places I think Static should be used but trying to use it sparingly. For example, I have a SceneLoader and I'm wondering if I make that static? Any ideas?

young warren
wintry quarry
tawny bolt
#

kk ima try it

young warren
#

like, is it a GameObject in the Hierarchy?

young fossil
young warren
young fossil
#

Yes, it is a singleton too

young warren
#

just make it a DontDestroyOnLoad singleton

#

then it's fine?

young fossil
#

Well, yea. But I'm wondering if I can use Static too

young warren
#

what? by it being a singleton, it means you can already refer to it using the typename, like a static variable

young fossil
#

It's fine, nothing criminal about leaving it a simple singleton

tawny bolt
young warren
#

you are using static when you use a singleton

young fossil
young warren
#

i see

young fossil
#

Not Static class

#

So for example, I have Load(Scene scene)

young warren
#

i can't really see any real benefit or downside to it, so if you could, you can?

#

it's just odd since it's already a singleton

young fossil
#

So for every script that uses Load, I of course need to get the SceneLoader script, which in Unity, is FindComponetByType()

#

Using static bypasses it

#

Better performance to my understanding

#

And easier readability

young warren
#

are you misunderstanding how a singleton works?

#

you could just do SceneLoader.instance.YourMethod()

#

SceneLoader being the class type

young fossil
young warren
#

why do you need to get the SceneLoader script?

young fossil
#

No no, I see how it literally is static now

young warren
#

yeah

#

see why I was confused? 😆

young fossil
#

Yep xDD sorry

young warren
#

it's good that you're thinking outside the box though, no harm in that

young fossil
#

Static seems really rare use case in Unity then

young warren
#

happy devving

young fossil
#

Thanks Wytea!!

carmine frost
#

Sorry if im stupid, but why does the target not registre hit?
When the target script is called "target" only, it works?

deft grail
#

2, because you are probably using the name target in the other script instead of target1

cinder crag
#

why does this appear brbrbrbrbrbr

amber basin
#

How do i keep my game from breaking whenever i press pause, then go to the mainmenu, then back to the same stage? I have this little tower defence game i am working on rn and i am veeeeery new to coding.

deft grail
#

or weapon is null

amber basin
# deft grail how does it break?

I have this little overview of all the UI and everything that has these values randomly selected. These values arent actually the ones i am working with, but i am using this as a sort of way to know that A. the game is not on and B. in case i run into the kind of bugs i have right now.
The game stays at this screen, no enemies spawn, i can build turret and pausing and retrying does not help at all.

deft grail
flat summit
#

To grab different gun type scriptable objects in my game I just made a gun manager in the hierarchy with a simple script that holds all of the guns, is this frowned upon?

deft grail
amber basin
deft grail
amber basin
cinder crag
deft grail
deft grail
#

whats the logic behind it

ocean dove
#

line 21 is you getting the weapon I'm pretty sure

cinder crag
deft grail
#

is there an error?

#

because i see you changed the code actually

cinder crag
amber basin
deft grail
cinder crag
amber basin
#

There is also a toggle () as well

wintry quarry
#

change it based on those other things.

#

You can do whatever you want in programming

#

just write it

amber basin
# deft grail and what does `FadeTo` do

It starts a Coroutine that is connected to some code that makes the scene fade in and out so it looks nice when you press retry or go to another level or the main menu.

deft grail
cinder crag
#

the only one that didnt get printed

deft grail
amber basin
deft grail
eternal falconBOT
amber basin
#

Ah perfect

deft grail
#

for just 1 line you would put ` at the beginning and end of the line

amber basin
cinder crag
deft grail
deft grail
willow scroll
#

Where is even the 24th line?

cinder crag
willow scroll
cinder crag
willow scroll
#

It's either equipmentManager or currentWeaponObject

willow scroll
#

The newWeapon isn't null, because there's nothing trying to access its fields on the 24th line

#

Simply check the equipmentManager and currentWeaponObject, the NullReferenceExceptions are the easiest to deal with.

deft grail
cinder crag
young fossil
#

Hey guys, I have an FSM and looking for some advice with my naming.

Firstly, the type FSM.State is a delegate. Then the properties of that type have methods assigned to them. I have State properties for Menu, Gameplay, Cinematic.. etc since this FSM deals with the game state.

So for the type name, State is okay, since it is a generalised FSM class.

As for the properties, I was thinking something as simple as "MenuState" or "Menu". But I've also heard "OnMenuState" is good since it implies there's some form of action (in this case a method) when it is the active state. Keep in mind, each state has functionaility for entering, on update and exiting.

Then the method, I would call "MenuState" too, which I obiviously can't, since you can't have the same names. So maybe "MenuStateMethod"? Or another could be "PerformMenuState" to imply activation of some kind.

Let me know your advice

willow scroll
willow scroll
cinder crag
#

lemme check again

willow scroll
#

Have you seen the screenshot you yourself have sent? There's written that the currentWeaponObject is null

willow scroll
summer stump
carmine frost
#

not working

willow scroll
cinder crag
willow scroll
# cinder crag how??

Well, I have to idea what you're trying to accomplish. Shouldn't you know it yourself..?

carmine frost
#

this is the target shooting, need it to work with script target1

amber basin
#

Is

(SceneManager.GetActiveScene().name);
``` not enough to reset a level?
willow scroll
willow scroll
#

You'll have to reset a level by actually loading the current scene

SceneManager.LoadScene(SceneManager.GetActiveScene().name);
willow scroll
#

Also make sure it's included in the build

static bay
#

Alright boys the objective is simple. Get Visual Studio Code actually working with Unity. For years this thing has freaked out either with formatting or some other bullshit.

#

It's time to conquer it.

#

I have uninstalled VS Code and removed all extensions/settings.

#

We're going in clean.

wintry quarry
#

Get Rider instead

#

Never look back

tiny geyser
#

I have a super entry level question if anyone has time on their hands to pm me, it's about a slightly annoying jump animation that I can't quite seem to get to play correctly.

amber basin
wanton crater
#

guys i have an image that is the child of a canvas ofc and when i did this it went to 0,0 of the world not the parent how do i fix that

wintry quarry
wanton crater
#

i want it to be 0,0 of the canvas

static bay
#

Or whatever that thing is called.

amber basin
amber basin
amber basin
naive pawn
#

uh do you still need help

#

you can just ask here

#

we can't moderate dms

static bay
#

For some reason code I paste just refuses to get autoformatted like in Visual Studio.

#

And opening a code block doesn't create a new line before the first {

naive pawn
#

vscode has a format feature

#

i think it's ctrl+alt+f or smth

#

can't remember

static bay
naive pawn
static bay
#

for c#

gaunt ice
#

shift alt f

static bay
#

when I do some javascript work

naive pawn
static bay
#

it immediately autoformats regardless of any other input

naive pawn
#

seems like both are true for c#

unreal pulsar
#

Is there a easy fix to my issue of my player character having these weird ice physics? In which they won't stop sliding around weirdly?

naive pawn
#

increase friction?

unreal pulsar
#

Where do you find that? Rigid body?

naive pawn
#

yeah, in the material you set

static bay
# naive pawn

This seems to cause another "action" to take place, so when I CTRL+Z it reverts to the un-formatted version.

#

Aka I need two undos to actually remove the paste.

naive pawn
#

right, that's what happens with js as well

#

at least, as far as i remember

static bay
#

You sure?

#

I could have sworn shit just works with JS.

#

Tbf, been a few months.

#

Might be gaslighting myself.

naive pawn
#

i mean, this isn't really broken

#

pasting is pasting, the setting just makes the paste trigger another action

static bay
#

It's just odd.

#

I would expect equivalent behavior across languages if the individual extensions for each language were doing their job.

naive pawn
#

there's a split second where you can see the raw paste before it's formatted as well

static bay
naive pawn
#

i enabled it to test

static bay
#

Disable it and then try pasting.

naive pawn
#

it just does the raw paste

static bay
naive pawn
#

i mean, could be another extension you have

static bay
#

Removed all extensions and settings.

naive pawn
#

well the format on paste is off by default as i showed in my screenshot

static bay
short hazel
#

It is default behaviour, maybe you have an .editorconfig file that dictates other format guidelines and VSC bases itself on that?

#

VS and Rider both do that, if it finds such file in the project directory it overrides the format settings

mighty cliff
#

hello i have a little problem and i dont know how to fix it. My Character dont jump but i dont see the problem in the code. I am a rly new beginner and i have no idea why its not working maybe one of you have time to help me and talk with in a discord speach channel .

naive pawn
#

it's also off by default though.

static bay
gaunt ice
#

you need some extension for editorconfig to work in vscode iirc

naive pawn
short hazel
#

VS formats on paste, and adds missing using directives if required. It does log the format as an action, so you need to Ctrl+Z twice to undo the paste. As for editorconfig I have no idea

#

It's properly configured though, right? You get the completion list and errors underlined

naive pawn
#

oh right, vs is more common

#

i mean vs and vscode do look kinda similar if i recall correctly

static bay
naive pawn
#

true

static bay
#

Oh and get a load of this.

#

look at this for loop

#

just wrote it normally

#

I copy it

#

and when I paste it

#

auto format puts the new line in the for loop block

#

but when I TYPE it it does not

naive pawn
#

right, that's a separate thing

short hazel
#

Do you have code style preference settings in VSC? They might be disabled

static bay
#

But I will check, where can I find that?

short hazel
#

Good question

#

Settings of the C# extension, probably

static bay
#

alright one of these shmucks then

short hazel
#

That would be the second one.
Before that can you test something out? Inside Update or any other method, hit backspace until you have no indentation left, then invoke a snippet (type for and Tab twice to insert it), does it format the whole thing correctly?

static bay
#

you mean like this?

short hazel
#

Yeah and then inside the braces {} type for and tab twice

static bay
#

oh that's not good

#

I wrote for, and then the intellisense menu opened up

#

first tab closed the menu

#

second tab actually did a tab

#

snippets broken

short hazel
#

Weird

static bay
#

this has been my life

#

with C# VS Code

#

It just seems to be completely broken on this PC

#

and I dont know why

#

but I do get this

#

and when I select it

#

when done in a properly formatted code block it does it right

short hazel
#

Hm yep seems like it's not applying format by default. Trying on my side

static bay
#

I am sad

short hazel
#

Yup not formatting either on my side lol

#

Even if the setting is enabled

static bay
#

what is going on

short hazel
#

Well for the braces, if I add a newline before opening them, it works.
Newline, open brace, enter.
But not open brace, enter

short hazel
#

Haven't found any code style setting so I think it's not shipped by default for VSC

#

Found a "format on type" setting but it does nothing, that's a bummer

young fossil
young fossil
#

Since they're properties I thought it was PascalCase

#

But does the fact they're delegates override that?

short hazel
#

Properties are supposed to be in PascalCase, but the two of type State are (1) not properties, and (2) even Unity does not capitalize properties (see: transform, gameObject, etc.)

#

It's pretty much freesyled in terms of naming conventions, but you do whatever you think is best

willow scroll
young fossil
short hazel
#

That is one yes

short hazel
#

It's a field when there is no accessors block after the name

young fossil
#

Sorry may have not explained it, that is how they're syntactically written in my context

#

So then we run into MenuState and MenuState

willow scroll
young fossil
short hazel
#

Good

willow scroll
young fossil
young fossil
#

It's a pretty vital part of my gameloop which is referenced a lot, so it does really matter

#

Hmm... What about MenuStateRunning for the method

short hazel
#

CurrentMenuState?If that's supposed to reflect the current menu state

young fossil
#

So there is only one menu state

short hazel
#

Hm why make a state machine for it then, if it never changes. Might as well make it get-only

young fossil
#

So there is a Gameplay state, a Cinematic state, etc

short hazel
#

Right so it's the "Menu" part of the name that shouldn't be there :)

willow scroll
young fossil
short hazel
#

I don't follow. What class is this property in?

young fossil
young fossil
short hazel
#

Okay so MenuState is alright

young fossil
#

Since it is a Game state, and it handles how the game behaviors

naive pawn
young fossil
#

stuff like how cameras, timeframe, certain graphics behave etc

young fossil
willow scroll
young fossil
#

Like dominos or something... Am I right?

naive pawn
#

but no to the latter

willow scroll
willow scroll
naive pawn
#

callbacks aren't a syntactic thing, they're just a term to specify intent

harsh wraith
#

I am having a problem in my game where my my player is floating when I start the game. I want my character to stay on the ground but I am unsure how.

young fossil
#

Ah this made sense... Got it

#

It's abstraction

naive pawn
#

if you've used stuff like ForEach or Map, the delegate you pass to those methods acts as a callback because ForEach will call that delegate to give info back to the caller

willow scroll
young fossil
#

@naive pawn @willow scroll @short hazel Thank you guys for the help

harsh wraith
#

specifically here in my script:

if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}

rich adder
willow scroll
rich adder
eternal falconBOT
harsh wraith
rich adder
#

make sure they aren't any invisible colliders

#

also no point of having capsule collider there, the character controller component is already a capsule collider

#

You know what.. its probably the skin width... since you're using isGrounded from the built in CC not an overlap/cast

harsh wraith
harsh wraith
rich adder
#

play around with value but don't put it too low or might cause other issues

harsh wraith
#

yep that was the problem. Thank you so much for helping me!

atomic sierra
#

how would you go about making 2d square sprite to rotate its axis around? I dont have the project open but ive been meaning to ask.

right now the way my sprite VISUALLY rotates is through this code

Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 dir = new Vector2(mousePos.x - player.transform.position.x, mousePos.y - player.transform.position.y);

player.transform.up = dir;

but ive seen that when i run the game and i look at the scene menu, my sprite object doesnt rotate its axis at all. it just VISUALLY looks like its rotating. im trying to make it shoot bullets and for the bullet to match the sprite's rotation, but its going straight up

So how would i go about doing this?

short hazel
#

That rotates. Maybe your Move Tool gizmo was in world space mode, in which case the arrows don't rotate at all?

#

And for the shooting you'll need to use transform.up instead of Vector3.up in the bullet direction calculation

grizzled zealot
#

Am I am doing anything wrong when I have about 20+ scripts on each object? moveable, health, shoot, spawnable, dockable, chatable, selectable, faction, ... and for each of them I have 3 scripts: model with the data, controller or presenter depending on MVC or MVP, and a view to any visual things.

now when I have 30 GOs in the view, I have 600+ scripts active.

Am I am doing something wrong? Is there any concern with being this deep into composition patterns?

queen adder
#

how can i add text that tracks your highscore in my game?

ivory bobcat
#
  • Add some text to the scene that would hold the high score value.
#
  • Have a high score value that updates correctly relative to the current score
#
  • Update the text when high score value changes
#

Maybe show what the error is

acoustic arch
#

i figured it out

winter cedar
#

So when i open my project settings unity crashes

timber tide
grizzled zealot
timber tide
#

The only issue about having a large gameobject is using GetComponent on that gameobject as it'll have to search through all components until it finds one, so it can range anywhere from O(1) to 0(n)

#

but not likely to run into that issue unless you are making one of those large wave based games where you may be checking hundreds of gameobjects in a single frame

#

Unless GetComponent methods do use a hashtable but I can't really seem that specific information anywhere

naive pawn
timber tide
#

right, if it was a hash it would be big O of 1

#

It may be a hash actually

naive pawn
#

not necessarily since hashes can still collide

#

but in practice may as well be O(1)

timber tide
#

Well, if someone can find me the docs that confirms this stuff since I'm getting different answers from the forums rofl

#

but either way, working with gameobjects with a ton of scripts a little hard for me. I like to keep them minimal if possible

grizzled zealot
#

I'm not worried about getComponent, I'm more worried about constant broadcast messages update etc.

timber tide
#

if you remove Update method from your components it wont

grizzled zealot
#

Doesn't c# still have to inspect the monoscript to see whether it has an update method and, if so, call it?

grizzled zealot
#

Or is this done more efficiently?

naive pawn
timber tide
naive pawn
languid spire
timber tide
#

will have to test it to see who's lying to me haha

abstract pelican
#

Can you please tell me why it doesn't work? Why it won't shut down.

ivory bobcat
abstract pelican
languid spire
#

So is that code even running? Debug it

ivory bobcat
# abstract pelican

Maybe the inspector isn't focused on the correct object or the lines of code aren't ever executed?

abstract pelican
rare basin
#

dont stack 20 scripts in one game object

#

i usually make sth like

  • Enemy
    • Scripts
      • Health System
      • Loot System
#

everything nice and organized, 1 game object for 1 script

#

i hate crowded, unreadable inspectors

static bay
#

If you have more than 20 components on a single gameoject you probably have other issues >_>

final kestrel
#

Hello all! A quick question. Should I learn Git using terminal? Or go with the desktop app?

rare basin
#

weird type of question

#

whatever suits you

final kestrel
#

Hm I was asking if one is better than the other actually in terms of flexibility and such.

timber tide
#

but that's like 50 bux

timber tide
#

Like I have having problems reverting a specific file with GitHub Desktop so I had to do it through powershell

final kestrel
zenith cypress
#

Fork has an indefinite evaluation period

frosty lantern
#

if I assign a struct in a component, am I passing a reference to the original?

timber tide
rich adder
#

its like winrar UnityChanLOL

zenith cypress
#

Yep

eternal needle
final kestrel
clever fable
#

I think I've done this wrong, I sent my whole project file to a friend, he gets this errror: Assets\Scripts\EnemyFollow.cs(28,19): error CS0103: The name 'BulletLife' does not exist in the current context; can't reassign the script, I believe is the way i shared the project. Any fix or way of sharing the project that would fix this?

rich adder
#

whatever you got on line 28, it has no idea what BulletLife is

eternal needle
stuck palm
#

why isnt the master volume slider being selected?

void SelectOptionsFirstItem()
    {
        optionsButton.Select();
    }
short hazel
#

The method you posted seemingly selects a button, not a slider

#

Based on the variable names

stuck palm
short hazel
#

In this case, make sure the GameObject the target Selectable is on is active and enabled, at the time .Select() is executed on it

#
// bad, I assume
btn.Select();
btn.gameObject.SetActive(true);
stuck palm
#

should be active

short hazel
#

Do you have an active EventSystem in the scene? The source code of Selectable.Select() just calls EventSystem.current.SetSelectedGameObject(gameObject)

stuck palm
#

i've made it inline now and its still not working

public void OpenOptionsScreen()
    {
        mainButtons.SetActive(false);
        optionsScreen.SetActive(true);
        EventSystem.current.SetSelectedGameObject(optionsButton);
    }
acoustic arch
#

!code

eternal falconBOT
acoustic arch
#

alright after figuring out the debugger I found an infinite code loop in lines 58 - 70

#

i know it has to do with the for loops repeating themselves but i cant figure out how

short hazel
#

(you didn't copy the URL after hitting "save" on the pastebin)

short hazel
#

Lines 62, 77: you increment i instead of n in your for loops!

#

The infinite loop occurs because n < userRuntimeDeck.Length always, since n does not change.

stuck palm
#

@short hazel

#
void SelectFirstItem()
    {
        if (!EventSystem.current.currentSelectedGameObject) {
            var child = mainButtons.gameObject.GetComponentInChildren<Selectable>();
            if (child)
                child.Select();
            print(child.name);
        }
        else
        {
            if (!EventSystem.current.currentSelectedGameObject.activeInHierarchy)
            {
                var child = mainButtons.gameObject.GetComponentInChildren<Selectable>();
                if (child)
                    child.Select();
                print(child.name);
            }
        }
        currentSelected = EventSystem.current.currentSelectedGameObject;
    }
#

i had this code line

#

it seems to be selecting play then moving to the new gameobject?

#

even tho its called after the gameobjects are set active

#
public void OpenOptionsScreen()
    {
        mainButtons.SetActive(false);
        optionsScreen.SetActive(true);
        SelectFirstItem();
    }
#

so i dont understand this

short hazel
#

Hm I don't remember if SetActive() effects immediately, but if it only applies on the next frame, then the event system may still see the object as inactive at the time it's activated

stuck palm
#

that is critical

short hazel
#

Can you try turning that piece of code into a coroutine, and placing a yield return null; before SelectFirstItem();?

stuck palm
short hazel
#

In OpenOptionsScreen, on the line before you call SelectFirstItem()

stuck palm
#

okay will truy

atomic sierra
#

how do i get better at fixing my own bugs rather than waiting and relying on the responses of others?

stuck palm
atomic sierra
#

cuz im stuck on this 1 frustrating bug right now but i dont want to take the time to record it, screenshot the code, and wait for people to respond to help me out.

it makes the whole process of just learning seem slow

slender nymph
atomic sierra
#

so should i quit on this project or remake it enirely?

#

i mean i dont have that much done but is that the best i can do?

slender nymph
#

asking for help is part of learning. you can't get better if you don't learn from your mistakes. so if you just give up you won't have learned anything from whatever issue you are facing and will therefore not have had the experience of fixing it to rely on next time you face a similar issue

atomic sierra
#

ok then

#

i might as well post my issue here

stuck palm
#

@short hazel okay even if i do a coroutine and wait for 1 second it still selects play what is happening 😭

short hazel
#

Ah, because in SelectFirstItem you search components under mainButtons which is not where your slider is, from what I see of the Hierarchy

#

Can you try just doing like you had before with slider.Select()? But still using the coroutine

brave acorn
#

been working on a small 2d pixle art style game in unity for about a week now, I have a small map, player, idel, walking, jumping and falling animation, along with one enemy a slime, I also have a health bar, but since im still new ive think im not properly doing things, my game works but the health bar over the enermy isnt reacting to the player inpact, and its just static empty off the start. I have a couple of screen shots of all my, scripts and interactive sprites if somone would be willing to tell me what i could possibly be doing wrong and why this not working the way i want it too

random ether
#

guys ive made a rigid body based character controller and have added a slide mechanics that adds a constant force to the player when sliding. For some reason it doesnt conserve momentum the the player just stops after the slide. How to fix

short hazel
#

@stuck palm
If that doesn't work, change how your system works. Add a script on the object you want to activate when the menu is enabled, and just add this in the class:

private void OnEnable()
{
    if (TryGetComponent(out Selectable s))
        s.Select();
}

This will find the first Selectable on the same object and if it exists, select it.
It's half past by midnight so I'm logging off, you can still ping me for updates but I'll see them later tomorrow (today? lol)

soft kernel
stuck palm
short hazel
#

Yes

stuck palm
#

i thought it just ran once

stuck palm
random ether
# soft kernel do you move the player using velocity?

yes: void Move()
{
Vector3 currentVelocity = rb.velocity;
Vector3 targetVelocity = new Vector3(move.x, 0, move.y);
targetVelocity *= speed;

    //Align Direction
    targetVelocity = transform.TransformDirection(targetVelocity);

    //Calculate forces on player
    Vector3 velocityChange = (targetVelocity - currentVelocity);
    velocityChange = new Vector3(velocityChange.x, 0, velocityChange.z);

    //limit force (just in case)
    Vector3.ClampMagnitude(velocityChange, maxForce);

    rb.AddForce(velocityChange, ForceMode.VelocityChange);
}
short hazel
random ether
#

this is the move function

short hazel
# brave acorn

Please embed !code as per the instructions below - this is very hard to read and not practical to copy-paste from!

#

!code

#

Ah, bot is ded

brave acorn
#

whats that?

short hazel
brave acorn
#

first time on thsi dis

#

alr

#

!code

random ether
#

ii have no idea why the momentum isnt being conserved

#

is it because movement is interupting or sm?

short hazel
# brave acorn !code

A bot usually responds to this, but seems like it's asleep like I should be rn

soft kernel
#

is this for movement or sliding?

random ether
#

this is sliding: private void StartSlide()
{
sliding = true;

    playerObj.localScale = new Vector3(playerObj.localScale.x, slideYScale, playerObj.localScale.z);
    rb.AddForce(Vector3.down * 5f, ForceMode.Impulse); //adds downward force so player comes to ground quicker

    slideTimer = maxSlideTime;
}
#

private void SlidingMovement()
{
Vector3 inputDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;

    Vector3 slideDirection = orientation.forward;
    slideDirection.y = 0f;



    //rb.AddForce(inputDirection.normalized * slideForce, ForceMode.Force);
    rb.AddForce(slideDirection * slideForce, ForceMode.Force);

   
    slideTimer -= Time.deltaTime;
    
    if (slideTimer <= 0)
    {
        StopSlide();
    }
#

sliding movement adds the force

brave acorn
soft kernel
#

you add force in the direction you wanna move?

soft kernel
random ether
random ether
#

as well as set the sliding boolean to false

amber basin
#

Okay big news. My reset button ACTUALLY works now but Going from being in a level, hitting pause, going back to the main menu, choosing the same level aaaaaaand it is still broken

#

No clue why xD

stuck palm
#

@short hazel still doesnt seem to work,

#
public class SelectOnEnable : MonoBehaviour
{
    private void OnEnable()
    {
        if (TryGetComponent(out Selectable s))
            s.Select();
        print(s.gameObject.name + "selected");
    }
}
#

i've made this class that selects on enable

#

applied it to my play button and my volume one, and it still doesnt seem to work

#

so extremely annoying for just a simple menu open

#

anyone else got a different implementation for menu changes?

void thicket
stuck palm
void thicket
stuck palm
void thicket
#

Can you post the slider’s inspector

stuck palm
#

one sec

stuck palm
void thicket
stuck palm
#

might just use a home page from the asset store tbh

sly wasp
#

whenever I do
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "jetpack")
{
if (!isJetpackActive) { }
{
StartCoroutine(Jetpack());
}
}
if (collision.gameObject.tag == "gatesCam")
{
cam.GetComponent<Animator>().Play("Gates", -1, 0f);
}

}

it doesn't do anythin, and I am unsure how to fix it
The collider has is trigger on, the gameObject has collision components

void thicket
void thicket
#

Only slider has issue?

stuck palm
hallow acorn
#

hi could somebody help me with fixing my diagonal movement? its always faster then the horizontal or vertical movement

void thicket
hallow acorn
stuck palm
hallow acorn
#

its really that easy?

void thicket
stuck palm
north drum
#

help I am trying to make it so that when I walk up to something and look at it and press "E" it activates an animation but I dont know howe to code it so that it activates the trigger I set up in the animation tab
my code:https://wtools.io/paste-code/bUEJ

#

the trigger is called "press"

summer stump
modest sierra
#

Is there a reason on why I shouldnt organize my code to have 2 lines put together into 1 line?
Test line 1; test line 2;
rather than

test line 2;```
modest sierra
#

Cool

summer stump
#

You SHOULD have it as two lines

stuck palm
modest sierra
#

cause it saves space

#

oh

stuck palm
#

dirty but gets the job done

summer stump
#

Definitely have it as two lines

modest sierra
#

Is there a difference though?

summer stump
#

Space saving is incredibly unimportant.
Readability is pretty much THE most important part of coding. Even more than performance to a certain point

modest sierra
#

Ok

summer stump
#

And the former is WAAAAAY more readable than having stacked up variables for no reason

modest sierra
#

In this scenario, since both lines do similar things, I thought I could combine em (the top line)

summer stump
#

To the compiler, there is no difference though

modest sierra
#

fine, then Ill keep it separate

summer stump
#

Always favor saving horizontal space over saving vertical space

#

I even split long statements vertically

modest sierra
#

ok

#

Im reworking my 214 lines of code to be more optimized and simpler to read

#

so yeah, just askin

summer stump
modest sierra
#

I already combined the position and rotation thingy

modest sierra
#

still a lot of mess

summer stump
#

Fair.
It's an ongoing process for sure

modest sierra
#

And a lot of it is ineffecient atm

#

Many lines of code that could be simpler being shorter

#

Hence why Im rewriting it with the new knowledge I have on what Im trying to achieve

#

I shouldve planned out my goal tbh

summer stump
#

Keep in mind that lines of code and line length have no affect on actual efficiency at all.
The compiler is going to rewrite it multiple times anyways

#

It's only the personal efficiency of being able to read it

#

And understand it six months later

modest sierra
#

Well yeah, but keeping the lines shorter also helps with readability in a way

summer stump
#

But yeah, refactoring as you gain new knowledge is gonna happen a loy

modest sierra
#

theres less area to look for

summer stump
# modest sierra theres less area to look for

Ehhh, it CAN sometimes.
But often making things longer with more descriptive names and clear separation is more readable.
But then you can hit a point where is is just spaghetti of course

#

It's a balance

stuck palm
modest sierra
#

I had this at first

grabbedObject.transform.rotation = grabTransform.transform.rotation;```
which I then changed to
```grabbedObject.transform.SetPositionAndRotation(grabTransform.transform.position, grabTransform.transform.rotation);``` since most of the 2 lines are the same anyway
summer stump
#

Yeah, that is a fine change. I would write it like this usually

grabbedObject.transform.SetPositionAndRotation(
  grabTransform.transform.position, 
  grabTransform.transform.rotation);
#

Which brings it up to three lines hahaha

modest sierra
#

Guess we view it differently

#

The way you just described would honestly make me more confused 😅

summer stump
#

Yeah, once you have been doing it a decade or so, you just find that scrolling or jumping up and down is easy af, and panning horizontally is a pain

Or you might assume you know what the cut off code says, which is super dangerous.

modest sierra
#

I tend to use a lot of booleans when I dont have to

#

Like when I can just say example != null

#

rather than example == true

north drum
#

this has been bothering me for a very long time and I think its pretty basic

wicked cairn
north drum
#

im not trying to make an object a trigger im tryuing to make pressing a button activate an animation trigger

rocky canyon
#

you mean a Trigger parameter within the Animator?

north drum
rocky canyon
#

you just access the animator and change the trigger..

north drum
#

im js trying to bind it to a key

rocky canyon
north drum
#

I have something really similiar to this

#

i acctually have this exactly

rocky canyon
#

if(Input.GetKeyDown(Keycode.Space){ ^ }

north drum
#

its giving me an eror

rocky canyon
#

well whats the error say?

wicked cairn
north drum
#

the error is the toilet variable hasnt been assigned but I assigned it in the inspector and its still not working

wicked cairn
#

Public void Interact() won’t work it needs to be “public void Update()”

rocky canyon
#

^ yea unless ur calling Interact(); in your update loop that code isnt even running

north drum
#

oh ok one sec

#

ill js move it to the void update

rocky canyon
#

Update is a prebuilt function that gets called by Unity automatically every frame

#

changing its name broke that feature

north drum
#

ok but wait now it wants me to delete

#

interact()

#

I get that

#

but wont it make it so that pressing e activates the trigger

#

at any time

sly wasp
north drum
#

im tyring to make it so when I look at the object

#

not js anytime

rocky canyon
#

that would require a bit more logic..

#

like a bool u enable when looking at it..

#

looking at it -> set bool to true

in update
if(pressbutton){
chck if lookin at it is true then allow code}

north drum
#

ok wait I think i fixed it

#

so when pressing e

summer stump
north drum
#

the animation sets

#

but now

#

the animation itself

#

is different then the one I created

#

and its breaking the object entirely

#

but I can see it transitioning in the animator tab

sly wasp
#

i wasnt 100% sure on that

willow relic
#

I don’t understand

north drum
frosty lantern
#

I have an enum that I am using for the validation of chess moves::

    public enum colorPiece { Dark = -1, Light = 1 };

    if ((int)BitBoard.positions[position + (move * (int)color)].color * (int)color == 1)
{
    valid = false;
}

the goal with the if statement is to prevent cannibalism, by getting the color of the piece in the projected square, multiplying it's color by the pieces color. If you get 1, [(-1x-1) or (1x1)] the move should be marked invalid before continuing on. this check works on the white pieces, but it doesn't work for the black pieces.

#

I swapped to directly test equality:

if (BitBoard.positions[position + (move * (int)color)].color == color)

and it still doesn't work, so it's not a math issue

deft grail
frigid sequoia
#

There is no way of modifying an audio clip speed straigh out in Unity right?

#

Cause I kinda need some audio to match out an animation on a very precise manner

summer stump
#

Otherwise you need a 3rd party solution

rocky canyon
#

ya, or setup uir animations to be exact

#

w/o unknown transition speeds

torn edge
torn edge
#

idk it just doesnt clamp the value

#

when i play the game, the value goes past 20

#

and when it goes into the negatives, it automatically resets to 90 degrees

covert cairn
#

What happens when you debug.log the newrotation float

torn edge
north drum
#

I am trying to make it so that whern I press E when my camera collider meets my object that it actives an animation in the already settup animator
I have set up a tirgger that activates the animation properly and am trying to get it when I press E when the camera collider meets the object that it activates the trigger
but for some reason it refuses to activate the trigger
https://wtools.io/paste-code/bUEN
WEB Tools
df csharp code
using System.Collections; using System.Collections.Generic; using UnityEngine; public class pooplol : MonoBehaviour { public Animator T
Image
pls help ive been trying for too long

frosty lantern
summer stump
torn edge
#

uno secondo

deft grail
torn edge
#

sorry i wanted to try something else first

spiral narwhal
#

Does anyone know how I can fix this?

deft grail
spiral narwhal
#

This doesn't seem to make sense

frozen burrow
#

A friend and I have been working on a wall slide that occurs when you press against a flat surface of an object (wall), if I'm wall sliding on the rotation the object is facing, I wall slide just fine, but whenever I try to wall slide on any other wall that faces a different direction, the character goes crazy trying to face the object's orientation. Is there a way to take the rotation or orientation of the face instead of the object? Does anyone have any insights on how I can handle this?

deft grail
eternal falconBOT
spiral narwhal
#

Hm after some reading it seems C# does not support covariance for arrays..

polar acorn
# spiral narwhal

You need to create a new array of GameActions, you can't just put the curly braces. var[] array = new var[] {a, b, ...};

polar acorn
#

Doesn't matter

spiral narwhal
polar acorn
#

You're specifying the default value of a property

#

So you need to actually create the array to put the values in

spiral narwhal
#

Tbh, that's the most convoluted syntax I've ever heard of

#

You mean create an array somewhere in the constructor and then assign that to the property?

polar acorn
#

You create the container, then you can use the {} syntax to populate it

spiral narwhal
#
        [ItemNotNull]
        public GameAction<IActionArgument>[] GameActions { get; } =
        {
            new AttackGameAction(),
            new MovementGameAction()
        };
#

How

timber tide
#

new

whole idol
#
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class next_level : MonoBehaviour
{

    public TMP_Text text;
    public GameObject m_clone;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter2D(Collider other)
    {
        if (other.tag == "NextLevelTag");
        {
            Debug.Log("Player passed through a pipe, score + 1 ");
        }
    }
}

Doesn't OnTriggerEnter2D need to be inside of Update()? Otherwise how else would it be called?

spiral narwhal
deft grail
whole idol
#

I got this error rn

spiral narwhal
whole idol
frosty lantern
deft grail
#

which shouldnt be there

summer stump
spiral narwhal
frozen burrow
# deft grail show the code !code

This section in the Player Movement handles the wall slide script:

if (wallCheck.wallD.z < 0f && currentMovement.z > 0f  currentMovement.z < 0f && wallCheck.wallD.z > 0f  currentMovement.x > 0f && wallCheck.wallD.x < 0f || currentMovement.x < 0f && wallCheck.wallD.x > 0f)
        {
            correctD = true;
        }
        else if (isMovementPressed){
            correctD = false;
        }

        if (wallCheck.isWall && currentMovement.y < -0.1f && isMovementPressed && correctD && isFalling && !wallSlide)
        {
            wallSlide = true;
            currentMovement.x = 0;
            currentMovement.z = 0;
            currentMovement.y = 0f;
           // transform.rotation = 
        }

        if (wallSlide == true && correctD == false) {
            wallSlide = false;
        }

And this one handles the Wall Detection for the player:

public class WallDetection : MonoBehaviour
{
    public bool isWall = false;
    public Vector3 wallpos;
    public Quaternion wallrot;
    public Vector3 wallD;


    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Wall") {
            isWall = true;
            wallpos = new Vector3(other.transform.position.x, other.transform.position.y, other.transform.position.z);
            wallrot = Quaternion.Euler(other.transform.rotation.eulerAngles);
            wallD = transform.forward;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Wall")
        {
            isWall = false;
            wallpos = new Vector3(0,0,0);
            wallrot = Quaternion.Euler(0,0,0);
            wallD = new Vector3(0, 0, 0);
        }
    }
    private void Update()
    {

    }
}
whole idol
frosty lantern
summer stump
spiral narwhal
frosty lantern
spiral narwhal
#

What suggestion?

whole idol
#

btw does anyone know why i get this?

polar acorn
spiral narwhal
#

It's @frosty lantern 's suggestion

whole idol
#

I have a prefab named pipes and inside of pipes I have an insivisible boxcollider item On Trigger, which is supposed to Debug.Log on the terminal that the player has officially passed on to the next level and will print a message on to the terminal

polar acorn
frosty lantern
whole idol
#
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class next_level : MonoBehaviour
{

    public TMP_Text text;
    public GameObject m_clone;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "NextLevelTag")
        {
            Debug.Log("Player passed through a pipe, score + 1 ");
        }
    }
}

deft grail
spiral narwhal
#

No this is the current version in my script:

        [ItemNotNull]
        public GameAction<IActionArgument>[] GameActions { get; } = {
            new AttackGameAction(),
            new MovementGameAction()
        };
#

Because of prettier

#

It automatically removes the unnecessary stuff

polar acorn
spiral narwhal
#

There is nothing it suggests though

frosty lantern
spiral narwhal
#

Nevermind my IDE, can you just tell me the syntax that allows me to initialise those two IActionArguments please?

polar acorn
spiral narwhal
#

Yes

#
    public class AttackGameAction : GameAction<AttackActionArgument>
#
    public class AttackActionArgument : IActionArgument
    {
    }
#
public abstract class GameAction<T> : IActionBehaviour<T> where T : IActionArgument
#
public interface IActionBehaviour<in T> where T : IActionArgument
timber tide
#

for the sake of testing, maybe forget the auto property for now and see if you can throw those into an array you initialized

void thicket
polar acorn
spiral narwhal
north kiln
#

I don't see how AttackGameAction is an IActionArgument at all Ah, I missed the wrapping type

spiral narwhal
#

It is not

#

It is a GameAction<AttackActionArgument>

void thicket
whole idol
spiral narwhal
void thicket
spiral narwhal
#

So how do I go from here

whole idol
spiral narwhal
#

I just want an array of multiple objects that inherit from GameAction and implement IActionArgument

#

That's all I'm asking for, C# 😭

void thicket
spiral narwhal
#

Ok

#

I'll try around a bit, thanks everyone

whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Xml;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
using static UnityEngine.RuleTile.TilingRuleOutput;
using UnityRandom = UnityEngine.Random;

public class Creator_Destroyer : MonoBehaviour
{
    public GameObject whatIstoBeDestroyed;
    private GameObject m_clone;
    //public TMP_Text scoreText;

    public float DestroyWhenReachesThisXPosition = -15f;
    // Start is called before the first frame update

    public float _timer = 0; //we need a time slowdown to slow the speed of generating new obstacles in our game
    public float when_timer_should_stop = 2f;

    Vector3 pipeSpawnVector;

    private float speed;
    private void Start()
    {
        

        cloneInstantiator();
        Vector3 pipeSpawnVector = new Vector3(7.73f, UnityRandom.Range(-3.15f, 3.3f), 0);
    }
    private void Update()
    {
        Check();
        _timer += Time.deltaTime;

        speed = _timer * 2.1f ;

        m_clone.transform.Translate(Vector2.left * Time.deltaTime * speed);
    }
    private void Check()
    {
        if (_timer >= when_timer_should_stop)
        {
            _timer = 0; //reset
            Destroy(m_clone);
            cloneInstantiator();


        }
    }
    void cloneInstantiator()
    {
        float randomY = UnityRandom.Range(-3.15f, 3.3f);
        m_clone = Instantiate(whatIstoBeDestroyed, new Vector3(7.73f, randomY, 0), transform.rotation);
    }

    /*
    void Check_If_Player_Passed()
    {
        float localXPosition = m_clone.transform.localPosition.x;

        if (localXPosition < -20)
        {
            float.Parse(text_score) += 1;
        }
    }

    */
}

#

Is there any way I could shorten this?

void thicket
#

First keep your coding convention consistent

void thicket
#

What is pipeSpawnVector for?
Is there a reason that spawner is responsible for moving and destroying? Otherwise you can split them into separate script and attach to spawned object.

whole idol
#

I dont want it to attach to a spawned object

#

I tried that many ways and it always creates exponential amount of spawnable objects

modest sierra
#

Doesn't c# compile the code?
Unity just behaved differently after I swapped 2 lines of code that should be runnning at the same time

frosty hound
#

Code doesn't run at the same time, it runs line by line

modest sierra
#

Then what is compiled vs interpreted?

#

I though interpreted was the line by line one

modest sierra
#

Not saying that I dont believe you or that you are wrong, Im just newish to coding

frosty hound
#

Are you asking this in the context of Unity?

modest sierra
#

Yes

#

Oh

#

So Unity reads it line by line?

slender bridge
#

I'm sensing your question has nothing to do whether or not c# is compiled or interpreted.

whole idol
#

Anyway, does anyone know why this script that I got fails to debug.log that my player has touched the invisible line that is supposed to tell whether or not I went through a pipe?

Eventually this invisible barrier is supposed to let me know and update text automatically

modest sierra
whole idol
frosty hound
#

Unity is single threaded, so it it will go line by line. You can look into DOTs if you need something otherwise, but that isn't something a beginner should even begin to consider.

modest sierra
#

Ill do a bit more research on that though, seems interesting

whole idol
#

btw this is the code...

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

public class next_level : MonoBehaviour
{

    public TMP_Text text;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "NextLevelTag")
        {
            Debug.Log("Player passed through a pipe, score + 1 ");
        }
    }
}

slender bridge
slender bridge
#

is your collider on the next level line set to istrigger ?

whole idol
#

On the level: yes, on the player: no

eternal needle
modest sierra
#

Im a year-ish in

#

I have tackled DOTs before with tutorials

whole idol
modest sierra
#

But Im no where near proficient with C#

summer stump
modest sierra
#

aight

summer stump
# whole idol

Show the collider gizmo
The collider component was also collapsed, which is pretty unhelpful

whole idol
#

and here's what it looks like if I turn the Sprite Renderer on

#

its a big fat pipe

frozen burrow
summer stump
# whole idol

No need for the renderer component at all if it's invisible.

But anyways, is the player rigidbody dynamic? Or kinematic?

slender bridge
#

Put a debug log outside of the if statement and see if any trigger is happening. If it is, then i would ask if you have saved your scene since making that tag in the inspector.

frozen burrow
whole idol
#

and don't see a difference

#

Perhaps what is wrong is the way this OnTriggerEnter2D() is structured?

slender bridge
#

you should be using other.CompareTag("NextLevelTag"), but can you put a debug log outside of that if statement, run the game, and see if anything else is firing off ? like Debug.Log(other.name)

#

Also i could be wrong but it looks like the class name on that script doesnt match the class name of the file name

rich adder
#

its fine just horrible convention

whole idol
#

its pretty much the same except my convention

summer stump
whole idol
#

yeah I just realized that

summer stump
#

But try .CompareTag I guess

whole idol
#

it doenst move if its Kinematic

#

yeah im trying that rn, doesnt work either unfortunately

slender bridge
#

show me the file name of that class in your project folder, can you at least verify your start method can log a line out ?