#💻┃code-beginner

1 messages · Page 125 of 1

native flicker
#

ah alright thank you

desert elm
#

hm- quick question, but how complicated is creating a pathfinding system for a very simple 2D game?

river roost
desert elm
river roost
#

Look up A*

#

there are plenty of guides on it

#

or you can just steal someones code

desert elm
robust condor
#

Or use navmesh

#

Oh it was 2D, nvm

desert elm
#

thanks as well-

lusty flax
#

why does this appear if my mesh does not have a rigidbody?

slender nymph
#

sounds like it probably does have a rigidbody. keep in mind that a parent object with a rigidbody still counts

lusty flax
#

the parent does have a rigidbody, but the game seems to work fine regardless

slender nymph
#

well that's exactly why you're getting that error message then

lusty flax
#

i made a small fix to remove the error message, it didn't affect the functionality at all it just made that annoying message go awat

rare basin
#

datetime.now is bad anyway

#

user can just change phone date

#

like old methods in 2010 games 😄

#

better to get some server online date

desert elm
# desert elm thanks as well-

also- is there a way to use OnTriggerEnter2D but only have it fire when interacting/entering a specific collider? ( i.e a collider of a specific name or something- )

slender nymph
#

put an if statement inside of OnTriggerEnter2D that checks that you are overlapping the thing you want to. it's recommended to use tags or check for a specific kind of component rather than relying on the name of the object though

desert elm
native flicker
slender nymph
languid spire
desert elm
#

Understood

#

what should I use for the if statement?

waxen oracle
#

i have no tools either

serene barn
#

I don't know if this a coding related issue but unity parameters are not reading the parameter that i set

desert elm
serene barn
#

i get 644 warning and im not to sure what to do

short hazel
serene barn
misty obsidian
#

Like I want it optional and... Do you mean this? It doesn't work Idk why :(

short hazel
serene barn
short hazel
#

You have a variable of type Animator in your code right?

languid spire
serene barn
polar acorn
short hazel
serene barn
#

im sick and having to force my self to write code

short hazel
#

Post the whole class, unedited, here. If it's longer than 20 lines or so, use a paste website (see below)

#

!code

eternal falconBOT
serene barn
#
using System.Collections;
using System.Collections.Generic;
using UnityEditor.U2D.Animation;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Events;

public class EnemyController : MonoBehaviour
{
    float timer;
    int direction = 1;

    Rigidbody2D rigidbody2d;

    public float speed;
    public bool vertical;
    public float changeTime = 3.0f;
    Animator animator;

    void Start()
    {
        rigidbody2d = GetComponent<Rigidbody2D>();
        timer = changeTime;
        animator = GetComponent<Animator>();
    }


    void Update()
    {
        timer -= +Time.deltaTime;
        if (timer < 0)
        {
            direction = -direction;
            timer = changeTime;
        }

        if (vertical)
        {
            animator.SetFloat("Move X", 0);
            animator.SetFloat("Move Y", direction);
        }
        else
        {
            animator.SetFloat("Move X", direction);
            animator.SetFloat("Move Y", 0);
        }
    }

    void FixedUpdate()
    {
        Vector2 position = rigidbody2d.position;
        if (vertical) 
        {
            position.y = position.y + Time.deltaTime * speed * direction; ;        
        }
        else 
        {
            position.x = position.x + Time.deltaTime * speed * direction; ;
        }
        rigidbody2d.MovePosition(position);
    }
    void OnCollisionEnter2D(Collision2D other)
    {
        RubyController player = other.gameObject.GetComponent<RubyController>();

        if (player != null) 
        {
            player.ChangeHealth(-1);
        }
    }
}

short hazel
#

Okay this searches the game object this script is on for an Animator.

#

Make sure the script isn't attached to another object, with another animator.
Make sure there is only one Animator on the game object this script is attached to

serene barn
short hazel
#

The variable was private so it was not visible to other code anyway (when you don't specify private or public or any other, it's assumed private)

short hazel
#

Can you go back to Unity for a second and in the search bar at the top of the Hierarchy, type t:EnemyController? This will filter out the Hierarchy so only objects that have your script are displayed. From there see if you didn't attach the script to another object by accident

queen adder
#

hi thats my enemy's ai code

#

the enemy can go to destinations

#

play idle animations

#

but cant chase me

#

i think the problem is about raycast

slender nymph
#

!code

eternal falconBOT
queen adder
#

how can i fix any advice? like how can i see my enemys raycast

short hazel
#

Code block too large, use a paste website

queen adder
short hazel
#

Some users won't be able to see that embed

slender nymph
queen adder
#

how should i send it

queen adder
#
    void Update()
    {
        Vector3 direction = (player.position - transform.position).normalized;
        RaycastHit hit;
        if (Physics.Raycast(transform.position + rayCastOffset, direction, out hit, sightDistance))
        {
            if (hit.collider.gameObject.tag == "Player")
            {
                walking = false;
                StopCoroutine("stayIdle");
                StopCoroutine("chaseRoutine");
                StartCoroutine("chaseRoutine");
                chasing = true;
            }
        }
#

it is the part of my code

#

how can i see the raycast

#

like gizmo or something

slender nymph
#

depending on your unity version you can either use the physics debugger to see it or you'll have to draw it with a Debug.DrawRay or something

queen adder
#

i think im using 2022 or 2023 latest lts

slender nymph
#

latest lts is 2022. so you should be able to use the physics debugger for viewing your raycast

queen adder
#

physics debugger ok

lusty flax
#

I want to show something like "PRESS [KEY] TO PICK UP" on the player's screen, but I don't know how to convert a keycode (for instance, KeyCode.E) into a string (which would be "E")

queen adder
#

i am checking it tysm

short hazel
serene barn
#

i figured it out

lusty flax
wintry quarry
radiant glen
#

Hey just got this error when I tried to load my project any fixes?

slender nymph
#

doesn't seem like a code issue

wintry quarry
#

and yeah not a code issue

radiant glen
#

Okay, where can I access a backup?

slender nymph
#

have you backed up your project in any way?

wintry quarry
radiant glen
#

I didnt...

wintry quarry
#

Then you are a bit out of luck. It's likely you'll need to recreate this scene from scratch

#

It's possible you could manually open the scene file and salvage it but not likely.

queen adder
slender nymph
#

that's not very specific. what do you mean you "couldn't do that"?

#

you just open up the physics debug window, make sure that the queries option is enabled and look in scene view and you'll see it

polar acorn
#

First image: UpgradeText is null, you never check if it exists.

Second image: upgraderSkrypt is null, there is no check around it

real monolith
#

vs not recognising some stuff, how to fix?

eternal falconBOT
real monolith
#

was looking for this, didnt remember the command

#

thank you

serene barn
#

Im in a ooga booga brain where i just do and no think

queen adder
#
    void Update()
    {
        Vector3 direction = (player.position - transform.position).normalized;
        RaycastHit hit;

        Debug.DrawRay(transform.position + rayCastOffset, direction * sightDistance, Color.green);

        if (Physics.Raycast(transform.position + rayCastOffset, direction, out hit, sightDistance))
        {
            if (hit.collider.gameObject.tag == "Player")
            {
                walking = false;
                StopCoroutine("stayIdle");
                StopCoroutine("chaseRoutine");
                StartCoroutine("chaseRoutine");
                chasing = true;
            }
        }
#

i added this Debug.DrawRay but it doesn't shown

slender nymph
#

do you have gizmos enabled?

queen adder
#

yea

slender nymph
#

then either that code is not running or the raycast is not where you expect it to be. or sightDistance is 0

queen adder
#

code is runing i think because the snowman moving

slender nymph
#

nothing in that code you've shown moves it

queen adder
queen adder
slender nymph
#

if only there were instructions for posting large blocks of !code

eternal falconBOT
short hazel
#

Just for good measure since they skipped it on the first one:

queen adder
#

i copied my code here

short hazel
#

Post the link!

queen adder
#

but idk what should i do

#

oh lol

#

mb

languid spire
#

your StopCoroutines are incorrect

Coroutine cor = StartCoroutine(...);
StopCoroutine(cor);
cunning rapids
#

Hey guys I need help on playing multiple particle systems simultaneously after a grenade explodes

slender nymph
cunning rapids
#

How do you exactly play particle systems

#

Is it some variable I'm unaware of that I can assign and then play in the grenade code?

serene barn
#

so unity you got some explaining to do as in the check scrips section this change DOESNT EXIST (on the new vector2 exist the second line is what im refering too)

queen adder
#

omg man you are right i changed the color of it to red to see where it is and it is here lmao

wintry quarry
#

what is the "check scrips section"?

serene barn
#

in the guide they have a check script section to make sure u "have" what they have

#

type of this its usually oh i missed something or i dont get something

wintry quarry
# serene barn position = position

what is the context of your question? Presumably there is some variable named position from earlier.
Or maybe they made a mistake and it's supposed to be transform.position

slender nymph
serene barn
serene barn
#

ruby world

#

ruby adventur to be correct

queen adder
wintry quarry
serene barn
cunning rapids
#

Guys, I really need help on how to play a particle system through code

slender nymph
#

literally the first result searching "particle system play unity"

serene barn
serene barn
slender nymph
#

that makes no difference, there is not a 2d particle system component because you can just use the ParticleSystem component

cunning rapids
#

It just gave me a sample GUI script

#

I have a game object holding all the particle systems I want to play

#

Does it work on empty game objects that hold particle system children?

#

I'm new to this, sorry

wintry quarry
cunning rapids
#

No

#

The forum

#

The documentation gave me a sample script

wintry quarry
#

If you want to play multiple particle systems, you'll need to call Play on each one of them

#

If you have them all in a list you can loop over the list and call Play on each one.

cunning rapids
cunning rapids
#

Thank you

#

Again, my apologies if it was a stupid question

#

I'm gonna guess the docs also mention how to control the system such as pausing and stopping the systems, right?

wintry quarry
#

of course, look through the docs for ParticleSystem, all that stuff is in there

cunning rapids
#

Alright I'll look into it

#

If my English is flawed it's because I'm working on this project late at night so I apologize if my sleepiness caused any misunderstanding

real monolith
#

ide doesnt work

slender nymph
#

if you have followed all of the instructions then close your IDE, regenerate project files, and restart it

real monolith
#

done

#

also restarted pc

slender nymph
#

then you've likely missed a step

cunning rapids
#

It's easier to configure VS than VSC

real monolith
slender nymph
#

what IDE are you using

real monolith
#

VS2022

slender nymph
#

do you have the unity workload installed?

real monolith
#

Italian, sorry

slender nymph
#

now show your external tools settings

real monolith
slender nymph
#

screenshot your entire IDE with a script open and the solution explorer visible

real monolith
#

1 sec

#

wait, gotta find out what "solutions are" 💀

robust condor
#

Why is this not working? I can't modify the value:

public class StatModifierItemData : ScriptableObject, IStatModifierItemData
{
    private float _modifierValue;

    public float modifierValue
    {
        get => _modifierValue;
        set => _modifierValue = modifierValue;
    }

    public virtual void Init() { }

    public float GetModifierStatValue()
    {
        return _modifierValue;
    }
}

public class HealthBoosterData : StatModifierItemData
{
    [SerializeField]
    public float boostAmount;

    public override void Init()
    {
        Debug.Log("Boost amount is " + boostAmount); // 500
        Debug.Log("modifierValue is " + modifierValue); // 0
        base.modifierValue = boostAmount;
        Debug.Log("modifierValue is now " + modifierValue); // STILL 0
    }
}
cunning rapids
#

Guys, I can't insert my particle system in the inspector

real monolith
summer stump
cunning rapids
slender nymph
# real monolith

right click the Assembly-CSharp solution and select the reload with dependencies option

languid spire
rich adder
summer stump
cunning rapids
real monolith
#

ight

summer stump
#

And what nav is saying is ANY compiler errors, even unrelated

real monolith
cunning rapids
summer stump
robust condor
#

@languid spireOh I see, thanks

real monolith
#

something while but i can ctrl click them

rich adder
slender nymph
# real monolith

don't multiply mouse input by deltaTime, it's already frame rate independent so by multiplying it by deltaTime you end up with stuttery camera controls

real monolith
#

okok thank you

cunning rapids
#

What's wrong?

#

@rich adder

true pasture
#

I have a function on a singleton, when its called by another script like this is it creating an instance of that function or does that only run the function on the singletons object? If so how could I instead use an instance of the function.

#

since Im running into a problem where if two people cast at the same time it mixes up the stats

rich adder
cunning rapids
#

Why not?

#

I did it before

rich adder
cunning rapids
#

Should I use public Gamobject

true pasture
#

only if the object in the scene was a prefab to begin with

#

I think you could drag it in then

rich adder
#

make a prefab out of that

#

and spawn VFX object

cunning rapids
#

It's no longer a prefab

rich adder
#

what ur doing now makes no sense anyway

#

the script is already on the flashbang for example you can drag them within prefab editor

cunning rapids
#

I just put 3 particle systems and I want to play them before the grenade explodes

rich adder
#

why you need all three I have no clue. They could all just drop a prefab down and maybe pool that, they could set to Play On Awake

cunning rapids
#

I followed a tutorial on making an explosion effect

#

I made one for the explosion, the other for the smoke, and another for the trails

#

All together they make one explosion effect from 3 systems

rich adder
#

I get it

cunning rapids
#

I'm sorry if I'm being obnoxious but may you please recommend a better way to handle this?

rich adder
#

VFX can just be a prefab is what i was saying

cunning rapids
#

Done

#

This is a screenshot directly from the hierarchy

#

Now what?

rich adder
#

did you make prefab enable all 3 particles Play ON Awake?

cunning rapids
#

Elaborate

summer stump
# cunning rapids

Drag it into the project window.
Drag the asset from the project window (not hierarchy) to the fields

cunning rapids
#

Alright

rich adder
#

so you dont have to manually call emit?

cunning rapids
#

Let me check

#

Yes it is

rich adder
cunning rapids
rich adder
#

then do Instantiate(vfxPrefab, etc..)

cunning rapids
#

Oh

#

You just instantiate them?

#

Seems simple enough

grand hare
#

should I switch from vs code to visual studio or it doesn't make much diffirence?

rich adder
#

drag the one in the Project tab (hopefully you deleted the unnecessary one in the scene..)

cunning rapids
#

Yeah I did

#

I'll make an instance to the one on the project tab

#

Oh!

#

I get it now!

sterile radish
#

!code

eternal falconBOT
cunning rapids
#

Since the systems play on awake, every time there is a new instance of the system, it plays the systems automatically.

#

Thank you for your help

sterile radish
sterile radish
#

my bad

wintry quarry
sterile radish
#

is there a way to implement all IPointer handlers at once?

wintry quarry
#

I guess you could write your own interface which implements all of them

#

seems silly though

#

you can also use the EventTrigger component instead of implementing the interfaces

sterile radish
#

alright, thanks!

weary finch
#

Is there any way to see small textures, bigger?

ionic zephyr
#

please I need help, the object I want to instantiate instatiates twice every time

#

Ex: first 1, then 2, then 4, then 8...

weary finch
ionic zephyr
#

I put it in the prefab

weary finch
#

So the object that you want to instantiate has the component that instantiates?

vast tangle
#

While not directly a code question, I have an assignment and I was wondering if anyone could provide some insight
One of the requirements was

Your implementation should allow the saving and loading of game state data from the selected storage types (In-memory, PlayerPrefs).
Your design should allow the implementation of new storage types (for example: Json file, network url) of game state data, without modifying your existing solution

I know how to implement those storage types, the part thats confusing me is the last line
How do you make a storage type without modifying the existing solution
seems like a weird requirement

wintry quarry
real monolith
#

xRotation -= mouseY;

vast tangle
weary finch
# ionic zephyr yes

Okay so what's happening is that every time you instantiate the object, a new object with the component that instantiates is there, and that new object will start instantiating more objects, and more and more. You have to move that component outside the object that is being instantiated

ionic zephyr
#

Oh my god how cant I have seen it

weary finch
#

XD we all have been there

ionic zephyr
#

its like a freaking virus bro

#

that´s interesting though

#

anyway, thanks A LOT

weary finch
#

no problem!

weary finch
# real monolith xRotation -= mouseY;

What would you like to understand from there? What I see is that the xRotation gets mouseY removed every time it moves. Mouse Y is a value that gets to 1 when the mouse moves, and 0 when it has stoped

real monolith
#

why am i subtracting mouseY?

weary finch
#

If you look at the axis, xRotation would be rotating around the X axis, and therefore the aparent vertical rotation (looking up and down is rotating through the X axis)

weary finch
wintry quarry
real monolith
weary finch
#

Look at the axis I sent (or also in unity) and you will see that the axis where the rotation should be applied is X

wintry quarry
wintry quarry
#

it's a rotation around the axis

weary finch
#

You can also create a new gameobject(cube) and rotate the X value on the transform, and you will see how it goes up to down

real monolith
#

OHH

#

ok

#

maybe i got it

#

bruh wtf why is y rotating horizontaly

weary finch
#

(a better diagram)

real monolith
#

ye i thought x was horizontal like in math

wintry quarry
#

x is horizontal

weary finch
#

x is horizontal

wintry quarry
#

rotating around the horizontal axis results in "looking up and down"

weary finch
#

exactly

real monolith
#

OH

#

ok

#

cool didnt really get "around"

weary finch
#

No problem!

real monolith
#

thank you sorry for my stupid a** xd

weary finch
#

(alttough im starting to thing that, unless i have a custom editor im not sure how im gonna do that, maybe there's a hidden button somewhere?)

summer stump
ionic zephyr
#

Guys, how can I make sure that when the scene loads the object that uses the transform of my player saves that transform from being destroyed?

icy ginkgo
#

Help With Camera States

ionic zephyr
ionic zephyr
#

Oh, really? thanks

rich adder
#

depends what your exact needs are too

ionic zephyr
#

the thing is there is an object that instantiates according to the player´s transform. But when I reload the scene, that association breaks

rich adder
spring skiff
#

Will this make what I hope?

    private Script1 my_Script1;
    private Script2 my_Script2;
    private void Start()
    {
        my_Script1.GetComponent<Script1>();
        my_Script2.GetComponent<Script2>();
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "PlayerCollider")
        {
            my_Script1.enabled = false;
            my_Script2.enabled = false;
        }
    }
}

I want to disable two scripts what are componments of a GameObjekt.
Do I will reach those Scripts like this or will this disable the entire GameObject?

ionic zephyr
rich adder
ionic zephyr
#

Ok, thanks a lot bro

primal tree
#

From the magical world of dumb questions, how can I prevent two layers from colliding with each other in 2D? I've unticked the interaction in the Project Settings > Physics > Layer Collision Matrix, but my character is still able to stand on top of platforms that should now be non-colliding... (Player / OneWayPlatforms)

rich adder
#

if you disable whole object any scripts stop working

spring skiff
rich adder
primal tree
#

Fair, apologies @rich adder .

ionic zephyr
#

but when I keep the player it is still there??

ionic zephyr
#

the little squares are the player

#

one stayed even though the scene loaded

primal tree
#

Thanks @wintry quarry . (facepalm)

rich adder
ionic zephyr
#

just a simulation

rich adder
#

put some color on the player ?
anyway whats the problem ? if you put DDOl then you can't keep one in the scene already
or make a singleton

ionic zephyr
#

what I want is taht this relation Target-Player isnt destroy when the scene loads

primal tree
#

I'm heading over to #⚛️┃physics, but it's worth noting that changing the setting in the 2D Layer Collision Matrix doesn't seem to have done anything either. =/

rich adder
ionic zephyr
modest lintel
#

I bought the complete c# course from Gamedev tv , but before starting the course I just want to know , in playmaker we use states to make our games and in those states we have stuff like "trigger event,float compare,translate,playsound,send global event etc" and this usually goes 1 by 1 but when i see c# code they use update or start and i never seen those in playmaker, lets say i triggered a event by pressing "Space key" and it did the code inside that if state, does it stay in that state or it just resets,if it does how does people make a story game

#

I was using playmaker a visual coding addon for 3 years and now I made the choice to switch to c#.

robust condor
#

How can a child object get the absolute top parent?

#

If nested multiple times

rich adder
rich adder
rare basin
rich adder
#

use links for large code

quick edge
#

Can you explain me how I can do that please ?

ionic zephyr
rich adder
eternal falconBOT
quick edge
#

Thanks mate

rich adder
ionic zephyr
#

the DDOL

rare basin
#

Then you did it wrong

rich adder
quick edge
#

Hello! I have an hard time figuring out why my jump functionlity in my program doesn't work. Can someone help me please? I've tried different thing but I can't figure it out. Thx!
https://gdl.space/avuvayunus.cs

ionic zephyr
primal tree
#

@rich adder Just to check... I shouldn't have to change Layer Overrides in CompositeCollider2Ds or TilemapCollider2Ds or Rigidbody2Ds, no? My assumption is that changing the matrix in the Project Settings should cover that. I also have PlatformEffector2D on the tilemap, which I suspect is the cause of this issue - does that make more sense?

rich adder
ionic zephyr
#

the problem is that whenever I use it, then every time the scene loads not only does the player generate another, but also the relation breaks anyway

rich adder
#

its not ideal, just use runtime find

#

or use gameManager.instance

ionic zephyr
#

I use a gamemanager

#

that script is from a gameManager

rich adder
#

yes mate I can read

rare basin
#

Or if you have only 1 player, then make him a singleton and reference him everytime you need

#

Many approaches

#

Pick one

ionic zephyr
rare basin
#

C# code

rich adder
#

myreference = GameManager.Instance.Player

quick edge
solemn wraith
#

Hi, why is my game view going to pause mode automatically whenever I start the game?

rich adder
#

and a console error

rich adder
quick edge
#

yes

rich adder
#

how you test?

quick edge
#

What do you mean ?

solemn wraith
ionic zephyr
#

it still deletes

rich adder
#

you can't do that

#

it wil break

solemn wraith
low perch
#

Destroy(inventoryParent.transform.GetChild(0));

in the editor it says Calling Destroy or DestroyImmediate on a transform is not allowed.
then what should I do

ionic zephyr
eternal falconBOT
quick edge
# rich adder how you test?

I don't really know what you mean. But I'm starting my game then I press run and jump while grounded and the jump "works" but not as intended. My character teleport to the location and fall really fast. I want it to jump like irl

rich adder
#

you cannot keep reference between difference scenes

ionic zephyr
#

oh okay so

rich adder
#

You need to find it at runtime

#

whatever it is you're trying to find

solemn wraith
#

Hi this is my Start() Function and I was wondering whether this is too much precomputation to happen in start. I think its like 2 nested for loops with like vector calculationshttps://hastebin.com/share/ogutuqoham.csharp

rich adder
neon spire
#

Hey ! I want to get the deltaRotation of an object by doig this : cs deltaRotation = deltaRotation - transform.rotation;
where delta rotation is Quaternion but there is an error because i can't use an operator to it. I don't know how to do

quick edge
#

🥲

#

The problem is the CharacterController not the new input system. When I press space bar it jump no problem on that. but I think it's the logic behind the jump

rich adder
quick edge
#

Still can't help me ?

neon spire
rich adder
rich adder
neon spire
#

thanks

quick edge
#

I guess

rich adder
#

idk what "not working as intended" means
Debug.Log your values

tall hill
#

I have this cloud particle system thing and I want to display it like all across the bottom of my game
how would I do that?

quick edge
#

I explained it earlier but I'm gonna explain it more clearly sorry. My code make the character teleport to the variable "jumpHeight" then the gravity do it's thing and the character fall. I don't want that, I want my character to jump like in real life then fall.

#

I tried += instead of =. I tried Mathf.sqrt(-2f * gravity * jumpHeight) for initial velocity but it doesn't work

quick edge
#

I also tried that

#

Maybe I miss wrote it

#

I'm gonna try again

rich adder
#

the only issue is that the character controller grounded bool sucks

#

it only works while you move

#

is better to make grounded check with CheckSphere

quick edge
#

Should I make an "isGrounded" variable myself with a raycast ?

#

I changed "direction.y = jumpHeight;" for "direction.y = Mathf.Sqrt(-3.0f * gravity * jumpHeight); "
And it still doesn't work. I have to put like jumpHeight = 200; to see something happen and what happen is just my character teleport instantly, then fall normally

#
    private void Update()
    {
        characterSpeed = isRunning && _controller.isGrounded ? playerRunningSpeed : playerWalkingSpeed;
        float xMoveValue = playerInputActions.GroundedGameplay.Movement.ReadValue<Vector2>().x * characterSpeed;
        float zMoveValue = playerInputActions.GroundedGameplay.Movement.ReadValue<Vector2>().y * characterSpeed;
        direction = new(xMoveValue, 0f, zMoveValue);

        if(_controller.isGrounded && isJumping && isRunning)
        {
            direction.y += Mathf.Sqrt(-3.0f * gravity * jumpHeight);
        }
        direction.y += gravity;
        _controller.Move(Time.deltaTime * direction);
    }
amber veldt
#

Hey guys, sorry I'm not so active on this forum but I'd like some point of view on a solution to a problem I have,

I instantiate an object which is essentially just a skinned mesh renderer and a rigidbody at a specific place using a parent transform. The object is then moved by an animation and it moves relative to the character I'm animating (drawing an arrow from a quiver if you want context)

I want to have a rigidbody so I can apply a force to the arrow when the string gets released, but if I add a rigidbody, the arrow gets "stuck" and does not follow my animation.

Using isKinematic won't work, or at least I did not find a solution using it. (I have no issues of placement of the arrow when there is no rigidbody btw)

I used ChatGPT so I would not waste you guys some time, and the AI found a solution : storing the rigidbody values, Destroy the rigidbody, then add a new rigidbody and add the destroyed rigidbody values.

Is that fine? Am I missing something easier ?

Thanks a lot if you read me,

OP7

quick edge
#

(the game isn't started here)

rich adder
quick edge
#

-9.8f

spring skiff
#

Is there a small and easy way to set all arrays to "true" without changing every single array to true with a for or while loop?

frosty hound
#

No

primal tree
#

@rich adder

#

Pretty sure the problem was the PlatformEffector2D, but I'm open to other suggestions.

quick edge
#

I really don't understand what I'm doing wrong, I'm new to Unity so it's probably something stupid

rich adder
primal tree
#

Very reasonable. I'm doing this for a friend, normally don't touch 2D.

rich adder
quick edge
#

How can I do that ?

rich adder
#

and check values

quick edge
#

I found something helpful. If you click the three dots in the top right corner of the gameObject inspector you want to debug there is a "debug" option that shows you all the variables

rich adder
#

yeah but that doesn't tell you everything, just the basic fields

quick edge
#

Ok I see

clever yew
#

Hello, new to the discord, I have been able to debug pretty much anything else so far in my project, however i have been stuck on this for almost a week so I think I need some help. My player will move correctly, won't be able to move while dead; however, if the player dies while moving, will slide off the screen into nothingness, resetting velocity, removing materials, and many other things haven't worked.

#

I am using a CharacterController not a rigidbody

slender nymph
#

show !code

eternal falconBOT
quick edge
clever yew
#

Okay, like I said new to the discord so Iwasn't sure where to post it and not spam the chat,

quick edge
#

np

clever yew
#

Thank you!

clever yew
#

thats my code

#

For the player script

quick edge
visual hedge
#

Hello there. Let's say I have enum with 3 options. How do I check which option is assigned thru if statement?
public enum ExpirePoint { BATTLE_END, TURN_START, TURN_END }

if (ExpirePoint == ???){}

rich adder
visual hedge
rich adder
#

you just created the enum , never actually use it anywhere

visual hedge
# rich adder you just created the enum , never actually use it anywhere

yes, so that's also is a part of a question... so I make the script that will check what this exact enum states... what do I add to the script so it can actually access that created enum? I guess instead of asking I just have to see some examples from code that I have that uses enums... brb 🙂

#

a ye, okay okay

visual hedge
rich adder
visual hedge
rich adder
sacred pulsar
#

do i need to learn c# for unity?

visual hedge
rich adder
sacred pulsar
rich adder
sacred pulsar
#

python, JS, HTML and now C#

#

it's kinda like JS right?

rich adder
#

more like Typescript-ish

#

out of what you mentioned

sacred pulsar
#

idk typescript tbh

visual hedge
#

html is considered a programming language?

rich adder
sacred pulsar
rich adder
sacred pulsar
#

but i'm a newb

#

.-.

visual hedge
#

you got this for sure

rich adder
sacred pulsar
#

well i started

#

i just don't know what to do

sacred pulsar
#

well i know the basics for python and JS

#

but like how could i use those

rich adder
#

nothing just knowing some concepts but thats about it

#

python and c# are pretty diff

sacred pulsar
#

i bet

#

lol

rich adder
#

js and python are both dynamically typed

#

the type is known only at runtime

twin bolt
#

How can i create a script that shortens my item dropping distance, when a wall is directly in front of the player? I'm having a issue with the player being able to drop items into walls.

rich adder
#

raycasthit.distance you can see how close something is in your throwing

#

just make distance shorter than that for throw

visual hedge
#

What's the basic difference between arrays and lists? I mean what would be the NO GO for each of those? List is more flexible I guess? If you remove certain thing from the list, nothing breaks, right? And if one removes some link from array, it can cause troubles?

rich adder
#

lists can

#

simple as that

robust condor
#

Does anyone have example of large project structure? It is becoming unbearable

visual hedge
rich adder
clever yew
#

!c

#

!cs

eternal falconBOT
quick edge
#

@rich adder I still don't know why the bug happened but at least it's fixed. What I did is I created a new Vector3 = Vector3.zero and to this Vector3.y I do all my magic and then do a different _controller.Move on this Vector3. And doing it like that make it work ✋ 🤠 🤚

#

Can you explain to me the thing about the sphere you talk about ? As you said isGrounded kinda suck because I need to move. What is the work around ?

rich adder
# quick edge Can you explain to me the thing about the sphere you talk about ? As you said is...
private bool Grounded()
{
    return Physics.CheckSphere(transform.position + groundCheckOffset, groundCheckRadius, groundLayers, QueryTriggerInteraction.Ignore);
}
private void OnDrawGizmos()
{
    if (!debugGizmosEnabled) return;
    if (cc == null) return;
    var color = Grounded() ? Color.green : Color.red;
    Gizmos.color = color;
    Gizmos.DrawSphere(transform.position + groundCheckOffset, groundCheckRadius);
}```
quick edge
#

👽

rich adder
quick edge
#

What use a Sphere and not a raycast ? (I don't know what is CheckSphere I just suppose it's a raycast sphere)

quick edge
rich adder
quick edge
#

Why ? I don't get it

rich adder
#

only a sphere makes much sense

#

you can use w/e shape ofc

quick edge
#

What is w/e ?

rich adder
#

whatever lol

quick edge
#

Ok thanks (not my first language sorry)

#

Thanks for the explanation then, I'll do that !

sturdy kelp
#

Hello everyone, have a sort of annoying minor issue I can't seem to find the solution to.

I get the "domain reload" popup every time I edit and save a script, and it prevents me from alt-tabbing back to unity and is generally annoying. Quick google says to turn off auto-refresh in preferances, I remember this working briefly but has since stopped working.

The way of Project settings --> Enter Play Mode Settings --> Enable Domain Reload has no effect either.

Am I missing something obvious? Or is this just something to deal with? Thanks.

rich adder
sturdy kelp
#

Yes, I think so

#

Is there a way to turn it off, or at least do it without the annoying popup window that prevents alt-tab (in the background?)

teal viper
#

Enter play mode settings only affect entering play mode.

sturdy kelp
#

This setting? It's disabled- still getting the reload.

#

when I save the script^

teal viper
#

It doesn't seem like compilation though. It says scene hierarchy repaint.

sturdy kelp
sturdy kelp
teal viper
teal viper
#

Try resetting it to something else and back to disabled. And if that doesn't help, restart the editor.

bold swallow
#

Am I doing something wrong when rendering Gizmos? Here is my code but I don't see it anywhere in the scene view. I tried using gizmos for the first time to see why my Physics2D.OverlapCircleAll was not working. I even set the radius to 100f and the PlanetMask to "Everything". Any ideas?

Gizmos code:

void OnDrawGizmosSelect()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(Vector2.zero ,1f);
    }

Overlap Code

        Collider2D[] colliders = Physics2D.OverlapCircleAll(Vector2.zero, 10    , PlanetMask);
        Debug.Log(colliders.Length.ToString() + " Planets found");
spring skiff
#

what happen if you make something like this?

[SerializeField] public int Numbers;
#

Is SerializeField usefull on a public variable?

summer stump
tacit estuary
slender nymph
#

do you have the object selected and the component unfolded in the inspector?

spring skiff
sturdy kelp
bold swallow
slender nymph
#

i mean, is the component not folded in the inspector

#

also do you even have gizmos enabled?

bold swallow
#

it appears I am not familiar with the term "folded" when it comes to gameobjects in the inspector.

#

and yes I have gizmos enabled

slender nymph
#

you know how every component has a little > arrow next to its name and you can click it and it hides the component as if it were some sort of foldout display?

#

not folded

#

folded

bold swallow
#

Oh ok I get it

#

no it is not folded

slender nymph
#

but it is selected in the hierarchy, yes?

bold swallow
#

yes

#

but I managed to find the OverlapCircleAll() issue

#

so there is no need to solve the gizmos thing anymore

sturdy kelp
slender nymph
#

i'm pretty sure it has to reload the domain when you compile 🤔

teal viper
#

Yeah, but it shouldn't compile on alt tab

slender nymph
#

it's entering play mode that domain reloads can be disabled for

slender nymph
sturdy kelp
teal viper
#

It will of course. It's blocking the main thread

sturdy kelp
#

is it just cope or get a second monitor lol

teal viper
#

The question is wether it happens after alt tabing from your ide

sturdy kelp
#

I don't think so, is the reload just a thing to deal with?

teal viper
#

Yes. That's what needs to happen on recompiling your scripts(to apply the changes that you made)

slender nymph
#

you might be able to turn off the auto refresh, of course if that stops it from reloading the domain, that means its also not recompiling so you'd have to trigger that manually

real monolith
#

nahh mate id need a physics degree for this

#

pardon, one question
I did this

#

insteaad of this

#

but theres some input lag

spark yoke
#

I don't think that would cause input lag on it's own. Did you change anything else?

real monolith
#

i didnt

spark yoke
#

Can you show some more of the code?

#

And, if you switch to the old lines, does the input lag go away?

spark yoke
#

I have no idea why changing those two lines would cause input lag. And can you clarify: By lag do you mean a delay, or unexpected rotation?

real monolith
#

little input lag + view lagging a bit more

#

i think its because it first moves the player object and then the camera so the camera gets rotate a bit later

#

can this be it?

spark yoke
#

The order does not matter, it's in the same update function so they will be done within the same frame.
Is anything else modifying either rotation?

real monolith
#

wdym

spark yoke
#

Do you have another script that interacts with either object?

real monolith
#

only a PlayerMovement class

#

this does not seem to interact with the camera tho

spark yoke
#

There's really nothing that should be creating lag then. Are you absolutely sure you notice a delay? And this delay goes away when using the one line instead?

real monolith
#

a bit less now

#

i removed some stuff from the terrain

teal viper
#

Mixing up rigidbody and character controller is a terrible idea and would cause more issues than just jiterring.

real monolith
#

idk lol, thank you Frog!

real monolith
teal viper
#

i think your issue is the only one being discussed now.

real monolith
#

there was a post before but i did not use any rigidbody

mortal spade
#

so im raycasting and my debug ray works as intended but the actual one doesnt? see attached any help is appreciated

private void FixedUpdate()
    {
        Debug.DrawRay(transform.position, transform.forward * maxDistance, Color.green);
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance))
        {
            Debug.Log("Raycast hit: " + hit.collider.gameObject.name);

            if (hit.collider.gameObject.CompareTag("screen"))
            {
                Debug.Log("Screen detected");
                script.playerLooking = true;
            }
        }
    }
twin bolt
#

How do i fix rigidbody jitter?

wintry quarry
teal viper
real monolith
#

np

wintry quarry
twin bolt
wintry quarry
mortal spade
wintry quarry
twin bolt
#

This is it ```targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        Vector3 MoveVector = transform.TransformDirection(Vector3.ClampMagnitude(targetVelocity, 1f) * playerSpeed);


        rb.velocity = new Vector3(MoveVector.x, rb.velocity.y, MoveVector.z);```
wintry quarry
slender nymph
#

are you sure it is the rigidbody that is jittering and not perhaps the camera?

mortal spade
twin bolt
slender nymph
#

yes

#

don't make your camera a child of the object. and also use cinemachine

wintry quarry
mortal spade
wintry quarry
#

what is it

#

also what is being printed?

slender nymph
#

you're also hiding your regular logs

twin bolt
wintry quarry
mortal spade
slender nymph
mortal spade
wintry quarry
mortal spade
twin bolt
mortal spade
#

i think i found the issue tho

slender nymph
mortal spade
#

aii i figured it out there was a collider in the way, thx for the help

twin bolt
slender nymph
nimble apex
#

as u guys see, im dealing with server error responses , i think a dictionary would be better than bunch of if in this case?

#

u guys think 658 part can be merged into the dictionary as well?

north kiln
#

This dictionary should not be allocated every time you call the method if it's not changing every time, that's the only thing I have to add

nimble apex
#

it wont be

#

its more like a constant

#

but its quite complex

verbal dome
#

Make it static?

#

In the class

nimble apex
#

this is dictionary<string,action>()

but the action in dictionary contains another action

#

which is declared inside a function

#

so i cant pull it out

#

aight

#

static class

#

maybe that will do

verbal dome
#

Class doesn't need to be static, unless you want it to

#

Just a static dict

nimble apex
#

oh ok

verbal dome
#

@nimble apex And yeah you can put 658 into the dictionary too, just pass a method or put the if-statement into the lambda

nimble apex
#

oh nice

#

btw cant pull it out, unless this dictionary is being put into a separate class, some variables are declared inside the function its in rn

#

u cant make dictionary static as local collection right?

verbal dome
#

Nah, you gotta restructure it a bit I think

nimble apex
#

inside the dictionary, their action will include the two actions above

#

wait

#

i can

#

i just need to make those two as a function

verbal dome
#

Yeah that's what I meant with 'pass a method'

#

If needed

nimble apex
#

nice ty

nimble apex
#

the script that i used now is from one of the controlling scripts

#

if i make it to a static class i dont need to put the dictionary into 10+ scene controlling scripts right?

sacred orbit
#

Would anyone know what I should look up if I wanted to splice two animations together if the animated object hits a collider? I know how to do the collider part, just don't know where to start with splicing animations

sacred orbit
nimble apex
#

eventually my dictionary is finished , ty👍

#

unity can do indexer on dictionary to add a new set of stuff if it doesnt exist in dictionary?

#

anyway this is my call part to the dictionary

#

yep its tidier lol

edgy fox
#

I opened unity and got hit with these errors. I think LinearOffset got unassigned somehow but I can not reassign it as the script is greyed out

gaunt ice
#

there are compile errors
so your script wont be compiled

formal escarp
#

hey guys i have a quick question

#

"PlayerTransform = GameObject.FindGameObjectWithTag ("Player").transform;" is a valid line of code. however
"PlayerTransform = GameObject.FindGameObjectsWithTag ("Player").transform;" is not?

frosty hound
#

Because the second returns an array of objects

gaunt ice
#

GameObject.FindGameObjectsWithTag ("Player").transform

tribal zephyr
#

guys i need a bit of help with my procedural generation script

nimble apex
#

u need to make another collection , loop thru and add up each transform of the game objects

gaunt ice
#

!code
format the code as inline code

eternal falconBOT
tribal zephyr
#

cuz it kinda spawns slightly at the edge, how can i prevent this

gaunt ice
#

i wonder how the -5.03, 0.57 0.09 come up
the rotation is correct btw by they overlap, that means the spawn position is wrong
and please dont Find() every time

tribal zephyr
#

if i remove all the adding and stuff, it'll like be going down for some reason

#

like a stair case a little

#

ok i removed those things, it worked ish, but it goes down and the rooms are like overalping with the previous room

gaunt ice
#

youo can watch this

tribal zephyr
tribal zephyr
#

(at least for the rooms that are straight

tribal zephyr
#

Ok now everything works now thanks

edgy fox
gaunt ice
sacred orbit
#

Is there a way I can relate a variable to another set variable?

Here's the code that I tried:

#

Variables I am trying to relate it to

gaunt ice
#

or you mean transform? though it is still not called as size but scale

sacred orbit
gaunt ice
#

@sacred orbit is your ide configured?

sacred orbit
gaunt ice
#

!ide

eternal falconBOT
gaunt ice
#

idk how you install your VS so pick the link yourself

north kiln
#

What do you mean by that? Switch statements are not heavy on anything

sacred orbit
#

oh really?

timber tide
#

maybe if you have a switch of 50 things you're checking every update

sacred orbit
#

It's just this would be in Update() so I thought running a switch statement every frame wouldn't be great

north kiln
#

More like a switch of 10,000 things, as in, running 10,000x

sacred orbit
#

ok thank you

charred spoke
timber tide
#

well, for a single instance I guessss

sacred orbit
#

I am really new to unity and c# so thiuss is good to know

#

I've been a bit too worried about lag then

north kiln
#

Don't consider yourself with performance until you're actually experiencing it and know how it works and how to resolve it

#

just speculatively avoiding things is a great way to get nowhere and write bad code in the process

charred spoke
north kiln
#

Whenever you're numbering variables you probably should just be using an array or list instead

sacred orbit
#

storagenGO is storage number game object, just swapping between 3 gameobjects for an inventory system

#

but my problem is solved, thanks

edgy fox
#

wait for some reason I moved the declaration of linearoffset (a box collider) into a line of declarations of gameobjects

#

no clue how I did that

#

or why at least

#

my visual studio no longer autofills variable types; what settings did I change that I need to unchange?

north kiln
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

north kiln
#

If it is already configured, you may just need to restart it

craggy oxide
#

I am a complete beginner to C# so I just wanna ask

Is there like a library or list or something so that I can know the properties that I need to call when I want to script things

I've worked with Luau before, used to do Roblox Studio and I want to move to Unity, so I think I can wrap my head around the basics of C# I just need to know how people are able to know like Variable.Instance.This.That.Etc

#

Is it just learning and memorisation or is there a cohesive list of properties that you can change/script with

keen dew
#

!docs

eternal falconBOT
craggy oxide
#

ah, thank you

edgy fox
shrewd cipher
#

I have this paddle boat set up and i have the paddle attached to the mouse, im just unsure of how to properly add thrust to the boat when the mouse is down/paddle is being used. How should I go about adding the movement?

north kiln
eternal falconBOT
edgy fox
north kiln
edgy fox
#

100%

north kiln
#

No idea then. I use Rider

edgy fox
#

damn

north kiln
# edgy fox damn

Try:

  • If you have compiler errors, if possible comment out those files so Unity can compile code.
  • Ensure the Visual Studio Editor package is installed and updated in UPM (com.unity.ide.visualstudio).
  • Regenerate project files via Unity.
    1. Close VS.
    2. Select regenerate project files in Edit > Preferences > External Tools.
    3. Reopen VS via Assets > Open C# Project.
  • Regenerate project files via VS.
    • If an assembly in the Solution Explorer is marked as (incompatible), right-click it and select reload with dependencies.
  • Restart your computer.
edgy fox
brittle folio
#

what are the practical usages of generics and polymorphism in C#?

north kiln
#

Generics allow you to write shared code once for multiple different types

gaunt ice
#

system.collections.generic

timber tide
#

I find generics pretty useful with data coupling when it comes to scriptable objects

north kiln
#

Polymorphism, requires a object-oriented approach so it's less useful; but storing similar things in the same place while having them run different implementations

lunar tapir
#

I'm trying to make conways game of life in Unity.

Is there a way to make these tilemap lines visible in the game view?

#

It looks weird without the lines

timber tide
#

if not, then consider drawing via GL Lines

lunar tapir
timber tide
#

Could maybe try LineRender as well, but I've not really used it for a large amount of lines before

#

would require a GO for each so extra overhead

gaunt ice
#

you can draw line this, but no one can understand your code after 2 months
(just fetch the eular path or solving chinese postman problem)

rich adder
vast ivy
#

Could someone help me figure out why this script is doing nothing? It is supposed to drag the image with my mouse but its not moving, the event is also not even getting called?

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class DraggableItem : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    public void OnBeginDrag(PointerEventData eventData)
    {
        Debug.Log("Begin Drag");
    }

    public void OnDrag(PointerEventData eventData)
    {
        Debug.Log("Dragging");
        transform.position = Input.mousePosition;
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        Debug.Log("End Drag");
    }
}

The script is attached to each image

#

im going to bed but any help would be read and appreciated in a few hours

lunar tapir
#

idk about the events but I don't think transform.position = Input.mousePosition; will work as expected, because Input.mousePosition returns the coordinates in Screen space

#

try
Camera.main.ScreenToWorldPoint(Input.mousePosition)

north kiln
radiant sail
#

how would i change the transform.LookAt rotation so its actually pointing at the player rather than pointing upwards in the direction of the player (the muzzle flash is pointing at an angle that the player cant see)

visual hedge
#

Hello everyone. I will try to explain the problem that I've encountered:
I am trying to create a turn-based game. Turnbase structure is approximately: Battle start / (Before Turn / Turn / After turn) / Battle end
Before turn - turn - after turn goes till one side is alive. So the side that has alive units wins at some points and triggers battle end. Pretty standard.
But the problem I have is at this point: I want to trigger some status effects that are placed on character (basically some buffs shall trigger something, like maybe healing at the end of turn).
I have no problem checking if the buff is still there and remove it from character if it expired, but I have problem with actually triggering the active part of the buff.
Do I use Events in this case and subscribe the buff script to "after turn" or "before turn"?
So basically if there's turn end and buff is triggered aat turn end, it will then receive that event trigger and will then fire it's active method?
I am sorry if I am not clear enough, it's quite complicated for me to explain at this point where the problem is.

cunning rapids
#

Hey guys, I'm wondering if deleting unused instances of an object will optimize my game

#

Since I'm constantly creating instances of prefabs and game objects in my game and there are lots of unused ones left over

#

I'm sure it would but I don't know the best way to implement such a feature

cunning rapids
#

Show us the code for your muzzle flash as well how you handle it

dark hatch
#

i have this code for a tentacle basically. the targetDir is a child of the linerenderer object so that i can determine the angle of the tentacle. How can i add something like a sine wave to basically make sure that the tentacle never comes to rest as a straight line, but in a wiggle.

wicked blaze
#

So, im trying to make an really basic crouch system and there are no errors in the console but i dont really see anything happening when i hold down left control and i dont really know whats going wrong. I made it by myself so I knew there would be some complications.

queen adder
#

also where did you put that code in. You should try to put some Debug.Log messages to make sure your codes are being called at least

wicked blaze
queen adder
#

also check the value in the editor, the numbers in the code doesnt matter anymore once your script is read by the editor already

north kiln
#

What are you expecting it to do? If controller is just a CharacterController it'll just make the collider shorter

cunning rapids
#

Guys, I have an issue with my muzzle flash. While the effect is working fine, the way it works is that it creates an instance of an object that contains the particle systems for the muzzle flash, however it keeps the unused instaces. Should i use an object pool?

wicked blaze
#

yeah im reading it all dont worry

cunning rapids
#

Only the collider is getting shorter, not the player itself

wicked blaze
#

yeahhhh i also just figured it out now

#

how do i make the player also shorter when its pressed

queen adder
#

you can change the scale, but depends on your cahracter

#

if it's like a simple box, that should work just fine

#

if it's like a human model, prolly not

wicked blaze
#

i can see that the character controller is changing to 0.7 when i press left control

queen adder
#

yea that should be fine, just change the transform.localscale

wicked blaze
#

alright

wicked blaze
cunning rapids
dark hatch
#

doesn't Vector3.one * height work here

cunning rapids
#

I think so

queen adder
#

actually no, that would change all dimensions

cunning rapids
#

No problem

wicked blaze
#

im thinking about adding crawling on the floor to my game just dont know how i would turn the player capsule so its in an laying position

dark hatch
#

oh right it's crouching

cunning rapids
#

and apply the same logic

dark hatch
queen adder
#

izza capsule, it should just roll blushie

wicked blaze
#

i just read that in an italian accent

cunning rapids
#

To pretend you're leaning I guess

wicked blaze
#

yeahh

cunning rapids
#

It's a first person game right?

wicked blaze
#

i just cant imagine when ill have to make an actual player models and then add all the animations for crouching, hitting, crawling, ect.

wicked blaze
cunning rapids
#

Unless it's multiplayer

wicked blaze
#

yeah

cunning rapids
#

Since you don't even see your own player model anyway

wicked blaze
#

yeah

#

thanks for the help everybody

cunning rapids
wicked blaze
#

im thinking about the ones that you can see in first person, if you are doing something with your hand ect

#

whats the key that is ussualy use when crawling

cunning rapids
#

You can still do that without having to see your own player model

cunning rapids
#

or C

wicked blaze
#

i think im going to have to use C since left control is for crouching for me

queen adder
#

z is usually for prone

wicked blaze
#

damn

#

well

cunning rapids
#

Shift for sprint

#

etc.

#

You can add a dropdown to change it in the inspector to whatever you think is best

wicked blaze
#

ill see

cunning rapids
#

It's easy

wicked blaze
cunning rapids
#

Just ```cs
public KeyCode crouchKey;

wicked blaze
cunning rapids
#

0, 90, 0 will rotate it 90 degrees in the y axis

queen adder
#

Quaternion.identity

cunning rapids
wicked blaze
#

alright

queen adder
#

Quaternion.Euler results are consistent anyways, (0,0,0) should work, but .identity is the peep for this

wicked blaze
#

definetly works but now i kinda cant even turn my camera or look in other direction

#

and my crouch kinda stopped working

#

i can look up and down

#

but side to side isnt working

cunning rapids
#

Quaternion.identity sets all your rotation to default (no rotation)

#

Show your code

wicked blaze
#

i dont really know why the crouching stopped working all of a sudden

queen adder
#

you should do a state machine

#

that make sure you are only in one state of chrouch, walk or crawl

wicked blaze
#

something new

cunning rapids
#

Do you have a boolean to check if you're crouching?

queen adder
#

just something like ```cs
public enum Movestate { walk, crawl, crouch};
public Movestate currentState = Movestate.walk;

cunning rapids
#

@queen adder

wicked blaze
#

i guess i should probably make one

cunning rapids
queen adder
#

actually, it's quite confusing to implement right now, and i dont really have much time to guide rn

#

just do a bool that keeps flipping back and forth, easy fix for now blushie

cunning rapids
#

That's what I do lmao

wicked blaze
#

so the looking still works when i crouch

deep bear
#

Hi all, I'm having an issue with my EventSystem. I have an EventSystem prefab that has a script attached to it that contains this code to make it persist between scenes and have it be a singleton:

{
    if (current == null)
        current = this;
    else
        Destroy(gameObject);

    DontDestroyOnLoad(gameObject);
}```

I have a scene called BattleScene that contains a Canvas with a button that when clicked, calls a function from the EventSystem (image attached). The EventSystem object referenced there is the one I dragged into the scene.

My issue is that when the "BattleScene" is the first scene loaded, it works fine. But if I start in another scene and then transition to the BattleScene, it doesn't work at all. It's as if the button doesn't have a connection to the EventSystem. What may cause this?
#

All of my scenes have the EventSystem prefab added as an object

languid spire
queen adder
#

doesnt matter though?

#

the problem is the reference is getting lost because they're recycling something from another scene

deep bear
#

Oh I see... If you don't mind me asking, what's the best solution in this case?

queen adder
#

not do ddol

deep bear
deep bear
queen adder
#

what is TriggerBattleDeckButton

deep bear
queen adder
#

EventSystem is a unity class though, if that is your script, you'll want to rename it, cause it can cause confusion (or potentially errors, someday)

deep bear
#

Oh I see, I had no idea. I usually reference it by saying EventSystem.current which gives it the static instance of the class. But I'll change the name just in case.

#

I tried removing the ddol but that doesn't seem to have worked.

queen adder
#

just change your whole awake to current = this

wicked blaze
#

i dont really know how i can set the rotation to the one that was before

#

the normal one

deep bear
# queen adder just change your whole awake to `current = this`

This unfortunately didn't work either, but I think I know what the issue might be. When I created my first Canvas, it automatically created an "EventSystem" object. I added a script to this object and made it a prefab. Is it possible that I should have instead just made a brand new "Event Manager" object instead of using the auto generated one?

queen adder
#

only then you will rotate the player

wicked blaze
#

aha

#

wait, so am i supposed to put the bool into an if or

#

i dont really understand

queen adder
deep bear
#

Oh it was my own script that I attached. But I think that I have a very poor understanding of the EventSystem.

Is Unity's EventSystem set in place so that you can have buttons interact with your game without writing code?

queen adder
deep bear
#

And here's the object

wicked blaze
#

but still the same problem when i try to craw it just turn my camera to one direction

#

and i cant move it left or right

#

only up and down

queen adder
patent compass
#

is this the right channel to ask doubts related to netcode?

queen adder
#

just put your codes that rotates everything inside

spiral oak
#

Is it a good idea to have a Init method which replaces constructor in MonoBehaviours?

static cedar
#

Why do u even have constructors for MonoBehaviours?

#

Unity builds components themselves. You won't get the chance to call init or the constructor to use them.

spiral oak
queen adder
static cedar
#

If you need arguments. I'd suggest make a static method.

#

Something like this is something like this.

public class MyComponent
{
  public int Something { get; private set; }

  public static MyComponent AddComponentToThat(GameObject game_object, int value_of_something)
  {
    MyComponent @new = game_object.AddComponent<MyComponent>();
    @new.Something = value_of_something;
  }
}
#

And try not to call AddComponent outside it. :p

#

I don't normally do this. I construct an entire game object with necessary components instead.

queen adder
#

Instantiate(yourClass).Init(34);

static cedar
#

Doesn't Instantiate return a UnityEngine.Object?

queen adder
#

it return a generic T

static cedar
#

Ah.

spiral oak
#

Well, I think I'll refactor the code so I don't have to inject dependencies into a MonoBehaviour. Thank you both!

static cedar