#💻┃code-beginner

1 messages · Page 780 of 1

bronze fossil
#

ooo i c thanks

glass summit
#

@frail hawk

frail hawk
#

why do i have a feeling that you need to learn the concept of oop.

frail hawk
#

so what error do you still have?

glass summit
#

i just have to not press the popup

#

but i was curious what that popup meant, since i always get it

hot wadi
#

Scene04Events ain’t a good name for a mono script

#

I might have a stroke reading this

frail hawk
hot wadi
#

Well if the script is doing what the name suggest, u will want to take a look at the event system

frail hawk
#

yep

glass summit
#

Clicking yes is a grave mistake

naive pawn
#

clicking yes just normalizes your line endings

sleek flare
#

Does anyone know what resource I should be looking into to convert a large json string into a small hash looking string? Like how some idle games let you export the web save into a string that tends to be short, and then import that string to load your save? I'm trying to do that, but I'm not quite sure what I should be looking for.

keen dew
#

Base64 would make the large string into an even larger string

#

You can implement a compression algorithm to reduce the size to maybe about half but I assume the exports you've seen are a custom format instead of compressed JSON

sleek flare
#

Ah, that would make sense. I tried messing around with some online string compression sites to test different compression methods, and all of them made the strings bigger, probably will just look into another way of doing so then, thank you.

gloomy heart
#

You can try out TOON, its just json but cleaner and smaller , its built for LLM's to reduce tokens

coral fractal
#

I don't know why am i come to this server without any experience

gloomy heart
#

What?

coral fractal
astral geyser
glass summit
#

hey for my Visual Novel game, i made a new scene with two images, with a background image and the hex code is adjusted. One is like yellowish for a day theme, and one is like a dark blue for a night theme. Now i want to randomize it each time the player enters the scene to be either day or night, and depending on the time of day, they should say something different. so now i've managed to make the image backgrounds random, but the text is always the same. Can anyone take a look at my code and lemme know what i did wrong here?

#

Nevermind I figured it out...

wintry badge
#

Hey, can someone help me with playermovement? I tried using couple of scripts, and one ready asset, but when I tried using it it failed to work.

radiant voidBOT
# hot wadi !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

gloomy heart
wintry badge
hot wadi
naive pawn
#

well, if you're below unity 6. you've conveniently cropped that out

wintry badge
naive pawn
#

can you show them

wintry badge
#

Script, yes?

hot wadi
#

The name mismatch would cause a compile error

naive pawn
#

maybe an error from unity? i don't remember, but either that or a warning

#

though, not on unity 6

hot wadi
#

Well we can’t be sure unless they provide the code

wintry badge
#

here

naive pawn
#

for future reference, !code

#

!code

radiant voidBOT
naive pawn
#

(but that's unnecessary here, just wanted to make sure the name was correct)

#

you haven't messed with the meta file, right?

#

is this happening to all your scripts or just this one?

wintry badge
#

Uhhh... And what is meta file?

wintry badge
naive pawn
#

it's a file with the .meta extension providing metadata for each asset

#

like for this script, there should be a PlayerMovement.cs.meta

#

(it won't show up in unity)

#

how'd you get the asset?

wintry badge
#

Asset store and rest of the scripts for walking from videos. I did exacly same thing as they but I had an error

wintry badge
naive pawn
#

how did you import them

wintry badge
#

Assets > My Assets > And then import asset and that's all

#

It showed up in my assets, and I used script for walking from asset store

tired python
#
IEnumerator BulletInstantiate()
{
    if (enemyCollision.EnemyList.Count != 0)
    {
        Transform bullet = Instantiate(prefabBullet, transformOfSpawnPoint.position, Quaternion.identity);
        _BulletPool.Add(bullet);
    }
    yield return new WaitForSeconds(4);
}``` if i call this caroutine inside `update`, will it only be called once every 4 seconds?
wintry badge
naive pawn
#

"if i do X, will it do Y" bro please

naive pawn
naive pawn
wintry badge
#

Yep, I even created new test project, same thing

naive pawn
#

from the same asset?

#

do you get the issue with scripts you create yourself?

tired vortex
#

Hello can someone help me with this

#

What should I do

hot wadi
# tired vortex

That means u don’t have a class named PlayerControls anywhere

hot wadi
tired python
naive pawn
solar hill
# tired vortex

im assuming the playercontrols class is supposed to be an input action wrapper class?

#

and that you probably dont have one generated

#

and if you do its probably not named that

tired python
#

will i be breaking anything if i am iterating through a list of transforms while i am destroying the elements inside it ? i have noticed locations after destroying become null

naive pawn
#

well.. destroying them doesn't remove them from the list

#

they become destroyed

#

that's what unity null is

tired python
#

are they managed by unity in a way such that they are removed when they turn null or something? or do i need to manually remove those indexes too...?

naive pawn
#

are they managed by unity in a way such that they are removed
no, that's literally just not possible

wheat surge
#

they become null objects in your list

naive pawn
#

it's why unity null exists to begin with

#

they aren't actually null

#

you do need to remove them, yes. the wrapper objects still exist

tired python
#

so after the whole process the list is gonna have null objects inside it, and i just check for all objects inside it which are null and remove them yeah?

naive pawn
#

or you could remove them as you iterate, which can work if you're iterating backwards for example

wheat surge
#

When you destroy them can you remove them?

tired python
#

i did think of it though

naive pawn
#

it will work if you do it correctly

#

consider being more specific than "breaks stuff"

tired python
#

wait lemme think it through

wheat surge
#

Did I miss what you are trying to do

tired python
naive pawn
#

no clue what you're talking about

#

i have no context on what you're trying to achieve

#

the order they're added in probably won't have an effect

tired python
naive pawn
#

you also just.. don't need to iterate backwards, that's not the only way to achieve it

tired python
#

i have a tower, the tower sees objects, adds them onto List<Transform> EnemyList, another script shoots bullets from that tower. i have a reference to both lists, so, suppose i see two enemies so List<Transform> EnemyList has two enemy transforms at index 0 and 1. The first enemy was added first, and then the second enemy was added, so the first enemy is at index 0 and second at index 1. now i iterate through my _BulletPool and List<transforms> EnemyList. Guess what happens when i iterate backwards? i check the last index first ie index 1, so the first bullet moves towards the second enemy instead of the first.

naive pawn
#

where does iterating the enemies and destroying them come in

#

you shouldn't be destroying from the tower to begin with

tired python
#
if (enemyCollision.EnemyList.Count != 0 && _BulletPool.Count != 0)
{
    for(int i = 0; i < Mathf.Min(_BulletPool.Count, enemyCollision.EnemyList.Count); i++)
    {
        Transform bullet = _BulletPool[i];
        Transform Target = enemyCollision.EnemyList[i];

        Vector3 direction = (Target.position - bullet.position).normalized;

        bullet.position += BulletSpd * direction * Time.deltaTime;
        Debug.Log($"{Vector3.Distance(bullet.position, Target.position)}");

        if (Vector3.Distance(bullet.position, Target.position) < BulletSpreadArea)
        {
            Debug.Log($"IN RANGE: {Vector3.Distance(bullet.position, Target.position)}");
            Destroy(bullet.gameObject);
            Destroy(Target.gameObject);
            _BulletPool.RemoveAt(i);
        }
    }
}```
naive pawn
#

i don't see any list you'd be iterating to destroy

#

the bullet should manage its own destruction

#

the enemies should manage their own destruction

tired python
#

using collision checks or something then?

naive pawn
#

distance stuff also works. you just need each thing to worry about itself

tired python
#

but this is gonna work though.

naive pawn
#

what do you even mean by "bullet child gameobject"

#

is one bullet calculating stuff for every bullet?

tired python
naive pawn
#

each bullet?

tired python
#

no, just the script

#

as in BulletShoot is the child of the Tower

#

not bullet

hot wadi
#

U just have to worry about cleaning up the null ref in the towers’ EnemyList when the targets are destroyed

tired python
naive pawn
#

also pretty fragile

tired python
#

not rly? u just check their distances, if they are less than something, destroy em

naive pawn
#

each tower expects to manage the destruction of every enemy it's created a bullet for?

#

what happens if an enemy is in the range of multiple towers

tired python
naive pawn
#

that's the part that's both overcomplicated and fragile

naive pawn
tired python
naive pawn
#

...so you have even more stuff handling this...

naive pawn
#

this is overcomplicated, yes.

tired python
#

O_O

naive pawn
#

"this isn't managed by the tower, this is just managed by ShootBullet which is part of the tower" bro please

tired python
#

i don't understand how it is complicated though...

tired python
#

that's just two lists...

naive pawn
#

are you aware of "single responsibility"

tired python
#

no

naive pawn
#

you have them correlated by index

tired python
#

elaborate

naive pawn
naive pawn
naive pawn
#

your tower should not be responsible for all its bullets if it doesn't have to

#

you could easily just make this a fire-and-forget system

#

the tower shoots a projectile at an enemy (or even just its position)
then the projectile has its own collision logic

hot wadi
#

Following ur idea, u will have to keep a reference of the parent towers on each bullet in order to access the EnemyList. Hundreds of bullets, each iterating through the list will cause performance issue, and the code itself is too tightly coupled to be maintained

naive pawn
naive pawn
naive pawn
gloomy heart
naive pawn
#

that's.. entirely irrelevant, but sure

#

UDP is fire-and-forget, not the other way around.

tired python
#

so i make a dictionary whose key are enemies and its elements are gonna be bullets? i have just one script which iterates through this dictionary and makes every bullet element of a enemy key fly towards it or something and if the bullet reaches a certain range, destroy the key(enemy) or something?

naive pawn
#

you don't need to save the bullets at all

tired python
#

then how do i manage the bullet's movement?

#

i did try to make a script for every bullet on instantiation, but i could not get it to work

naive pawn
#

the bullet manages itself

#

the tower just tells it where to go

#

that's the end of the responsibility for the tower

tired python
#

i will try it again then.

hot wadi
#

That makes me wonder: Is calling Update on hundreds of objects faster than updating each of them in a single Manager?

naive pawn
#
Tower:
  serialized float cooldown
  serialized int damage
  serialized Bullet bulletPrefab
  List<Enemy> enemies
  OnTriggerEnter2D: if collider.TryGetComponent(Enemy): enemies.Add(enemy)
  OnTriggerExit2D: if collider.TryGetComponent(Enemy): enemies.Remove(enemy)
  float nextShot = 0
  loop:
    if Time.time > nextShot && enemies not empty:
      target = enemies[0]
      bullet = Instantiate(bulletPrefab, transform.position)
      bullet.Initialize(target.position, damage)
      nextShot = Time.time + cooldown
Bullet:
  serialized float speed
  serialized float lifetime
  Vector2 target
  float damage // could be serialized here instead of the tower
  float expire
  Initialize(Vector2 target, int damage):
    this.target = target
    this.damage = damage
    expire = Time.time + lifetime
    transform.up = target - transform.position
  loop:
    if Time.time >= expire:
      Destroy(gameObject)
      return
    position += transform.up * speed // set rb velocity if using rb
  // collision handled with an rb or something would be the easy and natural solution, otherwise
  // - you could make it expire at the target position for a directed attack
  // - you could only check collision with the initial target, but that would probably be jarring as it passes through other enemies
  OnCollisionEnter2D:
    if collider.TryGetComponent(Enemy):
      enemy.Damage(damage)
      Destroy(gameObject)
```this is really all you need at the bare minimum. damage could be serialized with the tower or the bullet, up to you.
with a pool, there's some more stuff to store and you'd grab from the pool/return to the pool instead of instantiating/destroying
#

this is both the tower and the bullet.

gloomy heart
naive pawn
#

do you see what i mean about yours being overcomplicated
you can have fewer moving parts, less logic overall

tired python
#

Initialize(Vector2 target, int damage): this IS EXACTLY WHAT I WAS LOOKING FOR WTH

naive pawn
#

...were you not aware of this

tired python
#

look at my previous posts

naive pawn
#

that's.. unfortunate

#

it's a pretty crucial part lol

tired python
#

i kid you not, i had been so troubled by the fact that i could not pass information along with the Instantiate() method which unity already comes with, that's why i reverted to the method i was tryna use

hot wadi
naive pawn
#

though there's probably a jump between native and IL code, so maybe 100's of nanoseconds

ashen sorrel
#

it all just shows as yellow i don't know what to do?

wheat surge
#

is that ui

ashen sorrel
#

ok

tired python
tired python
naive pawn
#

yeah, and then they'd expire. that's a pretty normal thing to happen in tower defense

#

homing is generally an additional attribute making stuff better

#

consider what the projectiles represent diegetically

#

but if they're homing, they'd usually be targetting stuff near the projectile, not near the tower

#

consider: if there's 2 enemies, one inside the tower range, one outside (but near the first one)
then the tower shoots at the first one, but it dies just before the projectile reaches it
what should happen?

tired python
#

as the code currently is, since the bullet uses the target's position to map out its trajectory, it's gonna return a nullref error cus the target its trying to reference has been destroyed

naive pawn
#

that doesn't matter

#

what should happen, according to you as a game designer

tired python
#

it homes in on the next enemy present in the list

naive pawn
#

stop thinking about the list

#

that is not what i'm asking

tired python
#

ok

#

it finds the closest target and blows it kaboom

naive pawn
#

closest based on where the projectile currently is, right?

tired python
#

yes

naive pawn
#

what if when the tower shoots the projectile, there's an enemy right beside the tower, such that it's initially closer to the projectile than the intended target?

tired python
naive pawn
#

cool, so now we have a solid picture of how the projectile should act (there is another issue but we can get to that later)

#

only now, should you start thinking about how to implement that

tired python
#

oh

naive pawn
tired python
#

kinda...but my mind is going on a tangent wherein, the bullet calculates the distance between itself and all the enemies in enemylist and then finds out the closest one and homes in on it 💀

#

is it bad that that's the first thing my mind goes to...

naive pawn
#

well, not bad, but you gotta realize that you're getting ahead of yourself

#

that'll come naturally when you get more experience - you can design the behavior and the implementation together

#

but right now, you don't have the experience and foresight to do that effectively, and you'll end up coding yourself into a corner

#

the intended behavior should come first

lethal meadow
#

How do i build a NavMeshSurface at runtime?

naive pawn
#

like imagine this situation
yellow being the path, red being the enemies, green being the tower
orange being the targetted enemy, blue being the path of the projectile
imagine that orange enemy dies right before the projectile reaches it

intuitively, it should target the right enemy, right?
but using the tower's list of enemies, it'd go to the left enemy - or if that enemy wasn't there, the projectile just wouldn't find a next target

naive pawn
#

ah fuck i forgot

tired python
naive pawn
#

ehhh well i think it should be easy enough to guess?

#

the gray circle represents the tower's range, the blob at the middle of that circle is the tower
the rest of the blobs are enemies

naive pawn
# naive pawn given this, now it's clear that the list of enemies the tower holds isn't releva...

the flow for the bullet could go something like this (modified from above for brevity) (spoilered if you want to figure it out)
||```cs
Bullet:
Enemy target
Initialize(Enemy target, int damage):
this.target = target
this.damage = damage
expire = Time.time + lifetime
loop:
/* check expire /
if target:
transform.up = target - transform.position // set rb rotation if using rb
position += transform.up * speed // set rb velocity if using rb
else /
logic to find target */

tired python
naive pawn
charred monolith
#

I got a problem with my script, that when OnTriggerEnter is being called, I use Physics.Overlapshere and Everything in The Physics.Overlapsphere will get a rigidbody and and quick explosionpush.
but it doesnt do that instantly.
i think its Physics.Overlapsphere is getting called after one frame.
I dont want to change it to OnCollisionEnter becaue sometimes it is allowed to go through more objects for more realistic effects.
Here is the video and my Script: https://paste.mod.gg/eywsyhkefwgv/0

Note: please do not bully me just because my code is bad

cosmic dagger
naive pawn
cosmic dagger
#

doesn't homing projectiles stick to the main target?

#

well, even if you want to switch, you'd have to get a new list of enemies in range, then choose from those to avoid targeting any out-of-range . . .

naive pawn
naive pawn
naive pawn
cosmic dagger
keen dew
naive pawn
#

the force from the explosion isn't applied instantly

charred monolith
naive pawn
#

you could check for overlaps with FixedUpdate, which happens before the internal physics tick, but not sure it's worth it for 0.02 seconds as nitku mentioned

naive pawn
#

that would break a ton

cosmic dagger
#

you can set a bool to true in the trigger method, then call a method in Update or FixedUpdate that uses OverlapSphere . . .

charred monolith
naive pawn
naive pawn
#

it's the OnTriggerEnter that is after the internal physics update

#

so if you want to change the behavior, you'd have to do it all in a different message

cosmic dagger
#

also, I would ensure the objects have a Rigidbody and DestroyOtherGameObjetcsOnHightSpeed component on them. Adding multiple components to multiple GameObjects can be costly . . .

charred monolith
naive pawn
#

no

naive pawn
cosmic dagger
charred monolith
cosmic dagger
charred monolith
cosmic dagger
#

i saw the video. wait, there's a meteor, where?

charred monolith
#

no i think its to fast for you

cosmic dagger
#

i saw a player, then a board flip and hit the building . . .

rocky canyon
#

freezeframe

charred monolith
cosmic dagger
charred monolith
rocky canyon
#

just a quick hand i guess

charred monolith
#

i managed to capture it

karmic quail
#

any quick fix out there for a mesh not showing up in the 'Main Preview' panel of Shader Graph? no default basic shape or custom mesh show up

blazing kiln
#

hey, I had a merge conflict in git and one of the conflicts was one of Unity's meta files for a script. I'm a bit scared of those because I'm worried what happens if I have a "mismatch" between the changes I allow from the actual scripts (local version or remote version or a combination?) and the meta file hash or whatever it is. How does that even work?

wintry quarry
#

The danger here would be if your script is in use in any scene or prefab, those components would become broken references if the file id changes

blazing kiln
wintry quarry
#

I would recommend taking the remote meta file

#

However for an interface

#

realistically it's not going to matter

blazing kiln
#

in this case the script was not used in any scene or file, because it's a pretty new project.

wintry quarry
#

because no prefab or scene will be referencing the interface

blazing kiln
#

right

wintry quarry
#

yeah it doesn't matter then

blazing kiln
#

thanks for clearing that up, I'll be careful of that

#

I assume unity version control handles this better? I've never used it

wintry quarry
#

i don't think UVC would handle this any better or worse than git

blazing kiln
#

ah gotcha

naive pawn
#

!code

radiant voidBOT
ashen sorrel
#

ah gotcha

naive pawn
#

if you want to know the previous input, you'd just.. save the previous input

wintry quarry
#

wdym by "get the last input"?

#

you already had it saved in a variable from what I saw

ashen sorrel
wintry quarry
#

right so what exactly is the question here?

grand snow
#

😆 me confuse

ashen sorrel
wintry quarry
ashen sorrel
#

i can do that all i need is the last input

wintry quarry
#

transform.right = moveInput; pretty much

wintry quarry
#

moveInput

ashen sorrel
#

sorry i used a tutorial i did not now that was what it did

wintry quarry
#

tutorials are not a recipe to build a game with

#

they're examples so you learn the concepts so you can build your own stuff with the understanding you gained

weary flume
#

Hey, so im trying to learn unity and make something simple, im having an issue that im stuck on. So Im trying to get the direction that a collision occured between two players or a player and a stage part. The player part works fine, but the same code with the stage parts never triggers. Any help would be appreciated. I know this code is messy as well

solar hill
#

it could be a few issues.

#

your stage collisions may not trigger because the script is on the wrong object for example

#

the stage might lack a rb2D component

or youre using otherCollider incorrectly or youre trying to access a player component on a stage object that doesnt actually have one.

wintry quarry
#

btw .otherCollider in Collision is, confusingly, your OWN collider

#

not the other object you collided with

weary flume
#

oh ok

#

that might be it

wintry quarry
#

but you really need to just start debugging the code

#

Debug.Log

solar hill
#

var player = GetComponent<Player>();

wintry quarry
#

print out which object you collided with, etc.

#

Certainly (contact.otherCollider.gameObject.CompareTag("Player")) is probably working becuase YOU are a player

#

the .gameObject you have is never needed btw

#

there's a few things that make this code pretty tedious

weary flume
#

ok. I appreciate the help

weary flume
solar hill
#

work on fixing whats broken now first

#

then work on refactoring it in a more efficient way

#

as you learn more

weary flume
#

ok. Thank you

tired python
slender nymph
#

if you think it is because they are colliding with other objects then constrain the rotation on the rigidbody

tired python
#

@naive pawn it worked out. i now just need to figure out how to manage the homing mechanism

tired python
solar hill
#

if you are going to have a lot of towers creating and destroying bullets then you might want to have pooling

slender nymph
#

I would probably have a single pool shared by all towers to ensure that the projectiles get reused but also so that there aren't just a whole bunch of pools active at once

solar hill
#

yeah not one per tower

tired python
solar hill
#

i mean if towers share the bullets

#

why have seperate pools

tired python
#

good point

solar hill
#

in the case of towers that dont share bullets have them share their own pools with their respective different bullets

#

thats what i do in my game, each gun that has the same projectile type shares a pool

#

basically the amount of pools is equal to the amount of unique projectile types the player can have at any given time

#

which is never more than like 2 or 3

tired python
#

where would the script need to be on?

solar hill
#

i use the leanpool addon

#

i guess on the tower script?

tired python
#

but i can have many instances of the same tower, how would they all share the same pool in that scenario?

slender nymph
#

pass a reference to the pool to whatever component actually uses it when that object is instantiated

tired python
#

ok, last question. where do i attach the script which has the pool in it. i sure can't add it on the tower

slender nymph
#

where ever makes the most sense, it can be its own gameobject

solar hill
#

do you have some kind of game manager object?

tired python
slender nymph
#

yes

tired python
#

i will use singletons later on in another project but i am too far deep in it to apply it in here atleast

slender nymph
#

just FYI, just because something has "Manager" in the name does not mean it needs to be a singleton.
but also the "GameManager" does not need the object pool used by the towers either

solar hill
#

yeah a singleton is a class with exclusively one instance, not nescessarily one that appears just once in the scene

tired python
solar hill
#

i personally handle my enemy pooling within my gameManager and i havent really had any trouble with it so far, but you can just set it up on a seperate game object

grand snow
#

When you advance past the beginner stage then you should be able to judge better when and where an object pool should be stored and used

#

Ideally its whatever class is able to spawn and reclaim objects to return to the pool

tired python
#

i have a question. in scripts, we use the term GameObjects and in heirarchy, we use the term gameobjects too. don't people confuse them?

grand snow
#

erm no?

solar hill
#

what

grand snow
#

GameObject only means one thing, An object in a scene OR a prefab

tired python
grand snow
#

we can have many gameobjects in a scene. A prefab is a gameobject with many gameobject children

grand snow
#

that could be your game manager or a dedicated component

naive pawn
tired python
#

what are these

#

blue are prefabs

naive pawn
#

ah i thought you meant the one you selected

grand snow
#

Yep, they are still gameobjects in a scene

#

Just linked to a prefab asset

tired python
#

then won't people confuse it with transform.gameObject?

slender nymph
#

note that this is really only a concept within the editor. the scene view (and inspector) shows that these objects originated from a prefab.
this wouldn't be the case in a build since the concept of a prefab doesn't really exist in a build

naive pawn
# tired python what are these

every entry here is a gameobject in the scene
the ones with a blue cube are also prefab instances (not prefabs, though when unambiguous, they might be referred to as prefabs)

naive pawn
slender nymph
naive pawn
#

why would you confuse something with itself

grand snow
#
//This is true!
bool isSame = gameObject == transform.gameObject;
tired python
#

ohh

naive pawn
#

Transform is a Component
MonoBehaviour (and your own component that derives from it) are also Components
Component.gameObject refers to the GO the component is attached to
the transform is attached to the same GO as the MB, so their gameObject fields refer to the same object

tired python
#

okie

cloud agate
#

What would be a good system of keeping flags of events in the game?

#

I've seen people say that too many Unity Events is not good, but I see people say that too many Updates are not good either

#

(As an example, I want to complete a mini game, and then a bridge appears)

#

But I don't want to hardwire the script so that the only thing it does is make a bridge appear

ivory bobcat
#

Is it conflicting with your development/game? This isn't like C++ where best practices are absolute must haves.

cloud agate
#

Not really, but it might not be a good habit (not sure of course)

#

(refering to dalphat)

naive pawn
#

a foreach over an array is "not good" compared to a for loop in terms of perf but it literally just doesn't matter in 99.99% of cases

cloud agate
#

alr thanks

fading marten
#

Hi! Anyone here think they could help me with Cinemachine scripting? I'm trying to figure out how to change the horizontal axis of a freelook camera through a script

naive pawn
# cloud agate alr thanks

uhh to be clear im giving that as an example, not saying your situation is the same
you haven't really given enough context to really say whether the "not good" parts are relevant in your case

#

in any case, you should figure out why they're apparently "not good" and consider whether those downsides are relevant to your usecase

cloud agate
# naive pawn uhh to be clear im giving that as an example, not saying your situation is the s...

As an example, I have a steppable platform which activates 3 other platforms as accessible. The platform uses this script

public class GenTrigger : MonoBehaviour
{
    [Header("Events to run when the player enters")]
    public UnityEvent onPlayerEnter;

    [Header("Events to run when the player exits")]
    public UnityEvent onPlayerExit;

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log("Entered");
            onPlayerEnter.Invoke();
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log("Exited");
            onPlayerExit.Invoke();
        }
    }
}

This uses two Unity Events

#

I can use these to call any other method from other objects

naive pawn
#

i don't see any issue with the events here

#

i don't see why you'd use Update instead

rotund imp
#

I have been seeing people code and they get things auto filled for them like for example Destroy(); will just auto fill when they click tab even if not fully typed how can i get that?

#

i am new to the unity engine so if you ever see me ask dumb questions thats why

radiant voidBOT
wicked cairn
#

You can set up the plugin for unity using these instructions ^

rotund imp
#

Alr thanks

wicked cairn
# rotund imp Alr thanks

No problem, dont worry about a question being silly or not, this community is here to help everyone. Configuring your IDE will significantly help you solve errors. Enjoy

mystic crypt
#

quick question, if i wanted to instantiate a gameobject for every frame that the mouse is held down (using GetMouseButton(0)), do i have to multiply something in the code by Time.deltaTime so its not dependant on fps? when i use FixedUpdate() it works fine enough until i move my mouse even a little bit too fast, in which case the clones spawn super far apart and with way less than usual. ive read a couple forums that say mouse inputs are already safe from the fps stuff that Update() can be affected by but im just sorta lost. Here's the code im using for it if maybe im just missing something entirely:

{
    Vector3 mousePos = Input.mousePosition;
    mousePos = Camera.main.ScreenToWorldPoint(mousePos);
    mousePos.z = 0;
    transform.position = mousePos;

    if (Input.GetMouseButton(0) && touching)
    {
        cloner = Instantiate(cloned, mouser.position, mouser.rotation);
        cloner.transform.parent = parent.transform;
        ParticleSystem part = Instantiate(particle, mouser.position, mouser.rotation);
        part.Play();
        sketch.SetActive(true);
        
    }
    else
    {
        sketch.SetActive(false);
    }
    

}
#

-# ignore the sketch and particle system stuff its unrelated to my issue

#

touching just ensures that i can only spawn the objects inside of a specific area which works fine enough (except when i get the issue of moving my mouse too fast, in which case theyll leave the area)

timber tide
#

fixed update idea can work fine too and the idea is by using a rate of which you want to spawn them and over the distance from the previous point

#

otherwise if this is just rendering related and not tied to any gameplay logic then what you're doing seems fine assuming it isn't blowing up your frames

torn mango
#

hi can explain to me why does my character stop falling if I hold w towards a side of a building

#

im using rigidbody character movement

upbeat forum
#

i think i understand delta now?

placid jewel
# upbeat forum i *think* i understand delta now?

If it helps, time.deltaTime is just the time (in seconds) between this frame and the last one. So if you move an object by a certain amount, say distance, multiplied by delta time, eg position += distance * time.deltaTime, if you replace time.deltaTime with 1 second, you'll find that position changes by 1 * distance every second, regardless of how many frames or how fast the framerate.

teal viper
rough granite
placid jewel
hot wadi
blissful stratus
#

hello guys i looked the whole internet for a way to implement 2d side scroller enemy i couldnt find a good tot so if any one have a good totorial or a way to imploment it please let me know

blissful stratus
#

and i want to make my own attacks not like sword slashes or smth like that

eager cliff
#

Hey does anyone know why my script isnt working? just trying to play a gun sound effect on left mouse click.

placid jewel
#

Can you send a screenshot of the gunFire component in the editor's inspector window?

eager cliff
placid jewel
#

They're anything that goes on a gameobject

#

Somewhere an object called Gunfire has an Audio Source component

#

I can see it here

gloomy heart
#

in the AudioSource attach a sound file you want to play

placid jewel
#

You should be able to double click on the reference to go to the component

eager cliff
#

this one?

placid jewel
#

Yup

eager cliff
hot wadi
#

Perhaps put a Debug.Log to check if the input is receiving

placid jewel
# eager cliff this one?

There's definitely an audio clip there, but make sure you can hear it in general, and also make sure your code to play the sound is triggering by putting a Debug.Log("(some message)") underneath the audio play. Then test it again and look to see if/how many times the Debug.Log message was triggered

eager cliff
placid jewel
# eager cliff audio definitly works, if i set it play on the instance beginning i can hear it.

I'm guessing it might be one of two things, but not 100% sure:
1st since you're using GetMouseButton, that triggers every frame that the mouse is down, which I think would be causing the clip to restart every frame until the mouse is released (should use GetMouseButtonDown if you're using the old input system)
2nd, you mentioned using a tutorial that might have been old. There's a possibility that the tutorial is using the old input system and your project is set up for the new input system. If that's the case there should be a couple of easy fixes.

#

Can you put a Debug.Log, then test again and show what happens in the console?

hot wadi
#

A lot of stuff have happened in 12 months

gloomy heart
#

That's not too old, I've been using tutorials 4-5years old

placid jewel
placid jewel
eager cliff
hot wadi
#

If the input setting is wrong, Unity should give u a warning. It’s more likely the misuse of GetMouseButton

eager cliff
#

I changed it to GetMouseButtonDown but it i still cant hear anything

hot wadi
#

Did u put a debug log?

eager cliff
eager cliff
placid jewel
# eager cliff right, what should it be changed too?

There's a couple of options, it's not quite a single line of code change. Either you can switch the project to use the old system, which is easy but since I assume you're learning, it's not a good idea to learn something that's already being replaced. Alternatively you can find the new input system docs here: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/manual/index.html
and can search things like "unity new input system get mouse click" to find out how to use it

placid jewel
eager cliff
placid jewel
eager cliff
hot wadi
#

Study C# and OOP before u take any Unity tutorial

placid jewel
# eager cliff Right, yeah ok sounds good, btw for someone whose a complete newbie would you ha...

I don't know how well you'll be able to replace code with animation, and while I don't exactly have tutorials, there are plenty of first person controller tutorials out there. If you want to make it multiplayer, "Unity Multiplayer Tutorial" will probably get you a lot of useful basic tutorials, but I can't say for sure based on what you want. However, multiplayer is something best set up in a new Unity project, so decide about that one quickly I guess.

placid jewel
# hot wadi Study C# and OOP before u take any Unity tutorial

Agreed, at least to some extent. There's a lot you can do with only the basics of C#, or basic knowledge of any other language that could translate a bit, but you'll definitely need to be able to read the docs for sure. In general figuring things out from the docs is much more useful for learning than tutorials imo

eager cliff
placid jewel
eager cliff
balmy vortex
#

idfk if I'm just stupid or something

keen dew
#

Read the warning

hot wadi
#

“In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour”

naive pawn
pearl rune
#

Hello I'd like to make a game similar to FiveM's architecture, meaning that people can host their own server and add their own scripts: server and client included, but I don't know where to start.

wicked cairn
#

If so, make singleplayer first. Multiplayer is a massive step up and not going to be fun for beginners.

pearl rune
#

A school Rp

pearl rune
wicked cairn
wicked cairn
wicked cairn
pearl rune
wicked cairn
#

Fish net will have higher performance on dedicated servers. Where as mirror will have more options for self hosting

pearl rune
#

like fivem

wicked cairn
#

I suppose it would work like fivem. If it’s working out for you stick with it lol

solar hill
pearl rune
rapid coral
#

Hi guys

rich adder
rapid coral
#

Hi guys I am a beginner in c# coding nice to meet u all how do this server work pls

torpid glacier
#

Hello! My team and I are working on a local multiplayer game where players can team up with up to 4 players using controllers.
We’re exploring ideas for situations where there aren’t enough controllers—for example, 3 players but only 2 controllers.
Is it possible to let two players use controllers while the third uses keyboard input? Would that setup work well in practice?
We’d love to hear your thoughts or suggestions.

naive pawn
#

definitely possible, yes

keen dew
#

Surely your team are the only ones who could know if it would work well in your game

tough lagoon
#

Can you use a keyboard and controllers in a game? Yes.

#

Figuring out which player is keyboard on a splitscreen game is tougher

torpid glacier
#

we thought about splitting the keyboard into 2 parts

#

but this idea can make the game harder so we want help with design

raven marsh
#

Hi

#

Im new, who can teach me

#

How to script

#

I come from gdevelop

rough granite
radiant voidBOT
rough granite
#

otherwise unless you got specific questions you're asking in the wrong place

raven marsh
#

Ok thx

umbral hound
#

What is standard practice when I have multiple scripts that their methods need to be updated? Just make a "UpdateInputs" method and put them all in that? Maybe with if else null checks?

using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class Player : MonoBehaviour
{
    [Header("References")]
    [SerializeField] private CharacterController m_CharacterController;
    [SerializeField] private Transform m_Camera;

    public PlayerMovement m_PlayerMovement = new PlayerMovement();
    public PlayerLook m_PlayerLook = new PlayerLook();
    public CharacterController CharacterController => m_CharacterController;

    private void Awake()
    {
        m_CharacterController = GetComponent<CharacterController>();
        m_PlayerMovement.Initialize(m_CharacterController);
        m_PlayerLook.Initialize(transform, m_Camera);
    }

    private void Update()
    {
        m_PlayerMovement.UpdateMovementInput();
        m_PlayerMovement.UpdateMovement(transform);
        m_PlayerLook.GetInput();
        m_PlayerLook.Rotation(transform, m_Camera);
    }
}
naive pawn
#

what do you mean by "their methods need to be updated"

#

methods don't change

umbral hound
naive pawn
#

hi, not really how support servers like this work. just lurk around for issues you can help with

umbral hound
#

But since those scripts are basically SOLID principles, they don't derive from monobehavior since they are extensions

naive pawn
umbral hound
#

Yes

umbral hound
#

player movement, player camera control, etc

#

basically extensions of a player monobehaviour class

naive pawn
#

so they're monobehaviors

tiny tiger
#

Fantastic my dm
Are open for more details/ requirements

umbral hound
#

No

naive pawn
#

this is not a space for seeking commissions

umbral hound
#

They do not derive, instead, they are labeled with [System.Serializable] and they are variables in the main player script

#

initialized with new

naive pawn
#

what is the setup here

umbral hound
naive pawn
#

you mean this?

Objects or entities should be open for extension but closed for modification.

#

"extension" there is what inheritance is in OOP languages

umbral hound
#

Basically these (PlayerMovement.cs, PlayerLook.cs) are non-derivable classes that are labeled with cs [System.Serializable] and then they are brought in as variables in a monobehavior class, and their methods are used by said variable in the main script

naive pawn
#

ok, so there's just no extension here other than your component extending MonoBehaviour

umbral hound
#

Okay, I thought they used that term when I read SOLID

naive pawn
#

that term is used, you're misunderstanding what it's used for

umbral hound
#

My fault, again, I have trouble conveying thoughts, I apologize

naive pawn
#

it's also an OOP term, not specifically a SOLID term

umbral hound
#

Oh okay, well what you said earlier is what I meant

#

I just didn't know how to contain methods that need to be updated each frame in a way where my script doesn't look like spaghetti code

naive pawn
#

tbf, there is also an issue of terminology with "script" in unity

umbral hound
#

Okay, monobehaviour

naive pawn
#

"script" technically means the file itself, and it does not have a 1:1 correspondance with the types inside
but here "script" can also mean components

#

to make sure we're on the same page,

What is standard practice when I have multiple scripts that their methods need to be updated?
here you mean you have multiple non-component types that are used in a component, and they have a method that is supposed to be called every Update?

#

why not just make them components

umbral hound
#

Yes

#

Well because I know a lot of people who do it this way and it's easier for me

naive pawn
#

how's it easier exactly

#

i don't see the benefit

#

ah well i guess there's a time dependency, is that what you're referring to

umbral hound
#

Because I can just make a non-derivable class, label in serializable, and then call it in my main monobehaviour, and boom they control input, etc

#

Yes

naive pawn
#

(also why not use structs, do you really need that to be a reference type)

umbral hound
#

Can I ask you a question? I PROMISE I'm not trying to sound mean, it might because again... I have trouble saying what I wanna say PRECISELY, but why does it feel like I'm being told to code a certain way?

naive pawn
umbral hound
naive pawn
#

no, i'll explain in a sec

naive pawn
umbral hound
#

I really hope I didn't make you upset or anything I asked what I did. I spent all my life being misunderstood and because of that I take stuff a little too personal when people ask me to do things differently

naive pawn
#

i'm presenting an option that i think fits the scenario better and is easier to work with, to reason why your solution isn't needed - but you don't have to take my solution

umbral hound
#

Not my JOB but just as inn I want to

naive pawn
umbral hound
#

Oh?

umbral hound
#

Well, making components probably will be faster for prototyping small games, but when I get to making big games, I'll probably want to do what I'm doing now

naive pawn
#

why?

naive pawn
# naive pawn also, this is a pretty good read https://xyproblem.info

your actual problem (X) is trying to separate out the logic, making it more modular
your current attempt at a solution is using another layer of classes as members of the main component
-> that brings up an issue for updating those classes (Y)

i think a better solution to solve X would be to just use separate components

umbral hound
# naive pawn why?

Well, because I've learned pretty much from seeing other people's code, and there's one person in particular who made a big game this way. Like yeah, he uses inheritance, but for his player and some others, he does use the "variable" scripts like I am

naive pawn
#

ok, and what benefit does that provide

umbral hound
#

And playing through the game, there's really no bugs

naive pawn
#

you can do that with any pattern

umbral hound
#

I don't know

naive pawn
#

and you can get bugs with any pattern

umbral hound
#

I mean he did say years ago, before he even came out that he was "killing himself" learning how to make this project, so could that be it?

naive pawn
#

i honestly just don't see any benefit to doing this over just using separate components

rough granite
umbral hound
#

Well I think I know why. One is that he has systems, frameworks, that cross checks each other. Let's say he has an interaction system that checks stuff across scripts, can you do that with different components?

naive pawn
#

yes

umbral hound
#

Huh.

naive pawn
#

components are classes too

#

anything you can do with classes, you can do with components (aside from stuff related to the lifetime managed by unity)

umbral hound
#

So by that logic you don't need a local "player" script. You just need a component for movement, looking, etc

naive pawn
#

sure, that would decentralize the logic

#

and that is possible

#

but whether it's viable, depends on what you want to achieve overall

#

in a lot of cases, you do also want kind of a "mastermind" component to control the overall flow

#

maybe you can't move sometimes because you're in a cutscene or paused

#

if you had each component detect that separately, that'd be a lot of repetition

umbral hound
#

Well see, I'll be honest, I'm not into this whole "component" stuff, I was just afraid that if I didn't agree, I wouldn't get help

naive pawn
#

i mean.. unity is built on components

#

well, gameobjects and components

umbral hound
#

Yeah but I mean I was afraid that if I didn't denounce my way of working and conform to others', I wouldn't get help

#

That's my problem, even in IRL I'm a people pleaser, I'm so concerned people are gonna be p*ssed at me I don't even bother

naive pawn
#

im sure there was a reason the person you're referring to chose to use member objects instead of separate components
"personal preference" is a valid reason - and it is for you too
i'm just trying to provide solutions that will be easy to work with and maintain

#

and i think components would be easier to work with than member objects

#

but that doesn't mean you can only use components

umbral hound
#

Oh okay, do you think you can still help with my original question, or because you don't work that way you don't have an idea?

naive pawn
mystic crypt
#

does anyone know a quick solution for instantiating at a fixed interval regardless of fps? ive tried using fixedupdate but that makes the cloning process weird and somehow makes it slow when i move my mouse rapidly? (my mouse controls when to spawn), i can send relevant code if its needed but im just hoping for some general ‘instantiate at .3 seconds * time.deltatime’ or something lol

slender nymph
#

google "unity update timer"

naive pawn
# umbral hound Oh okay, do you think you can still help with my original question, or because y...

well, your original question was about standard practice.. i don't think there's a standard practice since this pattern isn't commonly used as far as i know (though, i don't have that much experience in the ecosystem.)

having a separate method for updating the modules could be viable if your Player has to do other stuff in Update, but if not, you could just do it all directly in Update.

another approach would be to have a uniform interface for the modules, and then you could have a collection to loop through to update all of them

some comments about the code, now that i'm reading it more closely

  • seems like the UpdateMovementInput() and UpdateMovement(transform) (and same for playerLook) should always come together - why not have a single method to do both?
  • i see you have an Initialize method used in Awake, why not use that to set the transform/m_Camera so you don't have to pass them in UpdateMovement/Rotation?
  • why is UpdateMovement using the transform if you have a CC? you shouldn't be modifying the transform's position, that'll be conflicting with what the CC is trying to do
umbral hound
#

I didn't know transform conflicted with my CC

mystic crypt
naive pawn
#

why wouldn't it

mystic crypt
#

its a painting program type thing with pixels that follow your mouse when its pressed down

#

i dont know it just. Doesnt

naive pawn
#

have you tried it

mystic crypt
#

yeah

#

ive got it set to 0.01f and its acting the same as 0.5f so i assume theres a limit

slender nymph
#

That's definitely doing painting wrong if you're instantiating objects for each pixel

mystic crypt
#

it gets deleted at a set time its not gonna cause a performannce issue or anything

naive pawn
#

it will

slender nymph
mystic crypt
#

it lasts for about 4 seconds total

mystic crypt
#

ive got an fps counter

#

it doesnt get affected when i spam it like crazy

naive pawn
#

you're trying to instantiate objects at 100Hz

#

that's.. going to create a lot of objects for GC

mystic crypt
#

that might be delving a little too deep i dont really know that kind of stuff

#

what else can i do?

naive pawn
#

if you do something at max once per cycle then it's going to be limited by deltaTime

#

that's what the inner while loop solves

naive pawn
mystic crypt
#

oh i just realised you have while in here

#

doesnt that crash update?

#

or well . Crash unity

naive pawn
#

if you have an infinite loop, yes

mystic crypt
#

weird

#

its crashed for me when there hasnt been one

#

ill try using that code and see if anything changes

naive pawn
mystic crypt
#

dont you usually make a coroutine with ienumerator?

keen void
#

Hey, I was just wondering whether I should use visual studio 2026 or 2022 for unity.

naive pawn
#

ah i just realized i had that template wrong....

mystic crypt
#

well uh whats the correct template

#

do i use that code or not?

keen void
mystic crypt
#

frankly i dont care about the performance because it doesnt seem to take a hit and its not a very big game at all anyway

#

i just need a quick bandaid fix

naive pawn
# naive pawn ah i just realized i had that template wrong....

it should look like this

float elapsed = 0;
/* some update loop */ {
  elapsed += Time.deltaTime;
  while (elapsed >= timeInterval) {
    /* do thing */
    elapsed -= timeInterval;
  }
}
```the "some update loop" can be:
- a unity message that is given continuously, in which `elapsed` would be a field.
- a coroutine, where `elapsed` would be a local, and the loop would be a `while (cond)` with a `yield return null;`
naive pawn
#

you aren't locked into your choice

mystic crypt
#

i dont understand that second part at all

naive pawn
#

which part exactly

mystic crypt
#

after the code

naive pawn
#

it just needs to be something that keeps running over time

mystic crypt
#

elapsed being a field ?
elapsed being a local ?
i just dont really get it its not clicking

naive pawn
#

do you know what fields and local variables are

mystic crypt
#

fields no

naive pawn
#

fields are the variables that exist in a class or struct scope, for example

#
class X {
  float t; // field of X

  void Method() {
    float x; // local variable inside Method
  }
}
struct Y {
  int v; // field of Y
}
mystic crypt
#

Uh . i dont get it

#

whatever im just gonna find another tutorial

naive pawn
#

go google "c# field" for a better explanation

keen void
naive pawn
#
float elapsed = 0; // field
void Update() {
  elapsed += Time.deltaTime;
  while (elapsed >= timeInterval) {
    /* do thing */
    elapsed -= timeInterval;
  }
}
``````cs
IEnumerator DoThing() {
  float elapsed = 0;
  while (true) {
    elapsed += Time.deltaTime;
    while (elapsed >= timeInterval) {
      /* do thing */
      elapsed -= timeInterval;
    }
    yield return null;
  }
}
```here's examples of how to use the template
mystic crypt
#

is invokerepeating fps dependant?

naive pawn
#

no

mystic crypt
#

aaoigugfhhh this sucks

naive pawn
#

but you also just.. don't get any control with that

mystic crypt
#

true

naive pawn
mystic crypt
#

oh no wait

#

i said it wrong i meant independant

#

lol

keen void
#

does anybody use jetbrains

naive pawn
#

plenty

keen void
#

is it good

naive pawn
#

fucking called it

#

it's usable

#

it's good if you think it's good

#

try it and see for yourself

mystic crypt
naive pawn
#

wouldn't you just use the cancel thing for that

mystic crypt
#

the what

#

now that im reading about invokerepeating it does seem a little finnicky

naive pawn
#

though, im not confident invokerepeating can run multiple times per frame

mystic crypt
#

let me try it

naive pawn
#

both could work

mystic crypt
#

yeah i just dont understand the first one lol

naive pawn
#

it's the same thing just without a coroutine

mystic crypt
#

everytime ive even thought about using while in update it crashes

#

no matter what

naive pawn
#

that would be an infinite loop

mystic crypt
#

i know but even when it Isnt

#

it just. doesnt like it

naive pawn
#

this one is written to not be infinite

mystic crypt
#

ill try it

naive pawn
#

if you're getting freezing issues, then there's something not completing

mystic crypt
#

shrug

#

wish me luck

#

this looks like it has the exact same issue with fixedupdate ,,,,,,,,,,,,,,

#

i dont think its an ‘issue’ though its just kinda how it works and im not sure if theres even a fix lol

#

when i move my mouse fast the clones spread out like crazy

naive pawn
#

you'd have to interpolate between the previous mouse position and the current one

mystic crypt
#

seems like more hassle than its worth

naive pawn
#

or you could draw a line between the previous mouse position and the current one instead of using pixels

#

i mean, the spacing out thing isn't really uncommon among poorly made versions

mystic crypt
#

ehhh pixels kinda fix the theming of the game im making

#

looks rougher

naive pawn
#

are they even on a grid

mystic crypt
#

they dont need to be

naive pawn
#

then they aren't really pixels

#

they're just square dots

mystic crypt
#

so what

#

all the necessary code for them works fine

naive pawn
#

that changes the constraints, it makes it easier

#

you can interpolate the mouse position

mystic crypt
#

uh. i dont really know what youre saying anymore

#

oh this new code fucks with my other code somehow

#

fuck it all im just going back to fixedupdate 😭

#

way too much effort for qol

keen void
#

Why is there no C# script option

#

Is it MonoBehavior script or am I missing something

#

yes it is monobehavior found it

naive pawn
#

yeah it was renamed

torn wraith
#

For whatever reason i just cannot get my colliders to collide at all. i've used debugs, ive changed around triggers, i have both objects with colliders and rigid bodies... the bullets are just going striaght through the other asset.

slender nymph
#

how are you moving them

torn wraith
#

public class Asteroid : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log("Asteroid trigger with: " + other.name + " (tag: " + other.tag + ")");

        if (!other.CompareTag("Bullet"))
        {
            Destroy(other.gameObject); // bullet
            Destroy(gameObject);       // asteroid
        }

        
    }
}```
slender nymph
#

also you are specifically checking that the other object does not have the Bullet tag

torn wraith
#
[SerializeField] private Transform bulletSpawnPoint;
[SerializeField] private float bulletSpeed = 15f;
[SerializeField] private float burstShotInterval = 0.1f;
[SerializeField] private float singleShotCooldown = 0.25f;
private float nextSingleShotTime = 0f;```
#
{
    if (bulletPrefab == null || bulletSpawnPoint == null)
        return;

    GameObject bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);

    Rigidbody2D bulletRb = bullet.GetComponent<Rigidbody2D>();
    if (bulletRb != null)
    {
        if (pewAudioSource != null && pewClip != null)
            pewAudioSource.PlayOneShot(pewClip);

        Vector2 direction = (Vector2)transform.up;
        bulletRb.linearVelocity = direction * bulletSpeed + rb.linearVelocity;
    }

    Destroy(bullet, 4f);
}```
torn wraith
slender nymph
#

okay so does the bullet object have the Bullet tag then?

torn wraith
#

indeed

slender nymph
#

Great! That means it will not be destroyed by the OnTriggerEnter2D method you showed before. Just like I said.

torn wraith
#

i don't understand what is going on as i have played with triggers many times before. I've only run into this problem the first time i dealt with them.

slender nymph
#

if (!other.CompareTag("Bullet"))
what is the outcome of this if statement when other refers to a Bullet object?

hot wadi
#

U say u have played with triggers many times but u clearly don't understand how a simple bool return works

torn wraith
#

i fixed that part. but it still wont detect if the asteroid is it. i have it so two players with Player tags can shoot each other, but not themselves.

torn wraith
#
        other.CompareTag(alienTag))
    {
        Destroy(other.gameObject);  // destroy target
        Destroy(gameObject);        // destroy bullet
        BasicExplosionAnimation();
    }
    if (other.CompareTag(playerTag))
    {
        // method to die and respawn
        Destroy(gameObject);
    }
}```
#

i have this script now attached to the bullet rather than the asteroid.

#

For what ever reason it just works now after remaking the asteroid asset. thanks for your help @slender nymph

radiant voidBOT
torn wraith
#

MY ISSUE IS I HAD SIMULATED TURNED OFF IN THE inspector

outer bluff
#

just a quick question when i try VS2026 the intellisense doesnt work but when i install the 2022 from unity hub it works straight away. isnt 2026 intellisense fully compatible yet?

midnight plover
#

!ide

radiant voidBOT
outer bluff
#

ill read thru it now but i dont see how 2022 works and 2026 wont but ty for the quick reply

midnight plover
torn wraith
hot wadi
torn wraith
# hot wadi It's not our fault that u ignored the hints we gave, especially when u claim to ...

It's unclear where your frustration is coming from as you seem to have very little patience for something you had little involvement with. My code is not the thing i was actually struggling with in the end. I made a typo in my code by accidentally removing my return in place for some brackets. You were not the one who pointed that out. So cheer up, have a cup of tea, friend. Life is too short to have frivolous gripes.

hot wadi
midnight plover
rancid cosmos
#

Hi guys

#

How to use the newest cinemachine version

#

I'm kind of confused

#

I'm making a platformmer btw

naive pawn
#

as in, how to access it or how to utilize it?

rancid cosmos
#

Ultilizing

#

I want my camera to be a bit biased to wherever the player is looking

#

😭

naive pawn
#

have you tried googling for cinemachine guides/tutorials

rancid cosmos
#

Yeh but the version is different

#

So i'm confused now

naive pawn
#

isn't the core concept the same

#

and you can always just add the version to your search query

rancid cosmos
#

I can't find it

#

And nearly all the components are different

#

😭

naive pawn
rancid cosmos
#

Thanks man

snow warren
#

Hi

#

Anyone in need of help

#

Today I am free so ask me anything

normal arrow
#

Heyyy, i've got some file i'm generating on my app (csv files) and i would like to make a zip out of them, but everytime i try, i've got an "Permission denied" error, any idea why ?

(i'm already doing a lot of stuff with theses files so idk why this thing specifically is annoying)

normal arrow
#

Yep ! i'm just doing that

    {
        Debug.Log("Tentative de création de zip depuis : " + sourceDir + " vers : " + zipPath);
        ZipFile.CreateFromDirectory(sourceDir, zipPath);
        Debug.Log("Zip créé : " + zipPath);
    }```
naive pawn
naive pawn
#

are you able to read other files from sourceDir or write other files where zipPath is?

snow warren
#

This is a simple read and write permission

normal arrow
normal arrow
naive pawn
#

to be clear, you're getting an IOException?

naive pawn
#

oh, that's different (i misread what the exceptions meant)

#

UnauthorizedAccessException

destinationArchiveFileName specifies a directory.
-or-
The caller does not have the required permission to access the directory specified in sourceDirectoryName or the file specified in destinationArchiveFileName.

#

just to make sure - check that it's not the first situation

broken mortar
#

hello?

#

can anyone help me in building Bus Simulator?

naive pawn
naive pawn
normal arrow
naive pawn
#

persistentDataPath is a directory

#

you're trying to write data into a directory

normal arrow
#

wait

#

i think i understand

silk night
#

you need place to be + filename

naive pawn
#

it's where the file is at, not where the file is in

normal arrow
#

ahahaha my bad, it was such a basic thing i'm sorry

#

but thank's !

#

how could i missed that

silk night
#

Nobody starts an expert, no worries 😄

normal arrow
silk night
#

Oh you should see the stuff my colleagues with 20years of gamedev experience sometimes fail on 😄 and I'm not better with 7 years

naive pawn
#

you never really stop learning with this stuff

#

honestly in my experience, if someone claims to be an expert, they're either a god with a lot of dedication and experience, or they're overconfident

silk night
#

I think Chris here had one or two moments where he wouldve liked to curse at me with the dumb stuff I was writing here 😄

naive pawn
#

i have less experience than most people here tbh

#

i just have more free time to be active lmao

silk night
#

Yeah but a good eye for details that I tend to miss

naive pawn
#

"one or two" would be on the lower end for me.. i don't remember any instances like that with you lol. most of the negative experiences i remember are people consistently being confidently incorrect and arrogant/stubborn

if someone doesn't know something and they learn afterwards, that's a positive experience

silk night
#

Yeah you help too many people here to really remember it but I had my moments where I thought you might be angry at me xD

#

I've also been more active but thanks to those damn crunch times in our industry I cannot really do that atm

naive pawn
naive pawn
silk night
#

I wouldve said something if you were rude for no reason

tranquil forge
#

why does it need to multiply with fixed delta time here? what it mean

polar acorn
tranquil forge
#

like just converting seconds to ms typa shi here?

#

then i suppose i can set a small speed instead and still make sense ?

silk night
#

To add to that: Your frame times are not consistent, neither on a device nor between devices

A device with 50 fps would move 5x the speed of a device with 10 fps,
So it behaves like:
50 x distance x 0.02 (Time.deltaTime) per second = 1x distance vs
10 x distance x 0.1 (Time.deltaTime) per second = 1x distance

naive pawn
naive pawn
#

it could work (specifically in this case with the fixed time step), but it wouldn't make sense.

polar acorn
silk night
#

isnt even fixed update not guaranteed to run on timing? Especially with lags

naive pawn
#

@tranquil forge do you understand deltaTime in general? (is your question about it being fixedDeltaTime, or just the deltaTime in general)

tranquil forge
#

why is the set (0,100,0 a per frame thing?

naive pawn
tranquil forge
naive pawn
#

there's no set (noun) nor set (verb) here

tranquil forge
naive pawn
#

fixedupdate is run many times, over time

#

you want to use a value of 100 per second, because that's easy to work with

#

but fixedupdate isn't running once per second

#

it's running faster than that, some x times per second
so 1/x gives you how many seconds each fixedupdate takes

that's fixedDeltaTime

tranquil forge
#

but this is not the same as seconds and miliseconds conversion ?

naive pawn
#

it is not, no

tranquil forge
#

but fixeddelta time is set 0.02 right ? it is unchange ?

oak stone
#

By curiosity, can we speak French in this community or not ?

naive pawn
#

it's not guaranteed to be 0.02

#

it could be affected by physics settings and timescale

tranquil forge
#

alr i think i get the gist, the fixed delta time here serve just a unit conversion

naive pawn
#

the same as deltaTime, yes

#

just for a different cycle

proper pond
#

Hello

polar acorn
# tranquil forge why is the set (0,100,0 a per frame thing?

Think of it this way, if you had a value for m_EulerAngleVelocity of 0, 100, 0:

  • Without FixedDeltaTime, it would rotate the object by 100 units every physics step, for a total of 5000 units per second
  • With FixedDeltaTime, it would rotate the object by 2 units every physics step, for a total of 100 units per second

They're both constant based on frame rate because it's in FixedUpdate, so neither one is wrong, but it comes down to what unit you want to deal with in the inspector

proper pond
#

just want to learn how to handle the basics of vectors, for moving things or moving the player

polar acorn
#

FixedUpdate runs independently of the framerate. It will double up or skip as necessary

naive pawn
#

yes, but it doesn't really change the answer

tranquil forge
#

bet

silk night
polar acorn
#

Remember - Rendering happens based on your framerate, so even if the physics calculations happen independent of time, if your game lags, you might not see the results until the next render frame

tranquil forge
brave compass
#

There's also a maximum delta time which Fixed Update will catch up with, after which it will skip updates. The default is 0.3333, so if you have a lag spike longer than that, Fixed Update will miss some frames.

naive pawn
#

using deltatime just makes everything easier

brave compass
#

There are valid reasons for changing the fixed timestep, possibly even at runtime, depending on which device is running, as a quality setting, etc. So you should still use delta time in Fixed Update.

#

You're already using delta time if you're using AddForce with the Force or Acceleration mode.

polar acorn
# silk night so yes the timing may be different between the calls but it doesnt matter cause ...

Let's say you have a game that runs at 60 frames per second consistently, with the default physics step of 0.2:

This means that a frame takes 0.0166 seconds, and FixedUpdate takes 0.02 seconds.
At frame one, you're doing both Update and FixedUpdate.
Frame two, 0.0166 seconds have passed, not enough for another FixedUpdate.
Frame three, 0.0332 seconds have passed, so it would run FixedUpdate, leaving you with 0.0132 "unaccounted" physics seconds
Frame four, another 0.0166 passes, putting you over the 0.02 budget again so another fixed update happens.

Now let's suppose you hit a loading zone that takes exactly one full second between frames four and five.
Your current time is at 1.0664 and you've done three fixed Updates, leaving 1.0064 seconds unaccounted for in physics time. This means that FixedUpdate will run fifty times right now. This "catches up" the physics engine with the game time. This means that any per-physics-step calculations like momentum do happen fifty times, each one doing the math as if they were exactly 0.2 seconds apart, and you see the result all at once when the render thread catches up after the load.

silk night
naive pawn
#

if you don't have deltatime itll still be tickspeed dependant

polar acorn
#

Yes, you could change the Physics Time Step or the Time Scale, which would affect the value of FixedDeltaTime, so if you want a number to respond to those changes you should use it

torn wraith
brave compass
#

Actually, it probably won't run 16 times. It sounds like it will run however many updates it can fit within 0.3333 seconds. So if your physics update is light enough, it might be able to do 50.

tranquil forge
#

whats make you want to specific set fixed step to 0.0139 percisely

brave compass
#

That's 1 / 72 Hz. This is from a Quest project that runs at a locked 72 FPS.

tranquil forge
#

you match it with update ?

#

i suppose make it smaller is better but larger is questionable

brave compass
# tranquil forge you match it with update ?

No, but that's a separate option.
If your physics update rate is lower than your rendering frame rate, you will see physics objects lagging every so often unless you enable interpolation on each and every rigidbody. For a VR project that needs to have a locked framerate and consistent frame times, it's better to match these.

polar acorn
livid anchor
#

Hey I would have a question about movement. Lets say I have a "drone" hovering at a fixed altitude, I want to move that drone on two axis X/Z. I know I can use translate to move the drone, but what if I want to use addForce instead ? How do I make it ,ot fall with a rigidbody ?

polar acorn
#

There should be a checkbox to disable gravity on the rigidbody

#

If it's a Rigidbody2D it'll instead be a "Gravity scale" field you can set to 0

naive pawn
#

if it can be affected by other stuff, you could also freeze Y position or apply a restoring force to the specified Y level

pliant dome
#

If the a gameobject jumped to a ledge and had a box collider touch both the wall and ground they become grounded even though they are jumping. I tried using ignorelayercollision but idk if thats what I should be doing.

#

Does anyone know some potential solution to this?

naive pawn
#

depends on how you're doing the grounded check

#

you'd generally try to make it so the wall isn't considered

pliant dome
#

I tried to but when I airdash into the ledge Ill start running

#

Was using tags

#

and hoping to say that if I collide with the wall then grounded is false

#

but Im colliding with both the ground and the wall

#

when I airdash into the wall by itself then I never become grounded

naive pawn
#

is that not what you want

pliant dome
#

It is

#

The issue is when I airdash into the wall ledge Im also textnically touching the ground

naive pawn
#

at the top?

pliant dome
#

Yeah

naive pawn
#

how are you doing the grounded check

pliant dome
#

If my gameobject box collider is touching the stage box collider

#

On collision enter

#

tags

wintry quarry
naive pawn
#

couldnt you just make the ground above the ledge not reach the ledge

fading marten
#

Anyone think they can help me? I'm trying to get access to a value in another component in a script

wintry quarry
polar acorn
fading marten
#

let me get the errors real quick

wintry quarry
radiant voidBOT
polar acorn
fading marten
fading marten
wintry quarry
fading marten
#

Its a value called LookOrbitX and I want to get the InputValue from within it

wintry quarry
#

you're trying to shove a square peg in a round hole

polar acorn
fading marten
naive pawn
#

@pliant dome you basically have this, right?

pliant dome
wintry quarry
fading marten
fading marten
naive pawn
wintry quarry
#

You should be getting mouse input from the input system

fading marten
pliant dome
polar acorn
# fading marten Its what I have left from tinkering with it and trying different things

= means "Assign to". It means you're putting a value in the box.

You've made a variable of type InputValue named movementData. The = would be telling it which InputValue you want that variable to hold. What you've done is instead tried to set it to InputAxisController, which is not an InputValue. You've essentially done int x = fish. They're not the same kind of data

pliant dome
#

You just constantly fall

polar acorn
pliant dome
#

I tried this earlier

fading marten
naive pawn
#

include positioning in that check

polar acorn
#

It's a category

#

which value do you want from that axis?

fading marten
naive pawn
naive pawn
fading marten
polar acorn
#

The lookOrbitX is something that reads from the given input value and does stuff in response to it

pliant dome
polar acorn
#

You want to read from the input system to get the mouse movement, which has nothing to do with the Cinemachine component

wintry quarry
pliant dome
#

Yeah Id imagine it be so

polar acorn
wintry quarry
naive pawn
pliant dome
# naive pawn

This wont be a concern as this is a platform fighter with no walls like that

wintry quarry
#

I can't tell - seemed to me they want some special action when touching a wall that is mutually exclusive with being grounded

wintry quarry
#

you could also go with this logic:

if (isTouchingWall) //
else if (isGrounded) //
else```
#

if the "wall touching" is always just prioritized over the grounded stuff