#💻┃code-beginner

1 messages · Page 496 of 1

timid ember
#

i have good idea learn assembly first

shell sorrel
timid ember
#

oops

#

i read a line of assembly code and i could barely watch without throwing up

shell sorrel
#

also assembly is vauge

#

like assembly for a x86 vs for a old console, or for a arm or risc is entirely different complexity and instruction set wise

devout flume
timid ember
devout flume
#

I mean it's just a few flags, some registers and instructions that do things 😂

shell sorrel
#

its more work but spec wise there is much less to learn then say C#

wintry quarry
shell sorrel
#

also there is no point since all it does is creates lots and lots of work

#

and then if you want to target a other platform you have to write yet more of it

#

also a good compiler will output more optmized code then you will write in asm

devout flume
#

Reading it without comments is awful tho

timid ember
#

i am still confused, why did it work for the tutorial?

#

is it an older unity ver?

hexed terrace
#

if it works in the tutorial and not for you, you missed something, did something wrong, or haven't gotten to a part where it works yet.

shell sorrel
#

also would remove the try catch infavor of doing a double.TryParse

#

that way you can properly handle both outcomes of the parse and not mask other potential errors

#

Also ButtonTap is never called and everything is public which makes it harder to tell what parts are supposed to be purely handled in this logic vs called from elsewhere

arctic arch
#

What does unity consider as "Long life code"?

shell sorrel
arctic arch
shell sorrel
#

ah

ruby python
#

I'm having a silly maths problem.

I have a value range of 14 - 100 but I need those values to be 'remapped' to 0-100. How can I do that?

shell sorrel
#

those will not be recompiled when other thigns change

arctic arch
#

So any dll/lib file I import then?

shell sorrel
#

nah dlls never get recompiled since that was manually done before hand

#

this is for AssemblyDefinations

#

so ones you define yourself or code in packages etc

arctic arch
#

So kinda like #pragma once in cpp?

shell sorrel
#

little smarter then that but similar idea

arctic arch
#

okay thanks

shell sorrel
#

like for example in my project i have a NPC behaviour editor i made

#

i made it over a year ago and it rarely every gets modified, but is a ton of code

#

in the new unity because i have that in its own AsmDef it would not recompile that assembly becuase i changed other code

burnt vapor
#

That's not the AI fault

#

This is the issue with copying code in general

#

You have no idea what it does if you never wrote it, and as a beginner you can't read it either

sand snow
#

I HAVE COMPLETED THE 1ST MISSION

rancid tinsel
#

!code

eternal falconBOT
rancid tinsel
#

hey guys im having an issue where its returning error because the nameText variable is null, any ideas? this is the object structure https://gdl.space/bulasehapa.cs

#

wait nvm turns out i needed to use TMP_Text instead of UGUI

wintry quarry
#

TMP_Text works for both

rancid tinsel
nocturne kayak
#

quickie here

#

what's the difference between | and ||?

#

let's say, i want to check if variable fruit is apple or orange

night raptor
#

then you use two

shell sorrel
nocturne kayak
#

and if it's either apple or orange, return true

shell sorrel
#

use || for booleans

night raptor
#

Very rarely you need to do bitwise operations and if you don't even know what they mean, you should stick to ||

shell sorrel
#

| still works on bool, but its short circuit logic differs would 90% use || unless its like bitwise logic on a enum

nocturne kayak
#

So this:

if (axisHandler = xAxisHandler || axisHandler = zAxisHandler){

 }
#

reads alright?

night raptor
#

two equal signs...

nocturne kayak
#

oh shit

nocturne kayak
#

yeah

shell sorrel
#

also same for & and &&

#

would use the && for all boolean stuff

night raptor
#

In some cases using bitwise for booleans may make sense (when you want to execute both sides regardless) but even then it would be bad for readability and therefore using a different solution would be highly suggested

shell sorrel
#

much more clear intent

night raptor
#

Yeah, not good for readability

shell sorrel
#

i have only used those operators for bitwise stuff

#

which does come up a decent amount of time

night raptor
#

same

ivory bobcat
# nocturne kayak what's the difference between | and ||?

Assuming you aren't doing any bit operations, they would behave like..
Logical OR (|):

The | operator computes the logical OR of its operands. The result of x | y is true if either x or y evaluates to true. Otherwise, the result is false.
The | operator always evaluates both operands. When the left-hand operand evaluates to true, the operation result is true regardless of the value of the right-hand operand. However, even then, the right-hand operand is evaluated.
Conditional Logical OR (||):
The conditional logical OR operator ||, also known as the "short-circuiting" logical OR operator, computes the logical OR of its operands. The result of x || y is true if either x or y evaluates to true. Otherwise, the result is false. If x evaluates to true, y isn't evaluated.

nocturne kayak
#

That's a bit of a better explanation, thank you

#

I'm sure there's a case for it, but i can't picture it right now

#

why would i ever need to do a bit operation within unity?

shell sorrel
#

flag enums

#

GizmoType.Selected | GizmoType.Active | GizmoType.NonSelected gives me a enum value that has all 3 of these bits set

#

var isSelected = (gizmoType & (GizmoType.Selected | GizmoType.Active)) != 0;
on the flip side this is true, if either of these bits is set

polar acorn
shell sorrel
#

keep in mind not all enums do this, only enums meant to be used as flag enums, where there are not overlapping bits betwene values

#

can do the same on any int type as well (byte, sbyte, int, uint, long, ulong, etc)

shell sorrel
#

yeah InverseLerp will get you to 0 to 1 range

ruby python
shell sorrel
#

then lerp can go from 0 to 1 to any range you want

nocturne kayak
#

So, something a bit more specific

#

This is really close to the behavior i want

#

But instead of dragging the cube, i should be dragging the handle, i moved the code to the cube itself

#

this is the code btw

#

My initial thought on how to fix this is to try and calculate the distance between the handler and the cube at first frame

#

and offset that at update if it's being dragged

timid ember
nocturne kayak
#

but i'm not entirely sure that's the best approach

polar acorn
shell sorrel
#

the code you posted just as it as a public method and nothing in that script ever calls it from a message like awake or update so must be called externally

zenith cypress
#

^ Cache offset on mouse down, add that offset to your final position, profit

timid ember
timid ember
polar acorn
shell sorrel
#

so break thigns down, add breakpoints or logs and find the exact flow

#

also get rid of that try/catch its just going to hide issues

timid ember
livid gale
#

Hello. I'm trying to set up an interface for a sprinting action in my project but the coroutines I established seem to be resetting the value instead of gradually increasing and reducing the stamina value according to the conditions I set.

Link is here:

https://hastebin.com/share/haqirolimo.csharp

timid ember
shell sorrel
timid ember
shell sorrel
#

at the point you are trying to parse a string into a double

timid ember
#

ok so the input

polar acorn
shell sorrel
#

if you use the TryParse instead of getting a exception on failure, you can just branch in a if statement.
the try/catch is very bad since its a very broad exception you are checking for, so if literally anything goes wrong it will do the catch, even if unrelated. that will hide error logs

polar acorn
#

Each instance of the DecreaseStamina coroutine is going to hit a single subtract call before hitting their yield, and that's the only reason this code doesn't crash unity

livid gale
polar acorn
shell sorrel
livid gale
polar acorn
#

Remember, a while loop runs to completion. Once a while loop starts, nothing else in the entire program can occur until it finishes. The yield in a coroutine "pauses" the loop for a moment, but Running is not a coroutine. That while loop is going to do absolutely nothing else in the entire program until stamina is 0

#

No new frames can render. No objects can visually change. No other objects can run any code at all

#

until Stamina hits 0

timid ember
#

error

shell sorrel
timid ember
#
 public void ans()
    {
        if (double.TryParse(CurInput, out answer))
        {
        answer= System.Convert.ToDouble(new System.Data.DataTable().Compute(CurInput,""));
        CurInput=answer.ToString();
        UpdateDisplay();
        }
        else
        {
            CurInput="invalid";
            UpdateDisplay();
        }
    }
    public void Clear()
    {
        CurInput="";
        answer=0.0;
        UpdateDisplay();
    }
    public void UpdateDisplay()
    {
        disptext.text = CurInput;
    }
}
#

printed invalid on 9+1(i may or may not have used in incorrectly)

shell sorrel
polar acorn
polar acorn
fervent abyss
#

i have an Array with a non specified size. If i do myNoSizeArray = otherArray, its going to copy size and the data, right?

livid gale
verbal dome
polar acorn
timid ember
#

yes, i am trying to use System.Data.DataTable().Compute because i am trying to make something not have multiple if statements for each operator

shell sorrel
#

myNoSizeArray will still exist if youj have a other reference to it

rich adder
polar acorn
verbal dome
#

I like how we gave the same answer in 4 different ways

polar acorn
#

If you subtract a value in Update, it's going to subtract that value every frame

fervent abyss
polar acorn
shell sorrel
rich adder
polar acorn
#

They will be two different variables holding a reference to the same array

fervent abyss
#

oh ok because i dont trust myself

#

💀

shell sorrel
#

no data copy has taken place, you just end up having mySizeArray point to the same data as otherArray

fervent abyss
#

ok

shell sorrel
#

so if you modify one, they both get modifed in this case

#

since they are the same object in memory

polar acorn
#

If you did this:

myNoSizeArray = otherArray;
myNoSizeArray[0] = "Fungus Amogus"
Debug.Log(otherArray[0]);

The output would be "Fungus Amogus"

rich adder
# fervent abyss oh ok because i dont trust myself

if you want a copy then you need to make a new array with same size and copy over data (if the items in the array are also reference types you need to cerate a new obj for each one or you're just putting the same objects)

timid ember
#

made me shed a tear

bright arch
#

ahh there has to be a way to do this right? or at least achieve something to the same effect?

rich adder
verbal dome
timid ember
verbal dome
rich adder
#

yeah you can def do that too, you just won't be able to ever change them outside of code / initilizer (in the inspector for example)

polar acorn
timid ember
#

also, this error confuses me as if it doesnt convert, why does it work on the tutorial? is there s library im missing?

#

currentl impoted system.data

rich adder
polar acorn
timid ember
#
public class Clac : MonoBehaviour
{
    public TextMeshProUGUI disptext;
    private string CurInput="";
    private double answer;

    public void ButtonTap(string val)
    {
        if(val== "=")
        {
            ans();
        }
        else if(val== "C")
        {
            Clear();
        }
        else
        {
            CurInput=val;
            UpdateDisplay();
        }
    }

    public void ans()
    {
        
        answer= System.Convert.ToDouble(new System.Data.DataTable().Compute(CurInput,""));
        CurInput=answer.ToString();
        UpdateDisplay();
        if (double.TryParse(CurInput,out answer))
        {}
        else
        {
            CurInput="invalid";
            UpdateDisplay();
        }

    }
    public void Clear()
    {
        CurInput="";
        answer=0.0;
        UpdateDisplay();
    }
    public void UpdateDisplay()
    {
        disptext.text = CurInput;
    }
}
polar acorn
rich adder
# timid ember

that doesnt show what DBNull is and what ur trying nvm

timid ember
#

which runs answer=system.data.whateverthelongcode

polar acorn
rich adder
timid ember
#

saved alr

rich adder
timid ember
#

oh

#
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Data;
using UnityEngine;
using TMPro;
using UnityEngine.UI;

public class Clac : MonoBehaviour
{
    public TextMeshProUGUI disptext;
    private string CurInput="";
    private double answer;

    public void ButtonTap(string val)
    {
        if(val== "=")
        {
            ans();
        }
        else if(val== "C")
        {
            Clear();
        }
        else
        {
            CurInput=val;
            UpdateDisplay();
        }
    }

    public void ans()
    {
        
        answer= System.Convert.ToDouble(new System.Data.DataTable().Compute(CurInput,""));
        CurInput=answer.ToString();
        UpdateDisplay();
        if (double.TryParse(CurInput,out answer))
        {}
        else
        {
            CurInput="invalid";
            UpdateDisplay();
        }

    }
    public void Clear()
    {
        CurInput="";
        answer=0.0;
        UpdateDisplay();
    }
    public void UpdateDisplay()
    {
        disptext.text = CurInput;
    }
}
#

wait

verbal dome
#

Should probably check if Compute returns a DBNull or not

timid ember
#

wheres my namespace

rich adder
#

its fine now but 18 is open bracket for some reason so 🤷‍♂️

timid ember
#

added it

rich adder
polar acorn
#

You could use a Linq query.
playerOwnedAccessories.Where(acc => acc.player == playerToLookFor).FirstOrDefault()

It'll check each element, store it in the temporary variable acc, and if that acc's player is equal to playerToLookFor, it'll retrieve it. FirstOrDefault will ensure you get exactly one answer, or null if there are none.

polar acorn
eternal falconBOT
rich adder
timid ember
#
System.DBNull.System.IConvertible.ToDouble (System.IFormatProvider provider) (at <8ce0bd04a7a04b4b9395538239d3fdd8>:0)
System.Convert.ToDouble (System.Object value) (at <8ce0bd04a7a04b4b9395538239d3fdd8>:0)
Clac.ans () (at Assets/Clac.cs:34)
Clac.ButtonTap (System.String val) (at Assets/Clac.cs:18)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <54724222b7684530a2810ae1eac94ec7>:0)
UnityEngine.Events.CachedInvokableCall`1[T].Invoke (System.Object[] args) (at <54724222b7684530a2810ae1eac94ec7>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <54724222b7684530a2810ae1eac94ec7>:0)
UnityEngine.UI.Button.Press () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
rich adder
#

mine lands on open bracket, make sure you saved and run the code again

bitter rover
#

Is there anyone that help me with coding a script that allows me to hold a button and freemove the camera with my mouse, but when I let go of the button, snap back to defaults?

polar acorn
timid ember
#

of unity

polar acorn
#

No, none of this is Unity's fault

rich adder
timid ember
#

screenshot?

polar acorn
eternal falconBOT
rich adder
#

as described in bot message

timid ember
verbal dome
#

DataTable.Compute returns DBNull.Value if it fails

rich adder
bitter rover
verbal dome
rich adder
polar acorn
bitter rover
#

I don't have the code - I need help coding it to begin with. I checked the Unity documentation and am not sure where to go with it.

timid ember
#

how do i send the hatebin link,

polar acorn
pulsar meteor
#

!code

eternal falconBOT
timid ember
polar acorn
pulsar meteor
pulsar meteor
#

it using in other scripts

polar acorn
timid ember
pulsar meteor
polar acorn
polar acorn
pulsar meteor
#

but why idk

languid spire
polar acorn
timid ember
#

thanks

polar acorn
languid spire
pulsar meteor
polar acorn
pulsar meteor
# polar acorn Show the line that sets `npcInteractie`

public void npcInteractie()
{
if (level == 0)
{
level = 1;
Debug.Log("ga naar de item");
Canvas1.gameObject.SetActive(true);
Debug.Log("je bent nu level 1");
itemInteractie.cangetitem = true; // hier gaat wat fout
}
}

timid ember
eternal falconBOT
polar acorn
#

This is a function named npcInteractie on a different object

#

I'm asking you

#

where do you set the variable

#

on the object that is giving the error

pulsar meteor
#

NPCInteractie [SerializeField] ItemInteractie itemInteractie;

polar acorn
pulsar meteor
#

never mind i didnt add my Serelized field

polar acorn
nocturne kayak
storm cedar
#

Could someone explain why this coroutine freezes my game for a split second when called to activate a very simple UI? I've narrowed it down to the UI being the issue, but it makes no sense why it would be. The UI in subject:

polar acorn
wintry quarry
languid spire
willow iron
#
public class MouseLook : MonoBehaviour
{
    private Vector2 Move;
    private Vector2 Look;
    public float mouseSens;
    public Transform playerBody;
    float lookx;

    // Update is called once per frame
    void Update()
    {
        lookx = (Look.x * mouseSens * Time.deltaTime);
        playerBody.Rotate(lookx * Vector3.up);
    }
    public void OnLook(InputValue value)
    {
        Look = value.Get<Vector2>();
        
    }
}```
storm cedar
#

I know that, but if I enable/disable it without the coroutine it doesn't lag (it's not a complex Canvas)

Also I did check the profiler @wintry quarry, and it spiked from scripts, when called the coroutine to activate the UI.

verbal dome
timid ember
willow iron
wintry quarry
nocturne kayak
nocturne kayak
polar acorn
nocturne kayak
#

hastebin interpreted it as a java file, interesting

#

But main thing is

polar acorn
#

It's already framerate independent

nocturne kayak
#

adding the axisHandler offset does jack

#

subtracting it creates a feedback loop

verbal dome
nocturne kayak
#

i'm adding it on update, so

nocturne kayak
verbal dome
#

C# is "Microsoft Java" after all

nocturne kayak
#

Huh

verbal dome
#

It was originally based off of java
E: Not technically, but syntax/design wise

nocturne kayak
#

I remember someone saying that a while back, but i don't quite understand what differentiates it

#

mainly because i don't know java.

willow iron
timid ember
nocturne kayak
#

Back to the task at hand, transform.position is set to new pos, which is then added to axishandler offset, which changed the transformPosition, which becomes newPos, which is added to axisHandlerOffset, ad infinitum

polar acorn
#

Do you even know what CurInput is when it fails?

nocturne kayak
#

So i don't understand the course of action to stop that here

timid ember
polar acorn
polar acorn
#

Because you can just... check

#

you don't have to assume

timid ember
#

how do i do that, i take 2+3 and the answer would compute but stops at dbnull, which is datatable

polar acorn
#

Log it

timid ember
#

what

polar acorn
#

Log it

#

log CurInput

#

see what it logs before the error

#

Basic debugging

verbal dome
#

It could be fixable if you don't make the handles children of the cube

#

But then you'd have to redesign it a bit

storm cedar
#

Sorry it took me a bit to reply was cooking

polar acorn
# storm cedar

Is this script on multiple objects? The hasNotepad bool should prevent it from running multiple times, but maybe a bunch of copies of this are running it at the same time?

storm cedar
timid ember
#

i feel its wrong, it should output "4+3"

polar acorn
# timid ember

What is the last log before the error occurs? You probably want to disable "collapse"

timid ember
polar acorn
# timid ember

Okay, assuming your log is right before the error, then it would seem 3 evaluates to DBNull

timid ember
#

but how

#

because a value wouldnt make it null

#

unless the data type is wrong

#

wait

storm cedar
#

@polar acorn chagpt has no idea whats causing this either

night raptor
polar acorn
# willow iron there we are

Instead of using a composite binding, you want to use a normal binding. Composite bindings are for creating analog outputs out of digital, so it detects if any movement occurs, and treats that as "1". Your "Look" action should look similar to the MouseAim I have here. You can also add a composite for the keyboard, just don't use a composite for the mouse.

polar acorn
storm cedar
#

Yeah will do that in a few mins

timid ember
timid ember
#

but operators wont work in int or double

#

make a different string called operator and make a big mess of it?

timid ember
#

messiah where are you

polar acorn
# storm cedar

Man I hate how similar some of the colors on this are, but it looks like that spike is from Garbage Collection, not Scripts

storm cedar
#

I've disabled everything but the scripts when I first tested it and it spiked hard

polar acorn
#

It's one of the dark browns, and GC is the most likely one of the dark browns to suddenly take 266ms and then shoot back down

#

A single coroutine will produce some garbage, but it shouldn't produce that much

storm cedar
#

one sec

timid ember
#

I'm new so I might sound stupid as fk

#

but isn't that what compute does

languid spire
polar acorn
storm cedar
polar acorn
timid ember
#

also, unity is taking these inputs as
4
+
3
which makes me think they aren't in the same string

polar acorn
verbal dome
#

Wait maybe this is the TextMeshPro empty character issue?

polar acorn
storm cedar
polar acorn
timid ember
#

wtf happened to my calc

polar acorn
timid ember
#

i didnt drag anythn

storm cedar
#

Exactly

polar acorn
#

At this point I'm stumped. I dunno if anyone else can see anything I don't but I really don't see how this could be taking up so much time unless there's a lot of stuff on the canvas, or the coroutine's running multiple times, and it seems neither is the case?

verbal dome
timid ember
#

yes

#

wait no

#

its tmp

#

not inputfield

#

it changes the text

polar acorn
#

It's just a raw TextMeshProUGUI, and not a child of an Input box?

timid ember
#

yes

#

its under panel as i saw in he tut

polar acorn
#

Okay, then it's not the invisible character issue

timid ember
#
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Data;
using UnityEngine;
using TMPro;
using UnityEngine.UI;

namespace TheProj{
public class Clac : MonoBehaviour
{
    public TextMeshProUGUI disptext;
    private string CurInput="";
    private double answer;

    public void ButtonTap(string val)
    {
        if(val== "=")
        {
            ans();
        }
        else if(val== "C")
        {
            Clear();
        }
        else
        {
            CurInput=val;
            UpdateDisplay();
        }
        Debug.Log(CurInput);
    }

    public void ans()
    {
        
        answer= System.Convert.ToDouble(new System.Data.DataTable().Compute(CurInput,""));
        CurInput=answer.ToString();
        UpdateDisplay();
    }
    public void Clear()
    {
        CurInput="";
        answer=0.0;
        UpdateDisplay();
    }
    public void UpdateDisplay()
    {
        disptext.text = CurInput;
    }
}
}

regarding ur earlier req

polar acorn
#

I said to do it before

#

literally the line right before

#

the logs are worthless as they are. If there's an error, we won't see it

#

The stuff that was logging was the things that did work

timid ember
polar acorn
timid ember
#

the error is at line 36, answer=system.convert.longessay

polar acorn
timid ember
#

im dumb

polar acorn
#

Meaning if there is an error in ans, the log does not happen

timid ember
#

this isnt log?

polar acorn
#

meaning that it passed the problem and printed

#

so, by definition, these are the values that did not cause an error

#

you have to log before the error. Not after.

storm cedar
polar acorn
#

Once an error occurs, the code stops

hallow acorn
#

!code

eternal falconBOT
languid spire
polar acorn
timid ember
polar acorn
#

"" is not an expression that can be evaluated

storm cedar
timid ember
#

i see

polar acorn
#

as people have mentioned a long ass fuckin time ago

timid ember
#

on public void buttontap(), the function takes input

hallow acorn
polar acorn
timid ember
#

val is a string on buttontap(string val)

#

public void

polar acorn
timid ember
gaunt solstice
#

Hello, I am using this video as a basis for an npc tank in my game so it will move more like a vehicle
https://www.youtube.com/watch?v=mNoyPz3LCy0
But is there a way to impliment the navmesh with this movement so that it won't keep running into walls

✅ Get the Project files at https://unitycodemonkey.com/video.php?v=mNoyPz3LCy0
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.

🌍 Interesting Game Dev Videos https://www.youtube.com/playlist?list=PLzDRvYVwl53vD6I_5QE8jV-TYjckA7w_w

Here's the Racing RTS I made for ...

▶ Play video
polar acorn
# timid ember ```cs if(val== "=") { ans(); } else if(val...
GAW

Link to source code: https://patreon.com/GameAssetWorld

🎮 Welcome to this Unity 2D Game Development Tutorial! In this step-by-step guide, we'll show you how to create a fully functional basic calculator using Unity, suitable for beginners and aspiring game developers.

Key Points Covered:

🔷 Setting up a new Unity 2D project.
🔷 Designing the c...

▶ Play video
#

Compare

timid ember
#
public void ButtonTap(string val)
    {
        Debug.Log(CurInput);
        if(val== "=")
        {
            ans();
        }
        else if(val== "C")
        {
            Clear();
        }
        else
        {
            CurInput=val;
            UpdateDisplay();
        }
    }
hallow acorn
polar acorn
#
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 178
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-09-26
timid ember
#

+= was the issue

polar acorn
#

Did you tick the box

timid ember
#

i was seeing this vid at 140

polar acorn
#

even if it was null

#

instead of just adding empty to the running function

#

which would have left it unchanged

timid ember
#

i wasted 4 hours because of video quality

hallow acorn
polar acorn
#

when you click it, it gets a ✅ in it

#

did you do that

steep rose
hallow acorn
#

Verily, I dost believe so.

steep rose
#

AKA click the Istrigger box

polar acorn
timid ember
polar acorn
timid ember
#

null

polar acorn
#

So, this would probably be why the tutorial had try-catch but it's a bad tutorial anyway and you shouldn't do that. Instead just check to make sure the length of CurInput is greater than 0 before running the stuff in ans

#

If its length is 0, don't do the calculation

hallow acorn
timid ember
#

private, woudl it still show in debug.log

polar acorn
polar acorn
#

If private were a problem it wouldn't compile

timid ember
#

theres no answer btw it still says cant convert into null

polar acorn
lofty lintel
#

guys im still getting that jittering we fixed yesterday ( but actually i think this a bit of jittering was there yesterday too, I didn't change anything with script, only changed sprite which has nothing to do with it)

Script is in fixedUpdate

//Player Rotate Follows Mouse.---------------------------------------------------------------
if (PlayerRotates)
{
    //Debug.Log("Should rotate");
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Vector3 lookDir = mousePos - transform.position;
    rb.rotation = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg + 270;
}
 Vector3 moveDir = new Vector3(moveX, moveY, 0f).normalized;
 Vector2 targetVelocity = moveDir * speed; // your movedirection * speed
 Vector2 velocityDiff = targetVelocity - rb.velocity;
 rb.AddForce(velocityDiff * acceleration);
lofty lintel
verbal dome
scenic escarp
#

Please help! I have a two scene game where the audio player is important to the game working. It works fine when I run the game starting in the gameplay scene and have the audio source placed via inspector. But if I start the game from the menu, the game objects lose the reference to the audio source and this doesn't seem to work.

lofty lintel
verbal dome
lofty lintel
#

Thats what im doing

#

it does stop jittering but actual rotation doesn't work

timid ember
verbal dome
#

Oh so with "rotate the other way" you mean moverotation

lofty lintel
#
//Player Rotate Follows Mouse.---------------------------------------------------------------
if (PlayerRotates)
{
    //Debug.Log("Should rotate");
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Vector3 lookDir = mousePos - transform.position;
    //rb.rotation = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg + 270;
    rb.MoveRotation(Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg + 270);
    //transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position);
}
polar acorn
lofty lintel
#

This is current script which stops jittering but stops character rotation aswell

#
//rb.rotation = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg + 270;

if I use this rotation works but it jitters

timid ember
#

see my references (ignore the warning, it was because i misused a text)

verbal dome
timid ember
#

onclick() and disptext in clac input

lofty lintel
#

yeah I don't know whats that

verbal dome
#

The "Constraints" tab in your rigidbody's inspector

lofty lintel
#

Did that

timid ember
#

this is for tmp

verbal dome
#

Yeah lol your rotation is frozen

lofty lintel
#

oh shit

#

wait I did that because of something as I remember

#

but wait i'll try

#

wow

scenic escarp
verbal dome
#

Okay cool
@wintry quarry It seems like rb2d.rotation does break interpolation after all
The reason that MoveRotation didn't work was because the rotation was constrained

lofty lintel
#

Oh I see so we know that too now

#

so instead of using rb.rotation I should use moverotation() to not break interpolation

verbal dome
#

I was always under that impression
The 3D rigidbody.rotation doc says:

If you want to continuously rotate a rigidbody use MoveRotation instead, which takes interpolation into account.
While the 2D doc doesn't say much

#

@lofty lintel Could you quickly switch back to rb.rotation but keep it unconstrained

#

And see if it still jitters

lofty lintel
#

ok i'll check

#

Yes it jitters using rb.rotation especially when I rotate the player (which makes sense)

lofty lintel
verbal dome
#

Alright then we can safely say that rb.rotation breaks interpolation

verbal dome
lofty lintel
#

rb.rotation

#

I see, thanks.

cosmic quail
verbal dome
#

Nope, that's fine

steep rose
#

afaik no

cosmic quail
#

oh that's good

lofty lintel
verbal dome
#

Only rb.rotation, rb.position and ofc transform.position/rotation which you shouldn't ever use with rigidbodies

timid ember
steep rose
#

i mean i could see why using rb.rotation would break interpolation because you are setting the rotation manually

lofty lintel
#

same as transform.position

steep rose
#

you would most likely use moverotation

cosmic quail
lofty lintel
#

yes

verbal dome
steep rose
#

keep in mind some things apply in 2D than 3D because they use a different physics engine

timid ember
#

now that digiholic died(rip), im now gonna cry

steep rose
#

what?

timid ember
#

we came close to solving my issues

#

and he just dipped

steep rose
#

he has a life lmao

timid ember
#

welp

#

ye ik

steep rose
#

be patient

timid ember
tawny edge
#

TLDR; I'm trying to make it so my car won't be able to turn if he is not moving or forward but my code didn't work.
my main objective here is not to primaly understand why this code did not work for learning purposes

I thought of making the car be unable to turn while he is not moving back or forward so i thought that making it so that
(if the car isn't receiving forward or back input, then his horizontal Input will be zero).
I made a if statement with that logic and placed it in update to make it happen every frame.

Since my car rotation value is multiplied by horizontal input, i thought making it zero would multiply with everything there and make it all zero, nullifying any rotation.

As you can see in the video, it didn't work (i made sure to save the code befor testing it).

Why didn't that work? what did i miss?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    //Private variables
    public float speed = 20.0f;
    public float turnSpeed = 45.0f;
    public float horizontalInput;
    public float forwardInput;
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

         if (forwardInput == 0)
    {
         horizontalInput = 0;
    }


        // here, we get the player's Input
        horizontalInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");

        //we'll move the vehicle forward based on vertical input
        transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
        //we'll rotate the vehicle based on horizontal Input
        transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed * horizontalInput);


    }
}

verbal dome
lofty lintel
verbal dome
#

Or just make it zero when forwardinput is near zero

#

Oh ok I see you tried that here:cs if (forwardInput == 0) { horizontalInput = 0; }
But you should do that after setting it to the input value

steep rose
#

also i see you are translating a RB

#

so it will ignore collisions

verbal dome
#

Also GetAxis has some smoothing by default so it might take a small while to reach 0

timid ember
tawny edge
verbal dome
#

Wait is this from the Unity Learn site?
The one lesson where they teach you to use transform to move a rigidbody? 🤦‍♂️

steep rose
#

yes as it will ignore collisions

verbal dome
#

Yes, shame on whoever wrote that

steep rose
#

and pretty much everything with the RB

red helm
#

Hey guys, can you build and run a project that has a database to your phone?

verbal dome
#

You might miss collisions entirely

lofty lintel
tawny edge
#

i'm confused

timid ember
verbal dome
timid ember
#

it works with console.writeline?

steep rose
verbal dome
#

transform doesn't always ignore collisions, it's just not reliable

#

It might seemingly work fine in a small demo like this, but them teaching it on the unity learn site is just awful

timid ember
#
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Data;
using UnityEngine;
using TMPro;
using UnityEngine.UI;

namespace TheProj
{
    public class Clac : MonoBehaviour
    {
        public TextMeshProUGUI disptext;
        private string CurInput="";
        private double answer;

        public void ButtonTap(string val)
        {
            CurInput+=val;
            Debug.Log(CurInput);
            if(val== "=")
            {
                Debug.Log(answer);
            }
            else if(val== "C")
            {
                Clear();
            }
            else
            {
                UpdateDisplay();
            }
        }

    public void ans()
        {
                answer = System.Convert.ToDouble(new System.Data.DataTable().Compute(CurInput, ""));
                CurInput = answer.ToString();
        }

        public void Clear()
        {
            CurInput="";
            answer=0.0;
            UpdateDisplay();
        }
        public void UpdateDisplay()
        {
            disptext.text = CurInput;
        }
    }
}
tawny edge
timid ember
#

this is my refined code

#

im confused as to which operand is needed

verbal dome
timid ember
#

the debug is for checking errors

verbal dome
#

Code executes from top to bottom

verbal dome
timid ember
#

i changed it to debug the log of answer, which computes the string

#

im dying

short hazel
#

Seems like you still add the = when you hit it, so you pass 1 + 3 = to the DataTable which is obviously invalid

timid ember
tawny edge
short hazel
timid ember
steep rose
#

usually you shouldnt use the RB transforms due to inacurate collision detections

#

but for something small, i believe your okay

verbal dome
short hazel
# timid ember so, how do i make = onnly execute the code?

Just like I told you, do not do CurInput += val; if you're not certain you'll execute UpdateDisplay().
This means that you need to move that line in the else so it only executes when you type a number or an operator (and not an = or a C, because yes it'll add the C at the end of the expression too!)

steep rose
#

but i have to say, its refreshing for a beginner to want to learn so thank you 😁

timid ember
steep rose
tawny edge
timid ember
queen adder
#

ello

steep rose
short hazel
timid ember
#

or when +,-,/ and * is used

short hazel
#

Prove it with a log, right before you do new DataTable().Compute(...)

timid ember
#

do i simply declare it as a string without value?

tawny edge
steep rose
timid ember
#
namespace TheProj
{
    public class Clac : MonoBehaviour
    {
        public TextMeshProUGUI disptext;
        private string CurInput="";
        private double answer;

        public void ButtonTap(string val)
        {
            Debug.Log(CurInput);
            if(val== "=")
            {
                ans();
            }
            else if(val== "C")
            {
                Clear();
            }
            else
            {
                CurInput+=val;
                UpdateDisplay();
            }
        }

    public void ans()
        {
                answer = System.Convert.ToDouble(new System.Data.DataTable().Compute(CurInput, ""));
                CurInput = answer.ToString();
        }

        public void Clear()
        {
            CurInput="";
            answer=0.0;
            UpdateDisplay();
        }
        public void UpdateDisplay()
        {
            disptext.text = CurInput;
        }
    }
}
short hazel
#

There you go, your inputs aren't registered into the string

steep rose
eternal falconBOT
timid ember
#

inputs would register into val and change curinput

#

but curinput doesntchange

short hazel
#

Debug further. Log the value and the Length of val, make sure the else part is even executed

timid ember
#

oh no.

#

need help yall yo

polar acorn
timid ember
short hazel
#

The length of a string is the number of characters in the string

timid ember
deft grail
jade tartan
#

Well... After doing a tuto to allow my character to respawn, I noticied that sometime my character respawned into the ground. After checking the comments section, I found out that i needed to to have the "Player" object deactivated when entering inside the DeathZone and then reactivate it with a Coroutine, but the one who gave that solution forgot how they did that, so I tried by creating a boolean variable with a script for activating Player. Here's the tuto in question (in French) and the current states of both the Player Activation and Deathzone scripts: https://youtu.be/5MmX3Mea29Y https://hastebin.com/share/agivupigur.csharp
https://hastebin.com/share/aweraticos.csharp

Aujourd'hui on regarde comment ajouter des zones d'élimination dans nos niveaux. Cela nous permet notamment d'éliminer le joueur s'il tombe dans le vide ou se rend dans une zone inaccessible.

☕ Soutenir la chaîne ☕
➡️ sur Tipeee : https://www.tipeee.com/tuto-unity-fr
➡️ sur uTip : http://utip.io/tutounityfr

📥 Télécharger le projet de la série ...

▶ Play video
upper thistle
#

Running this in my code and I get these errors that it doesn't exist

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[RequireComponent(typeof(CharacterController), typeof(Animator))]
public class CharacterHandler : MonoBehaviour
{

    CharacterController characterController;
    private Animator animator;

    [SerializeField]
    private float movementSpeed, rotationSpeed, jumpSpeed, gravity;

    private Vector3 movementDirection = Vector3.zero;

    // Start is called before the first frame update
    void Start()
    {
        characterController = GetComponent<CharacterController>();
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 inputMovement = transform.forward * movementSpeed * Input.GetAxisRaw("Vertical");
        characterController.Move(inputMovement * Time.deltaTime);

        transform.Rotate(Vector3.up * Input.GetAxisRaw("Horizontal") * rotationSpeed);

        if(Input.GetButton("Jump") && characterController.isGrounded)
        {
            movementDirection.y = jumpSpeed;
        }
        movementDirection.y -= gravity * Time.deltaTime;

        characterController.Move(movementDirection * Time.deltaTime);

        //animations
        animator.SetBool("isRunning", Input.GetAxisRaw("Vertical") != 0);
        animator.SetBool("isJumping", !characterController.isGrounded);
    }
}

#

It won't swap animations even though movement and everything else works

upper thistle
#

Oh

#

that's a moment lol, thanks

upper thistle
#

or make it faster at least

lofty lintel
#

Guys how would I reach all of those in loop
(like inside code)

float min = StickUiParent.Find("Spawn").position.x - 9f;
float max = StickUiParent.Find("Spawn").position.x + 9f;
float randomPos = Random.Range(min, max);
if (LastPos.IsUnityNull())
{
    LastPos = new Vector3(
        Random.Range(StickUiParent.Find("Spawn").position.x - 9f,
        StickUiParent.Find("Spawn").position.x + 9f),
        Random.Range(StickUiParent.Find("Spawn").position.y - 1f,
        StickUiParent.Find("Spawn").position.y + 1f), 1);
}
else
{
    //StickUiParent.Find()
    //while (randomPos >= LastPos.x - 0.4f || randomPos <= LastPos.x + 0.4f)
    //{
    //    randomPos = Random.Range(min, max);
    //    if (randomPos <= LastPos.x - 0.4f || randomPos >= LastPos.x + 0.4f) break;
    //}
    LastPos = new Vector3(
       randomPos,
       Random.Range(StickUiParent.Find("Spawn").position.y - 1f,
       StickUiParent.Find("Spawn").position.y + 1f), 1);
}```
Basically what im trying to do is that when I initialize them in position I don't want any of them to be like too close to each other. I want them to be aligned with a bit of distance.

And second question is what I asked in [#📲┃ui-ux](/guild/489222168727519232/channel/502171135350407168/)  so basically how do I move stoneUIs behind that brown UI (im confused since they don't have order in layers.)
rocky canyon
lofty lintel
timid ember
#

bruh lol when length=<0

wintry quarry
upper thistle
pliant pecan
#

maybe a weirdo question, but i want to make a script that only exists to do one thing, and will only ever be called for that one purpose. I want ohter scripts to be able to call functions in this script. How would i approach this?

upper thistle
rocky canyon
upper thistle
#

Oh

wintry quarry
upper thistle
#

Thanks, I appreciate you guys

lofty lintel
pliant pecan
wintry quarry
#

so you can use it in a loop

#

Also why not just put them in an array in the inspector though

lofty lintel
lofty lintel
wintry quarry
wintry quarry
#

then you have the list at all times

wintry quarry
#

use a for loop

pliant pecan
wintry quarry
lofty lintel
# wintry quarry yes you do
 public GameObject StickUI;
 public Transform StickUiParent;
 public GameObject StoneUI;
 public Transform StoneUiParent;```
lofty lintel
#

alright i'll try.

wintry quarry
#

"global data"?

#

Make a singleton

lofty lintel
pliant pecan
#

Nah i want to send a list to the helper script, and get back a messed up version of that list

timid ember
#

alright yeah im giving up on unity

wintry quarry
timid ember
#

ive asked the solution of an error for 9 hours for no solution lol

lofty lintel
wintry quarry
upper thistle
#

I can't seem to jump on my character. Not sure if it's to do with how unity handles IsGrounded or not with the CharacterController. I can't seem to find where you can check if you're grounded or not

deft grail
pliant pecan
upper thistle
# upper thistle I can't seem to jump on my character. Not sure if it's to do with how unity hand...

No errors, but spacebar won't work

https://gyazo.com/b3943acb16f4d219abd5fd228b87299e

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[RequireComponent(typeof(CharacterController), typeof(Animator))]
public class CharacterHandler : MonoBehaviour
{

    CharacterController characterController;
    private Animator animator;

    [SerializeField]
    private float movementSpeed, rotationSpeed, jumpSpeed, gravity;

    private Vector3 movementDirection = Vector3.zero;

    // Start is called before the first frame update
    void Start()
    {
        characterController = GetComponent<CharacterController>();
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 inputMovement = transform.forward * movementSpeed * Input.GetAxisRaw("Vertical");
        characterController.Move(inputMovement * Time.deltaTime);

        transform.Rotate(Vector3.up * Input.GetAxisRaw("Horizontal") * rotationSpeed);

        if(Input.GetButton("Jump"))
        {
            movementDirection.y = jumpSpeed;
        }
        movementDirection.y -= gravity * Time.deltaTime;

        characterController.Move(movementDirection * Time.deltaTime);

        //animations
        animator.SetBool("IsRunning", Input.GetAxisRaw("Vertical") != 0);
        animator.SetBool("IsJumping", !characterController.isGrounded);
    }
}

deft grail
wintry quarry
#

It depends on the circumstance

#

you should go through !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

silk night
verbal dome
upper thistle
silk night
#

Then please show your code

silk night
#

"Jump" is not a button 😄

#

Use KeyCode.Space

upper thistle
#

ah okay

#

Thanks fam

steep rose
deft grail
verbal dome
#

GetButton takes a string, if you wanna use KeyCodes then use GetKey

silk night
#

thought that was the old one

steep rose
#

he must not have it set up in the input system

upper thistle
#

I think the issue is grounded

#

Cause the rig will jump right at the start of the game

#

but can't use it again

silk night
#

You should log at which part the operation fails

#

(or debug if you know how to)

verbal dome
upper thistle
#

used to lua

#

The issue is in regards to grounded

silk night
#

Just put some Debug.Log("TEXT") in there

#

and see where it stops

upper thistle
#

I removed it and I can jump, but not sure how to fix this issue. Is there a place I can check if IsGrounded is true or not

steep rose
#

its integrated into it

upper thistle
#

that's what I'm thinking

silk night
#

does your character lift off the ground at all or just not play the animation?

upper thistle
#

like the height/scale

steep rose
#

but you can do your own grounded function as well by doing a raycast

upper thistle
#

Is there a way to do an if not statement in this?

#

Like if, but the opposite

steep rose
#

spherecast etc

silk night
#

if (!condition)

steep rose
#

so if your model is suspending it, it will not work

upper thistle
#

this isn't hitting the floor then right

lofty lintel
deft grail
wintry quarry
#

Find is extremely slow

#

and finicky

lofty lintel
#

no no that's not what im asking

#

but ok I understand now

wintry quarry
#

what are you asking?

upper thistle
#

Still floating

steep rose
lofty lintel
#

i just got other idea so I'll do it and ask in the end if it was a good practice like that, also I am kind of forced to use while loop...

upper thistle
steep rose
wintry quarry
#

for and while can both be used for anything

upper thistle
steep rose
#

if skin width is to small/big it messes with it

upper thistle
#

It was oddly too much

steep rose
#

glad we were able to fix it

upper thistle
#

had to reduce it to 0.03

short hazel
upper thistle
#

appreciate the help man

lofty lintel
upper thistle
timid ember
#

3 days in a row im dyin but really appreciate yall sticking oout

polar acorn
steep rose
#

other than that, im not sure why since you have nothing checking if you can jump other than the keycode

verbal dome
#

Low Skin Width can cause the character to get stuck.

upper thistle
round mirage
steep rose
upper thistle
#

is there a task wait in C sharp I can use or a coroutine to delay my jump? Or can I setup an animation event to listen for somehow?

upper thistle
silk night
#

would be an easy way to speed it up

steep rose
#

try invoking it first

upper thistle
#

What's invoking it?

#

never heard of that in lua

steep rose
#

this is not lua

silk night
#

invoking a method ~= calling a method

lofty lintel
# wintry quarry You are never forced to use a while loop

looks like my logic didn't work after all.

float minX = StickSpawn.position.x - 9f;
float maxX = StickSpawn.position.x + 9f;
float minY = StickSpawn.position.y - 1f;
float maxY = StickSpawn.position.y + 1f;
float randomXPos = UnityEngine.Random.Range(minX, maxX);
float randomYPos = UnityEngine.Random.Range(minY, maxY);
if (StickUIs.Count == 0)
{
    SpawnPos = new Vector3(randomXPos,randomYPos,1);
}
else
{
    SpawnPos = new Vector3(randomXPos, randomYPos, 1);
    foreach (var stick in StickUIs)
    {
        while (randomXPos <= stick.transform.position.x - 10f || randomXPos >= stick.transform.position.x + 10f)
        {
            randomXPos = UnityEngine.Random.Range(minX, maxX);
            SpawnPos.x = randomXPos;
            if (randomXPos >= stick.transform.position.x - 10f || randomXPos <= stick.transform.position.x + 10f) break;
        }
    }
   
}
StickUIs.Add(Instantiate(StickUI, SpawnPos, Quaternion.identity, StickSpawn.parent));

what do you think...

upper thistle
#

okay cool

#

invoking, I'll try that

lofty lintel
wintry quarry
#

that code doesn't make much sense

#

use the Graphic raycaster to check if your chosen position has anything there

verbal dome
lofty lintel
#

wait look

silk night
#

i meant almost the same as

verbal dome
#

Yeah I figured

upper thistle
#

Thanks. Invoking it worked @steep rose

#

ty for the reference

lofty lintel
lofty lintel
#

would Graphic raycaster check that distance?

wintry quarry
#

idk what you mean by that

timid ember
steep rose
round mirage
steep rose
eternal falconBOT
upper thistle
#

seems to have different names here

lofty lintel
#

And im tyring to do that with while loop

wintry quarry
#

I recommend using the raycaster

steep rose
lofty lintel
#

basically what Im trying to do is that lets say One stickUI spawned at X position 5, if There is another one spawning it should either spawn at X greater than 7 or lower than 3

steep rose
upper thistle
wintry quarry
#

you can do this:

do {
  // pick a random spot
  // use the raycaster to check if there's anytthing in that random spot
} 
while ( /* something was in the spot you picked */)

// spawn at the spot

Just don't get caught in an inifnite loop

upper thistle
#

Lua is also competent in a lot

#

appreciate the help though

lofty lintel
lofty lintel
#

xd

ruby python
#

Am I right in thinking that Scriptable Objects can reference things in the project, but not in the scene? (as in public fields?)

lofty lintel
#

if(!StickUI.GetComponent<GraphicRaycaster>().blockingObjects.IsUnityNull())

upper thistle
#

Does anyone know if after jumping, I can then start listening for isGrounded temporarily? I can't do it prior for a few reasons

#

Not sure how to approach that

lofty lintel
hexed terrace
ruby python
steep rose
slender nymph
steep rose
ruby python
round mirage
upper thistle
hexed terrace
ruby python
upper thistle
#

threading stuff

silk night
steep rose
deft grail
upper thistle
steep rose
#

this is why i mentioned making your own

upper thistle
#

that's not what I'm asking

deft grail
steep rose
upper thistle
#

I want to either start listening for isGrounded post jump, not prior or delay and turn IsJumping off after 0.5 seconds

#

one of the two

verbal dome
silk night
verbal dome
#

Oh if you need multithreading then yeah you need something else than coroutines

silk night
#

As someone who recently had to learn it for my new job, I can only recommend R3 for async / multithreading

upper thistle
#

not atm, I may get into procedural gen a bit later but I'm too new atm to more complex code

silk night
#

oh that sounds like a perfect task for the jobsystem

upper thistle
#

I was doing procedural gen for a day and messing with perlin noise color maps and all that

#

never even touched code remotely that complex on roblox lol

upper thistle
upper thistle
steep rose
#

and wait for 0.5 seconds and turn jumping off

silk night
#

just make sure the user cant jump 15 times by spamming space before isgrounded turns off 😄

steep rose
#

i would check if grounded in jump if statement and i would also suggest moving all of that logic to a private void Jump() so you can call it whenever

lofty lintel
upper thistle
#

good practice exercise

lofty lintel
#

Shit I think While broke my game

#

yeah

slender nymph
#

considering that condition cannot change inside the loop then your loop will never end

lofty lintel
#

just realized it won't

#

And i don't know how to use graphicraycaster

slender nymph
#

either just make that an if statement and stick it in Update (if it isn't already), or use a coroutine and yield return null inside the loop

lofty lintel
#

u know what im trying to do?

delicate zinc
#

these scripts are meant to work together to let me pick up and drop items, but whenever i try picking up any item that isnt the latest one created with the script attached it doesnt let me drop it
its rly weird cos the debug.log that ive dropped it shows up in the console, but nothing else happens and it stays parented and kinematic

slender nymph
#

no

eternal falconBOT
lofty lintel
delicate zinc
lofty lintel
#

I chekced that doc but didn't understand anything

slender nymph
#

you need to call the Raycast method

lofty lintel
#

Like how?

delicate zinc
#

these scripts are meant to work together to let me pick up and drop items, but whenever i try picking up any item that isnt the latest one created with the script attached it doesnt let me drop it
its rly weird cos the debug.log that ive dropped it shows up in the console, but nothing else happens and it stays parented and kinematic
https://hastebin.com/share/uxuzutemer.csharp

slender nymph
# lofty lintel Like how?

there are beginner courses pinned in this channel, you should perhaps start there if you cannot recognize that you are missing the two parameters required to call that method.

lofty lintel
#

No I realize that haha

#

I just don't know what does those parameters take like what is PointerEventData or the list that it needs

#

Im good with c# i just have a hard time understanding Unity library

rocky canyon
#

no worries.. at this point in time (starting learning and stuff) docs are a way of introducing you to functions and methods that unity uses.. ofc ur not going to understand all of them..

#

but the take-a-way is knowing what ur looking for.. keywords and stuff.. can help massively when doing ur own research or looking for other reference material

lofty lintel
#

I do that a lot but thats why I joined this server to like actually understand unity by getting help from people yk

rocky canyon
#

ofc ofc

lofty lintel
#

one thing now is that how would Raycast help me with that?

rocky canyon
#

i enjoy being part of the channel b/c of basically this.
i know how to search and learn my own stuff.. but i can't possibly know all of whats available

rocky canyon
#

users here help introduce me to new functions and ideas on the daily (usually)

lofty lintel
#

yeah it's been two days since I joined and already got a lot out of this server

rocky canyon
#

in ur case.. u could raycast onto the canvas and know whether theres already an object where u plan on spawning one..

#

if ther is.. u can ignore that position and find a new one

#

rinse and repeat

inner folio
#

Does anyone know why my TextMeshPro input field doesn't let me type in it? It's selected, but whenever I actually type, nothing happens

rocky canyon
#

it should...

#

is the game running?

inner folio
#

yeah

rocky canyon
lofty lintel
slender nymph
# inner folio

this isn't code related, but do you have an event system in the scene? i don't see one in the hierarchy

swift elbow
inner folio
rocky canyon
# inner folio

is it possible that setting it selected every frame is stopping the input

inner folio
#

possibly

#

ill fix that

#

it's only selecting it whenever it's not focused so that should only happen whenever the terminal is first opened

lofty lintel
# lofty lintel yes but how would check if something was in this radius like for example there a...
//Code to be place in a MonoBehaviour with a GraphicRaycaster component
GraphicRaycaster gr = StickUI.GetComponent<GraphicRaycaster>();
//Create the PointerEventData with null for the EventSystem
PointerEventData ped = new PointerEventData(null);
//Set required parameters, in this case, mouse position
ped.position = SpawnPos;
//Create list to receive all results
List<RaycastResult> results = new List<RaycastResult>();
//Raycast it
gr.Raycast(ped, results);```
and how do I even know if im going right way xdd
inner folio
#

its probably the event system, but im not sure what i could do otherwise, since without the event system, it doesnt get selected at all

slender nymph
lofty lintel
#

Its this code

#

from the website other guy gave me

swift elbow
#

plus the comments would be a lot more detailed

lofty lintel
#

don't know if im going the right way tho

slender nymph
lofty lintel
#

well anyways it's not AI xd

slender nymph
#

have you considered testing it?

lofty lintel
#

yes

#
float minX = StickSpawn.position.x - 9f;
float maxX = StickSpawn.position.x + 9f;
float minY = StickSpawn.position.y - 1f;
float maxY = StickSpawn.position.y + 1f;
float randomXPos = UnityEngine.Random.Range(minX, maxX);
float randomYPos = UnityEngine.Random.Range(minY, maxY);
if (StickUIs.Count == 0)
{
    SpawnPos = new Vector3(randomXPos, randomYPos, 1);
}
else
{

    //Code to be place in a MonoBehaviour with a GraphicRaycaster component
    GraphicRaycaster gr = StickUI.GetComponent<GraphicRaycaster>();
    //Create the PointerEventData with null for the EventSystem
    PointerEventData ped = new PointerEventData(null);
    //Set required parameters, in this case, mouse position
    ped.position = SpawnPos;
    //Create list to receive all results
    List<RaycastResult> results = new List<RaycastResult>();
    //Raycast it
    gr.Raycast(ped, results);
    if (!gr.blockingObjects.IsUnityNull()) { Debug.Log("worked??"); }
    if (!gr.blockingMask.IsUnityNull()) { Debug.Log("worked??"); }
}
StickUIs.Add(Instantiate(StickUI, SpawnPos, Quaternion.identity, StickSpawn.parent));```
rocky canyon
lofty lintel
rocky canyon
#

@inner folio let me see if i cant find my code.. there may be something in there thats helpful

inner folio
#

i originally had a seperate scene for the terminal, but that didn't work since the position of objects in the main GameScene would get reset when i switched back to it

rocky canyon
#

b/c i have to manually manipulate it to get my command terminal to work correctly

inner folio
#

interesting

rocky canyon
#

i'll look for it

inner folio
#

if i dont include the EventSystem, the input box doesn't get selected though which is weird lol

rocky canyon
#

ya, if its a UI element. you need a EventSystem to even interact w/ it

slender nymph
inner folio
#

this is also my first time using unity so im a little bit confused

#

i didnt have an EventSystem on my original scene for the terminal though i dont think (nvm it was in the root hierarchy)

lofty lintel
#

(that one stick is also ui)

inner folio
#

omg

rocky canyon
inner folio
#

i moved the EventSystem into the root hierarchy and it worked lmao

rocky canyon
#

sooo not perfect.. but it works for the first part (focusing on the input)

rocky canyon
inner folio
#

yeah 🔥

rocky canyon
#

cool Tux

inner folio
#

his animation is supposed to be a running animation... still havent figured animations out 😭

rocky canyon
# inner folio

ya, soo that makes sense.. the event system wasn't working correctly.. b/c it was activated along side of the terminal.

inner folio
#

ah okay

rocky canyon
#

best to have it always active before hand.

inner folio
#

that makes sense, i didnt think the original terminal scene even had one, but it did by default; i guess whoever started this scene in my group removed the EventSystem or something

rocky canyon
#

like i was saying.. i keep my event system cached.. in the game manager

#

always nice to have a reference to it at all times (imo)

inner folio
#

i see

rocky canyon
#

usually its not very important.. but since i swap entire UI and Canvases I have a Master event system that i carry from one scene to another

inner folio
#

it works though :D

rocky canyon
rocky canyon
#

is that running actual windows shell or something?

inner folio
#

nah it's just a virtual file system

rocky canyon
#

ohh okay.. i thought u tapped into windows command prompt or something

#

lol

inner folio
#

i should also probably not use C: ... > since its not windows cmds anyways lmao

rocky canyon
#

ya, the C:\WINDOWS\System32 part threw me off

rocky canyon
inner folio
#

coded myself but watched a video for the actual UI stuff

inner folio
rocky canyon
#

i use this one b/c its GUI code...

#

its not an actual gameobject UI panel

#

all drawn at runtime.. i like that for whatever reason

inner folio
#

yeah

#

mines probably not optimized at all but i dont really care since im just trying to get this working lmao

rocky canyon
#

my favorite part is its tied into the Console.. soo it will log debugs and stuff inside the terminal as well as the console

inner folio
#

that looks pretty nice

upper thistle
#

https://gyazo.com/6ee5f42e998414535c9744103f1e5743 this lava that should teleport you to spawn won't work for some reason.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Teleporter : MonoBehaviour
{

    public Transform teleportTarget;
    public GameObject thePlayer;

    private void OnTriggerEnter(Collider other)
    {
        thePlayer.transform.position = teleportTarget.transform.position;
    }
}
#

IsTrigger is on

slender nymph
#

have you confirmed that OnTriggerEnter is actually being called

languid spire
upper thistle
#

using an if statement in the update should work to debug that right

upper thistle
languid spire
#

then add some to your code and show the logs

upper thistle
#

Thanks man, you seem like a respectful dude

#

will do that

rocky canyon
# upper thistle https://gyazo.com/6ee5f42e998414535c9744103f1e5743 this lava that should telepor...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Teleporter : MonoBehaviour
{
    public Transform teleportTarget;
    public GameObject thePlayer;

    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Here to know if your collision takes place");

        if(other.CompareTag("Player")
        {
            // usually theres a 2nd conditional to check for specific objects
            // you don't want *any* collider to trigger the logic (usually)
            
            Debug.Log("Also here to know if the collision is the Right collision");

        // finally if it is
        thePlayer.transform.position = teleportTarget.transform.position;
        }
    }
}```
upper thistle
#

What's CompareTag?

rocky canyon
#

you could even use other.transform.position = teleportTarget.transform.position

upper thistle
#

I get other using the parameter of collider

upper thistle
#

thanks

rocky canyon
upper thistle
#

I'll write a debug log myself and check it out

rocky canyon
#

its to decide if the Tag is the tag ur expecting.. theres many different types of comparisons tho..
you could check for Tags.. u could check if its on a certain layer.. u can even use TryGet to see if it has a sepecific Script/Component

upper thistle
#

Not sure if it has that tag unless it's on it by default

#

I don't know how the unity tagging system works yet

rocky canyon
#

u'd assign it

upper thistle
#

I'll look into it, thanks bro

slender nymph
#

you've also seemed to have missed the actual solution to your issue

rocky canyon
upper thistle
#

So it does trigger

rocky canyon
#

ahh, good good

rocky canyon
#

then the collision works 👍

slender nymph
rocky canyon
#

ohhh snap

#

yup ^ hes got a point.. sorry i missed that

upper thistle
#

oh interesting

#

didn't know that