#šŸ’»ā”ƒcode-beginner

1 messages Ā· Page 709 of 1

native seal
#

oh duh

#

thanks

wintry quarry
#

Probably want to just install the whole 2d tools bundle

native seal
#

would it be possible to just change the renderer in a 2d project?

#

cause i have everything there

wintry quarry
#

everything is possible

#

it's all just configuration and packages

native seal
#

kk

past sentinel
#

Any tips on how best to make menus? I’m trying to use the built in button but I don’t know how they work and the docs arnt helping

ivory bobcat
#

Explain where you've gotten stuck. Other than that, pick and follow a tutorial

spring otter
#

If it were 3D shouldn't the shadow get thiner in certain angles because of the sprite plane?

timber tide
#

there's a bunch of tricks you can do and one of these is making shadowmap data from sprites pointing towards the directional light source and using that data on the main rendering

#

ssome easier solutions such as just offset the shadowing

spring otter
#

Ah yes, I just watched the video, I'd bet on 3D too now

#

The game is beautiful by the way

#

Those artists are talented

native seal
#

i know, i want to do something similar so bad but its so complicated haha

past sentinel
past sentinel
rough granite
#

Buttons have inputs where they call a function when pushed

past sentinel
#

And I di wanna clarify the UI button

#

The button component

rough granite
#

in the On Click () part of the button you can pick a Object and from there the drop down shows all components

past sentinel
rough granite
#

if you make a script then put it on one of those objects it'll be there

past sentinel
#

I thought you needed to do a special thing ljke how the input system worked where it needs to have InputAxtion.callbackContent content jist diffrent for the click

rough granite
#

where you have different options inside each class all being functions these are base MonoBehaviour ones you can add your own functions to the script and they will show there

past sentinel
#

ok then thanks

#

i shpuld be able to hanel the rest i hope

rough granite
#

only thing is the function can't have special variables in the () only base values like a string, bool, int, enum

past sentinel
#

amm ok noted. i wastn really planning on having any but good to know

rough granite
#

so (string Name) would work but (ClassThatDoesSomething Something) wouldn't

#

i think it's value types that work and reference that don't but i might be wrong since i don't mess with it enough

past sentinel
#

also is there a more effective way to have different parts of the pause menu than something like this where i need to enable and disable each section?

past sentinel
#

my current system is gonna be
if you click options disabel all but options
if you click restart disabel all but restart

past sentinel
#

I have an idea behind my menu and ima see if i can do it or not

merry path
#

How do you send messages from one script to another if the scripts are in different game objects?

rich ice
#

get a reference to the script and call a function

#

usually you'd use GetComponent, make a singleton reference or just set it in the inspector

native seal
timber tide
#

interesting idea

native seal
#

way over my skill level haha

spring otter
wintry quarry
hidden fossil
#

does anybody know why this code its like causing to like continuously repeat the attack animation even though i want it to play only once

#

.code

#

.paste

#

yo whats that bot command called again i forgot

#

.easy.gg

rich ice
hidden fossil
#

oh

#

wrong code

#

!code

eternal falconBOT
hidden fossil
wintry quarry
hidden fossil
#

did i set this up correctly

hidden fossil
#

exit or enter?

#

ok

#

thx

#

chatgpt screws up my game mroe

hidden fossil
#

well im following their official website tutorial

#

i like how they give u challenges and never give u the answer to the challenge

past sentinel
#

Im wanting to make a laser to connect show connections to the player. I see the Line Render but it doesn't seem to do what i want and i also wanna try and do dotted lines for when its off. What would be the best way to make this? I would also like to be able to make a list that connect them

timber tide
#

line render probably most performative, and you can use a dotted texture, otherwise probably just init a bunch of circles like quads w/ texture

past sentinel
timber tide
#

LineRender? Can do it all in the editor

#

then you set the two points you need

past sentinel
lofty mirage
#

Hiii guys

past sentinel
lofty mirage
#

What is the diff between Start and Awake?

#

Does one start before the other?

naive pawn
#

Awake is called when the gameobject becomes active
Start is called when the component becomes enabled (on the first frame that it is enabled)

#

Awake comes first

past sentinel
#

Most of the time tho (in my experience) they are interchangeable unless you have an object disabled at the start but needs to do a thing before hand

naive pawn
#

that "unless" is doing a lot of heavy lifting lmao

#

that's not really an uncommon situation

lofty mirage
#

Couldn't you just use Start() and write out the things that should happen first be done first?

#

Or maybe the deactivated object depends on other scripts (?)

naive pawn
#

sometimes you need to make something initialize before something else

lofty mirage
#

So by default what should I use?

keen dew
#

The rule of thumb is that you do internal initialization in Awake and everything that involves other objects in Start. That way you don't run into issues trying to access something that isn't initialized

lofty mirage
#

oh okay makes sense

naive pawn
#

there is also OnEnable, btw.

sour fulcrum
#

Yeah usually Awake for stuff dealing with just itself and Start is when you leave the house and talk to others

The mindset of this is by the time Start happens things should be ā€œreadyā€ (via Awake) for communicating

#

If your class needs a shower and morning coffee thats in awake

naive pawn
# naive pawn there is also `OnEnable`, btw.

it first happens after Awake, but before Start, then anytime the component gets enabled (including the gameobjetc getting activated while the component is already enabled)
it's part of the component lifecycle
it's useful for doing initialization that may need to be redone after disabling or deactivating

sour fulcrum
#

OnEnable & OnDisable kinda feel like clocking in and out it work imo

strange kelp
#

Time for unity, lets see how it goes!

#

Wow Unity loads up fast, last time it took way longer lol

lofty mirage
#

Depends on the project haha

strange kelp
#

My last Unity project was a tutorial I quit after the first episode not working lol

#

So where do I place my own config file that my project is gonna use? In the assets folder?

#

Wait, nvm I forgot I can set components of my camera

naive pawn
#

config for what?

strange kelp
# naive pawn config for what?

Oh no I don't need it anymore, but it was for the camera scale size. Because my planets will be near real life size, I will have to scale them down by a factor(that'd be camera scale size or smth similar) to make unity render it properly

#

Like Kerbal Space Program does it

lofty mirage
#

Is there any reason plugging a subsclass between a base class and a subclass make the subclass not behave as with only it inheriting from the base class?

#

I currently have
DragonfryController : EnemyBaseGround

#

and I want:
FlyingEnemy : EnemyBaseGround
DragonfryController : FlyingEnemy

#

however, even with "nothing" in the intermediate subclass FlyingEnemy

lofty mirage
naive pawn
#

that's a very vague question

#

perhaps share some !code

eternal falconBOT
strange kelp
#

Guys I'm getting this error:
transform.position assign attempt for 'Earth' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform:set_position (UnityEngine.Vector3)
Gravity:Update () (at Assets/Scripts/Physics/gravity.cs:33)

using UnityEngine;

public class Gravity : MonoBehaviour
{
    public string type;
    public double mass;

    public Vector3 velocity;
    public Vector3 position;
    public GameObject[] planets; // array to hold planets
    private double gravitational_constant = 6.67384e-11f;
    void Start()
    {
    }

    void Update()
    {   
        if (type == "Planet")
        {
            foreach (GameObject planet in planets)
            {
                Gravity planet_gravity = planet.GetComponent<Gravity>();
                float distance = Vector3.Distance(planet_gravity.position, position);
                if (distance <= 0f | distance*distance <= 0f) continue;
                double planet_mass = planet_gravity.mass;
                double Force = gravitational_constant * ((mass * planet_mass) / (distance * distance));
                double acceleration_magnitude = Force / mass;
                Vector3 direction = (planet_gravity.position - position).normalized;
                Vector3 acceleration = direction * (float)acceleration_magnitude;
                velocity += acceleration * Time.deltaTime;
            }
            position += velocity * Time.deltaTime;
            transform.position = position;
        }
    }
}
#

Why is it NaN?

fickle plume
#

Did you debug what numbers you are trying to assign?

strange kelp
#

no

raven pilot
#

Would the most straightfoward of getting the current position of the player Object would to use a vector3 and Find the Game Object tag Player so something like

var currentPlayerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;

šŸ¤”

frail hawk
#

just create a direct reference to the target and get the position

#
[SerializeField] Transform player; // declared as class variable (at very top)

Vector3 pos = player.position; // in the update method
raven pilot
#

šŸ¤¦šŸ½ā€ā™‚ļø just started all of this today so appreciate that.

strange kelp
#

How can I multiply all numbers in a vector 3 by a float?

fickle plume
#

Find methods are very slow and generally should only be used in debugging or perhaps in third party tools that have no other way of getting a direct reference.

raven pilot
#

example?

fickle plume
# raven pilot example?

When you are working in a team and need to debug a variable without changing core code, so you temporarily get that variable through Find, so you won't forget and deploy PR/merge that changes core code.

#

Basically you never use it unless you really have to.

raven pilot
#

So basically Find Methods are normally just a temporary debugging type of thing is what I'm understanding.

fickle plume
#

It's a very slow way of getting a reference globally anywhere, which is already bad in itself. There are better ways

strange kelp
#

Ay, my planet is moving finally lol. But I need to rewrite their gravity code, ChatGPT screwed up big time...

strange kelp
#

Yeah

raven pilot
strange kelp
#

But tbh, I just wanted a solution, and I didn't know how to apply my acceleration to the velocity vector because I'm horrible at maths lol

strange kelp
#

And I didn't want to make seperate variables for x, y and z. But that's the way I'm gonna be doing it

frail hawk
#

and avoid using Find methods in the update, you can if you have to, use them once but don“t ever use them every frame

raven pilot
#

But the approach you showed earlier With Using SerializedField Can be use in update or is this considered a type of "find" šŸ¤”

fickle plume
frail hawk
#

i edited the code with comments for you, @Tyler

strange kelp
raven pilot
frail hawk
#

do you also understand the wisdom behind it?

#

as a beginner it is really important to understand code and the way it works, especially in the beginning

raven pilot
#

Not exactly no.

frail hawk
#

well now instead of searching for the GameObject every frame you already have the reference (assigned via inspector) . now you just get the position of the object every frame

raven pilot
#

Which is due to the [SerializeField] correct?

frail hawk
#

yes , you manually assign the player to this field

raven pilot
#

So [SerializedField] Allowed it to be public to the inspector Transform is just stating the class we're wanting to use and assigning it to the player?

frail hawk
#

you could also use [SerializeField] GameObject player instead [SerializeField] Transform player

#

since you are interested in the Transform it would make sense to declare the Transform. otherwise you“d have to do player.transform.position

naive pawn
#

you can just, do that

strange kelp
raven pilot
#

So [SerializedField] is making it visible to the inspector Transform is just including the class we're wanting to use and assigning it to the player

I"m tryna make since of this line by line so to speak

naive pawn
#

you aren't assigning anything to player in that line, you're declaring that player is of type Transform

raven pilot
#

gotcha that's what i was tryna make sense of.

strange kelp
#

Why can't I use force_x even though I declared it outside of the if statements

frail hawk
#

would you not have to parse the mass too

naive pawn
strange kelp
#

I declared the mass earlier outside the if

naive pawn
#

only fields get default-initialized
it's not legal to use local variables that haven't been assigned to

strange kelp
#

(mine's in german so I'll translate)
Usecase of the not declared local variable "force_x"

#

Wdym not assigned to?

naive pawn
#

you sure? it's saying it's a local variable so it knows it's declared lol

#

it's more likely saying it's not defined

naive pawn
strange kelp
#

But it has

naive pawn
#

i was vague, mb

#

it hasn't definitely been given a value

#

if distance_x is <= 0, then it wouldn't be assigned to

strange kelp
#

Oh, so I'll just set it to 0 at the start

frail hawk
#

is there any reason you want them as doubles?

#

just asking

strange kelp
#

The earth realy accelerated the mun to 200m/s

strange kelp
rough granite
strange kelp
#

I mean I like it more this way

rough granite
#

right but this is more effective since you only have to deal with one variable

strange kelp
#

Yeah propably, but idk tbh.

#

it propably is easier and smarter and more performant, but my CPU is beefy enough

rough granite
#

it's not about the cpu :/ it's about the ease of writing the code, you wouldn't want to have to change something here months later to go crap wtf why did i go the easy way out and have to rewrite it all

#

Idk i guess it's preference though im not goonna go out of my way to force something you wouldn't like.

rough granite
# strange kelp

But you do have to multiply distance for each axis by itself here this is currently incorrect and leads to a miscalculation

strange kelp
#

Lol. But knowing myself, I will stop this project befor I can launch a simple rocket off a planet lol. But you're right. I'll propably come back tomorrow when the gravity isn't working for some reason and think why I did it that way lol. But eh, it's fine. I just don't have the motivation to do it tomorrow. Tomorrow I'm gonna make this way clearer making my own functions like applyaccekeration or converttoacceleration
btw, ignore the non existent underscores, but discords formatation is annoying

strange kelp
hot wadi
#

Should I use ScriptableObject to save the spawn point of collectibles in a 2D platfomer?

frail hawk
#

why not just save them on the object

hot wadi
strange kelp
#

Guys, why is the earth flying away when I start the game

#

Earth is at the handles, the mun is the tiny speck

keen dew
#

Show the gravity script

strange kelp
naive pawn
#

!code

eternal falconBOT
strange kelp
naive pawn
#

force to acceleration doesn't involve time, the Time.deltaTime is technically wrong - it should be applied when turning the acceleration to velocity

strange kelp
#

Now even the mun is crazy far away lol

naive pawn
#

that shouldn't have made a difference...

strange kelp
#

this right?

naive pawn
#

yeah, it wouldve just been moving the calculation, not actually changing it

strange kelp
#

Befor i had it like this

naive pawn
#

yeah?

#

you removed one that i didn't tell you to remove

strange kelp
naive pawn
#

this is the change im talking about

- float acceleration_x = (float)(force_x / mass) * Time.deltaTime;
- float acceleration_y = (float)(force_y / mass) * Time.deltaTime;
- float acceleration_z = (float)(force_z / mass) * Time.deltaTime;
+ float acceleration_x = (float)(force_x / mass);
+ float acceleration_y = (float)(force_y / mass);
+ float acceleration_z = (float)(force_z / mass);

- velocity += new Vector3(acceleration_x, acceleration_y, acceleration_z);
+ velocity += new Vector3(acceleration_x, acceleration_y, acceleration_z) * Time.deltaTime;
strange kelp
#

Ohh, thx

naive pawn
#

though just making this a Vector3 would probably simplify it...

strange kelp
#

It's still way too fast I think

naive pawn
#

also, you should have planets typed as Gravity instead of GameObject so you don't have to do GetComponent every frame

naive pawn
#

if you're scaling stuff make sure to scale different values by appropriate amounts

#

i'd guess that your mass vs velocity vs distance are just off

strange kelp
#

Oh I'm so stupid

#

I have to set the position in the gravity variables, not the transform section lol

naive pawn
#

why not just use the transform position though

#

seems pretty unnecessary to store that a second time if they're going to be the same values

strange kelp
#

Since I want to scale up the planets to a realistic scale, and unity wont take those transform values well

naive pawn
#

you plan to move everything to doubles and do the math there then convert to float or something?

#

unity runs on floats anyways

strange kelp
#

I want to scale the whole solar system up or down, depending on the current scale_value

#

Since I want to actually scale the planets up to real size

#

The moving part in the transform is just for testing rn

naive pawn
#

you want to change the size of stuff at runtime?

strange kelp
#

yea

naive pawn
#

...why?

strange kelp
#

Kerbal Space Program does it too

strange kelp
naive pawn
#

ok, but you can just do that once, and then keep that scale

#

why do you want to change it at runtime

strange kelp
#

For example: when I'm on a planet, I want higher resolution so I scale it up

naive pawn
#

because that seems really unnecessary to have to go through every object and change its scale and position and velocity and mass

naive pawn
#

you just use a higher resolution mesh for that

strange kelp
#

Well, if my planet is 1.0 size, the increments will be a bit higher than if it was 1000 or 2000

#

So the mesh can be more accurate ig

naive pawn
#

the next number from 1 is 1.00000011920928955078
the next number from 1000 is 1000.00006103515625
are those.. supposedly micrometers, really that significant

#

i think you're thinking too far ahead. get something that works for now, before making it good

strange kelp
#

Yeah good point. I'll propably only scale them down when I first start the game. So I can still type in 40000km (radius of earth or smth) in the script and get the scaled down script. makes working with it easier
radius of earth is around 6000km, lol

naive pawn
#

40000 is circumference iirc

cedar token
#

I'm sorry, i'm new here.
I have some animation trouble here, where can i ask about that?

strange kelp
#

Yeah could be that

cedar token
#

Thank you!

strange kelp
#

I think I need to make my planets way, way slower

frail hawk
strange kelp
#

Uhh, I'm gonna tip my toes into some ui. I can't watch this simulation for 1 hour just to see if i got an orbit

graceful abyss
silk night
naive pawn
#

stats such as max health, health regen, max hunger, inventory space can go in scriptableobjects
current state like current health, current hunger, what's actually in the inventory would be stored with monobehaviours (perhaps indirectly)

graceful abyss
#

how I have it right now is a struct with the stats then in the Start I initialise them with their values, I have age, hunger, hungerthreshold, thirst, thirst threshold, and hasPartner, so for a SO i'd just have the hungerthreshold and thirst threshold really in it?

#

doesn't seem worth it in my specific case

ivory bobcat
#

SOs are very niche. You probably won't need them unless you're making inventory items

graceful abyss
#

I guess i'd have model prefab too later on or something

graceful abyss
hot wadi
ivory bobcat
#

It doesn't matter if it's in the form of a struct, class or a field member.

worn peak
#

The bullets from my player are being spawned by using animation events. When my player moves and shoots at the same time, then the second bullet moves diagonally instead of straight upwards vertically.

public void ShootLeft()
{
    Vector2 spawnPos = (Vector2)transform.position + new Vector2(-Mathf.Abs(positionOffset), 0f);
    Instantiate(projectilePrefab, spawnPos, Quaternion.identity);
}

public void ShootRight()
{
    Vector2 spawnPos = (Vector2)transform.position + new Vector2(Mathf.Abs(positionOffset), 0f);
    Instantiate(projectilePrefab, spawnPos, Quaternion.identity);
}

The only difference is, that the spawn point on the x axis is the negative.

That is the script for the movement of the bullet.

private void Update()
{
    if (Camera.main != null)
    {
        Vector2 viewportPos = Camera.main.WorldToViewportPoint(transform.position);
        if (viewportPos.y > 1.1f) // Bullet is off the top of the screen
        {
            Destroy(gameObject);
        }
    }
}

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag("Obstacle"))
    {
        Destroy(gameObject);
    }
}
hot wadi
worn peak
ivory bobcat
#

SO is practically a MB component that isn't associated (attached) with/to a Game Object.

#

With intended restrictions such as immutable etc

fresh fox
#

Hello everyone I’m making a third person shooter, so I have an enemyAI. By itself it works fine (basically perfect). But when I right click and duplicate it and move another one to another location. They both just break and almost sink into the ground. This is an annoying issue and some help would be useful

wintry quarry
ivory bobcat
wintry quarry
#

You need to show us the code that moves the bullet

wintry quarry
#

You need to debug your code

fresh fox
eternal falconBOT
fresh fox
# wintry quarry !code

I’ll show you what happens when I press play too as that’s where the issue is

worn peak
floral garden
#

Isn’t you coded it ?

worn peak
#

Yeah, but I just blindly followed a tutorial

floral garden
#

Give the projectileprefabs script

ivory bobcat
worn peak
#

I think I found it

fresh fox
#

https://paste.mod.gg/basic/viewer/pdcluvauxity/0

Here is the enemy AI with the code I wil also provide screen shots with 1 enemy ai and then with 2. The second one is duplicated with the position just set a few units away from the other. With 1 it is perfeclty following me and shooting me like it is supposed to and then with 2. It just becomes whatver this is atwhatcost

worn peak
#
private void Start()
{
    rb = GetComponent<Rigidbody2D>();
    rb.linearVelocity = Vector2.up * 5f;
}
ivory bobcat
#

What you've shown is where you're spawning the bullet and how the bullet interacts on collision etc.

worn peak
#

That is the whole script for the prefab

using UnityEngine;

public class ProjectileMovement : MonoBehaviour
{
    private Rigidbody2D rb;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        rb.linearVelocity = Vector2.up * 5f;
    }

    private void Update()
    {
        if (Camera.main != null)
        {
            Vector2 viewportPos = Camera.main.WorldToViewportPoint(transform.position);
            if (viewportPos.y > 1.1f) // Bullet is off the top of the screen
            {
                Destroy(gameObject);
            }
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Obstacle"))
        {
            Destroy(gameObject);
        }
    }
}
ivory bobcat
floral garden
ivory bobcat
#

Is it perhaps.. child to the player or some object in the scene etc?

worn peak
#

It is a child of the player

floral garden
#

Oh

#

You shouldn’t, as it will move if the player move, the move of the player will be applied on the bullet

worn peak
#

I see

floral garden
#

As exemple in unity you create a cube

#

Create another cube as child and move it away

#

Then rotate the cube parent, you will see the child will move around the parent

worn peak
#

Interesting. My current structure is, that the player is the parrent object with guns as a child, the individual gun as another child and then the bullet as the last child

floral garden
#

Oh 😟

#

The bullet must be free , otherwise, it trajectory will be affected by the player UnityChanThumbsUp

worn peak
#

I don't know where to call my bullet now

keen dew
#

The new bullets are spawned at the top of the hierarchy so it doesn't matter where the original is

#

I'm guessing it's bouncing off the player's collider

worn peak
#

If it were bouncing off the collider, wouldn't the first bullet be affected then too?

keen dew
#

Depends where the spawn points are. Maybe it's far enough to not hit the collider

#

Disable the colliders and see what happens

worn peak
#

You are very smart

#

Somehow my collider was the issue

floral garden
#

You can disable the collider of the gun

#

I am sure the bullet spawn point is a the end of the gun lmao

worn peak
#

The player collider was the issue

ivory bobcat
fresh fox
ivory bobcat
#

Two so that we can verify if they're both targeting the correct target

fresh fox
#

Okay sure

worn peak
ivory bobcat
#

You're using Find in Start which has potential to behave unwantedly with expectations (especially if the enemy ais are tagged players too!!!)

floral garden
keen imp
#

Hey all, was wondering if there were any good reliable resources to start learning C# , this would be my first time working with any kind of coding or programming. I apologize in advance if this is the wrong channel for this

ivory bobcat
fresh fox
fresh fox
worn peak
unreal ibex
#

why wont the circle appear on the game tab

ivory bobcat
#

Do the bullets fly towards the player?

fresh fox
#

yes i see them

silk night
fresh fox
#

and the particles too

unreal ibex
#

2d

ivory bobcat
#

So their targeting is fine

silk night
fresh fox
unreal ibex
#

its in the assets but it is spawned in with a button

silk night
#

yeah but do you parent it in the canvas when spawning?

unreal ibex
#

how do i do that

silk night
#

show the code how you spawn it

ivory bobcat
fresh fox
#

alright sure

unreal ibex
silk night
eternal falconBOT
unreal ibex
#

how

naive pawn
eternal falconBOT
silk night
unreal ibex
#

i dont understand this

silk night
naive pawn
tidal tide
silk night
naive pawn
#

no that's vsc

unreal ibex
#

what is that

silk night
#

oh lol

#

configuration instructions for your code editor

naive pawn
worn peak
# floral garden Oh i see okk

Would it be possible to get the y vallue of the parent object and then enable the collider of the bullet, after a certain value is reached?

unreal ibex
#

i clicked it

silk night
#

what is localizedString?

fresh fox
unreal ibex
#

what do i do after clicking it

floral garden
#

The distance from the player ? Yeah you can

tidal tide
floral garden
#

But i don’t see the utility

silk night
#

why do you think it would contain "OldValue"?

floral garden
#

As if you shoot short range on a wall, it wil’ just pass through it

naive pawn
unreal ibex
#

but i already have visual studio code

hot wadi
naive pawn
#

those are instructions to configure it

ivory bobcat
silk night
#

I am not 100% sure cause i havent used unity localization, but i would assume if you add a field that already exists, it overrides it

ivory bobcat
#

Thus why they may be digging their graves because they're at the location minus y offset

worn peak
ivory bobcat
#
EnemyAI current position: (-25.00, 1.42, -25.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:50)

EnemyAI destination: (-25.00, 1.17, -25.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:51)```
naive pawn
#

what's the content you're getting?

fresh fox
silk night
#

can you show how you initialize the localizedString?

unreal ibex
#

why do i need to do this

ivory bobcat
tidal tide
# hot wadi Physics.IgnoreCollision

Or on the onCollisionEnter you can just check the tag of the collided object and if it's the player or enemy then do nothing, depending on who's firing the bullet

ivory bobcat
#

If could be you simply logging the incorrect reference

naive pawn
#

is it perhaps just not finished in the same frame?

fresh fox
naive pawn
#

ill have to go check the source though...

fresh fox
silk night
#

are you using the variable "value" anywhere in the base string?
Like i said please show how you initialize that localizedString

naive pawn
#

also yes try previewing your smart string

unreal ibex
#

i dont understand the page

ivory bobcat
fresh fox
#

sure

fresh fox
unreal ibex
#

i deleted console by accident

ivory bobcat
#

Doesn't matter. Log it and see if the value changes

fresh fox
#

ok

silk night
#

alright, what magic/initial string is in your binding for that one?

ivory bobcat
silk night
#

well you are not using the value variable anywhere

#

mhh maybe see if you have access to that in code

ivory bobcat
#

Suggesting that this cs Vector3.Distance(lastTargetPos, target.position) > 0.5fmight not ever be true

fresh fox
# ivory bobcat Doesn't matter. Log it and see if the value changes

I replaced my debug logs with Debug.Log($"{gameObject.name} lastTargetPos: {lastTargetPos}");
Then it says EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

And the other one was changning a bit EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

EnemyAI (1) lastTargetPos: (-5.20, 1.33, -13.93)
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:49)

#

sorry for filling chat mbmb

ivory bobcat
ivory bobcat
#

In particular this line where it's supposedly set ```
if (Vector3.Distance(lastTargetPos, target.position) > 0.5f)

        {

            agent.SetDestination(target.position);

            lastTargetPos = target.position;

        }
ivory bobcat
unreal ibex
#

was it the unity extension that i had to install

silk night
fresh fox
#

Because it is bizarre how it works when there is 1 by itslef

ivory bobcat
ivory bobcat
#

You only need to post a single iteration of messages for both objects (don't spam chat)

worn peak
#

I tried to use ignorecollision, but I get a nullReferenceException, when I use it. I am using a while loop to climb the hierarchy and get the parent I need with the "Player" tag, because I need the collider from that parent object.
It is in the script of the prefab for the bullet.

private Collider bulletCollider;

private void Start()
{
    bulletCollider = GetComponent<Collider>();
    Transform t = transform;
    while (t.tag != "Player")
    {
        t = t.parent;
    }
    Physics.IgnoreCollision(t.parent.GetComponent<Collider>(), bulletCollider, true);
}
fresh fox
# ivory bobcat Log both the last target position and current player target position and see why...

Ok I put this
float distToTarget = Vector3.Distance(lastTargetPos, target.position);
Debug.Log($"{gameObject.name} lastTargetPos: {lastTargetPos}, target.position: {target.position}, distance: {distToTarget:F3}");

if (distToTarget > 0.5f)
{
agent.SetDestination(target.position);
lastTargetPos = target.position;
}

Into my code and this happened the first line when i pressed play looks a bit weird no? https://paste.mod.gg/hcsjmjelgnjp/0

ivory bobcat
fresh fox
ivory bobcat
#

Your position says you're at the dead center of the world minus some offset

fresh fox
#

Ill move a lot and send over the console

ivory bobcat
#

Either way, the value should be larger than 0.5f but the if statement isn't true

fresh fox
ivory bobcat
#
EnemyAI lastTargetPos: (0.00, 0.00, 0.00), 
target.position: (0.00, 2.33, 0.00), 
distance between lastTargetPos and target: 2.330``` The last target position isn't ever updating. It should not be (0,0,0)
#

It should have been (0,2.33,0) etc

fresh fox
#

`EnemyAI (1) lastTargetPos: (0.00, 0.00, 0.00), target.position: (0.00, 1.00, 0.00), distance between lastTargetPos and target: 1.000
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:51)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00), target.position: (0.00, 2.33, 0.00), distance between lastTargetPos and target: 2.330
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:51)

EnemyAI (1) lastTargetPos: (0.00, 0.00, 0.00), target.position: (0.00, 2.33, 0.00), distance between lastTargetPos and target: 2.330
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:51)

EnemyAI lastTargetPos: (0.00, 0.00, 0.00), target.position: (0.00, 2.33, 0.00), distance between lastTargetPos and target: 2.330
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:51)

EnemyAI (1) lastTargetPos: (0.00, 0.00, 0.00), target.position: (0.00, 2.33, 0.00), distance between lastTargetPos and target: 2.330
UnityEngine.Debug:Log (object)
EnemyAI:Update () (at Assets/EnemyAI.cs:51)

`

ivory bobcat
#

It isn't ever changing. Either you're setting it back to a vector zero somewhere or that statement isn't ever true. Put a random log in the if statement and see if it prints

fresh fox
ivory bobcat
#

I'm guessing it works now because your last target position is updating now

fresh fox
ivory bobcat
#

Well, the destinations are properly being set. Maybe they're unable to move because there isn't any valid path (bake the nav mesh etc)

fresh fox
#

Unless i need to bake again after duplicating?

#

Do i bake just the ground?

#

I assume yes

ivory bobcat
#

Try placing the player at like (2,0,5)

fresh fox
#

When there is just 1 it just runs towards it and shoots like it is supposed to

fresh fox
ivory bobcat
fresh fox
#

if i delete it

#

and then just have the original one it works fine

#

its just the second i duplicate it to have 2 they both break down

#

I fix it may be an unfixable issue

#

tbh

#

I WORKED IT OUT I THINK

#

I THINK WHEN I HAVE 2

#

THEY BOTH GO INVISIBLE

#

and they then follow me invisibly

#

and there almost shell is just sitting there

#

and the soul follows me

patent wedge
#

i have this public static void for my multiplayer game but i seemingly can't run serverRpc stuff inside.

An object reference is required for the non-static field, method, or property 'Sound.PlaySoundServerRpc(AudioClip, Vector3, NetworkObjectReference)'

slender nymph
#

a static method cannot call a non-static method without a reference to the object you want to call that method on because static means it is not part of a specific instance of the class

patent wedge
slender nymph
#

wdym by a "universal function"

rocky heart
#

the function of the universe

rich adder
#

the irony of codebeginner with Networking questions

wintry quarry
#

You can't do non static stuff in a static method

#

It doesn't make sense

#

You're going to have to show your code if you want more specific actionable advice

patent wedge
slender nymph
patent wedge
slender nymph
patent wedge
slender nymph
#

any object can access any public method provided they have a reference to the object. which is what you are providing using the singleton pattern there.

wintry quarry
patent wedge
wintry quarry
patent wedge
median depot
#

yo, idk where to say this since its a big server, but does anyone know how you make first person with animations and you can see your character? cause i dont wanna use a normal capsule. i tried seeing some tutorials but they were either; really confusing or outdated, so i was hoping i could get help here.

patent wedge
median depot
patent wedge
# median depot alr alr

but your also going to have to learn how to use unity's animator etc... there should be some tutorials online.

naive pawn
median depot
patent wedge
ivory bobcat
#

Have some audio manager that references an audio source/clips and send the necessary data over the server to be able to play that source/clip on other clients etc

median depot
naive pawn
#

but you should start researching in !learn or via google

eternal falconBOT
#

:teacher: Unity Learn ↗

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

ivory bobcat
#

Data may consist of things like.. an index of some array to indicate which audio to play and location of source, if 3d sound is necessary etc

patent wedge
ivory bobcat
wintry quarry
low copper
#

Sorry. I don't have that as an option on my discord šŸ™

naive pawn
low copper
#

OK...that's it. Thanks for the directions!

gentle gale
#

hey, i am making a soccer game in unity, can someone help me increase the shooting speed or add a power shot

past sentinel
gentle gale
#

ı need powwershot

naive pawn
#

what part are you stuck on specifically?

#

making the shot powerful, the input, the graphics, etc?

gentle gale
#

i don't feel the code is working

#

Can you check if there is any mistake if I send you the code?

past sentinel
#

!code

eternal falconBOT
past sentinel
#

You can send it here with the links

gentle gale
#

wha

naive pawn
#

you gotta provide more context/info than that

#

we aren't psychic

gentle gale
#

Okay, here's the screen, I'm sorry, letme show you like this

gentle gale
#

game

gentle gale
past sentinel
gentle gale
#

my friend is asking

gentle gale
past sentinel
#

the code

#

we cant help if we dont know what the code looks like

#

or what the issue is to begin with

gentle gale
#

@past sentinel

#

The code looks like smash acceleration

#

mean powershot

#

visual studio code

naive pawn
#

that doesn't give us any info at all

past sentinel
#

they sent it to me one sec

grand snow
#

Gotta love a "help plz read my mind thing no worky"

polar acorn
past sentinel
#

this is their code

past sentinel
#

maybe the other person dosent know English all to well

gentle gale
naive pawn
#

you didn't tell us what the issue was

gentle gale
#

I paste the code, activate it, but it doesn't work in the game.

#

this code

naive pawn
#

ok, how doesn't it work

#

what is the actual issue

#

we cannot help unless you tell us

gentle gale
#

I don't know either, that's why I'm trying to learn from you. I don't know if there is a mistake in the code, I paste it into visual studio and save it, and when I enter the game, my shot

naive pawn
#

no, you do know the issue

wintry quarry
naive pawn
#

if you didn't have an issue you wouldn't be here

#

something is happening that you don't want to happen, or something that you want to happen isn't happening

gentle gale
wintry quarry
#

Then nobody can help

floral garden
wintry quarry
#

Imagine you take your car into the mechanic and you just say "fix it?" and the mechanic says "what's wrong with it?" and you say "iunno"

#

then the mechanic will jsut shrug and do something else

naive pawn
wintry quarry
#

how do you expect it to work and what is happening instead?

floral garden
#

I am looking wat is his problem

naive pawn
#

and you can do that silently without spamming.

gentle gale
#

I want my shot to accelerate but it doesn't accelerate.

polar acorn
wintry quarry
floral garden
gentle gale
naive pawn
#

is the rigidbody kinematic or dynamic?

gentle gale
naive pawn
#

have you saved and recompiled

gentle gale
#

yes

#

ı save

polar acorn
#

Have you logged the force in the function after you computed it

wintry quarry
gentle gale
#

you firend add me ?

gentle gale
wintry quarry
#

show the inspector

gentle gale
#

come dm

wintry quarry
#

no

gentle gale
#

why

#

ı show you game and code

wintry quarry
#

YOu can do that here

#

I'm not your personal helper

#

make a thread and share your stuff

gentle gale
#

I don't know how to do that

wintry quarry
#

you already shared code

gentle gale
#

is everything right?

wintry quarry
#

show the inspector

#

we don't need to see the code again

gentle gale
polar acorn
wintry quarry
naive pawn
#

in unity

gentle gale
#

bro what isnpector

#

what eman

#

mean

polar acorn
#

The window that says "inspector" in the title

polar acorn
#

Where you set values in the script

gentle gale
wintry quarry
polar acorn
#

The inspector

wintry quarry
#

wrong program entirely

polar acorn
#

Not the code

gentle gale
#

what

wintry quarry
#

UNITY

floral garden
#

Inspector is on unity

gentle gale
#

hat

#

what

floral garden
#

Not on your IDE or visual studio

wintry quarry
gentle gale
#

will this code work from the unit?

floral garden
polar acorn
#

Read the link

#

Show that

floral garden
#

You are using unity and you don’t know what is unity ?

gentle gale
#

I am Turkish

past sentinel
gentle gale
#

just tell me this

wintry quarry
gentle gale
#

Am I doing the wrong program?

polar acorn
gentle gale
#

Can you tell me what I should do? For example, download some samples.

wintry quarry
#

You should show us the inspector

polar acorn
gentle gale
#

bro inspector ne

#

wait

naive pawn
#

the one that looks like this

gentle gale
#

ı dowland this?

naive pawn
#

you should already have it

polar acorn
gentle gale
#

hey

#

nvida inpsector?

naive pawn
#

Unity inspector

polar acorn
gentle gale
#

can you send me a download link?

wintry quarry
#

no

polar acorn
#

Is the program this channel is for actually installed on your machine

#

If you don't have Unity, why are you here

gentle gale
#

ıdont have unity?

wintry quarry
#

Then you're in the wrong Discord

naive pawn
#

do you have unity

#

do you know what unity is

past sentinel
#

well thats an issue

gentle gale
#

br

#

Stop making fun of me, I just don't know anything.

naive pawn
#

have you seen this icon before

gentle gale
#

Stop making fun of me, I just don't know anything.

past sentinel
#

we arnt making fun of you

naive pawn
#

buddy this is the thing you asked about

wintry quarry
#

Either you are trolling or there is a serious language barrier here. Either way I don't have faith we will make any further progress.

gentle gale
#

I just want to say, what will Unity be good for me? Isn't it for making games?

polar acorn
gentle gale
polar acorn
naive pawn
#

<@&502884371011731486> attention needed @gentle gale

polar acorn
#

If you don't have it why are you asking for support on Unity code

past sentinel
#

maybe their frend does?

#

but idk

gentle gale
#

omg bro

#

i was just asking for help

polar acorn
floral garden
gentle gale
polar acorn
naive pawn
#

we haven't been asking about the code for 10 minutes

gentle gale
naive pawn
#

do you have a game project

gentle gale
#

why bro

#

unity makes game_?

naive pawn
#

oh it isn't even in a unity project

polar acorn
# gentle gale

I did not ask for another screenshot of your code. How are you attempting to run it

gentle gale
#

just playing with unity

naive pawn
#

clearly not, this isn't in a unity project

wintry quarry
#

you need to have Unity to play with Unity

past sentinel
gentle gale
polar acorn
gentle gale
#

no

naive pawn
#

code isn't magic

gentle gale
#

insataled

naive pawn
#

it isn't working because you haven't done anything that would make it work

#

just existing doesn't make it work

polar acorn
gentle gale
#

This is not how the code works

gentle gale
naive pawn
#

cool, we don't support modding here šŸ‘

#

good luck with... whatever you're trying to do

polar acorn
naive pawn
#

it probably won't help but hey, we tried

past sentinel
gentle gale
#

omg... ıdont sayI don't want to say anything to you..

#

you could have just told me the problem

naive pawn
past sentinel
#

okay then

naive pawn
#

for legal reasons, and also because it's quite a different situation than the normal unity dev we typically discuss

polar acorn
#

It's a gigantic waste of everyone's time

past sentinel
#

anyway so i remember there's a thing for this but i forget how it works. I'm basically wanting an input output system. Input scripts look for Output scripts and run a function called Activate(). I remember there being a way to have a group of scripts share a common thing but i don't remember how it works

naive pawn
#

"just Debug.Log the value"
"i can't, i need to inject raw ui math as machine code"

gentle gale
#

Are you talking about me?

#

?????Are you talking about me?

rich adder
#

quit spamming

polar acorn
#
naive pawn
#

the way you've described it at least

rich adder
#

you could do Scriptable object if they are sharing data ?

naive pawn
#

but yes interfaces sound like what you're looking for

past sentinel
#

okay then

#

to summarize i want all things like doors, and whatever else i may need eventually turn on/off like platforms can use this (idk if class is the right word?) to be told when an input has turned them on or off

rich adder
#

interfaces

past sentinel
#

okay then ill use interfaces thanks

rich adder
# past sentinel okay then ill use interfaces thanks

IToggle implemented with method void Toggle
You can commonly call Toggle on any of those that implement IToggle in their class
you are forced to implement the methods and properties of a Interface so you are guaranteed they share it

past sentinel
#
public interface output
{

    public void Activate()
    {

    }

    public void Deactivate()
    {

    }
}
#

would it kinda look like this?

naive pawn
#

c#/cs, not c++/cpp

timber tide
#

You just specify the signature of the methods but not actually implement them in the interface

naive pawn
#

and the methods wouldn't have definitions

#

(also types are PascalCase, also interfaces are prefixed with I by convention)

dusty drift
#

Can i Use cpp in unity?

naive pawn
#

i mean, i guess?

#

but unity uses primarily c#

#

you'd have to define extern'ed methods in c# anyways i think

dusty drift
#

You Thing that c# is better

naive pawn
#

i don't really know the workflow there

dusty drift
#

Ok

naive pawn
#

but c# is definitely much more straightforward to use with unity

#

unity's workflow is kinda built around c#

dusty drift
#

No i mean its better in combi with unity

#

Or easier

timber tide
#

use c#

naive pawn
#

if you're still asking, that means you don't have enough experience to decide

#

just use c#

frosty hound
#

You can't use anything but C#. Implying there could be alternatives is just misleading.

naive pawn
#

can you not use extern'd stuff?

frosty hound
#

Like are we playing the "well technically" game because then yes, technically anything is possible.

naive pawn
#

ah, i thought it was a practical option

frosty hound
#

Given the context of this channel, it's misleading.

#

It's not, no

naive pawn
#

good point

patent wedge
#

how do i get all the audioclips from a folder/entire project into an array or list?

patent wedge
grand snow
#

e.g. "t:Texture2D"

#

or use search service

rough granite
#

oh wait nvm

verbal dome
#

AssetDataBase is editor only

grand snow
#

hmm @patent wedge by editor code i mean in editor outside of play mode

rough granite
grand snow
#

huh?

rough granite
#

wait it is no?

grand snow
#

in editor we can freely search the asset database using this

#

for runtime/play mode code we are restricted to FindAll/Resources/Addressables

verbal dome
patent wedge
grand snow
#

the search string supports this type filter

rough granite
#

then couldn't you just fill out the array with the audio clips? you cant run functions outside of runtime so how would this work huh?

patent wedge
naive pawn
grand snow
rough granite
patent wedge
grand snow
#

CONFIRM WHAT I ASKED

rough granite
#

i thought they were saying that they just wanted to fill out an array in the inspector

grand snow
#

šŸ™ otherwise we will go nowhere helpful

#

we can use this as editor only automation to find many asset guids, load the assets and populate some serialized list/array

patent wedge
naive pawn
#

what do you want this functionality for

grand snow
# patent wedge what do you mean?

The AssetDatabase class is only usable in the unity editor. It is UNUSABLE in a build. It can be used in editor to automate things or manipulate the project in ways not needed during gameplay and builds.

#

plz confirm what you require this for

patent wedge
grand snow
patent wedge
grand snow
floral garden
#

Loadassetasync can handle guid

#

Directly

#

Yeah, 30 min later haha

upbeat dirge
#

Hi, everyone.

Are there any prerequisites before learning SOLID principles?

I have used object-oriented programming with other programming languages but not with C# (I'm a beginner with C#).

Any advice?

eternal falconBOT
topaz chasm
#

hey

#

can ı keep a static bool in a json?

#

ım newbie sorry for basic question but ı need answer

wintry quarry
#

I think what you're actually asking is "can I serialize static variables to JSON" and the answer is you can do whatever you want, but presumably you're using some existing JSON formatter and most won't do that, no

#

It's not a good idea anyway. It's best to put all your serializable data in a class, without any static anything

topaz chasm
#

ty for answer

#

the

#

save and load part is too hard?

#

beginner in unity and c#

wintry quarry
#

save and load is very simple once you understand the basics

#
  1. decide what data you want to serialize
  2. create a class that holds all that data
  3. create an instance of that class to hold the data at runtime
  4. save/load it from json as needed
#

most beginners fail to do step 1 and 2.

topaz chasm
#

also is there anything ı can use instead of statics?

#

ı use it bcs ı dont use dontdestroyonload

#

so ı have a character in every scene

wintry quarry
#

Talking about a singleton game data manager, not the character itself.

topaz chasm
#

makes sense

#

tysm <3

ivory bobcat
topaz chasm
#

like hp,monster statements(alive,dead)

ivory bobcat
#

You can do that without static with just normal proper referencing

topaz chasm
#

so ı should use a gamemanager script with dontdestroyonload i think

wintry quarry
#

something like that yes

topaz chasm
#

@wintry quarry sorry for ping but should ı add the gamemanager to all scenes with auto destroy if there is more than 1 will it be a performance lost?

#

or should ı create a system that if there is no gamemanager in the spesific scene it will auto generated

ivory bobcat
#

The game manager would be using the Singleton pattern. Which would limit the number of instances to one.

topaz chasm
#

so if i add the gamemanager to all scenes for save and load later it will be ok?

#

i tried and it works for me now

#

but wonder if it will be a problem while save and load

rocky canyon
#

u usually add the gamemanager to the first game-scene (then its DDOL)
meaning the next time u change a scene it comes along..

DDOL objects get put into their own scene which loads alongside the other scene
having the gamemanager in every scene is redundant.. b/c the singleton pattern will realize theres already one and destroy itself

topaz chasm
#

the problem is if player starts in second scene i mean

#

he played the first scene and saved it

#

then it will be start from second scene

#

if there is no gamemanager object in second scene

#

how can ıt run as dontdestroyonload

rocky canyon
#

well if it was in the first scene or the ones before that it'd already be there

#

but u can initialize it and start it in the 2nd scene (if thast when the game actually starts) it kinda depends on its job as well

#

my gamemanager keeps track of the menu settings and stuff as well so mine loads in the first scene

topaz chasm
#

ı dont have coding skills to do that lol

#

mine looks alright tho

#

ı hope

carmine skiff
#

can you call functions in Scriptable objects from other things? probably stupid question
I have a scriptable object that rolls random loot and the get lootdrop function is on the scriptable object so could i call it in my UI? im guessing so but want to double check

past sentinel
carmine skiff
#

okay thats fine it is

#

would i have to call the specific LootTable Get random item thought or just in general im guessing the specific lotttable

past sentinel
untold shore
#

Hey! I'm a very new 3d coder (and coder in general), so if there's anything that seems awfully weird, that's probably my doing šŸ˜… Please let me know so I can fix it, even if its not apart of this question 🧔
Currently, I'm creating a movement system using the Unity 1st Person Starter Kit as a backbone. The main thing that I want to do is create a sliding mechanic: when the player presses the sprint and crouch button at the same time, the player character does a slide. Whenever I attempted to do this though, it would only go to Sprint or Crouch, not the slide speed.
Here is the code: https://paste.ofcode.org/399bzBcp5z7fKuwBe3HF2Rf
Any ideas as to how I can create this new mechanic? Thanks! (Please @ me if you respond!)

wintry quarry
#

Remember code always runs from top to bottom in order.

untold shore
#

Gotcha. Thanks!

acoustic belfry
#

i have a question, when would you need to make a variable private?

#

i mean, some variables i dont need to be ferenced, but sometimes they originally weren't and then they were, and then i had to change them manually, wich i wouldnt if they were public in the first place

so why are variables set to private?

frosty hound
#

So you can't modify them outside the class. It's purely organisational.

wintry quarry
acoustic belfry
#

w h y ?

#

just organization?

#

i mean, what if doesn't bothers me

wintry quarry
#

as a rule you don't want to expose anything uncessary to outside classes

frosty hound
#

The why was answered

#

So you can't modify them outside the class.

past sentinel
#

And also in modern Unity, all public stuff like an int or whatever is a field

wintry quarry
#

if you need to access it from outside you should create a limited accessor that doesn't allow setting

cosmic dagger
# acoustic belfry w h y ?

It stops you and others from modifying the variable directly as this creates bugs. If it must be referenced or changed from outside the class, there are other (better) ways to access it . . .

past sentinel
acoustic belfry
#

bugs?

#

how?

past sentinel
#

Editing a thing you didnt wanna edit

acoustic belfry
#

i think it makes sense

wintry quarry
# acoustic belfry bugs?

imagine if you were driving a car and instead of just seeing a steering wheel and a couple of pedals you also saw like the engine's timing belt, the pistons, etc

#

it wouldn't be great if you started messing with that kind of stuff while just trying to drive the car

#

encapsulation is the principle that we should only present the steering wheel and pedals to the user, and not all the internal workings of the car

acoustic belfry
#

makes sense

lavish violet
#

I just started making games and have no idea how to code can anyone help me

eternal falconBOT
#

:teacher: Unity Learn ↗

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

eternal falconBOT
#

:teacher: Unity Learn ↗

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

lavish violet
#

šŸ˜„

boreal plinth
#

Hey, how would I get mobile controls to work here? I followed a tutorial to the tee, but it doesn't move my character.

  1. On-Screen stick set to left stick gamepad
  2. Player tagged as Player
  3. Left stick gamepad in input settings
  4. The snippet of code in the Player that detects input
wintry quarry
#

which completely ignores all of the rest of the setup you showed

#

you would need your code to use the new input system and use an action bound to Left Stick (Gamepad)

#

On Screen Stick is part of the new input system - it doesn't work with the old.

boreal plinth
#

Gotcha

wintry quarry
onyx patrol
#

Hello everyone!

#

I'm working on a map strategy game and have started making a pixelated region map

#

Some closer shots

#

It's set in the medieval period and I want the player to be able to place castles on the map

#

For that I'd like to make a tilemap out of my image.

#

How can I make a tilemap where each pixel from this image is a tile?

wintry quarry
#

Nothing about this seems conducive to a tilemap to me

#

Tilemap is for when you have tiles (repetitive sprites that you use to build up an environment)

#

that doesn't fit this situation

onyx patrol
#

If you've ever played the Civilization series the map is made of of thousands of hexes where you can place cities

#

Kind of what I want to do here

wintry quarry
#

A Civ map is like... 1000 tiles

#

The images you shared above are approximately a million pixels each

onyx patrol
#

What I would really like to know is if it's possible to kind of slice the map up in Unity to make tiles out of it

wintry quarry
#

The way I see it you have essentially two options, and a tilemap is not necessarily involved in either of them

#
  1. Take the image as-is, and just overlay a hex grid on top of it. You could use some heuristic like "the color with the most pixels in the cell are what the cell counts as"
  2. Take the image and run it through a "hexification" pass, which you could write yourself in C# or possibly using a shader, where you walk through a hex grid covering the image and for each cell you look at all the pixels in that cell and analyze them to decide what color that cell should be. The end result is a much lower resolution image in approximately the same shape but made up of "hexels" (hexagon pixels). YOu can then do option 1 and the visuals will line up much better
#

Unity has a Grid component (which TIlemap uses) that lets you deal with grid coordinates more easily (can be square grids, hex grids, 2d or 3d)

onyx patrol
wintry quarry
#

that might be the most straightforward way

onyx patrol
#

I guess I could also just make it so that when you are trying to place a city/castle your mouse would just snap to intervals which line up with the pixels

#

The point of having "tiles" for me is that when you place a city there's would be a radius around it, and the amount of water and land in that radius gives different benefits

#

So in my mind being able to count how many water and land pixels (which I thought tiles might be good for but maybe not now) would yield different benefits

#

Maybe there's another way to do this that doesn't involve making the tilemap? Because as you said it would be quite large

wintry quarry
#

Tilemaps are for rendering repetitive sprites in a grid

#

ultimately a Tilemap is an optimized sprite renderer for displaying a large number of repetitive sprites in a grid.
The grid part is just... a Grid

onyx patrol
#

How could I go about making a grid for the map? If you don't mind my asking

wintry quarry
#

It's just a component

#

you add it to a GameObject

#

then it's there

#

you interact with it through scripting

onyx patrol
#

I will do some more research into that

regal magnet
#

where can i learn 2d random map gen i find some good videos on youtube but not realy what i was searcing for i want to create tons of room as prefab and randomly use them on map

strange kelp
#

Oh my I'm stupid

mortal grove
#

Hey I got a simple question

#

If im using a canvas to hold a script that uses an event trigger can I just put a secondary script in that for another clickable ui?

hazy slate
mortal grove
hazy slate
#

it kinda go trough the wall

hazy slate
grand snow
#

Either its own pass or a second camera to render after the main content

hazy slate
grand snow
hazy slate
lapis pond
#

Can someone help me, why is my albedo all white? I want to make it a cloud shape

bold pebble
#

Guys any pro c# devs here?

nimble apex
#

i need new input system pro lol

wintry quarry
hexed terrace
eternal falconBOT
#

: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

bold pebble
#

Kay

polar yarrow
#

Hey I need some help on this movement system in my game. (I'm using using Unity 6)
I want to set a limit on how fast the player can go but it only controls the speed in one direction and its just broken in general

if (Input.GetKey(KeyCode.Space)) {
    if (rb.linearVelocity.x >= 5) {
        rb.linearVelocity = new Vector3(0, 5, 0);
    }
    if (rb.angularVelocity.x >= 5) {
        rb.angularVelocity = new Vector3(0, 5, 0);
    }
    if (rb.linearVelocity.z >= 5) {
        rb.linearVelocity = new Vector3(0, 0, 5);
    }
    if (rb.angularVelocity.z >= 5) {
        rb.angularVelocity = new Vector3(0, 0, 5);
    }

    rb.AddForce(forward * 2f, ForceMode.Force);
} else {
    rb.linearVelocity = Vector3.zero;
    rb.angularVelocity = Vector3.zero;
}
boreal violet
#

Is it possible to make a shader that will cut this off?

boreal violet
#

I mean this boards, to connect edges of faces based on heightmap(tessellation)

teal viper
boreal violet
#

I'm trying to make something like this, but when i use POM and tessellation, i get this...

teal viper
#

How are you using tesselation?
As for POM, it doesn't alter the mesh geometry, so if you look at parallel to a surface, it will still seem flat.

#

In the second screenthot it seems like POM is working correctly. I can see unevennes in the surface

boreal violet
#

So how to get this 3d effect...

teal viper
#

You do have it

#

Beyond that, you'll need vertex displacement

boreal violet
#

Here's Tessellation Displacement

teal viper
#

Do you have enough vertices to displace though?

#

Can you show the mesh in wireframe mode?

teal viper
hazy slate
wintry quarry
#

If your object has a Rigidbody, that should go on the parent.
Renderer and collider go on the child

hazy slate
boreal violet
teal viper
teal viper
teal viper
boreal violet
teal viper
hot wadi
#

Right now I'm using this child object's script to detect ground and oneway platforms


public class GroundTrigger : MonoBehaviour
{
    public Player player;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        int layer = collision.gameObject.layer;

        if (layer == 3)
        {
            player.OnGround = true;
        }

        if(collision.tag == "OneWay")
        {
            player.currentOneWay = collision.gameObject;
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        int layer = collision.gameObject.layer;

        if (layer == 3)
        {
            player.OnGround = false;
        }

        if (collision.tag == "OneWay")
        {
            player.currentOneWay = null;
        }
    }
}```
But I see another way using `RaycastBox` which keeps everything in player's script and eliminate the child object. Idk which method should I use for my platformer game
#

That code is a bit messy, I still not finish it yet

teal viper
boreal violet