#💻┃code-beginner

1 messages · Page 822 of 1

rich adder
#

based on what?

brave token
#

what i mean is that when the player moves the mouse down, i want the sphere to roll forward.

rich adder
#

look how you did rotation

kindred prairie
#

i be back in a bit just gotta go out ok

#

need to get food

rich adder
#
var newVel = collision.relativeVelocity.normalized * moveSpeed
rb.linearVelocity = newVel;
//or rb.AddForce(newVel)```
kindred prairie
#

So what should I do or replace

rich adder
#

the solution is simple, you set the bool true when moving or flase if not moving

#

like the original docs shows you do it just using a blend tree and based on inputs value

#

the isMoving is valid to add, just redundant

kindred prairie
#

Whst u mean redundant

#

The line 29 should I do animator.SetBool("isWalking", true/false);

#

Would that fix it

rich adder
#

ideally..it has to be based on something...

kindred prairie
#

What you mean

#

Could you elaborate

rich adder
#

is how bools are usually used... based on some condition

kindred prairie
#

Right

rich adder
#

so what is the condition that sets it to true or false in animator

kindred prairie
#

On the animator it says the book is isWalking from idle to walking mode is true then walking to idle is false

rich adder
#

in the code not the animator

kindred prairie
#

What line on the code

polar acorn
#

So if you set isWalking to a specific value, it's going to go to that value every frame

kindred prairie
#

Sorry for being so stupid

kindred prairie
#

And not true or fake

#

False

polar acorn
#

Do you want a number or do you want a boolean

kindred prairie
#

What’s a boolean

polar acorn
#

look it up

rich adder
#

I think you might be trying to run before learning to crawl and thats whats messing you up

kindred prairie
#

Sometimes yt helps but this animation way isn’t helping lol

rich adder
#

yt itself doesnt matter its what you looking up that does.
You need to start from the ground up, you're juggling multiple different things at once

polar acorn
#

not just windmill slam someone else's code into your project without reading it

rich adder
#

c# basics first, then unity starter learner path

#

check pins in this channel

static laurel
#

Yoo

#

I just started learning Unity and I'm making my first project, I'm really confused on something.

#

I have no clue how to use it. I've tried searching online for vids on it, but I can't find anything honestly. Sorry, I'm really new to Unity and I'm a huge noob lol.

#

I'm also using Unity2d, so I don't know if this is only a Unity3d specific thing too.

grand snow
polar acorn
static laurel
#

Oooh okay, I see.

grand snow
# static laurel Oooh okay, I see.

Perhaps a full game course is what you should start with https://learn.unity.com/course/2d-beginner-game-sprite-flight

Unity Learn

In this course, you’ll build a 2D game in Unity — starting from a completely blank project with no assets provided, you’ll create the entire game from start to finish. In the game, you fly a simple triangle-shaped ship using mouse clicks (or screen taps on mobile). Your goal: stay alive for as long as you can by dodging flying obstacles wh...

static laurel
# polar acorn This just generates the mathematical concept of a rect. If you want one that's v...

Interesting, okay. I'm using something called a 2d primitive rectangle primitive https://docs.unity3d.com/6000.3/Documentation/Manual/2DPrimitiveObjects.html#square which kind of gets me what I want, actually.

I guess I'm basically trying to find a way to change the width/height of that white square primitive sprite, essentially. The closet thing I see to that is changing the values of transform scale, but I'm not sure if that's the same thing as width and height.

static laurel
polar acorn
#

Yes, you'd probably be changing the scale. Keep in mind that the scale is in world units, not pixels. Sprites have a "pixels per unit" value you can use if you want to do some math to get specific pixel sizes

grand snow
#

^ yes scale is the way

static laurel
#

Oooh okay, so scale is essential that.

#

That makes so much sense. The naming was really through me off, got it.

polar acorn
#

It's called "Scale" instead of "Width/Height" because you're not always dealing with basic geometric shapes

static laurel
#

I see, yeah.

#

Thank you

#

I also notice that when I put the scale value of y to 0 (essentially, making the "width" of my rectangular sprite to 0), the rect kind of disappears from the whole scene.

#

Instead of having the rectangle "squash into itself" like this image here which is really what I'm going for.

#

I can take a vid of what I mean

grand snow
#

Sorry why do you think a web canvas acts the same as unity?

#

This is expected behaviour

static laurel
#

Because they're both using width and height, right?

grand snow
#

NO

static laurel
#

Like it's the same thing.

#

Oooh

#

Interesting

grand snow
#

the js rect is being nice and still drawing a border

#

0 scale smushes the mesh together meaning nothing is visible

naive pawn
#

scale and size are not the same thing

static laurel
#

Oh, they're not the same thing? That makes so much sense.

naive pawn
#

eg doubling the size keeps the same border, but doubling the scale makes the border twice as large

static laurel
#

Yeah, I'm definitely trying to get the size or whatever parameter there is in Unity to get the outcome above.

naive pawn
#

maybe a 9-sliced sprite with an Image?

#

a recttransform does have a size

static laurel
#

rect transform... Going to Google that

naive pawn
#

this is unity ui stuff

grand snow
#

no no dont use that

static laurel
#

That may sound like that's what I need.

#

Oh, no?

naive pawn
#

i don't know what the overall goal here is though so my suggestion is without context

grand snow
#

Sprite pixels per unit, transform scale and camera orthographic size all matter here

naive pawn
#

@static laurel what's the overall goal here? kinda feeling like an x/y problem

grand snow
#

The unity default cube sprite should be 1 unit wide by 1 unit tall. Here we can take the camera ortho size into account to make it be a certain size on screen (if thats the goal)

static laurel
naive pawn
#

right so that's the Y

#

what's the X

#

what's the overall goal here

static laurel
#

I can actually video it because it's hard to explain lol

#

Give me a sec

grand snow
#

Sounds to me like you want a border around a sprite

static laurel
#

Kind of...

#

Here

#

So I'm basically making my own "bar fill animation" by having one rectangle and then having another rectangle overlayed on top of it with a height of 0, so that the first rectangle kind of starts at the "bottom" of the second rect.

#

Then I want the hright of the first rect to gradually increase until reaches the full position of the rectangle that its overlaid over. It sounds so weird but this is a vid of what I'm going for

naive pawn
#

is this a gameplay thing or a ui thing

static laurel
#

gameplay thing

#

I'm going to build upon it with special effects, particles, etc.

grand snow
#

Perhaps world space UGUI (ui) would be best

naive pawn
#

what's it supposed to be

static laurel
#

That's why I'm trying to find the "height" attribute of these rectangles in Unity and I was very suprised when I couldn't find anything online for it.

grand snow
#

its not a rectangle

naive pawn
sour fulcrum
static laurel
# naive pawn what's it supposed to be

I'm trying to make a bottle that "fills up" with water once droplets makes contact with the rim. You can kind of see the bottle sprite over to the right there and essentially I want to simulate that before in the vid, but in a whole grid system, then I'm going to make that grid extremely small, place the grid inside of the bottle, and then kind of simulate a water bottle/flask filling up with liquid.

naive pawn
#

ok, this is the X

static laurel
#

That one tile is an example of one rect out of a whole grid that I'm trying to get working first. Like get the idea down

grand snow
#

You can do this by scaling a sprite just fine, it just needs maths

naive pawn
#

for future reference, when i brought up x/y problem and asked "what's the overall goal here", the correct answer is just this part

I'm trying to make a bottle that "fills up" with water once droplets makes contact with the rim.

grand snow
#

It will be harder because the default square has its pivot in the center

static laurel
#

Not that good at math, but I can see if I can figure it out

naive pawn
#

i don't think scaling would be appropriate here tbh, it'd mess up the actual sprite once you have one

static laurel
#

Yeah

naive pawn
#

you could probably scale a spritemask

#

that seems.. subpar though

#

just use that

#

i forgot SpriteRenderer had these

static laurel
#

Oh sweet, I'm going to check this out.

#

Find some vids on it

naive pawn
#

those 2 modes work similarly, just depends on if the graphic should tile or expand

static laurel
#

Sweet, I'm going to research what they do lol

naive pawn
#

i guess with intermediate water graphics in the middle you'd need it to tile

frosty talon
#

hi guys

static laurel
#

Oh yeah, but this is very beginner lol.

static laurel
frosty talon
#

any of y’all ever played gorilla tag games ? or anything like it? i’m a kinda young coder and i need help with my gane

frosty talon
#

it’s in prealpha

naive pawn
radiant voidBOT
# naive pawn !ask

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

polar acorn
naive pawn
#

apparently this is supposed to be a gameplay element

static laurel
frosty talon
#

sorry i just needed help

naive pawn
static laurel
polar acorn
naive pawn
static laurel
#

Ohh, I see.

sour fulcrum
#

aside from physics stuff

naive pawn
#

unity3d is one way to refer to the engine because the game engine is 3d
anything 2d in unity is just ignoring Z

#

there's no unity2d

static laurel
naive pawn
#

(but yes there are separate physics (3d) and physics2d sets of components because they link with different physics engines)

static laurel
#

That makes a lot of sense, thank you

#

I'm going to check this out.

static laurel
#

Actually, is it actually possible to make an animation for this? Like your own sprites, water sprites and stuff?

naive pawn
#

yes

static laurel
#

Oooh

naive pawn
#

the answer to "is it possible" without constraints is 99% of the time yes, since you just described it

static laurel
#

Makes sense lol.

#

I might try that, actually.

#

feel like it may be easier lol

fossil plaza
naive pawn
#

the second screenshot is unrelated

#

for the rest, socket hang up usually means a network issue

#

perhaps try a different network

wise cairn
#

hey guys so how do i make the textmeshpro input field's cursor thing move and have the text stay in place rather than the other way around? the cursor is stuck in the middle of the bar right now

naive pawn
wise cairn
naive pawn
#

check both

#

also this is a code channel

pseudo summit
#

im changing its position upwards each time i click W and it just phases through the solid colllider

sour fulcrum
#

changing position does not care about collision

#

because your changing, not moving

zealous flare
#

Quick question, if i have 5 guns in a game (for a rougelite), should i implement them with scriptable objects or normal mono behavior code for each gun ?

for example imagine the weapons in Megabonk, how would you implement them ?

sour fulcrum
#

depends tbh, most likely both but it depends on how comfortable you are with c#

zealous flare
sour fulcrum
#

the general idea is scriptableobjects are for knowing things and monobehaviours are for doing things (this is more of a guideline more than a strict rule)

this means you might have a scriptableobject asset and monobehaviour instance/component for each gun that are kinda siblings (one has the data, one uses the data)

because your guns do different things you would use inheritence to extend on these when neccasary

#

if you don't know what inheritance is and/or are not comfortable/familiar with it yet then that's probably the big knowledge gap your running into right now

zealous flare
sour fulcrum
#

performance is a complete non concern for anything related to this, don't worry

sour fulcrum
zealous flare
sour fulcrum
#

yes but via inheritance

#

it's something online stuff will teach you better than i would but it's a way of building off of other scripts

#

so you would have like

public class Gun : MonoBehaviour

public virtual void Shoot()
{
}
public class Shotgun : Gun

public override void Shoot()
{
}
public class GrenadeLauncher : Gun

public override void Shoot()
{
}

etc.

zealous flare
undone moss
#

hi guys, im new here, i just need help on how do i refrence a script or class in another class? all the resources i found were on different problems and didnt help.. SOMEONE SAVE ME AHHHH

slender nymph
undone moss
#

turns out i made the most hidden typo in history i quadruple checked and jsnow discovered so thanks anyways discord people

slender nymph
#

!ide 👇 make sure your IDE is configured so you don't make silly spelling mistakes

radiant voidBOT
stoic sage
#

!methods

radiant voidBOT
stoic sage
#

!functions

radiant voidBOT
stoic sage
#

Ig not

sour fulcrum
#

what don't you understand about them

cyan shoal
#

hi, I'm working on a small game where the player is on mars, and when he/she leaves their base, their oxygen goes down, and when they go into the base, the oxygen stops going down. I'm using StartCoroutine() to make the oxygen go down every few seconds. ```using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using TMPro;
using System.Threading;
using System.Collections;

public class PlayerOxygen : MonoBehaviour
{

public int maxOxygen = 100;
public int currentOxygen;

public oxygenBar oxygenBar;
public TextMeshProUGUI oxygenText;

public bool canBreathe;


void Start()
{
    currentOxygen = maxOxygen;
    oxygenBar.SetMaxOygen(maxOxygen);
}

IEnumerator LowerOxygenRoutine()
{
    while (true)
    {
        LowerOxygen();
        yield return new WaitForSeconds(5.0f);
    }
}
void Update()
    {
        oxygenBar.setOxygen(currentOxygen);
        oxygenText.text = currentOxygen + "%";
    }
void OnTriggerExit(Collider other)
{
    if (other.CompareTag("IsBreathable"))
    {
        StartCoroutine(LowerOxygenRoutine());
    }
}

void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("IsBreathable"))
    {
        StopCoroutine(LowerOxygenRoutine());
    }
}


// Update is called once per frame


void LowerOxygen()
{
    currentOxygen -= 10;
}

}

slender nymph
elfin pike
#

Is it worth reading "write great code"? How I understand it explains, how to write code with machine in mind.

stoic sage
naive pawn
#

use docs for that, not the bot

#

bot messages are related to interacting/asking/helping here

stoic sage
#

Ah

#

Ight

severe snow
sour fulcrum
#

A coroutine is fine for that

#

borderline preferable as with a little adjustment you could remove update entirely from that script

severe snow
#

you could do something like:

if (drainOxygen)
currentOxygen -= drainrate * Time.deltaTime
currentOxygen = Mathf.Clamp(currentOxygen, 0, maxOxygen)

#

not at my pc but along those lines

sour fulcrum
#

thats not the same behaviour

#

you could do that sure but it is a different thing

severe snow
#

so its important that the oxygen is lowered by a certain amount in this case? like 10 every 5 seconds something?

sour fulcrum
#

i mean i don't know, which is kinda the point

#

if they want to do what they are doing then coroutines are a pretty fine way of doing so

severe snow
#

again can be accomplished in update using a float for timer, personally i would avoid using coroutines for this because as i think i can see, theres nothing that stops this coroutine being triggered multiple times and running simultaneously

#

for example if you walk between breathable zones,

#

you could have a flag to stop it but then, solved if it can only happen once in the update loop

sour fulcrum
#

which is a fair point, but not neccasarily a reason to not use coroutines, thats just two more lines of code to fix

burnt vapor
#

Better to just fix the Coroutine than to suggest a refactor because it would be better

#

Especially for a beginner

#

Because sure, it would be better. But their case is also very much valid and only missing a step to work

livid anchor
#

Can I write that in C# ?

RunnerEventSystem.OnFlyUp += () => _isFlying = true;

And if yes, how do I unsubscibe the event afterward ?

verbal dome
#

Your IDE probably has a quick action to convert the lambda into a method

#

So then you'd have

// Sub:
RunnerEventSystem.OnFlyUp += StartFlying;
// Unsub:
RunnerEventSystem.OnFlyUp -= StartFlying;```
cyan shoal
#

it was easy, I just had to add a few things.

west ridge
west ridge
cyan shoal
#

hi?

west ridge
cyan shoal
#

I don't really accept DM's dude, sorry 🙁

west ridge
verbal dome
#

If you need unity help, ask here (or in another appropriate channel)

west ridge
cyan shoal
livid anchor
#

I have a weird bug in the animator... I start on a walk animation then after some time trigger a run animation, but it then revert instantly to walk right after run has played once

obtuse yoke
livid anchor
livid anchor
#

Then how do i handle that issue ?

obtuse yoke
#

actually i'm wrong -and you're correct if the exit time is unchecked and you have no additional conditions, it will be ignored...

#

so, it's more than likely, your trigger is being triggered multiple times/frames ?

livid anchor
#

It is not, it's called only in one place and I've checked that it's not called wrongly. Plus I just tested with booleans instead, and in that case it works normally

obtuse yoke
obtuse yoke
livid anchor
#

I have put a debug log before the trigger, it is not caaled wrongly

obtuse yoke
#

..the reason i ask what's calling it, is.. things like 'behaviors' or statemachinebehaviors are called multiple times per frame... unlike monobehaviors

livid anchor
#

I have an event called "On StartWalk" or something like that, that calls the trigger

alpine dew
#

Hey all, it's probably an implementation issue on my end but I've been trying to get the player's current speed by the rigidbody velocity magnitude, but for some reason even though the speed will reach a maximum and stay constant, the velocity keeps going up as long as movement persists. Any ideas for why that might be?** **

obtuse yoke
verbal dome
#

If you are using AddForce and there's no friction or drag/damping to slow you down then you will accelerate forever

alpine dew
#

now that you mention it, there isn't any linear damping for it

#

that probably has to do with it

obtuse yoke
#

..does anyone know how to get the URP render feature 'render objects' to work with transparent objects, to stencil them out?
-i've got it working fine with opaque objects but i'd like it to work with both transparent and opaque objects...
--Ok nevermind got it to work

alpine dew
dapper field
#

So I just found out a few hours ago I can’t serialize interfaces for dependency injection to the unity inspector, and I saw someone suggest online the use of abstract classes in its place.

public interface ICashDisplay
{
    public void UpdateText(int cash);
}

public class CurrencyDisplay : Monobehaviour, ICashDisplay
{
    [SerializeField] private TextMeshProUGUI text;
    
    public void UpdateText(int cash) => text.text = “Cash $” + cash;
}

public class SomeOtherClass : Monobehaviour
{
    [SerializeField] ICashDisplay cashDisplay; //this doesn’t show in inspector
}

//pretend the naming convention for interfaces applies idk what else to call it rn

public abstract class ICashDisplay : Monobehaviour 
{
    public abstract void UpdateText(int cash);
}

public class CurrencyDisplay : ICashDisplay
{
    [SerializeField] private TextMeshProUGUI text;
    
    public void UpdateText(int cash) => text.text = “Cash $” + cash;
}

public class SomeOtherClass : Monobehaviour 
{
    [SerializeField] ICashDisplay cashDisplay; //Would this serialize to inspector? Is it bad practice?
}

I’m not at my pc rn and can’t really test it myself, and I also want to know if it’s bad practice to do this (because of composition over inheritence, overengineering, I might need to inherit something else, all that)

#

trying to avoid tight coupling between some other class and a few other classes cause my code is spaghetti rn. Tryna fix it :(

teal viper
dapper field
teal viper
#

But yes, an abstract class should serialize.

dapper field
#

Is cheesing it like this bad in any way though?

teal viper
#

Not really. It depends on the specific case. As with the example you provided, there might be a better way.

#

It might be more difficult to replace with dummies for unit testing and such, if you plan to do that. Though, probably still easier than no base class at all. It's not entirely clear what your intention is behind using interfaces/abstract classes.

dapper field
teal viper
#

Well, in that case it might be way more useful to share an actual example of your code that you think needs refactoring.

#

Then we might be able to suggest an actually working solution.

sage mirage
#

Hey, guys! Is tehre a way to get reference to these color properties??

#

I thought maybe its color block struct

wintry quarry
sage mirage
#

oh Color32 struct

wintry quarry
#

It's just a Color

#

or Color32, sure

sage mirage
#

there is a struct called color32

#

yes

wintry quarry
#

Color and Color32 are essentially interchangeable.

#

Color32 just doesn't support HDR

sage mirage
#

I wanted RGBA and hexadecimal basically

#

oh hexa is not there

#

how to get reference to hexa

wintry quarry
sage mirage
#

So, its a static class and I was trying to find the property hexadecimal after declaring the field of Color Utility

#

So, I see there are some methods including this one ToHTML

#

from the class itself thanks!

#

ok, I think I am not sure how to use its methods XD

north sparrow
#

#base-unity

wintry quarry
#

To use a static method you just do this (ClassName.MethodName(...)):

string hexString = ColorUtility.ToHtmlStringRGBA(myColor);```
sage mirage
#

so I Store the value on a string?

#

Yes but

wintry quarry
grand snow
#

The method to parse from a hex colour is a tad different if that is confusing you

wintry quarry
#

or do whatever else you want to do with the string

sage mirage
#

lets say I want to get this specific value

sage mirage
#

oh, let me try

wintry quarry
#

if you plug that color into that function you will get the string "959595"

#

well actually this one includes alpha

#

so you'll get the alpha too

#

if you don't want alpha you should use the RGB version

sage mirage
#

There is TryParseHTML method

#

I think that one I need

#

Also, like I see there is a problem using ColorUtility itself because there is a class called ColorUtility on Unity.VisualScripting namespace, so I have tried using the UnityEngine one, I mean why they gave them the same name XD

grand snow
#

You need to explain what you actually want to do better 😐

sage mirage
#

No, I found a way

wintry quarry
sage mirage
#

UnityEngine.ColorUtility.TryParseHtmlString("959595", out Color color);

#

Thats how I did it

wintry quarry
#

Ok yeah if you're trying to go from the string to the color, you need the parse method

#

but you were saying you wanted to go from the color to the string

#

so which one is it?

grand snow
#

yea so you explained it soo bad you were told the opposite

wintry quarry
#

p.s. if you're just trying to hardcode a color with hex code 959595, you can do new Color32(0x95, 0x95, 0x95), you shouldn't parse a string here if it's hardcoded.

sage mirage
#

I got confused guys

#

I just wanted 959595 this color

wintry quarry
#

er actually

sage mirage
#

bascially the hexacdecimal only

grand snow
#

I think you have been told how to go both directions now so do as you need

grand snow
#

e.g. "#FFFFFF"

sage mirage
#

Oh I can do it this way as well

#

like praetor said

wintry quarry
#

really though... why not just define the color in the inspector? 🤔

grand snow
#

static was mentioned so who knows

sage mirage
#

Its a hovering effect

#

I will be calling pointer enter

wintry quarry
#
public Color hoverColor; // assign in the inspector

public void OnPointerEnter(PointerEventData evt) {
  // something using hoverColor
}```
sage mirage
#

I think

silent karma
#

Hey I’m metrix and I’m wondering if anyone can teach me how to code c++ our c# pls dm me if you can

grand snow
#

check the pins for c# learning resources. go elsewhere for c++

radiant voidBOT
polar acorn
#

You're not going to find a personal tutor here

silent karma
silent karma
marble hemlock
#

to clarify, i can have a script reference a scriptable object without that scriptable object being attached to some item, right?

#

like i can just have the data in a folder, and then directly have other scripts take the data from that scriptable object?

#

i want to make absolutely sure i'm understanding this right

wintry quarry
#

you can reference them from anywhere if they're assets, yes

#

that's the point basically

marble hemlock
#

feels a bit weird but thank you

#

i know i cant put it on game objects like monobehaviors but admittedly i havent used them a lot for more than like inventories

pseudo summit
#

Why doesnt this work

#

its not colliding with the oter thing even though both have box colliders

polar acorn
marble hemlock
#

my brain is struggling to comprehend scriptable objects i think

pseudo summit
polar acorn
pseudo summit
#

public class p1 : MonoBehaviour
{
public Rigidbody2D rb;
public float movespeed = 2f;
private bool bordersHit = false;

// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    if (Input.GetKey(KeyCode.W) == true && bordersHit == false)
    {
        transform.Translate(Vector2.up * movespeed * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.S) == true && bordersHit == false)
    {
        transform.Translate(Vector2.down * movespeed * Time.deltaTime);
    }
}

private void OnCollisionEnter2D(Collision2D collision)
{
    bordersHit = true;
    Debug.Log("Collided");
}
private void OnCollisionExit2D(Collision2D collision)
{
    bordersHit = false;
}

}

#

this is the code

radiant voidBOT
radiant voidBOT
polar acorn
#

DOUBLE KILL

marble hemlock
#

fuck

naive pawn
marble hemlock
#

i dont even know if what i asked just made sense, it doesnt even make sense to me

polar acorn
pseudo summit
polar acorn
#

You should probably never change data on a ScriptableObject for this reason - it can affect other objects using it

marble hemlock
#

and if i alter a value of that scriptable object through one of those references, they all get the update, right?

naive pawn
marble hemlock
naive pawn
#

show the set up

naive pawn
polar acorn
#

You shouldn't change data in an SO

pseudo summit
#

When i make it dynamic its getting affected by my push and being thrown

naive pawn
#

well yes, dynamic rigidbodies are simulated

pseudo summit
#

Im like COMPLETELY NEW btw so sorry if i say dumb things

marble hemlock
#

save/load are insanity im about to just have them restart the entire game and accept it

pseudo summit
#

how do if xi that

#

fix

naive pawn
#

non-simulated rigidbodies don't experience collisions

polar acorn
pseudo summit
naive pawn
#

there's a lot of ways depending on what you want to behavior to be

#

eg, if they should not collide, set up the layers to specify that

pseudo summit
#

i just want a border thar can stop my movable object that cnt get pushed around

naive pawn
#

you're still leaving out a lot of context

#

it sounds like it's the moveable object that needs the rigidbody

pseudo summit
#

I have it only move on the y axis (its 2d btw if i forgot to mention) and whem it hits the border it also gets pushed and turned 🥲 @naive pawn

naive pawn
#

i guess apply constraints?

#

you're really not describing the goal and issue well

pseudo summit
pseudo summit
# naive pawn https://xyproblem.info

ok so basically i have a slider thing that i can move up and down but i want to set borders and when it collides with that border i want it to not be able to move that direction anymore so badically not be able to move past it

naive pawn
#

and what's the current setup

#

consider taking screenshots of the inspectors for each object

naive pawn
pseudo summit
#

Thank you constraints fixed it

midnight tree
#

Hello there!
Can somebody explain me what is the meaning of using IDisposable interface in !Unity! scripts? I just cannot find any good explain. Just ehh... event just invokes when game ends, right?

#

I would be very grateful

polar acorn
#

Presumably, when the game ends, it calls Dispose on anything that implements that interface at some point

midnight tree
#

Hmm
And in what cases is it useful to use it?

#

I mean I can write same interface myself at any time.

wintry quarry
#

i.e. when the object represents some external resource, not just an in-memory C# object

#

a file handle, a network connection, etc.

midnight tree
#

Oh, ok
Thanks❤️

wintry quarry
# midnight tree Oh, ok Thanks❤️

Just to expand on that a little bit - most C# managed objects get cleaned up automatically by C#'s garbage collector. But if we're talking about an unmanaged resource, i.e. anything not managed by the C# runtime, those things often need some special handling to clean them up. That's the point of IDisposable - it creates a common, known interface for cleaning up such external rsources. For example releasing a file handle, flushing any buffered bytes, closing network connections, freeing up unmanaged memory in C++ objects with explicit free() calls, etc.

verbal dome
#

The using syntax is quite handy with IDisposables. For example, I have a type GUIColorScope that temporarily changes GUI.color:

using(new GUIColorScope(Color.red))
{
    // Everything drawn here is red
    GUI.Label("Yo");
} // Dispose gets called here because the scope ends

// Everything drawn here uses the original color
#

GUIColorScope sets the GUI.color when it is constructed, and then reverts it back to the original value when Dispose is called

#

Idk if that's too complex - just wanted to show a practical example 😁

#

Also if an exception happens inside the scope, it will still call Dispose which is handy so you can always clean up resources.

midnight tree
#

No, I understand :)
I knew that, but I asked for examples that you use yourself.

#

Thanks :)

runic lance
#

I love this one for poolable collections

using var poolable = ListPool<Vector3>.Get(out List<Vector3> positions);
#

automatically returns the collection to the pool at the end of the scope

solar kettle
#

Hi all, I'm developing a multiplayer game that allows for a variety of game modes, and I'm unsure how to tackle this.
I want each game mode to have their own code for various events, as well as certain variables set, all handled through a game manager MonoBehaviour class, so I figured I would create an abstract Gamemode superclass, with the other gamemodes as subclasses of that.

Now I am wondering how to store these classes. Would it make sense to make something like a polymorphic array, using a Gamemode[] array, storing singletons of each gamemode, such that the game manager class can refer to a particular gamemode's code through an index, or is there a design pattern that makes more sense for my use case?

edgy tangle
solar kettle
# edgy tangle ScriptableObjects with Strategy Pattern seems like a good fit for this. Hard to ...

Ohh that sounds good - I haven't actually used ScriptableObjects at all, but I might need to look into that.

For context, my GameManager class just keeps track of various game data, such as which round it is, what teams are which etc. The gamemodes could be Deathmatch and Capture The Flag, where events such as "OnDeath" events would be handled differently depending on which gamemode is active

#

And so my initial idea was to have the aforementioned array, such that

Gamemode[] gamemodes = { new DeathmatchGamemode, new CaptureTheFlagGamemode }
int currentGamemode = 0;

And the game manager could call for example, gamemodes[currentGamemode].OnDeath();

toxic ledge
#

how can i learn to code becas ik i shudunt use ai olways

radiant voidBOT
cosmic quail
#

and the pinned messages in this channel

toxic ledge
hushed flame
#

Hello

cosmic quail
hushed flame
#

🙂

toxic ledge
hushed flame
#

I need your help. I need to know how to graffiti a wall. How to make it come out of the spray can. Could someone explain it to me? Or where can I find a video that explains it?

frosty hound
hushed flame
#

Which codes can I use? I've looked for tutorials but I'm still confused.

frosty hound
#

There is no bult in "codes"

#

There are many parts to making this feature, I'm not sure how you could expect anyone to give you a definitive step by step guide.

cosmic quail
frosty hound
#

I would start by looking up how to paint things onto a surface, if your graffiti needs to be player made (like look up a tutorial on how Splatoon does their stuff for example)

hushed flame
#

I simply need a video that's close to what I'm looking for.

frosty hound
#

Okay, and you want us to find it for you?

#

What makes you certain a video exists that does exactly what "ELMonoSabio" needs?

toxic ledge
hushed flame
#

Not much, I'm just compiling every video about how to paint in Unity. From there, I'm experimenting with each piece of code.

cosmic quail
#

and then start doing the junior programmer stuff

undone moss
#

hey guys, i keep getting the same null exception error even though everything is working fine, can someone help me get rid of this error?

solar hill
#

can you show us the error.

slender nymph
sage mirage
#

Hey, guys! I would really like to learn how to use Scriptable Objects. Can somebody recommend a video or a good tutorial on scriptable objects or even explain to me how I can work with it?

slender nymph
#

scriptable objects are really just a way for you to define your own type of asset, there's nothing super special about them that warrants an entire tutorial

sage mirage
#

How I am supposed to start learning how to use it?

slender nymph
#

look at the docs to learn how to define a scriptable object and create an instance of it

sage mirage
#

I am just programming using Monobehaviours

#

I dont know about scriptable and I really want

sage mirage
#

So, its a data container basically right

slender nymph
#

it's a way to define your own asset

sage mirage
#

Can you use methods and more in scriptable object

#

If I am not wrong there is no Update, Start and some other built in methods compare to mono

slender nymph
#

you do realize it's just a class, right? there's nothing special about it that prevents you from using anything a normal class can do

sage mirage
#

It has onDestroy(), OnEnable, OnDisable and OnAwake

#

something like that

slender nymph
maiden tundra
#

Hello, I am working on a dungeon generator that uses a dictionary to handle the grid, and when using .ContainsKey, it is still giving me an error? I would appreciate some help with this one.
(The Vector2 key is the grid space, and the Vector4 is for door positions)

edgy tangle
#

@sage mirage the thing about ScriptableObjects is as Boxfriend mentioned they’re just assets defined by you. This makes them very flexible to all sorts of implementations. But if you’re totally new to them then using them as shared data containers is a good place to start.

#

For example you could have an SO which defines the base attributes of some enemy. Then for example rather than having every enemy instance store a member for, say, movementSpeed, they instead read that value from the asset. This is really handy for testing things out at runtime, because then you can do things like changing that movementSpeed value and all current instances will be using that value and move faster or slower

grand snow
#

Use Vector2Int if your positions are integers

#

Oh i just realised the keys used in both operations may not even match (you dont use the same variables?). Anyway i expect my main points to be ignored so

maiden tundra
edgy tangle
#

@sage mirage Brackeys’ Hearthstone example is a pretty good introduction to using SOs as data containers.

https://youtu.be/aPXvoWVabPY?si=5NERrsGS1jxLEBeR

When making a game you need a good way of storing data. This is where Scriptable Objects come in! In this video we’ll learn how to use them by looking at an example: Making cards for Hearthstone.

● Project on GitHub: https://github.com/Brackeys/Scriptable-Objects

❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU
...

▶ Play video
grand snow
maiden tundra
#

so testing it, it still does not work with Vector2Int, and I have a different section that does a similar thing and works, so I need to look through and see what is different

grand snow
#

But yes if your positions are ints then use Vector2Int for the keys to avoid floating point math imprecision fucking up stuff

maiden tundra
grand snow
#

Also sometimes its better to make a variable and use that instead of copy pasting some crap like that

#

That also prevents silly mistakes

#

also that if else on one single like is discusting ew 😆

maiden tundra
grand snow
#

No you made a vector2 for the Contains() check then seemingly try to do the same or something for the [] access

#

anyway i could say even more but best i stop there

#

TryGetValue + Vector2Int

hushed flame
#

One question: what videos do you recommend, or is there a course I need to take to get my spray paint to work on a wall?

sour fulcrum
#

Decals

fierce sleet
#

how can i sort these? like putting them under categories or something

rich adder
fierce sleet
rich adder
fierce sleet
#

is it possible to indent the contents? or is it just visual and theyre not really stored under anything

sour fulcrum
#

it is but that gets into custom code and/or third party asset territory

#

or base classes or structs

fierce sleet
#

oh i'll just stick with this then. not really anything other than qol for myself anyways

#

thanks

final trellis
#

How do i make UpdateCardVisuals() any time changes are made to the scriptable object whichGR_Card card is referenced to?

#

(only in editor)

frosty hound
#

Specifically, the OnValueChanged attribute

#

Actually, if you want it to be on values on the SO and not changing the reference itself then that probably won't work

final trellis
#

damn

eternal needle
#

Otherwise there isnt a great way in general to do this because this monobehaviour would exist in scenes that may not be open, or prefabs too.

edgy tangle
#

Or just use OnValidate

final trellis
#

seems like OnValidate is individual

eternal needle
#

I see no reason to not just put this logic in awake/start

#

Even if on validate works, its not going to affect any of these instances if its in a scene that isnt open

edgy tangle
#

Oh nvm you want it to change when the SO changes

final trellis
eternal needle
#

It can run when your object is loaded and immediately set the values of the text elements

final trellis
eternal needle
#

Then id just make it an event on the scriptable object that this monobehaviour listens to, and calls this function you want

#

It wont necessarily affect a build unless youre trying to update SO values at runtime, which you ideally shouldn't be

final trellis
#

yeah dw its just for a in-editor tool

final trellis
#

hell yeah, works perfectly

#

events seem cool idk why i dont use them more

brave helm
#

hello there, anyone want to go over the basics of C# with me?

brave helm
elfin pike
#

you can dm me

brave helm
#

alrighty

brave helm
white orbit
#

@brave helm

brave helm
solar kettle
#

Hi all, I'm getting into using ScriptableObjects for my project, and for this example, I'm using weapons.
So I have a ScriptableObject named Weapon, and from that I have Gun, Knife and Grenade.

I have then made a second ScriptableObject named WeaponRegistry, which holds a Weapon[] array, where the different Weapon objects are stored. In a game object in my scene, I have a WeaponRegistry field, where that scriptable object is put, so I can always gain access to the array of weapons.

Is there a better way to do this, or is this fine?

frail hawk
#

if you are notplanning to modify the WeaponRegistry at runtime, it is fine

#

are you defining the Weapon type with an enum?

solar kettle
frail hawk
#

sure

solar kettle
#

What would that look like, the enum's index corresponding to the index of the weapon in the array?

#

Such that WeaponType.Gun = 0 and weaponArray[0] is the Gun object?

frail hawk
#

no

#

much easier, you will have to find out how enums work

naive pawn
solar kettle
#

- or how to use the enums to reference elements in an array

naive pawn
#

@brave helm @white orbit consider utilizing community servers - the purpose of these servers is so there's a large audience to view and answer questions, provide alternate answers, or validate/dispute answers if necessary.

so, just ask here or in the c# server, depending on what you're discussing exactly
and https://dontasktoask.com

#

delegating to DMs wholly negates the benefits of a community server - being public is the point 😉

naive pawn
frail hawk
#

why do you wan to reference an element in the array, you just want to define the type of your weapon

solar kettle
#

So I need a way to do something like spawn(WeaponType.Gun)

solar kettle
nova vapor
#

Please how do I develop on unity through mobile

naive pawn
#

you couldn't make this generic in a proper way with an enum thonk

naive pawn
nova vapor
naive pawn
#

please do not ping specific people for help

white orbit
frail hawk
#

the type of your weapon is something else and the weaponregister is somehting else.

naive pawn
frail hawk
#

the weaponregister holds a collection of weapons

fossil plaza
#

i js got unity and it wont install?

solar kettle
#

Not calling the enum directly

white orbit
naive pawn
fossil plaza
#

ok

naive pawn
#

yeah if it's on unity's end you could only really just try again

solar kettle
naive pawn
white orbit
#

he helped both of us together in a gc so thats all that matters, but ty though

naive pawn
naive pawn
#

ime, 0% of the people well-experienced in the topic and in teaching said topic are interested in going to DMs.

#

asking directly in a community would generally give better answers, is all i'm saying

white orbit
#

but thanks again

naive pawn
#

trying to prevent footguns here lmao

#

good for you.

fossil plaza
#

it doesent work still

naive pawn
#

@solar kettle are you using polymorphism for your SOs, ie can you just use the Weapon type directly rather than needing specifically Gun/Knife/Grenade?

fossil plaza
#

i have no internets to connect to

#

they all have passwords

solar kettle
naive pawn
#

that's not exactly what i asked

#

to use a Gun, do you need a field of type Gun, or is Weapon adequate where you could use Weapon.use or whatever

solar kettle
#

Yes that is what I meant sorry :) There is no Gun class to use, just the Weapon class, so a Weapon field is adequate

#

But I also only started digging into scriptable objects yesterday, so I'm not sure if that is the best way to do it

#

The Gun exists only as a Weapon asset, with particular name, texture, damage etc.

naive pawn
#

ah i see, i misunderstood, i thought you had stuff inheriting Weapon

solar kettle
#

I had that until yesterday :P

naive pawn
#

that simplifies it then

#

i think what murado was suggesting was to have separate fields for each type? not 100% sure though

elfin pike
solar kettle
naive pawn
#

an idea i have would be to have a serialized dict over than enum, so you wouldn't have to add extra fields and logic when adding new weapons, you'd have easy access, and the serializeddict can check for missing enum members if i recall correctly

naive pawn
#

oh wait that's just a getter?

#

hmm kinda shrugsinjapanese then

solar kettle
#

Currently have the Weapon assets stored as such

naive pawn
solar kettle
#

With the game object in question having a WeaponRegistry field, which can gain access to the array of Weapon assets

elfin pike
naive pawn
#

what makes these questions not "normal"?

solar kettle
#

No question is stupid or not normal when it comes to learning :)

solar kettle
naive pawn
#

yeah, i was thinking of the spawn you had in a previous example, assuming that would be instantiating some other gameobject from the SO

solar kettle
elfin pike
naive pawn
naive pawn
#

beginner questions are expected

elfin pike
solar kettle
naive pawn
#

we can't verify that you used the right links, etc.

#

and like i mentioned before, no-one i know who's both experienced with a topic and with teaching it would delegate to DMs when they're in a relevant community. so to be blunt, i do not trust that you've given quality help from that

naive pawn
#

i may have misunderstood the question, could you clarify

solar kettle
# naive pawn well, a Weapon field?

Sorry I misworded - not which field to use, but how to gain access to the Weapon scriptable objects (e.g. Gun) to use when instantiating a WeaponInstance object

elfin pike
solar kettle
#

If the texture of a gun is stored in the Gun asset from the Weapon SO, how do I gain access to that texture in a newly created WeaponInstance object

naive pawn
solar kettle
naive pawn
#

yeah, that's what i suggested originally

#

though i'm not super in the mindset of gamedev at the moment, there's probably better ways

#

this should be adequate though

solar kettle
naive pawn
#

wouldn't it be worse with private support anyways lol
what's the argument here

elfin pike
#

Saying, what is difference from stranger asking questions here or in DM. I understand if people like Chris or rob5300 join in discussion

naive pawn
#

if you've provided info and context for the past 30 minutes you will then have to repeat it all when you ask someone else

#

or if they say something incorrect or ambiguous, no-one else is there to point it out

#

other beginners lurking or future people searching cannot benefit from the discussion either - ive learned a ton just reading through other people answering questions

#

ive been in several communities over what, 7 years now? the communities and their prominent helpers all hold this stance for similar reasons. there's a reason these communities exist, and DMs wipe away all benefits

verbal dome
# solar kettle So my point is just if there is a better way to access a specific type of weapon...

Didn't read the whole convo, but in some cases using enums as indices to an array is a valid strategy.
For example, i'm currently making a tilemap system and each Tile in the map has a TileType enum field.
I then have a TileDefinition[] array of shared tile data that takes the TileType as an index, which is efficient for lookup.
Then I can easily access any tile's definition:

var tile = map.GetTile(xy);
bool isSolid = tileDefinitions[(int)tile.type];```

But this is more of a data oriented design, not something to stress about just yet. Just though i'd point out that what you said initially is sometimes valid
elfin pike
#

In the ends it's not our choice to make, where they hang out

naive pawn
river bobcat
#

I'm new to unity and I made some player movement scripts, I've added them to the player and they show up on the side but they are not running, can anyone help?

frail hawk
#

show code

river bobcat
#

NVM I FIXED IT

#

I just needed to install some visual studio thing lol

#

I've been trying to fix this for half an hour and as SOON as I ask for help I find a solution 😭

frail hawk
#

rubber duck in action

naive pawn
#

do some debugging - see if the message in question is being triggered, erc

river bobcat
naive pawn
#

relatable

river bobcat
naive pawn
#

ouch, slow network

naive pawn
river bobcat
#

it probably recompiled 🙏

#

well it said that the unity thingy was 'not compatible'

#

so reloading probably fixed that

naive pawn
#

another possibility could be that you hadn't saved, so keep that in mind (though adding a log and seeing it should rule it out)

river bobcat
#

alr tysm!

lament shore
#

How is find reference actually useful? Is there no way to find only the objects that refer the object directly in an inspector field?

#

Instead it finds a ton of reference of several orders

#

Anything that's maybe in the hierarchy of referencing the object

grand snow
#

You can also find asset references but that uses new search and often takes ages

lament shore
#

I mean find references in scence is quite bad. I only want what the inspector directly refers in a field

grand snow
#

You are right its quite puzzling sometimes why things show in this search when they dont reference the object/component

#

But its the only way unless you do your own search by checking all serialized properties

lament shore
#

Yea, I can probably make my own editor function to do it. I just wondered if an option like that exist already

glacial pivot
#

Quick question
I'm trying to write a mod for the game "Ultrakill" using Bepinex
But the Update() function is never called, contrary to Awake().

VS mentions that Update() is called every frame, if monobehaviour is enabled.
So my question is; how do I enable it?

frail hawk
#

you are not using a MonoBehaviour

glacial pivot
#

Here, yes?

frail hawk
#

yes

glacial pivot
#

When I changed BaseUnityPlugin to MonoBehaviour, my mod would not load

verbal dome
#

If BaseUnityPlugin already inherits from a MonoBehaviour then this is also a monobehaviour

glacial pivot
#

whoa!
I think it worked

verbal dome
#

What did you change tho 🤔

frail hawk
#

i wonder

ivory bobcat
glacial pivot
#

but the player still doesn't jump

ivory bobcat
#

Place a log in Update and first see if it's actually being called

#

This looks like an xy problem

verbal dome
ivory bobcat
#

For all we know they may be using the new input system etc

#

So Update is called?

glacial pivot
#

okay, so when it comes to this line
I do notice small screen jerking whenever I press K

glacial pivot
frail hawk
#

you are making somethign else jump

#

player is another script, it might be this object that is jumping

verbal dome
#

I do notice small screen jerking whenever I press K
Sounds like something else is overwriting the velocity next frame

glacial pivot
ivory bobcat
#

Should probably consider adding force as impulse since this is in Update

open socket
#

I suggest you to keep the BaseUnityPlugin class really light.
Create a new script Monobehaviour and call it from your BaseUnityPlugin class with something like:
NewMovement.Instance.gameObject.AddComponent<MyCustomScriptMonobehaviour>()

glacial pivot
#

So maybe the game's code changed

open socket
ivory bobcat
#

Oh, this is related to modding..

glacial pivot
#

I changed a code a little to experiment and I succesfully set player's hp

glacial pivot
ivory bobcat
west otter
#

Can anyone maybe help me add textures to my 3d bear, I’ll give you the download for it and I have a picture on what I want it to look like

spare summit
#

anyone know y my Foot IK is greyed out?

naive pawn
elfin pike
#

Long time ago, had issue. and its back. it doesnt save field, goes back to 0. ```public abstract class IdObject: ScriptableObject
{
[SerializeField] public int id {get; private set;}

#if UNITY_EDITOR
void OnValidate()
{
    if(id == 0)
    {
        System.Random random = new();
        id = random.Next();
    }
}
#endif

}```

slender nymph
river bobcat
#

I'm trying to deal damage to an enemy in my game, and I keep getting this error

#

does anyone know how to fix this?

cosmic quail
cosmic quail
river bobcat
#

collision.gameObject.GetComponent<Enemy>().Health();

#

under the if statement

#

left image

cosmic quail
river bobcat
#

this is my first day of unity so bear with me but what does that mean 😭

cosmic quail
river bobcat
#

I AM SO STUPID

#

I DIDN'T AND NOW IT WORKS

#

TYSM

vital otter
#

Hey, so if I have a player that has 2 stats regarding movement, speed and acceleration, how do I make the player follow the mouse cursor on the X using that?
I think Vector2.SmoothDamp could be good here but I don't know what should go in the smoothTime parameter.

keen acorn
vital otter
keen acorn
#

Hold on, lemme get on unity and test it out

keen acorn
vital otter
# keen acorn alright, may i take a look at your current code?
using UnityEngine;

namespace AOR.Core
{
    public class Bowl : MonoBehaviour, IBowl
    {
        public float Position
        {
            get => transform.position.x;
            set {
                var p = transform.position;
                p.x = value;
                transform.position = p;
            }
        }
        public float Target
        {
            get => target.x;
            set => target.x = value;
        }
        public float Velocity
        {
            get => velocity.x;
            set => velocity.x = value;
        }

        public float Speed
        {
            get => speed;
            set => speed = value;
        }
        public float Acceleration
        {
            get => accel;
            set => accel = value;
        }

        public Vector2 target, velocity;
        public float speed, accel;

        Vector2 RealTarget
        {
            get => new(target.x, -3.5f);
        }

        void Update()
        {
            transform.position = Vector2.SmoothDamp(transform.position, RealTarget, ref velocity, speed / accel, speed);
        }
    }
}```
#

i didnt get it to track player movement just yet, still trying to figure out why im not getting input actions

#

nvm found it

grand snow
#

Lerp can be used to animate from a to b over x time

#

Too many beginners use Lerp incorrectly

vital otter
#

or is SmoothDamp using lerp?

grand snow
#

You arent but I am warning you about what others said

spare mountain
#

smoothdamp is not the same as lerp

vital otter
#

yeah I know
1 - Mathf.Exp(-Time.deltaTime * speed)

keen acorn
keen acorn
vital otter
keen acorn
#

Awesome! What I did is just took the mouse position and turned it into its world position, and assigned that as the target. I did change a few things from your file since I have no idea what AOR.API or IBowl is, shouldn't make too much of an impact. Here's my code

using UnityEngine;

namespace AOR.Core
{
    public class Bowl : MonoBehaviour
    {
        Vector2 mousePosition;
        public float Position
        {
            get => transform.position.x;
            set
            {
                var p = transform.position;
                p.x = value;
                transform.position = p;
            }
        }
        public float Target
        {
            get => target.x;
            set => target.x = value;
        }
        public float Velocity
        {
            get => velocity.x;
            set => velocity.x = value;
        }

        public float Speed
        {
            get => speed;
            set => speed = value;
        }
        public float Acceleration
        {
            get => accel;
            set => accel = value;
        }

        public Vector2 target, velocity;
        public float speed, accel;

        Vector2 RealTarget
        {
            get => new(target.x, -3.5f);
        }

        void Update()
        {
            mousePosition = Input.mousePosition;
            mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
            target = mousePosition;
            transform.position = Vector2.SmoothDamp(transform.position, RealTarget, ref velocity, speed / accel, speed);
        }
    }
}```

btw im a beginner as well, there might be a better way of doing this, I'm not sure.
#

anyhow, im gonna get going, have a nice one

grand snow
#

Oh now i understand, looks good bar the use of a property for RealTarget

vital otter
north glade
#

void OnTriggerEnter(Collider target)
{
if (target.CompareTag("Enemy"))
{
BasicSkeletonEnemyScript EnemyScript = target.GetComponentInParent<BasicSkeletonEnemyScript>();
int output = EnemyScript.Health - damage;
Debug.Log(output);
}
}
}
im a beginner scripter but im stuck because the script doesnt give out any errors but it doesnt print anything either. If i make a different debug.log and put it outside the if statement it prints
i dont know what im doing wrong since the enemy has the "Enemy" tag

solar hill
#

!collab

radiant voidBOT
# solar hill !collab

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

last stone
#

Tysm

solar hill
north glade
#

enemy tag

solar hill
#

read the bot message.

#

read the first sentence

last stone
#

Idk how to do that

solar hill
#

do what?

#

you cant miss it

solar hill
last stone
solar hill
#

not this server

#

there is no collab or job posting here thats what the bot message is telling you

last stone
#

How do i like what do i do

solar hill
#

its against the rules of the server, so go there

solar hill
#

thats how forums work

last stone
#

Ok

#

Now what

north glade
#

basically

rich adder
last stone
#

I think im special

north glade
last stone
#

H e l p

fickle plume
#

@last stone Stop spamming the channel

last stone
#

Wdym im not

fickle plume
#

!mute 1336499403988668481 3d spam

radiant voidBOT
brave token
#

how do i get an object's rotation info and run an if statement if the object is upside down?

frail hawk
#

and to check if it is upside down there are many ways on how to do it, one way is to check the transform.up < somevalue

brave token
frail hawk
#

would clamping the values not be a better approach?

brave token
frail hawk
#

ah okay

brave token
#

it's a mechanic in the game i want to create

elfin pike
#

Any suggestion before i switch my 2D player float movment to int movement to be pixel perfect

zealous lantern
#

Hello

#

On a scale 1 - 10 How hard is coding

timber tide
#

impossible, quit while you are ahead

solar hill
zealous lantern
#

OH WELL

#

Illl do it anyways

vast matrix
#

I have a procederal generation code and a navmesh ai. How would I get the NavMesh to affect everything thats been Prodecerally generated.

solar hill
vast matrix
solar hill
vast matrix
#

Thank you

elfin pike
elfin pike
zealous lantern
vast matrix
waxen adder
#

Alright, so I'm finally at one of the cooler parts in my game. Ability making! Yay!

Only thing is that I'm not sure how I want to structure this. I have a base Ability class. I know I want that. But when constructing other abilities (assume that they are going to be unique, so something like scriptable objects won't necessarily work for them all), do I make a bunch of scripts for each ability that inherits the Ability class, or do I make like a super script that constructs all the abilities?

wintry quarry
#

Look into composition instead

#

i.e.:

class Ability{
  string name;
  
  List<Cost> costs;
  List<Effect> effects;
}```
waxen adder
#

Yeah, started to think inheritence was a bad idea too

waxen adder
wintry quarry
#

possibly, or make it all serialzable and edit in Unity

#

or use spreadsheets or json or yaml

waxen adder
#

Gotcha, what would you recommend? I'm just curious, I think I'll do manual building in code right now

wintry quarry
#

that's a good way to start

#

do that first

#

you can change it later

waxen adder
#

Gotcha, thanks for the help!

waxen adder
#

Thinking about how I want to make abilities "do their thing" in an elegant way. This is what I got at the moment:

using System;
using DataStructures.Enums;

public class Ability
{
    public string abilityName;
    public int actionPointCost;
    public AbilityActivationType activationType; //To do: vague/too general. iterate on this more
    public Action<AbilityContext> activationBehavior;

    public void Activate(AbilityContext context)
    {
        if (activationBehavior != null)
            activationBehavior.Invoke(context);
    }
}

The main thing to look at is activationBehavior and Activate(), but any feedback on the rest of the stuff is welcome.

Currently, AbilityContext is just a basic Object class that contains who is activating the ability and who they're targetting.

#

The idea here is to hopefully allow myself to specify what abilities should do when building them while still activating them in a centralized way

timber tide
#

Composition is the best way to do things usually

#

The largest problem with ability systems that I do have is targeting. Usually the most top defined behaviours will include them but can ultimately split logic if not done correctly.

waxen adder
#

Now that I'm piecing things together a bit more, I think scriptable objects are kinda goated for this

#

Being able to visually see what's been built is nice

waxen adder
#

Some of their stuff is kind of dated though, like the event system. I'm warming up to unity's a bit more

#

And the obvious fact they're using unrealscript XD

#

So no dictionaries for example

grand snow
waxen adder
#

Nice thing about this is I can iterate on this pretty nicely. Effect priority, other, optional functions that can be added to AbilityEffect, or more abstract functions

#

Oh, and it all loops into ScriptableObjects, so if I want to reuse effects/abilities, I can do that without any code

dusky hawk
#

how do i get my visual studio to appear like this?
mine is the second picture, its missing colors and it often autofills incorrectly

slender nymph
#

!ide

radiant voidBOT
brave token
#

how do i assign a button ?

frail hawk
#

what component is that?

brave token
brave token
oak creek
#

You need a update function checking if a specific key(s) was(were) pressed in the update frame, if so then call your desired method for that key bind is the simplest

brave token
#

well i was asking how can i check if a key is pressed because everything i tried failed

oak creek
#

Did you try the if ( Input.OnKeyDown(KeyCode.V) ) inside a update method in a class that's live at runtime?

brave token
#

wait lemme try

oak creek
#

Might be OnKeyUp, I don't remember I use a custom class I made for key inputs

#

I believe that's also legacy input however for that method in general

brave token
#

OnKeyDown does not exist in Input

oak creek
#

Yeah thought as much

frail hawk
#

are you not using the new input system?

oak creek
#

Add import UnityEngine.InputSystem

brave token
brave token
oak creek
#

Then check if(Keyboard.current.vKey.wasPressedThisFrame)

frail hawk
#

if ( Input.GetKeyDown(KeyCode.V)

oak creek
#

That should be correct I believe

brave token
oak creek
#

Input.GetKey is legacy

#

I was just seeing what you were using

brave token
#

maybe the methods are the problem

oak creek
#

Your methods are fine

brave token
frail hawk
#

you said you are using both, so what i posted should work

brave token
#

nothing works

oak creek
oak creek
brave token
#

no errors

oak creek
#

Show me the class?

brave token
#

nothing happens when v is pressed

#
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

public class CamViewChanger : MonoBehaviour
{
    public Camera firstPersonCam;
    public Camera thirdPersonCam;

    void Start()
    {
        SetToThirdPerson();
    }
    void FixedUpdate()
    {
        if (Keyboard.current.vKey.wasPressedThisFrame)
        {
            if (firstPersonCam.enabled == true)
            {
                SetToThirdPerson();
            }
            else
            {
                SetToFirstPerson();
            }
        }
    }
    public void SetToFirstPerson()
    {
        thirdPersonCam.enabled = false;
        firstPersonCam.enabled = true;
    }

    public void SetToThirdPerson()
    {
        firstPersonCam.enabled = false;
        firstPersonCam.enabled = true;
    }
}
oak creek
#

Attach the script to your player object

brave token
#

the start part was to test if the methods are working

brave token
oak creek
#

Does it go to third person when you load scene?

brave token
#

no

#

im pretty sure that it's the methods or unity

zinc zenith
#

How can I show code in here

oak creek
#

Can you add a debug.log to the Start() and see if it pops up in console?

frail hawk
radiant voidBOT
frail hawk
#

Fuad for user input you need to use Update instead FixedUpdate

#

unless you want to spam the key to catch the input you would have to go for Update

oak creek
radiant voidBOT
#
<:error:1413114584763596884> Command not found

There's no command called code using.

oak creek
#

Oh my

brave token
fickle plume
oak creek
# brave token

You might want to delete that duplicate audio listener event too just fyi

oak creek
#

1 per scene

#

Anyway hold on

fickle plume
oak creek
#

Oh I'm blind as hell

#

@brave token in your settothirdperson method you set first person cam twice

#

Make sure the second boolean is the third person boolean

brave token
#
using UnityEngine;

public class BulletHit : MonoBehaviour

{
    public GameObject enemyPrefab;
    public string enemyTag = "Enemy";
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {

    }

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

    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag(enemyTag))
        {
            Destroy(other.gameObject);
            Debug.Log("Enemy is Dead");
        }
    }
}
fickle plume
#

@zinc zenith You can delete or edit your messages as well, don't leave the spam

oak creek
#

Also replace your fixed update method with this

void Update()
{
    if (Keyboard.current.vKey.wasPressedThisFrame)
    {
        if (firstPersonCam.enabled)
            SetToThirdPerson();
        else
            SetToFirstPerson();
    }
}```
#

It's cleaner

brave token
#

it finally works thanks

zinc zenith
#
using UnityEngine;

public class BulletHit : MonoBehaviour
    
{
    public GameObject enemyPrefab;
    public string enemyTag = "Enemy";
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
       
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag(enemyTag))
        {
            Destroy(other.gameObject);
            Debug.Log("Enemy is Dead");
        }
    }
}
#

That's all the code

oak creek
#

What did you need clyde

zinc zenith
#

I want the player to not disappear when the bullet hits the enemy

fickle plume
oak creek
fickle plume
#

@zinc zenith Not deleting the spam after you again. Clean it up or I will time you out.

oak creek
#

Shouldn't matter because the collision isn't hitting the player but

zinc zenith
#

Where is the spam

#

Which one

oak creek
#

This one

#

Probably

zinc zenith
#

I have never post code in here before

zinc zenith
oak creek
#

Just confirming

zinc zenith
#

My own player

#

My own player disappear

oak creek
#

Does your player also have a method to delete yourself when hit with a bullet?

#

Or 'die'

zinc zenith
#

No

frail hawk
#

can you disable the BulletHit script for a second and test if it is working as you want

zinc zenith
#

No

#

If bullethit is disabled then the enemy won't die

oak creek
#

If your player shares the same collider as the Enemy object you will also be deleted. E.g player has a child named "Enemy"

brave token
#

Is the enemy's tag enemyTag or enemy?

zinc zenith
#

Enemy

oak creek
grand snow
#

Id presume the cause was your "player" having the Enemy tag

brave token
#

Try putting enemy instead of enemyTag in your script

oak creek
frail hawk
#

guys dont forget he is using 2 different scripts he has them on both objects it seems

zinc zenith
brave token
#

Or try putting a logical gate like

if (other.CompareTag(Enemy) && other.CompareTag(!Player))
grand snow
#

😆 why

brave token
#

Just in case

grand snow
#

also you cannot use ! with a string 😐

#

complete nonsense

oak creek
grand snow
brave token
brave token
grand snow
#

perhaps TagHandle has some funky way to use this operator but otherwise no

oak creek
zinc zenith
#

Let me send my screen hierarchy

oak creek
#

@zinc zenith let me see your scene hierarchy while in runtime before you shoot anything

#

Will help

brave token
#

Also show the console

grand snow
zinc zenith
#

Here you go

oak creek
#

That is not a screenshot sir

#

Lol

grand snow
#

WIN + Shift + S

zinc zenith
#

here

brave token
#

Please record your screen while killing the enemy

#

Hope you have obs

oak creek
#

Damn it's 5pm for this dude

#

5am for me

zinc zenith
#

I can't send recordings because they tend to be too big for discord normal

#

I don't have nitro

brave token
zinc zenith
#

Aight

brave token
#

Make sure to record to mp4

swift sedge
#

this server is boosted and has 100mb upload limit

brave token
sage mirage
#

Hey, guys! You know I have a problem. I have a locked icon on my game and an interaction icon as well, so when the player detects a locked door locked icon is being displayed, but for one reason I do see the locked icon clearly, but I can see also barely the interaction icon at the same frame. Probably something is happening here with the detect locked door method i have.

{
    if (IsDoor(hit.collider.tag) && IsLocked(hit))
    {
        interactHUD.SetActive(false);
        lockedIcon.SetActive(true);
    }
    else
    {
        interactHUD.SetActive(true);
        lockedIcon.SetActive(false);
    }
}```
Could you please help me?
frail hawk
#

shouldn´t the second part also be hit.collider.tag , you only have hit there

night raptor
#

IsLocked probably checks the lock state of the hit object so should be fine

queen vale
#

And the order of operations looks fine.

sage mirage
#

its an E button that is in there

queen vale
sage mirage
grand snow
#

I feel like too much information is missing to judge what is wrong...

sage mirage
#

thats why I am thinking maybe it has to do with the frame

grand snow
#

What do you want to happen?

sage mirage
#

probably

#

so at the frame where I move away and then again point over the door at this frame probably

grand snow
#

If you are doing this raycast each frame then shouldnt matter

#

For this other icon to be revealed then a raycast needs to be performed, hit something and this must not be a door and not locked

night raptor
#

Also the else block is not executed if your raycast doesn't hit anything, should it?

grand snow
#

I pointed that out just now yes BUT we have no idea do we?

#

fuck knows what happens to get to this function

sage mirage
#

Do you want me to share my raycast logic?

grand snow
#

yes

#

or we can guess and get no where 😆

#

An important skill to develop is being able to "walk through" your logic and deduce what is happening

#

If you can do that you can also see what other things need to be shared for others to help

#

e.g. the raycast performed prior to DetectLockedDoors() being called

frail hawk
#
if (raycast)
{ do something; }
else
{ do someting else ; } //this part is missing

to visualize what rob and aleksiH already pointed out

sage mirage
#

I think I found the issue give me a second

#

I am using layers for 3 different types

#

just give me a sec

queen vale
#

I could be wrong but do you have 2 seperate scripts trying to control the cursor/icon?