#💻┃code-beginner

1 messages · Page 767 of 1

meager siren
#

I plan to make the Main Camera bob

rich adder
#

yes I understand

meager siren
#

and etc

rich adder
#

I'm just letting you know if you notice most fpv games animate whatever you're holding / arms

rich adder
rich adder
#

depending on game, but so usually it doesn't mess with your aiming

#

weapon moves but camera is static

meager siren
#

oh

#

mines not a shooter

#

I have extra stuff for the head bobbing

#

the games going to have sanity and the higher sanity you have the harder you will bob and what not

rich adder
meager siren
#

do you know how to explain it?

#

and make it repeat?

#

I think I understand a way for it to repeat

#

actually

#

I can use a while statement correct?

rich adder
#

just like use sin with Time.time for example that should give you a simple up and down then multiply it by some val

meager siren
#

wait

#

your telling me

#

theres a better way. To do

#

timers?

#

wth man

meager siren
#

tysm

#

im back in school

rich adder
#

I'm sure if you lookup any these headbob things they have sin somewhere

meager siren
rich adder
#

though I personally prefer cinemachine as it gives more randomized noise added on

meager siren
#

instead of copying

meager siren
#

I'll just go with Sine

#

for now

meager siren
#

where'd you get this

rich adder
#

I had it in my YT playlist for unity since a couple years

meager siren
#

alright

vocal orchid
#

Hi

#

How can disable the gameobject Parent since all the gameobjects childs are disable

rich adder
#

transform.parent.gameObject.SetActive(false) but its kinda dirty to do..

meager siren
vocal orchid
#

But when all the gameobjects are disable

#

Example

rich adder
vocal orchid
#

The gameobject parent have 3 gameobjects childs

#

When the 3 gameobject childs are disable, the gameobject parent is will disable

rich adder
rich adder
#

what are you even showing me here?

vocal orchid
vocal orchid
#

Script of the gameobject child

rich adder
vocal orchid
#

Script to active the gameobject parent

#

So, this active the gameobject parent but, not their gameobjects childs

rich adder
vocal orchid
meager siren
#

Not entirely sure on how to do it ngl

vocal orchid
#

But I still not working

rich adder
meager siren
#

Do I have to make a variable for it then?

#

im guessing

rich adder
#

read whats in the link and you'll understand what the error is telling you

meager siren
#

Its fixed but it still doesnt move at all

rich adder
meager siren
#

ah

#

Im supposed to

#

man I have dumb moments lmao

rich adder
#

value types only copies the values, messing with a copy wont do much if you dont assign it back to something

meager siren
#

alright

#

Do you mean like this

#

or Should I be doing +=

rich adder
meager siren
#

doesnt work

rich adder
vocal orchid
#

Still not working

rich adder
meager siren
#

Anyone understand how to make a camera lag behind whilst rotating it?

zenith harness
meager siren
#

seriously?

#

well

#

the scripts in cameraholder

slender nymph
#

obligatory: use cinemachine

meager siren
#

how

zenith harness
#

my speed variable doesnt work.

#

using UnityEngine;
using UnityEngine.InputSystem;

public class asd : MonoBehaviour
{
public float speed = 500f;

private float movX;
private float movY;
private Rigidbody rb;

void Start()
{
    rb = GetComponent<Rigidbody>();
}

void OnMove(InputValue movementValue)
{
    Vector2 movementVector = movementValue.Get<Vector2>();
    movX = movementVector.x;
    movY = movementVector.y;
}

void FixedUpdate()
{
    if (Camera.main == null) return;

   
    Vector3 camForward = Camera.main.transform.forward;
    Vector3 camRight = Camera.main.transform.right;

    
    camForward.y = 0f;
    camRight.y = 0f;
    camForward.Normalize();
    camRight.Normalize();

   
    Vector3 movement = camForward * movY + camRight * movX;

    
    rb.AddForce(movement * speed);
}

}

radiant voidBOT
zenith harness
#

oh mb im new

naive pawn
#

what's speed set to in the inspector?

zenith harness
#

its set to move a sphere on this absalutly wonderful plane

#

it moves, it just doesnt scale

#

@naive pawn

polar acorn
#

What's the speed set to in the inspector

zenith harness
#

now how would i double the gravity of the ball

naive pawn
#

set the gravity scale to 2

mortal folio
#

[Error :Il2CppInterop] During invoking native->managed trampoline
Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at (il2cpp -> managed) Tick(IntPtr , Single& , Il2CppMethodInfo* )

Anyone able to help with this? notlikethis

#

I have a BepinEx plugin working for preventing loss of Hunger, Thirst and Temperature for the player, and I have the objects (clone)'s for NPC villagers but when I try to apply the code to both somewhere along the line it's resulting in this being spammed in the console before I've even loaded into my save

#

I've tried using ChatGPT to try to troubleshoot this but it seems unable to atwhatcost

placid jewel
mortal folio
#

Developers for ASKA literally allow mods

sour fulcrum
#

unfortunately it's still not allowed here, iirc because it breaks terms of service

mortal folio
#

But whatever, be facist, I'll just let people know

sour fulcrum
#

why are you being weird about it homie

placid jewel
fading swan
tired python
#

i have a question related to architecture...currently, i have a script which spawns units manually(i press certain keys to spawn them), and i wanna automate it in the future. I have another script which controls when the unit gets destroyed(when it goes outside the map). I wanna be able to animate the units in a certain way based on which direction it's currently moving in. for that, i am currently calculating the t ratio inside the script which controls when it gets destroyed. should i make another seperate script for its animation and attach it or just build it inside the destruction script that's already present

placid jewel
tired python
hardy blade
#

Hey guys, I have a very beginner question

#

I want to enable all children of a gameobject, that have a mesh filter, I thought I did it right, but apparently not

placid jewel
tired python
#

prolly not...

placid jewel
# hardy blade

You're only setting meshFilter to be active, and not instances, I'm not 100% sure but I'd guess that's the issue

placid jewel
#

Or is that no longer necessary

hardy blade
#

Do you know?

tired python
sour fulcrum
#

@tired python personally from reading your stuff i would do something like this

placid jewel
sour fulcrum
#

actually i'd go one step further and say instead of the unit killing itself, the unit asks the manager to kill it

tired python
frail hawk
sour fulcrum
#

yeah each hard-edge box would be a monobehaviour or some script in general

hardy blade
frail hawk
#

i know, you said "enable" them

sour fulcrum
#

You may want to split unit stuff into seperate components later down the line if certain units have notably differing behaviour but if your early on i'd just say 1 script per responsible "party" if you feel me

meager siren
#

Anyone know how to use direct raycast?

tired python
sour fulcrum
#

having UnitManager be in charge of middle-manning every job of "managing" the units allows the units, your input manager and whatever automation you want to touch the same system in the same way

placid jewel
frail hawk
placid jewel
tired python
hardy blade
meager siren
meager siren
#

ty

placid jewel
# meager siren ty

one more thing that's not explicitly covered by the docs (but is visible in the first example script) is, if you want to get a reference to the thing the raycast hit, you can add out hit to the parameters when you call it. Then when you write hit afterwards in your code it will refer to the object hit.

meager siren
#

I think I know what I'm doing wrong ngl

placid jewel
#

Yeah, I just realised as you sent that you need to define RaycastHit hit; beforehand

placid jewel
meager siren
#

wait

#

hold on

placid jewel
#

So like this

meager siren
#

I'm trying to make sure the door checks if the player is close enough

placid jewel
#

(you also don't have to call it hit lol)

meager siren
#

and if it is we can open it

#

I think I'm doing it wrong ngl

#

and I might have just figured it out

tired python
placid jewel
# meager siren

For the direction field, you'll probably want transform.position - player.position

meager siren
#

oh alright

#

wdym error

placid jewel
placid jewel
tired python
meager siren
placid jewel
meager siren
#

my fault

placid jewel
placid jewel
naive pawn
#

out RaycastHit hit or out var hit for example, in the argument position

placid jewel
#

Yeah

#

Either method works the same, unless there's a reason to use one over the other that I'm missing

meager siren
#

Its not working

naive pawn
placid jewel
meager siren
#

oh

#

right

#

LMAO

#

I CANT SEE AND READ

naive pawn
meager siren
#

its meant to be like this

meager siren
#

matter of a fact

#

I dont even know what nested means anymore

#

dont even think I ever knew

placid jewel
placid jewel
placid jewel
meager siren
meager siren
#

I have prior coding experience to C#

#

Ive done python before. My teacher taught me nested if statements

#

and I forgot

#

but thanks for reminding me

placid jewel
#

There's nothing wrong with the concept of nesting, but currently it might be hard to tell where the problem is, seeing as two conditions have to be fulfilled for the innermost line of code to be executed

placid jewel
#

If it's not working the best way to debug it is to put a Debug.Log in each level of the nested if's, with different messages, to see exactly where the code gets to

meager siren
#

yeah

placid jewel
#

And then you'll know which condition fails

west sonnet
#

When the player changes to a new gun, the gun is instantiated for the player to use. I'm trying to set the "WeaponAnim" value on the player, to the Animator that is stored on the Weapon and the Weapon ScriptableObject. It is being assigned, but my animator is not playing and I'm not sure why.

I have a trigger called "ShotFire" which is being called whenever the player mouse clicks, and I've used Debug.Log to ensure it should be being called. But my animator never starts and I'm not sure why. Can anyone help please?

naive pawn
#

you know single-line if statements?

#

this is basically that

tired python
#

@placid jewel

using UnityEditor.ShaderGraph.Internal;
using UnityEditorInternal.VersionControl;
using UnityEngine;
using UnityEngine.Splines;

public class DamnDeseDucks : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    [SerializeField] private SplineAnimate aniSpline;
    [SerializeField] private Spline spline;
    void Start()
    {
        aniSpline.Completed += onComplete;
    }

    // Update is called once per frame
    void Update()
    {
        CalculateTangent();
    }
    
    void onComplete()
    {
        Debug.Log("Duck will be destroyed.");
        Destroy(gameObject);
        Debug.Log("Duck was destroyed.");
    }

    void CalculateTangent()
    {
        float tratio = aniSpline.ElapsedTime / aniSpline.Duration;
        float3 tangentVector = SplineUtility.EvaluateTangent(spline, tratio);
        Debug.Log($"Ratio t is: {aniSpline.ElapsedTime / aniSpline.Duration}");
        Debug.Log($"The tangent is: {tangentVector.x}, {tangentVector.y}, {tangentVector.z}");
    }
}

somehow, the Debug.Log($"The tangent is: {tangentVector.x}, {tangentVector.y}, {tangentVector.z}"); is printing (inf, inf, inf)

meager siren
#

wait how tf do I bring back the console

#

help whatd I do

tired python
meager siren
#

wth man

#

why now

placid jewel
meager siren
#

you can bring it back right?

placid jewel
meager siren
#

right?

naive pawn
meager siren
#

Yeah it's just not hitting overall

#

heres the funny code

placid jewel
#

I think I might have given you the wrong vector direction to use

meager siren
placid jewel
#

Vector from points A to B is b-a

meager siren
#

oh

#

testing now I guess

placid jewel
#

So player.position - transform.position

meager siren
#

alright

#

it works

#

its just the door not opening

#

does Mathf.Lerp work for Sin

naive pawn
#

@placid jewel the format of ifs (and control statements in general) basically goes like if ( condition ) statement
that statement could be anything, including another control flow statement, the empty statement ;, or a block statement { ...statements }

#

to my knowledge, all c-syntax languages obey this

naive pawn
#

if you use them correctly you can use them together fine

placid jewel
frail hawk
meager siren
meager siren
naive pawn
meager siren
naive pawn
#

but itll apply to just the immediate statement

naive pawn
meager siren
#

Never knew that

naive pawn
#

sine and cosine basically already have smoothing built in, what is the extra lerp smoothing supposed to do?

naive pawn
#

that's not what i asked

meager siren
#

I'm not entirely sure. This is the one thing I did not write

#

Since I couldn't figure it out myself

placid jewel
#

Where did you get it from?

meager siren
#

somewhere

#

idk

placid jewel
#

Damn

#

Someone put it up for people to use

meager siren
#

yeah

placid jewel
#

Does it work? Like exactly as you want it to, not just a close approximate?

meager siren
#

works perfectly. there is more to it

placid jewel
#

Because if so don't worry about it for now and come back when you feel a bit more confident to figure it out on your own I'd say

meager siren
meager siren
naive pawn
#

have you tried just using the smoothing from sin/cos instead of adding the extra lerp smoothing?

meager siren
naive pawn
#

the wrong lerp means the result will be framerate dependant

meager siren
placid jewel
#

Ideally you'd want to do it in a coroutine right?\

meager siren
#

just a geniune question

meager siren
naive pawn
placid jewel
naive pawn
meager siren
#

Many friends accompanying me lmao

tired python
#

tratio is getting printed

placid jewel
meager siren
tired python
#

one thing to note though, while the tratio debug does stop printing, the infinity debug gets printed

placid jewel
placid jewel
meager siren
#

Hey, how do I make it so that I dont have to hold down interact so I can just click it instead?

tired python
#

lemme send you a vid

placid jewel
#

Both are still printing

#

Wait

tired python
#

exactly

placid jewel
#

How is it set up? What objects have what scripts?

placid jewel
#

I think I know the issue maybe

tired python
placid jewel
#

Can you add a Debug.Log(spline) line somewhere with the other debug.logs?

#

You don't need to use a formatted string like the others it can just be put like I wrote

tired python
placid jewel
#

Yeah

#

What does it print

tired python
#

oh wait, ratio is 0 keeps printing

placid jewel
#

Yeah

tired python
#

everything is printing at all times

#

i guess it has to...cus its part of the update()

#

i don't even check for whether the gameobject exists or not i guess...

placid jewel
#

Wait, is Spline assigned properly under enemyAni?

placid jewel
#

Can you click the arrow next to Spline

tired python
#

wait what the hell

placid jewel
#

Is it not assigned?

tired python
#

demn it's not

placid jewel
#

It makes sense since the only time you got an error was the only time you use the Spline itself

#

You're taking the t value from aniSpline and using it to check something in spline

tired python
#

then...wouldn't evaluatetangent make a null ref error if spline is not even assigned?

placid jewel
#

Evidently not

tired python
#

why O_O

#

spline gets assigned a default value or smth?

placid jewel
#

Presumably it doesn't check if the spline exists and still tries to do math with it

#

It's not explained on the docs

#

Anyway are you able to assign it and if so does it work now? @tired python

tired python
placid jewel
#

Alright fair enough

naive pawn
#

it's just the default value, like ints being 0 or Vector3s being 0,0,0

#

the spline does exist, it just doesn't have any data

tired python
naive pawn
#

if you already have a spline referenced somewhere else, why is this one serialized

tired python
tired python
#

not a single code of mine does that...

naive pawn
naive pawn
tired python
#

this spline object that i am using, isn't a copy of the spline i made inside the scene

naive pawn
#

what's the type of spline

tired python
naive pawn
#

the one in the scene

tired python
naive pawn
#

is it a value in a component on some gameobject?

#

im referring to how it exists, rather than how you drew it

placid jewel
#

At least it's referred to by SplineAnimate

#

So probably possible to get in the required script via reference to that one

naive pawn
#

(you wouldn't be getting a script, but sure)

#

oh wait, i skipped over the "in" lmao

#

mb

tired python
naive pawn
#

sooo did you find out what component holds the data of the spline you drew

naive pawn
#

might be SplineContainer, considering SpliteAnimate refers to it

#

ah yeah

#

so you'd need to get a reference to that container and get the spline from that

tired python
#

oh ya...

naive pawn
#

and SplineAnimate seems to have a reference to the container, so you could use that existing reference you have

placid jewel
#

Yeah I don't think Spline is a type that can naturally (easily) be assigned via drag and drop in the editor

naive pawn
#

then you can remove the serialized spline field, it's not doing anything (you could just make it not serialized and use it to cache the spline though)

naive pawn
tired python
tired python
#

ok, i have reached my wit's end, i need your help.

#

so i added a Spline Container component onto my duck prefab which currently has a list of all my knots

#

like so

#

now, i am trying to get a list of these knots using this

#

BUT, KnotLinkCollection returns a KnotLinkCollection data type, not a Spline data type

#

damn my eyes are droopy

#

@placid jewel @naive pawn

#

wait a sec,i think evaluatetangent is a method of SplineContainer too

stark meadow
#

ive scoured the internet but im yet to find a soln for this. when playing looping tracks through the audiosource, there is always an audible click sound when the track loops, even when the track is seamless. anyone knows how to fix that?

placid jewel
tired python
#

guys, i have encountered a problem

grand snow
#

Due to differing scales and positions

#

(inherited from parent gameobjects)

#

Also damn your spline is way more complex than needed, i presume you dont know about changing the in and out handles to alter curvature

tired python
#

my pc lags whenever i try to select all of the knots

grand snow
#

you probably only need 6 points in that spline

naive pawn
#

holy hell that's an insane spline

polar dust
grand snow
tired python
grand snow
#

you need to correct the scale of parents or where you position the spline

tired python
#

the prefab is positioned perfectly

#

its the damn clones that are doing this messed up thing, not only that, now, its the damn spline that moves, it's not even the duck it's the actual spline that moves

#

why do i need to have so many problems with my duck spawning. leave my ducks alone

grand snow
#

There should be 1 spline and thats it

#

and the ducks would be spawned, connected to the spline in the scene and animated along that

#

What is the setup you actually have?

tired python
grand snow
#

Doesn't answer my question

#

You probably aren't doing this in a smart way

#

When you scale objects to make em bigger/smaller it's easy to get these issues

#

Ideally we have a parent with 1 scale and then children we scale up/down

tired python
grand snow
#

Check your transforms

tired python
#

it's at 1

#

actually, nvm, my initial img is microscopic

#

just spent 30 mins doing nothing

tired python
slender nymph
#

don't cross post. and consider posting the actual code you need help with instead of expecting people to watch a tutorial to know what you are trying to do

orchid pasture
frail minnow
#

Hey everyone, look im pretty new to unity cause ive been working in a diff engine for years (no not unreal), and im trying to code a shader that uses my existing shader i use for triplanar materials for terrain materials, anyone know how i could achieve/go about that?

#

I tried coding one just using albedo, but i get

grand snow
past nacelle
#

// Apply Anti-aliasing setting
var urpAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;

    if (urpAsset != null)
    {
        switch (temporaryAntiAliasingMode)
        {
            case "off":
                urpAsset.msaaSampleCount = 1;
                urpAsset.antialiasing = AntialiasingMode.None;
                break;
            case "fxaa":
                urpAsset.msaaSampleCount = 1;
                urpAsset.antialiasing = AntialiasingMode.FastApproximateAntialiasing;
                break;
            case "taa":
                urpAsset.msaaSampleCount = 1;
                urpAsset.antialiasing = AntialiasingMode.TemporalAntiAliasing;
                break;
            case "smaa":
                urpAsset.msaaSampleCount = 1;
                urpAsset.antialiasing = AntialiasingMode.SubpixelMorphologicalAntiAliasing;
                break;
            case "msaa4x":
                urpAsset.msaaSampleCount = 4;
                urpAsset.antialiasing = AntialiasingMode.None;
                break;
            case "msaa8x":
                urpAsset.msaaSampleCount = 8;
                urpAsset.antialiasing = AntialiasingMode.None;
                break;
        }

Hello 👋
Setting up my first video settings menu and can't seem to figure out what definition to call from UniversalRenderPipelineAsset to switch on FXAA, TAA, & SMAA respectively.
Using urpAsset.antialiasing = doesn't seem to work.
Any help would be greatly appreciated. Thank you. ^^

rich adder
past nacelle
#

Maybe there is idk couldn't find it.

#

XD

rich adder
#

things have probably changed since that URP version..

#

what exactly isn't working ?

past nacelle
past nacelle
spark knoll
#

can anyone help me with a small issue with coding please?

radiant voidBOT
# wintry quarry !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

spark knoll
#

Don;t know how to fix these errors, ik it is common and easy but it's killing me!!

wintry quarry
#

or you defined the class(es) twice in that file

#

either way - you need to find and delete the second copy

spark knoll
#

I can't find any honestly

#

is there a way to share them?

wintry quarry
#

just open your IDE (code editor) and search for "class BearData"

#

you will find two

#

delete one of them

pine heart
#
    {
        if (groundCheck == null)
        {
            groundCheck = transform; // fallback
        }
        isGrounded = Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, groundMask);
        //nearLedge = 

        if (currentPath == null || targetIndex >= currentPath.Count) return;

        Vector2 targetPos = currentPath[targetIndex].worldPosition;
        Vector2 dir = (targetPos - (Vector2)transform.position).normalized;

        // If about to fall off a ledge, stop or jump
        //if (isGrounded && targetPos.y <= transform.position.y)
        //{
            //rb.linearVelocity = new Vector2(0, rb.linearVelocity.y);
            
       // }

        // Move horizontally
        rb.linearVelocity = new Vector2(dir.x * speed, rb.linearVelocity.y);

        // Jump if target is higher and on ground
        if (isGrounded && targetPos.y > transform.position.y + 0.5f)
        {
          rb.linearVelocity = new Vector2(0, jumpForce) return;
        }

        // Proceed to next node
        if (Vector2.Distance(transform.position, targetPos) < 0.3f) 
            targetIndex++;
    }```
#

any idea why this crashes my game when the character jumps?

wintry quarry
#

when you say "crash the game" what happens exactly?

ivory bobcat
pine heart
#
    {
        if (target == null)
        {
            if (GameObject.FindWithTag("fruit") != null)
            {
                target = GameObject.FindWithTag("fruit").GetComponent<Transform>();
            }
            else if (GameObject.FindWithTag("Enemy") != null)
            {
                target = GameObject.FindWithTag("Enemy").GetComponent<Transform>();
            }
            
        }
        if (target != null)
        {
            currentPath = Astarbrain.Instance.FindPath(transform.position, target.position);
            targetIndex = 0;
        }
    }```
wintry quarry
ivory bobcat
#

Is isGrounded a property?

wintry quarry
#

Just share the full script!

#

!code

radiant voidBOT
pine heart
wintry quarry
#

Does the whole program freeze and need to be shut down manually? Or something else?

#

Another question would be - what is Astarbrain? Is that a plugin? Or something you wrote yourself?

ivory bobcat
#

The path finding looks very concerning

pine heart
#

yes, it needs to be shut down through task manager

wintry quarry
#

I'd say most likely it's an issue in Astarbrain

#

probably when you jump it can't find a path

pine heart
wintry quarry
#

but it isn't handling that correctly and is perhaps entering an infinite loop somewhere

pine heart
#

astarbrain

wintry quarry
#

while (openSet.Count > 0)
Yeah this is probably it

#

It's possible there's a bug in the code here and this loop is never terminating

#

To test if this is the problem can you see if commenting out InvokeRepeating(nameof(UpdatePath), 0f, updatePathInterval); for the time being stops the crashing?

#

though I guess it seems like your jumping is not manual

#

RetracePath could also be the problem

#

If there is a cycle in your graph

pine heart
#

doesn't crash until the player jumps over the target

ivory bobcat
#

I'm going to assume jumping isn't the problem but something that's dependent on not being displaced by jumping is

wintry quarry
pine heart
#

It can jump until the target is below it

ivory bobcat
#

Try commenting the invoke repeating line out like suggested

pine heart
#

I commented it out, player can't move anymore

ivory bobcat
#

Or rather, check if commenting out the Find Path statement removes the crash

pine heart
#

character just stands there

ivory bobcat
pine heart
#

oh

#

doesn't crash

#

but doesn't move either

ivory bobcat
#

It's most likely an infinite loop with your while statement

#

Where open set count is never less than one

#

Or retrace while (currentNode != startNode)

pine heart
#

just commented out:

#
        {
        //    path.Add(currentNode);
          //  currentNode = currentNode.parent;
        }```
#

and it crashed as soon as the target fell below the player

drowsy tiger
#

well, it would, because if the while loop has no exit condition

ivory bobcat
#

Try limiting how often this line can runcs while (currentNode != startNode && path.Count < 1000)

#

If this while loop was the culprit, it should remove the crashes at the expense of not behaving how you likely want it to behave

pine heart
#

still crashes

wintry quarry
#
int iterations = 0;
while (openSet.Count > 0 && iterations++ < 10000)
{
// blah blah
}
if (iterations >= 9999) {
  Debug.LogError("Too many iterations");
}``` do this too
languid pagoda
#

i am sure this doesn't exist but maybe unity does have this data posted some where.

What are the most common apis used in the engine? implementing all of them in my scripting language isn't realistic but id like to make sure I get all of the popular ones.

ivory bobcat
#

You've got a lot of potential crashes as your looping a whole lot

wintry quarry
#

Like understand them?

drowsy tiger
languid pagoda
ivory bobcat
#

Sounds subjective

ripe shard
drowsy tiger
#

Your language...is for a game engine? or a game?

ripe shard
#

you can also look at what bolt supports and work with that subset.

languid pagoda
drowsy tiger
#

Bolt supports almost everything, and most of it is generated

wintry quarry
drowsy tiger
#

Now, that required the entirety of unity's APIs

#

Do you require all of it? What is the purpose

languid pagoda
#

Now I am wondering if there is a list of the most commonly used apis so I can expose them to said scripting language

wintry quarry
#

Definiutely nobody has such a list

drowsy tiger
wintry quarry
#

other than perhaps Unity

ivory bobcat
#

So... are you like.. needing to lookup Unity's implementation of certain functions or... ?

ripe shard
#

fwiw, the answer to your original question is: it depends an what someone needs, no list exists

languid pagoda
wintry quarry
#

A general list for all game types is probably not that useful to you anyway

drowsy tiger
#

start with basic types, Transform, Gameobject, Object, Vector3, Quats. And... Mathf. That should get you started....maybe

wintry quarry
#

I bet it depends on the genre or camera style or other things

languid pagoda
drowsy tiger
ripe shard
#

It makes little sense to approach this statistically. I believe you have to compose that list with personal understanding what’s useful and needed

slender nymph
drowsy tiger
#

but, I just know about it, havent used it

#

its original function is different, but it can be used as a mod enabler

languid pagoda
#

its been being used since like 2002 without any security holes

languid pagoda
pine heart
#

@ivory bobcat it works now

mild citrus
#

Can someone please help me with this error

slender nymph
#

!input

radiant voidBOT
# slender nymph !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

mild citrus
rich adder
#

!vscode

radiant voidBOT
pine heart
#

@wintry quarry your suggestion stopped the crash, but it still won't move once above the goal

thick tusk
#

!ask

radiant voidBOT
# thick tusk !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

thick tusk
#

does anyone know how I would go about making parry, blocking, and attacking animations better in a 2d game (only x movement not y movement)? Would really appreciate the help.
I could not find much about it only other than people sharing there devlog, if there are any videos or something that I can use to code these mechanics knowing of them would be really helpful.

tough lagoon
#

But if i come across anything ill ping you :D.

thick tusk
tired python
wintry quarry
subtle cape
#

Hi there i want to make a simpel silksong type 2d game just to try and learn making games for fun but im wondering what the best way is to start because i really have no idea how to make games

radiant voidBOT
ashen trail
#

Im getting this error even though there is a variable named deathCount in basicEnemyMovement

rich adder
ashen trail
#

thanks idk how these little things keep happening to me

rich adder
#

gremlins in your pc messing with you

ashen trail
#

lol

#

Im getting an error on this line of code and I have no idea what it means, anyone know the problem?

rich adder
ashen trail
#

but there is a gameobject named Enemy

or do prefabs not count as gameobjects

sour fulcrum
#

names are not tags

rich adder
#

notice I said, Tag

#

also please tell me you're not running this in Update 😵‍💫

#

cache it once in start or sum

#

scanning every object in the hierarchy every frame is not efficient

ashen trail
#

not at all

rich adder
#

bit rhetorical tbh. I already know lol

ashen trail
#

also I miss spoke, the enemy prefab has a tag of Enemy

rich adder
#

well if that line is running before you spawn a prefab with that you get the error

ashen trail
#

ohh,

#

I'll just put a prefab in the scene then ig

rich adder
#

I mean you want only 1 specific Enemy? there is probably a better way to whatever it is your doing, if you explain it then its easier to suggest something

ashen trail
#

okay so I have an enemy prefab and I want the score on a piece of text to go up every time the enemy is killed

rich adder
ashen trail
#

I made a new script to keep score, could I have just done it in teh script where the enemy dies, wouldn't like connecting the text and that script be hard

#

like if I keep one enemy in the scene it works

rich adder
#

yes just connect the score with the text, why does enemy care about the text

#

something like
enemy
Awake(){
scoreThing = FindGameObjectByTag("Score");

Death(){
scoreThing.AddScore(1);

#

or even better search the component not a tag Awake(){ scoreThing = FindAnyObjectByType<ScoreScript>();

#

scorescript
AddScore(int amount){
score+= amount;
//update text too

ashen trail
#

i did that, but then in a different script I go, i go

scoreText.text = "Score: " + basicEnemyMovement.deathCount.ToString();

to update the score

rich adder
#

why?

#

why is there a death count on an enemy..

ashen trail
#

so that I can put that count in the top corner of the screen(dont mind the assets)

rich adder
#

that doesn't really clarify why would you track that in EnemyMovement ?

ashen trail
#

because thats where I detect if the enemy has died,(very new to unity btw, ik alot of my code looks dog)

rich adder
#

spaghetti af

#

at most you'd add the score from enemy on death into a scriptscore tracker

#

like i shown above

rich adder
#

no you're trying to access an int on a specific enemy

ashen trail
rich adder
#

ok but why does enemy have deathCount

#

how many enemies you gonna have ?

ashen trail
#

so I know how many times the enemy died, then I can give a goal of a certain amount of deaths for the player to reach

ashen trail
#

if I had more though would I have to change code?

rich adder
#

well yeah you're literally searching for a specific instance

#

if you destroy it now you got an error until you spawn another and so on

#

its good to start separating these in the beginning, enemy should do enemy things not deal with tracking scores or deaths

ashen trail
#

okay this is 100% a dumb solution but what if I put an enemy prefab in the scene where the player cant reach him then freeze the enemy

ashen trail
rich adder
#

I would just let enemy know score/death tracker "Hey I died"
thats it

ashen trail
#

okay

rich adder
#

if enemy dies it doesnt implode the thing searching an enemy tag , every frame especially

waxen torrent
waxen torrent
#

i dont see an animation channel

rich adder
waxen torrent
#

that didnt appear for me until you shared me ill post it there tho ty

eternal needle
thick tusk
#

I've seen a lot of people use velocity over linearVelocity which one should I be using?

rich adder
#

linearVelocity is just the newer renamed version

thick tusk
waxen torrent
#

i figured it out myself. If anyone cares, unity doesnt recognize type metarig, had to generate the actual rig for unity

mild citrus
#

How do I get that Scratch like scripting in regular Unity that I saw in Unity Studio?

keen dew
#

It's not available for normal Unity. The closest equivalent is Visual Scripting

drowsy tiger
#

Is this a known thing where the console stops auto scrolling randomly when you have a bunch of logs spitting out in Unity 6.2.X? Or have I managed to change some setting

real thunder
#

I meant to use Array.Exists just to check if a class is already in an array am I? That looks bit too elaborate

#

nvm Contains seems to be the one

grand snow
real thunder
#

yeah thanks that's bit confusing

#

almost like a C# devs screwed up with naming a bit

grand snow
#

Then best to stick with a List

real thunder
#

Contains works with an array too it seems

grand snow
#

for speed you would want to use a list and Contains() or loop over the array yourself

#

again, if this confuses you stick with List

keen dew
#

If you just want to check if an element is already in the array then Array.IndexOf(array, element) > -1. Only works if it's the exact same element and not an object with same values

real thunder
#

that would work too but I don't get it why would contains work worse

keen dew
#

Contains is a LINQ extension so there might be a small overhead. Not enough to care about it probably

glass summit
#

Could anyone check if i have any errors with my code or am i all good?

night raptor
elder canyon
#

My character is a first person shooter and it uses a character controller. A rigidbody cube basically attaches 5 units in front of the character.

By 'attaches', what I've done is I created a magnetic field 5 units infront of it and the cube basically tries to get to the desired point(ie 5 units in front of the character).

The logic works perfectly fine. But the movement seems slightly jittery. I suspect it is due to different update cycles?

Anyways this is the cube gameObjects logic https://paste.ofcode.org/qze5qJ6Pa2Q6uhytM5PKYF

real thunder
#

in general I don't like the idea of keeping a gameplay state in a bunch of coroutines

real thunder
#

so I guess

#

have you turned on a rigidbody interpolation tho? might help

brazen aurora
#

im making a tower defense game right now and im trying to stop the towers being able to be placed ontop of each other. Right now whats happening is that it will place but if it ever comes close to an invalid spot, that tower will never be able to be placed.

    {
        if (!spawned.gameObject.GetComponent<TowerBehaviour>().isInvalid)
        {
            spawned.gameObject.GetComponent<TowerBehaviour>().isPlaced = true;
            spawned.gameObject.GetComponent<TowerBehaviour>().isInvalid = false;
            spawned = null;
        }
    }```
#

something seems to be happening here as if i release the mouse button then it cant be placed

night raptor
# glass summit https://paste.ofcode.org/5W5Qp2yJMc7C5FJEB5yKeq

Couple points that I can see by quick readthrough:

yield return new WaitForSeconds(0.05f);
yield return new WaitForSeconds(1);
```The two lines above don't seem particularly useful. Is there a reason not to just wait 1.05 seconds once to begin with?
You are using GetComponent quite extensively. It is not inherently bad but in this case I would think getting the two text elements once in `Start` (store them in variables) would be better for both readability and performance. Whether the code logic actually works I cannot comment on really since I don't know what it is supposed to do.
nimble apex
#
throw new InvalidOperationException("Insufficient Gold!");```

invalid op wont show as an error on terminal?
real thunder
#

I hope you are not using that for gameplay but only as an internal sanity check or something

#

this line of code making me chuckle

#

I am not having a solid grasp on that but if you throw an exception that's a damn error and it's not meant to happen and it will get shown in console likely

elder canyon
nimble apex
cedar jolt
#

@compact roost

polar acorn
compact sandal
#

for (int i = 0; i < roomSpawns.Length; i++)
{
GameObject[] currentWaveSpawns = new GameObject[10];
for(int j = 0; j < roomSpawns[i].transform.childCount; j++)
{
Transform currentChild = roomSpawns[i].transform.GetChild(j);
if(currentChild.gameObject.tag == nestSpawnTag)
{
_nestSpawnPoints.Append<GameObject>(currentChild.gameObject);
}
if(currentChild.tag == antWaveSpawnTag)
{
currentWaveSpawns.Append<GameObject>(currentChild.gameObject);
}
}
_antWaveSpawns.Append(currentWaveSpawns);
}

im trying to get children based on their tags but for some reason both the ways to get their tag return untagged while they should be tagged. (nothing here is null)

grand snow
#

First mistake is using tags

#

If you had a custom component you could just GetComponentsInChildren()

verbal dome
#

Also what type is _nestSpawnPoints

timber tide
#

I applaud you for using superior for loops

verbal dome
#

I don't see why you'd use Append instead of a list + add

compact sandal
#

im quite new to unity itself so i did know of add before

grand snow
compact sandal
grand snow
#

It will allocate a new managed string each access

compact sandal
grand snow
#

CompareTag() exists for this reason

vital fractal
grand snow
vital fractal
#

thats bs

#

lol

grand snow
#

No its just how it works

compact sandal
#

damn alr

vital fractal
#

no no i mean, the way it works is bs

#

i get it

grand snow
#

native <-> managed crossover has its challenges

compact sandal
#

but anyways, do i add like an empty component to each of the children and use that as identification?

grand snow
vital fractal
#

yeah i get that too, but if you create something that has such behaviour that people usually dont expect, its objectively not very viable...

verbal dome
verbal dome
#

This way you get only 1 extra component

grand snow
#

Its fine because past the beginner stage you basically never touch tags again

compact sandal
#

alright. Ty guys

vital fractal
#

also, what is your alternative @grand snow ?

grand snow
#

Components always

vital fractal
#

you TryGetComponenet?

#

also, @compact sandal let me poison you for a sec... but here are 2 falid ways of nesting for loops:

for (int i = 0; i < length; i++) {
    for (int j = 0; j < length; j++) {
        for (int k = 0; k < length; k++) {
            for (int l = 0; l < length; l++) {

            }
        }
    }
}
for (int i = 0; i < length; i++) {
    for (int ii = 0; ii < length; ii++) {
        for (int iii = 0; iii < length; iii++) {
            for (int iv = 0; iv < length; iv++) {
            
            }
        }
    }
}

monkdevious

compact sandal
#

0_o.... poison was effective

vital fractal
#

hehehe

compact sandal
#

if i have a component from a gameobject, how do i get its object?

#

NestSpawnPoint currentNest = GetComponentInChildren<NestSpawnPoint>();
_nestSpawnPoints = currentNest.gameObject;

this doesnt seem to work

naive pawn
#

how exactly is it not working?

#

(though btw, do consider serialized references)

compact sandal
#

on the second line

naive pawn
#

so it does work

#

you're just assigning it to a variable that expects an array

compact sandal
#

this is the error it gives me

naive pawn
#

sorry, shouldve been clearer

#

the .gameObject does work

#

it's giving a GameObject

#

the assignment doesn't, because _nestSpawnPoints is a GameObject[]

compact sandal
#

omfg yeah, mb

#

was stupid

vital fractal
# grand snow Components always

im still actually curiosue how you apply this, its pretty relevant for me currently as im on a problem involving tags and wanna see if your way would be viable for me to also implement

grand snow
#

You either pre assign the objects via some Serialized list/array or as i said, have a component on each child object

#

Then you already have access to them all or can locate them easier

vital fractal
#

fair enough, so its basically just a custom system

grand snow
#

Everything we do is custom

vital fractal
#

would it actually just be faster to make a manager for this and put references of types of objects in seperate lists in that manager?

#

cuz that does seem really easy to make

grand snow
#

Thats like asking if its better to write code to make something work (ANSWER IS YES)

kindred dome
#

so if I have like a thousand npcs that are all going to try to update a variable in a different script, what would be the best way to do that?

#

right now I just have them all doing it but that doesn't seem super efficient

vital fractal
#

theoretically

grand snow
#

The best solution is not even using tags

#

Because they are not useful enough

kindred dome
vital fractal
grand snow
grand snow
#

how tf would a tag be sufficient here anyway

grand snow
vital fractal
#

but i do despretaly want to get out of that system as its wierd and annopying

grand snow
#

Id use layers here instead

vital fractal
#

like, im way past the point of hardcoding yet this is still hardcoding

grand snow
#

or you try get component.
If the detection is done the other side (by the wall) then a monobehaviour for that makes sense

kindred dome
peak umbra
#

hello

vital fractal
# grand snow Id use layers here instead

thats fair, i been using those more lately and am liking them.
though, im still currently targeting layers by getting the mask with the string names of the layers, i assume there is a better less hardcoded way to do this?
i was thinking to just make a constents script where i define the layers i have but there must be a way to just fetch it from unity right?

grand snow
peak umbra
#

helo

grand snow
#

hello spam

runic lance
vital fractal
#

maybe he just wants to be greeted
/j

vital fractal
#

like you collide with any object, and the object can be many different things where x can have all different components of y

grand snow
#

Then perhaps a common component that has this data in it?

vital fractal
#

yeah exactly

#

thats what i was cooking up just now

grand snow
#

As soon as an idea goes past "is this thing x" you realise tags no longer work

vital fractal
#

true

#

thats where im at for a while now but im also trying to do less custom stuff as im super good at over engineering stuff that doesnt need it

cosmic dagger
vital fractal
grand snow
#

because c# cannot do multi inheritance we can use interfaces instead

#

public class Door : MonoBehaviour, IInteractable

#

^ Now my door can implement the interface and keep its current base class

vital fractal
#

oh shit right, i know what interfaces are and used them, i just completely forgot about them...

cosmic dagger
vital fractal
#

also, anything that lets me use less of c# inheritance is good cuz im super done with abstracting more and making everything more complicated for no benefit...

vital fractal
peak umbra
#

@grand snow From the unity badge of sleep John Kho ferri Bekam

grand snow
cosmic dagger
vital fractal
#

that doesnt quite click for me yet, but in the back of my head that does sound better and less complicated so i guess its time for me to dive back into some research

grand snow
#

yea i realised 😆

runic lance
#

interfaces are a bit more general than abstract classes, if you want to think that way

#

nowadays you can provide default implementations for interfaces too, so even in that sense they're not that different

grand snow
#

Its a contract that states "if you implement me, you need to provide x,y and z"

#

"i dont care how but you have to!"

#

super classes are different, its a way to extend a class and inherit functionality (and optionally override bits)

vital fractal
#

im also at that point of programming that im trying to learn more why things are used over other things, and honestly its a lot of fun but takes so much more time while programming as i need to stop and research the basics again but deeper this time...
like struct vs class and which one to use in what situation. learning that was really nice actually and i could apply it right away as there is now a clear reason why you should use one over the other.

runic lance
#

more general as in, if you have a struct, such as Vector3, it can implement interfaces, but it cannot inherit from any base class

vital fractal
fickle plume
radiant voidBOT
grand snow
#

IInteractable -> bool Interact()
IDamagable -> void Damage(float damage);

vital fractal
#

wait, can fields also be specified by interfaces?

#

instead of a method

runic lance
#

no, but properties can

grand snow
#

no only properties and methods
properties are just fancy getter and setter methods anyway

vital fractal
grand snow
#

so in reality its just methods 😆

vital fractal
#

fair, so then you can just make a field that is actually a property that is just a getter but then the class has to create the thing that is fetched?

#

thats a bit confusing, so that must be wrong

grand snow
#

Maybe i confused you

vital fractal
#

no your fine thats likely my own doing

grand snow
#

public float MyFloatProperty {get; set;}

#

thats a property with an auto get and set

vital fractal
#

yeah no i know what properties are

#

and fair, i did kinda forget you dont have to specify what get gets

#

so yeah then they can be used as fields

grand snow
#

Well they are not fields but yes "act" like one

#

they wrap a field behind the scenes

slender nymph
vital fractal
#

which means, if we try tying it back to that unity tag system problem, i can make an interface like so:

public interface ITag {
  public string Tag {get; private set;}
}
#

but thats dumb tho

#

but it could work

ivory bobcat
runic lance
runic lance
#

but that example misses the point a bit, with interfaces you can have much more than tags
you have type safety and can declare specific functionality for each type

timber tide
#

tags are a failed concept

vital fractal
#

but its def not something i would actually do

timber tide
#

the idea around them were supposed to be editor friendly way to organize these objects but it even fails at that

vital fractal
timber tide
#

godot has an interesting concept called groups where you can tag specific objects that all can have similar method calls, so it presents this interface idea onto the editor level, however they aren't type safe as the nature of its language

forest wolf
vital fractal
#

oof

vital fractal
forest wolf
#

Here's an explanation:
https://www.youtube.com/watch?v=DWj_mPUtuqw
then here is one more example:
https://www.youtube.com/watch?v=zBD4r9UxLpQ
and then if you would rather use that in 3d game, here's a video:
https://www.youtube.com/watch?v=cx9y5TV3TS0

In this unity tutorial we will explore the C# interfaces. We will do it on a practical example - we'll create objects that react to player shot. Your scripting will jump on to new level!

In this series we will cover a lot of useful concepts. This and few other episodes will be fully dedicated to interfaces as I noticed this is one of the subjec...

▶ Play video

Learn how to create openable door, containers with loot and message spawning elements practicing usage of INTERFACES! This is second episode in the scripting series and it builds on top of theory we discussed previously (over here: https://www.youtube.com/watch?v=DWj_mPUtuqw).

There is quite a lot of interesting elements in this tutorial:

  1. B...
▶ Play video

In this FPS/Horror episode we'll create a customizable and extendable interaction system. We'll create a button and a toggle, however in the future we'll create also other types of interactions!

You will learn:

  • How to detect what object is under the crosshair
  • How to make interactable button
  • How to make interactable toggle
▶ Play video
#

Let me know if that is what you were looking for :)

vital fractal
vital fractal
forest wolf
#

Yay! Happy to hear that :D

vital fractal
#

wait, can you check if a class inherits an interface?

timber tide
#

They're useful for composition that's for sure. Usually you can get away with some abstraction

sour fulcrum
vital fractal
#

lol watsup @sour fulcrum

sour fulcrum
#

if (MyBehaviour is IExampleInterface)

eg.

vital fractal
#

huge i thought it may be something like that

#

thats makes them even better

timber tide
#

The one problem with interfaces with unity is that you can't serialize by them which does make abstract classes a bit more appealing

vital fractal
#

well fair, its only methods right

#

also cant you just semi serialize them by create private copies of fields for important values?

sour fulcrum
#

the instance of the interface itself is what you'd want to be serialized

#

eg. a list of IEnemy

timber tide
#

The problem is you can't specify the type when trying to serialize by the interface on the editor. There needs to be some extended option for the editor but Unity hasn't implemented a way for that. You'd have to make a custom drawer using serialized references

vital fractal
# sour fulcrum eg. a list of `IEnemy`

going with this example, would i be able to make a list<IEnemy> and then populate the list with class A : IEnemy but also add class B : IEnemy in the same list?

sour fulcrum
#

in c# yes, in unity inspector no, because no interface serialization

timber tide
#

You can however declare as an abstract type and present a more derived (non-abstract) object into these fields on the editor

vital fractal
sour fulcrum
#

interfaces pop up way more often if you were doing just straight c# since unity's component system tends to solve a lot of problems you'd otherwise look at interfaces for

timber tide
#

interfaces are easy to append to existing classes, while abstraction you are modifying the root which can change the behaviour of alll of these derived classes

vital fractal
#

yeah exactly, which is another thing to always consider, what unity does with the code you write

forest wolf
timber tide
#

usually you want to strive for composition as much as possible. You can dig yourself a hole pretty easily with abstracting everything as is the nature of OOP really

vital fractal
timber tide
#

Yeah, I've yet to really play around with Odin but they've a bunch of things that you expect Unity would have natively

#

they should really buy them out, but seems like they've some partnership as of recent

sour fulcrum
#

some of odin gets abit weird tho tbf

#

like iirc they just say "dont use serialized dictionaries in prefabs"

forest wolf
#

Yeah, I am afraid of using this type of complex assets. Even though I like it, I feel like writing my own editor script is much easier and stable long term.

#

Because as you say there is always this one thing that doesn't work and you are always wondering - is it you or the asset

vital fractal
#

I really like odin for the simpler stuff they have, but yeah there is some weird stuff that sometimes comes with it... but overall its ability to orginize the inspector for each component a bit more efficiently is super nice

#

@forest wolf @sour fulcrum @timber tide
here is a good example of that:

#

its not a whole lot different from what unity can usually do, but its enough to not fully cover the whole inspector with a lot of fields that just usually dont apply for that situation

lone thunder
#

Cinemachine package. Player Index is that for local play? if there are multiple player like coop games? if im doign networking can i just ignore it?

grand snow
grand snow
#

and it should be referring to local players

compact sandal
#

how do you get the length of a list in unity?

#

for some reason can't find it online

#

oh nvm, its count

rich adder
forest wolf
#

When it comes to Odin its license scares me a littl bit 🤣

forest wolf
vital fractal
forest wolf
#

Bloody hell, sorry! I wrote .size(), I am using different language at work haha! I fixed the message to show the correct property :D

slender nymph
forest wolf
#

Hah, sorry! I missed the point!

vital fractal
#

lol

#

@forest wolf did you participate in the jam?

forest wolf
#

Yes! I did! It was tough 48h :D - my entry is called La Maestra.

#

I need to disappear for a moment, I will be back in a while! See you soon guys! :D

vital fractal
onyx gazelle
#

Hi guys!

#

The part of code was like this

#

And I solved it like this. Was this a decent solution?

vital fractal
#

what is the problem?

onyx gazelle
#

I mean there's no glitch existing now, so, is it maybe decent?

onyx gazelle
slender nymph
#

why not keep the original horizontal velocity? why overwrite it with half the jump height?

onyx gazelle
#

Apparently the speed is being turned to 0

onyx gazelle
slender nymph
#

well yes, you were explicitly setting it to 0 in the first snippet

#

show how you tried that

onyx gazelle
#

Okay 👍 Let me

vital fractal
slender nymph
#

or just not using a separate if statement at all and using math to do the sign check

vital fractal
#

true

onyx gazelle
#

I've altered it as you said

slender nymph
#

now show the code

vital fractal
#

i still dont really know what i mlooking at

onyx gazelle
vital fractal
# onyx gazelle

so before we help you with your code, how long have you been programming in unity for total?

slender nymph
wintry quarry
vital fractal
#

thats good to know, ill adjust my answers based on that

onyx gazelle
wintry quarry
#

oh I was looking at the vertical

onyx gazelle
wintry quarry
#

yeah i mean, just don't set it to 1

#

btw are you aware that Rigidbody2D has .linearVelocityY; which you can modify directly to completely avoid touching the x

wintry quarry
#

PlayerRigid.linearVelocityY = Jumpheight;

slender nymph
# onyx gazelle Sorry? 😅

instead of using HorizontalAxis there, use the existing velocity there. or assign only the Y axis. or add force like you're doing for movement anyway

wintry quarry
#

(JumpHeight isn't a good name for that variable imo)

onyx gazelle
vital fractal
# onyx gazelle

Also worth to mention that you really dont want to do a rigidbody.AddForce call inside Update()
isntead, that line should be inside a FixedUpdate() method as rigidbody.AddForce is a physics calculation and those should only happen in FixedUpdate.

onyx gazelle
#

Okay, I will read about those. Thank you for help guys 👍 I appreciate it

wintry quarry
indigo thorn
slender nymph
#

doesn't really sound like a code question
is your camera perhaps not getting cleared? i don't know if that affects things in the UI, but that's one of the few things I think it could be. you'd have to show the inspector for your camera if you are unsure

indigo thorn
#

Ah sorry, I'm only seeing unity-talk and code-beginner channels, is there a better one to ask this? Here is my Camera Inspector.

slender nymph
#

id:browse to see all channels and their descriptions.
also are you rendering your UI to a render texture by any chance?

indigo thorn
#

Thanks for the channel tip! Here is my Canvas settings:

#

And the TMP settings:

indigo thorn
#

I posted my question in Rendering/2D, thanks again 🙂

compact sandal
#

I wrote the following coroutine to toggle a door. For some reason it only works when the door is alligned along the x axis and not when its alligned along the z axis.

private IEnumerator ToggleDoor(float dot)
{
Quaternion targetRotation = _closedRotation;
if(!_isOpen)
{
if(dot < 0)
{
targetRotation = Quaternion.Euler(new Vector3(0, _closedRotation.y - _openAngle, 0));
}
else
{
targetRotation = Quaternion.Euler(new Vector3(0, _closedRotation.y + _openAngle, 0));
}
}
_isOpen = !_isOpen;

while (Quaternion.Angle(transform.rotation, targetRotation) > 0.01f) 
{
    transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * _openSpeed);
    yield return null;
} 
transform.rotation = targetRotation;

}

rich adder
#

also 👇

#

!code

radiant voidBOT
compact sandal
rich adder
compact sandal
#

fixing the lerp didn't help

#

It's just weird that it works perfectly on some doors and doesnt on others$

rich adder
#

I never said the lerp would fix it, i just said you wrote it wrong

compact sandal
#

alr

rich adder
#

you need to check those values you're passing through

#

you'd need to show more like _closedRotation what values etc

slender nymph
#

you probably want to be assigning to the local rotation rather than the object's global rotation (assuming the object has a parent that it can pivot around)

#

otherwise you need to make sure that _closedRotation is the actual target world rotation (accounting for any extra rotation for the object at rest)

compact sandal
#
[SerializeField]
private float _openAngle = 90f;
[SerializeField]
private float _openSpeed = 2f;

private bool _isOpen = false;
private Quaternion _closedRotation;
private Coroutine _currentCoroutine;


public bool IsOpen
{
   get { return _isOpen; }
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
    _closedRotation = Quaternion.identity;
}

public void Toggle(Vector3 pos)
{
    if (_currentCoroutine != null)
    {
        StopCoroutine(_currentCoroutine);
    }

    float dot = Vector3.Dot(transform.forward, pos - transform.position);
    _currentCoroutine = StartCoroutine(ToggleDoor(dot));
}

private IEnumerator ToggleDoor(float dot)
{
    Quaternion targetRotation = _closedRotation;
    if(!_isOpen)
    {
        if(dot < 0)
        {
            targetRotation = Quaternion.Euler(new Vector3(0, _closedRotation.y - _openAngle, 0));
        }
        else
        {
            targetRotation = Quaternion.Euler(new Vector3(0, _closedRotation.y + _openAngle, 0));
        }
    }
    _isOpen = !_isOpen;
    
    while (Quaternion.Angle(transform.rotation, targetRotation) > 0.01f) 
    {
        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * _openSpeed);
        yield return null;
    } 
    transform.rotation = targetRotation;
}
#

oh this looks better

hexed terrace
#

put cs after the 3 ` and it'll look even better

rich adder
#

oh no you're mixing quaternion and v3

#

like _closedRotation.y - _openAngle doesn't make sense

mild citrus
#

How do I fix this "setbool" error"?

rich adder
#

also

#

!vscode

radiant voidBOT
mild citrus
rich adder
#

what are you trying to SetBool() on?

#

as far as the computer knows, you want to call a method SetBool(). Apparently it doesn't exist

mild citrus
#

got it thanks

blissful fable
#

~~https://paste.mod.gg/~~ (link below)
I've been trying to fix this for 45 minutes now, I'm at my whit's end. It just doesn't make any sense.

For some reason, my controller inputs work completely fine. However, my mouse inputs...just don't? You can see from the 4 debug messages that no inputs are being detected when I try using the mouse (Rotation Input is always 0). Anyone have any ideas?

blissful fable
#

oh both link to the same thing, one sec

#

oh

#

Well, lol

#

Do I have to save it?

rich adder
#

yes you must save to generate the link

blissful fable
#

Thanks

#

As far as I can tell, there's nothing different about how these are handled, I have no idea how one can work while the other doesn't

#

OMG

#

I FUCKING SOLVED IT ARE YOU SERIOUS

#

So uh

#

Turns out when you enable Keypad
It doesn't automatically enable the mouse 😆
And so even though Delta(Mouse) was under Keyboard&Mouse

#

I still had to explicitly say you can use a mouse :P

#

Welp

eager stratus
#

Exactly how close does Mathf.Approximately have to be in order to register as true? Because I was expecting it to consider 2.291054E-07 and 0 close enough and they're apparently not

verbal dome
eager stratus
#

Because I feel like I've gotten a positive value with a bigger margin of error than that before

eager stratus
# verbal dome Wdym by this?

I mean I feel like I've gotten it to return true when there was a bigger difference between the two numbers than that

verbal dome
#

Was trying to link that but github search is not working for me 🙃

eager stratus
#

Because for some reason it's not for me

verbal dome
wintry quarry
eager stratus
# wintry quarry "any" inaccuracies? no

I mean inaccuracies that should just naturally arise from floating point. If a difference is greater than that value then I should be assuming it's the result of something else, right?

wintry quarry
#

Especially since it's easy for such inacurracies to compound over repeated calculations

#

there is no limit to how large your floating point error can be

#

It is also different depending on the magnitude of the numbers involved in the calculations

verbal dome
#

Yeah, the precision errors can also accumulate

eager stratus