#💻┃code-beginner

1 messages · Page 104 of 1

rare basin
#

why do i need to send you this

#

3 times already

#

!code

eternal falconBOT
rare basin
#

follow the rules

#

yes

queen adder
#

um its not writing the hiwassup

#

when i start the game

rare basin
#

because you didin't put it in Start

#

so why would it log when you start the game?

#

read the docs on how to trigger the OnTriggerEnter

queen adder
#

man

#

i added rigidbody to book and now it says wassup

#

tysm for helping me man

rare basin
#

no problem

stuck palm
#

@rare basin you mentioned serialisable dictionaries earlier, how can i do that?

timber tide
#

iterate over a list and insert it into a dictionary

#

and when you want to serialize it then you do the same backwards

#

rather a list of structs that holds tuples couples a kvp

#

something like that

rare basin
#

free license to use in commercial

stuck palm
rare basin
#

well that is not a dictionary

#

just array of a serializable class

stuck palm
#

yeah ik but

#

i think it works better

solemn sentinel
#

can someone help me with this

stuck palm
#

do you think this looks good?

#

in terms of item data

rare basin
#

i dont know what do you want to achieve, but dictioanry would look much better ;p

#

what if you require X items in order to craft another?

#

you can do List<ItemData> craftWith

#

or with Dictionaries you can just do Dictionary<ItemData, List<ItemData>>

#

where the key is the item you wil lcraft, and value will be list of required items for it

rare basin
queen adder
#

@rare basin hi again me

#

if you free can you look sir

rare basin
#

i showed you how to share code 4 times

#

i wont help you if you dont adapt to the rules

queen adder
#

yy its ok

#

i made it

#

there is no problem on that code

rare basin
#

you don't even nuderstand

#

what am i saying to you

#

if you will keep posting code as a screenshots

#

i wont help you

queen adder
#

bro i made what you said i am asking another thing

rare basin
#

read again what am i saying

rare basin
# queen adder

this will never work, you cannot have 2 tags on 1 object

#

the if will never be true

queen adder
#

yea i was trying to ask that

#

like what can i use

#

i want if this 2 book colides

#

destroy the gate

rare basin
#

i have no idea what is gate what is book

queen adder
#

theese are the bokes

#

if i press e they go back and touch the trigger

#

its like puzzle

queen adder
#

i tought you was saying about the old codes is the same as this you was talking about another thing

#

ok i will use the other sharing methods

rocky canyon
#

those are some fat books

sage mirage
#

Are those books real 😂 ??

rich adder
#

I'd love to read a book on wrestling 23

rich adder
timber tide
summer stump
# queen adder

What they're saying is don't post screenshots of your code

queen adder
sage mirage
#

Hey, guys! I am dealing with a problem here. I am making pause and unpause functionality and for one reason only pause works and it not unpauses, I have used Time.timescale for both cases?

#
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (pauseIsActive)
        {
            
            StartCoroutine(ResumeAfterDelay());              
        }

        else
        {
            StartCoroutine(PauseAfterDelay());             
        }      
    }       
}

IEnumerator ResumeAfterDelay()
{
    yield return new WaitForSeconds(pauseMenuScreenDelay);
    pauseIsActive = false;
    pauseMenuScreen.SetActive(false);
    Time.timeScale = 1f;
    Debug.Log("Pause menu screen is disabled after delay!");
}

IEnumerator PauseAfterDelay()
{
    yield return new WaitForSeconds(pauseMenuScreenDelay);
    pauseIsActive = true;
    pauseMenuScreen.SetActive(true);
    Time.timeScale = 0f;
    Debug.Log("Pause menu screen is enabled after delay!");
}```
timber tide
#

because when you pause it freezes the coroutine

#

so then you cant unpause

#

;)

sage mirage
#

So, with couroutine how to make it work it is my first time dealing with that I mean in pausing and unpausing with coroutines?

timber tide
#

Look into unscaled time

sage mirage
#

How to look? Is there a function?

wind meteor
#

how to asigned ?

rich adder
sage mirage
#

@timber tide Do I have to make that on the same method or do I have to change and make another one?

wind meteor
#

i have this

timber tide
slender bridge
#

Leszek your character controller and ground check are not assigned. You need to follow the link sent to you about variables and the inspector assignments.

rich adder
summer stump
# wind meteor i have this

It is still a transform 🤷‍♂️
But looks like that is just a .... different script. Why is it relevant here?

rich adder
#

are you just geniunly skimming through shit not reading ...

rich adder
#

and they don't understand what the variable they wrote is even doing or what they need to do

#

i suspect they read 0 of it

stuck palm
rich adder
#

Object reference fields
As well as bool, string, and numeric fields, you can also make any field whose type inherits from UnityEngine.Object editable in the inspector. This includes all built-in component types (such as Transform, AudioSource, Camera, Light), your own MonoBehaviour script types, and many asset types.

This allows you to make use of the Unity Editor’s powerful drag-and-drop system in your own scripted components. For example, if you create a public Transform field in your script and add it to one GameObject, you can then drag another GameObject into that field in the inspector to set up a reference to that GameObject’s Transform component
, which you can then access at run time in your script. @wind meteor

maybe if i give you a snippet you will read it

safe carbon
#

i am tryin to get the 2d character to face the platforms surrounding him but it doesn't seem to face it and faces a different place

#

wait

#

let me fix it

eternal falconBOT
queen adder
summer stump
#

It's shown in the message right above you

queen adder
#

i used it

#

but it doesnt seem like that

summer stump
#

It is not single apostrophes

#

It is a backtick, which on my keyboard is to the left of the 1 key

summer stump
#

Maybe that was the issue?

timber tide
# stuck palm where would i put the dictionary?

You can keep it in the SO, assuming this is a unique SO (you've only one of these item data profiles per game, well it actually should be fine either way but it would make more sense to keep this unique).

safe carbon
#

i am tryin to get the 2d character to face the platforms surrounding him but it doesn't seem to face it and faces a different place

summer stump
#
//code
queen adder
#

"//code"

#

//code

summer stump
queen adder
#

"//code"

#

lol

#

i feed dumb fr

#

i copied an added this "

summer stump
#

It is three

#

In their own lines

#

Did you literally copy paste the formatted message or are you typing it? Not sure what is going on here

queen adder
#

i clicked this one

#

and added "

summer stump
queen adder
#
//code
#

oh mann

#

alrightt now i understand lmao

#

thanks for the help

rich adder
#

its backtics bruh

#

' is is not a backtic

queen adder
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GateOpen : MonoBehaviour
{
    
    public GameObject Gate;
    void Start()
    {
        Debug.Log("hi");
    }

    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("hi wassup");
        if (other.gameObject.tag == "first" && other.gameObject.tag == "second")
        {
            Debug.Log("aaa");
            Destroy(Gate);
        }

    }
}
undone inlet
#

What if I want to use UGUI's Mask, but I don't want to parent the Mask Gameobject to the Gameobject being Masked?

twin bolt
#

Why is this code not unloading the loaded scene? ```
IEnumerator UnloadLevelAsync()
{
Progress = SceneManager.UnloadSceneAsync("1.0 Loading");

    yield return null;
}```
slender bridge
tidal swift
#

I dont know what key i pressed by accident, my scene is full white everything except the game

slender bridge
tidal swift
#

Yup it was the F key 😅 thx cheers

verbal silo
#

seeking help for implementing animations and states into my code

stuck palm
#

how can i change the model that the guy is holding in code?

verbal silo
verbal silo
#

you can use this code i made for my project a while ago, it works by swapping two objects

#

using UnityEngine;

public class ModelSwitcher : MonoBehaviour
{
public GameObject modelA;
public GameObject modelB;

// Called when you want to switch the model
public void SwitchModel()
{
    // If modelA is active, deactivate it and activate modelB
    if (modelA.activeSelf)
    {
        modelA.SetActive(false);
        modelB.SetActive(true);
    }
    // Otherwise, deactivate modelB and activate modelA
    else
    {
        modelA.SetActive(true);
        modelB.SetActive(false);
    }
}

}

#

ModelA and ModelB should be your models

#

Attach this script to an empty GameObject in your scene.
Assign the modelA and modelB GameObjects to the respective fields in the script using the Unity Inspector.
Call the SwitchModel method from your code whenever you want to swap between the two models. You can do this in response to user input, events, or any other trigger in your game.

#

the second model will be replaced at the same coorinates and angle as the character's child

rare basin
short hazel
#

Probably AI-generated

rare basin
#
public class ModelSwitcher : MonoBehaviour
{
    public GameObject modelA;
    public GameObject modelB;

    public void SwitchModel()
    {
      modelA.SetActive(!modelA.activeSelf);                                     
      modelB.SetActive(!modelB.activeSelf);
    }
}
rare basin
short hazel
#

And the instructions below, the way they're formatted

rare basin
#

yea lmao

stuck palm
#

looks cool but what if i have multiple models

eternal needle
#

Use an array, and use the index to set one to true while setting all others to false

rare basin
#

or List, if you want to add/remove to it during runtime

languid spire
#

even better, events

stuck palm
#

i didnt realise it would be so hard to change the model

rare basin
#

just a matter of approach

#

it is not hard at all

#

what exactly do you want to do?

#

sorry I didn't follow previous talk

stuck palm
rare basin
#

oww you are the craft guy 😄

#

so I assume you want to change the model when you "craft" new item?

stuck palm
#

yeah basically

rare basin
#

i'd redesign it a bit

stuck palm
#

in the item class it turns the class into an actual dictionary

rare basin
#

to as I said, serializable dictionary (no this is not a dictionary you mate)

#

and as a value have a serializable class

#

CraftOutput

#

where you have craftInto variable (the item that will be crafted)

#

reference to the new model

#

and needed items to craft it

#

then after crafting, access that new model and replace it

stuck palm
rare basin
#

make it <ItemData, CraftOutput>

#

where CraftOutput is your serialized class

#

where you store as i said

#

required items to craft it, model to swap after crafting

#
public class CraftOutput
{
 public List<ItemData> requiredItems;
 /// other code like mesh to replace etc
}
#

but again without serializable dicitionaries this isn't possible to do (easily)

timber tide
#

Really you only need lists to serialize stuff

stuck palm
#

what does craftoutput do

timber tide
#

dictionary is for lookups

stuck palm
#

i dont understand

#

if its only one item i dont need that

rare basin
#

well for each item

#

you have ItemData right

#

and that ItemData has a dictionary

#

where the dictionary is a list of craftable items

timber tide
#

I mean it's convenient to have a serialize dictionary, but the only thing serialize dictionary does is do 1 less step for you and it's loading the dictionary in start

rare basin
#

in the dictionary as a key you put a craftable item

#

in the value you put required items, model to swap (CraftOutput)

stuck palm
#

i see

#

i'll have a go at my idea first

#

i just wanted to know how to swap my model because i have an idea on how i'm making this

timber tide
#

it's a fine model, you've 1 item to a struct of item(s)

#

if that's what I think you're trying to accomplish

#

your key being the item type, and the struct are the values you need to construct the item

stuck palm
#

im pretty sure i can just change the mesh

#

and then change the materials

timber tide
#

oh, for some reason I thought item data was a table of items, but if it's per item then you want to create the dictionary outside like an ItemManager class which you'd load into

stuck palm
#

i could just change the mesh filter right?

timber tide
#

ye

stuck palm
#

whats the difference between the filter and the renderer?

rich adder
swift crag
#

A mesh filter is one way to provide a mesh for a mesh renderer to display.

#

(hence TextMeshPro's name!)

#

MeshCollider also looks for a MeshFilter to figure out what shape the collider should have.

#

That's why MeshFilter is a separate thing -- many things might need to reference the same mesh

swift crag
#

"Mesh filter is the form of an object on the screen. While Mesh Renderer is the way it will look like on the screen."

#

I guess it's halfway there

#

MeshFilter provides a mesh. MeshRenderer displays a mesh.

#

i see why TextMeshPro was so popular

rich adder
teal viper
timber tide
#

I use legacy for world text with shaders and it's aight

pseudo whale
#

Has anyone else been having issues with TextMeshPro just showing up as invisible or giant black squares in the viewport/game view, but being perfectly fine in the scene view?

#

Cuz I've tried everything, including just using the default fonts provided by TMPro, but it just doesn't seem to work properly in game-view

#

Game view (left), scene view (right)

latent jetty
#

hey to make variables persistent across scenes what do you do?
is it as simple as making them static variables or adding a don't destroy on load?
or is it more case by case?

timber tide
#

static or singleton

tranquil glacier
#

How do I set a rotation of an gameobject (an image in the canvas) to a certain value?

timber tide
#

static exists throughout all scenes, while singletons you can manage their lifetime + some extra benefits

pseudo whale
eternal needle
eternal needle
tranquil glacier
rich adder
eternal needle
#

that is not a valid quaternion

rich adder
#

look carefully

ivory bobcat
vast matrix
#

Im using input.getkey and I could not find any way to make it detect when I input space bar.
Please help thanks

prime cobalt
#

Idk if this technically would go under code but can I have something that replaces textures where a raycast hits? Like a bullet hole decal but rather than being overlayed on top of the object it replaces it. So that if part of the bullet hole is transparent you can see through it into the object.

rich adder
#

you could potentially modify the original texture/ material to add dynamic alpha map

#

not trivial probably

prime cobalt
#

Ok thanks I'll try looking into that

solemn fractal
#

if the values increase the same amount and also if they dont increase the same amount

static cedar
#

Yes.

#

Kinda.

rich adder
static cedar
#

If each line progresses by a constant number, you just just do a loop.

#

But the pattern keeps breaking here and there.

cosmic dagger
solemn fractal
#

hmmm never heard of those terms.. collection and curve.. will check iut out

#

thank you guys

cosmic dagger
static cedar
#

Span<int> my_span = stackalloc int[] { ... }

solemn fractal
#

ohh, ok ok. got it, I think I saw that when I did a bootcamp. didnt remeber about it, will check it better thank you guys

teal viper
#

A collection is just any form of array or list

#

Dictionary, queue, etc...

cosmic dagger
#

Also, if the numbers don't follow a pattern, you can store them in teo separate arrays and just loop depending on the condition (if statement) . . .

cosmic dagger
solemn fractal
#

its just me why say them? I am confused.

#

o.O

teal viper
#

Them is a way to refer to a person.

cosmic dagger
solemn fractal
#

what? what do u mean? didnt something change in the grammar? sorry I am not english native speaker

solemn fractal
#

ok thank you guys..

static cedar
cosmic dagger
teal viper
#

Yep. That. You suddenly jumping in with the stackalloc and spans could make them think that it's something specific to that.😅

static cedar
#

Why was that statement pointed to me then. :p

#

Oh maybe ambiguity.

#

By them you meant the guy.

cosmic dagger
static cedar
#

Yeah I see that now.

#

I thought the them referred to the Spanish.

cosmic dagger
#

Ahah, I see . . .

static cedar
cosmic dagger
#

But yes, Span is a cool thing to use . . .

static cedar
#

Actually I just realised, if we're using arrays each time, and we're not mutating them, you can just make a static read-only field.

#

Make the type ImmutableArray<> too.

abstract finch
#

What is the equivalent of animation blending /transition time in code? Is it Lerp or MoveTowards? Im using code to animate and rotate an object but i would like to use its current pos as a starting factor then move toward the target quicker over time

violet topaz
teal viper
cosmic dagger
#

Or just use a custom animation curve within Unity . . .

abstract finch
cosmic dagger
abstract finch
#

ah right

static cedar
#

I think that's correct. :p

north kiln
#

well, the curve will be inconsistent, appearing exponential but actually entirely dependent on the rate it's called

static cedar
#

I think it's close enough.

#

It's how I move my camera.

#

I honestly don't know what's up with cinemachine.

glass urchin
#

Where can I post code to have people help with it?

#

!code

eternal falconBOT
static cedar
#

Fr.

glass urchin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FloatingPlatformMovement : MonoBehaviour {


float MovementScaleY;
float LoopDuration;
float Overshoot;
float IndicatedPosition;

    // Use this for initialization
    void Start () {
        transform.scale.y = transform.scale.y * MovementScaleY;
        bool IsGoingUp = TRUE;
        float InitialY = transform.position.y;
        float UpperBound = intialY + MovementScaleY;
        float LowerBound = intialY - MovementScaleY;
    }
    
    // Update is called once per frame
    void Update () {

        if (IsGoingUp)
        {
            IndicatedPosition= transform.position.y + (MovementScaleY*Time.deltaTime * (1/LoopDuration));
        }
        else if (! IsGoingUp)
        {
            IndicatedPosition= transform.position.y - (MovementScaleY*Time.deltaTime * (1/LoopDuration));
        }

        if (LowerBound<=IndicatedPosition<=UpperBound)
        {
            transform.position.y = IndicatedPosition;
        }

        else if (IndicatedPosition>=UpperBound)
        {
            Overshoot= IndicatedPosition - UpperBound;
            transform.position.Y= UpperBound - Overshoot;
        }

        else if (IndicatedPosition<=LowerBound)
        {
            Overshoot= LowerBound - IndicatedPosition;
            transform.position.Y= LowerBound + Overshoot;
        }
    }
}
#

So does this look right?

polar acorn
#

What is the problem

glass urchin
#

Like I can edit the MovementScaleY and LoopDuration variables per instance right?

polar acorn
glass urchin
#

what's the difference?

polar acorn
summer stump
#

@glass urchin To add to that, when you don't write public or private or anything, it defaults to private. So all your variables are inaccessible to other scripts or the inspector unless you serialize them or change them to public
Best to keep them private unless you NEED them to be public (which you rarely do)

glass urchin
#

Also a bunch of other errors I'm looking at.

#

a bunch of my variables "don't exist in the current context"

eternal needle
glass urchin
#

and it won't let me use <= for floats?

#

should I use double?

polar acorn
#

What is IsGoingUp?

#

You have no variable by that name

eternal needle
glass urchin
#

its a boolean. and i havent even added the code to make it change once it's going down

static cedar
#

This is immediately all over the place.

glass urchin
eternal needle
eternal falconBOT
glass urchin
#

I'm not using an IDE

eternal needle
#

well, start then

wintry quarry
glass urchin
#

what about monodevelop?

wintry quarry
#

MonoDevelop hasn't been a thing for like 5 years

eternal needle
#

just use visual studio, the guide on how to install/configure it is in the bot command above

glass urchin
#

my problem is that transform.position.y is only the component position. I want to change the position of the game object

ivory bobcat
#

You'll need to have a properly configured ide to get help on this Discord server though

eternal needle
#

After that, you can actually see what your errors are

glass urchin
#

I'm gonna see how much I can do without coding then.

eternal needle
#

I cant imagine you'll do anything, since you wont be able to build your game with errors

ivory bobcat
cosmic dagger
polar acorn
cosmic dagger
rich maple
#

is there a way to smoothen and slow down GetSpectrumData() ? basically i want to draw a wave that is very simple with very minimal up and down

small mantle
#

Why isn't this working? I have it working when the "doorCollider" is set to collision but when I try to use the doorCollider it doesn't work. Also the doorCollider works but only without TryGetComponent?c# private void OnTriggerEnter2D(Collider2D collision) { if (doorCollider.gameObject.TryGetComponent<PlayerInput>(out PlayerInput s)) { print("HitEnter"); } }

polar acorn
small mantle
polar acorn
small mantle
#

Are you saying that the doorCollider is not detecting the PlayerInput?

polar acorn
#

I am saying that doorCollider has no PlayerInput component on it

small mantle
polar acorn
#

Whatever doorCollider is

small mantle
polar acorn
small mantle
polar acorn
small mantle
#

Left is Player, Right is the Door Gameobject

polar acorn
small mantle
#

Yes, the right one is.

polar acorn
polar acorn
# small mantle No

Then the code is doing exactly what you told it to do. You're checking if doorCollider has a PlayerInput component, and logging if it does. Since doorCollider does not have a PlayerInput component on it, nothing logs

small mantle
#

How can I make doorCollider like collision?

wintry quarry
wintry quarry
small mantle
wintry quarry
#

How to do what? Your code is already doing it, just on the wrong object

small mantle
wintry quarry
#

collision is a reference to the collider you collided with

#

Your code is ignoring it

#

And instead checking doorCollider for the PlayerInput component

#

Just use the right object reference

small mantle
wintry quarry
#

No...

#

I didn't say that

#

Just call TryGetComponent on the right thing instead of the wrong thing

small mantle
#

Can you just send me the code you are talking about? Here is the code I am using: ```c# private void OnTriggerEnter2D(Collider2D collision) {
if (doorCollider.gameObject.TryGetComponent<PlayerInput>(out PlayerInput s)) {
print("Door Collision");
}
if (collision.gameObject.TryGetComponent<PlayerInput>(out PlayerInput s1)) {
print("Collision");
}
}

wintry quarry
#

You're massively overthinking it

small mantle
#

This? c# if (TryGetComponent<PlayerInput>(out PlayerInput s)) { print("Door Collision"); }

eternal needle
# small mantle

is this the same code you used in this screenshot? Because the debug that you see "Collision" should really tell you which object is the one that has the PlayerInput on it

small mantle
eternal needle
#

I know that it is a string, but since that is the only thing printing in your console, which of the if statements do you think is correct?

small mantle
small mantle
#

I'm now just confused why "collision" is working and not "doorCollider" because they are both Collider2D ?

polar acorn
#

They're different objects

small mantle
polar acorn
#

they're two different objects

polar acorn
#

these are different objects

#

collision and doorCollider are variables that refer to different objects

small mantle
#

is there another way to refer to the incoming Object?

polar acorn
eternal needle
#

you've already found your answer in which object has the player input component

#

collision is the incoming object

polar acorn
small mantle
small mantle
polar acorn
eternal needle
#

if your player has a collider thats not necessary, remove it

#

the door shouldnt be suffering because of an issue with the player

small mantle
polar acorn
frosty hound
#

Seperate them into two different objects with two different tasks

#
Door
 - DoorAnimationTrigger
 - SpawnPointTrigger
small mantle
frosty hound
#

However you want to organize it, as long as the two colliders are separate and handling their own things

small mantle
#

I litterally thought that "collision" effected even the Parent of an Object notlikethis Thanks for the Help!

iron veldt
#

How do I make a game object always have the same rotation so that when it collides with another object it doesn't just start spinnin?

nimble scaffold
#

Guys can I just get models and graphics like ue4/ue5 in unity?

polar acorn
iron veldt
teal viper
nimble scaffold
#

How?

teal viper
#

That was a joke obviously. You're not limited to what assets you use in any of the engines.

nimble scaffold
#

Btw can u tell me how games like smash karts, kirka.io made?

teal viper
#

Same as any other game. Time, effort, development experience. Probably a team with these 3 things and a budget.

nimble scaffold
#

No

#

What engine

teal viper
#

Any engine

nimble scaffold
#

Then how they make a seperate website?

teal viper
#

Host it on a server.

nimble scaffold
#

How

teal viper
#

*host the WebGL build on a server.

nimble scaffold
#

I have repl website

teal viper
nimble scaffold
#

I have my free repl website

teal viper
#

I'm not sure if it's enough for a WebGL build, but you are free to google that.

#

This is not really unity related question.

nimble scaffold
#

Ok

#

And without animator controller can I do animation on key presss

robust ledge
#

if you want to host a webgl build for free, you can use Unity Play or itch.io.

iron veldt
#

Right now when I press play my spaceship immediately points toward the direction I click, which is what I want it to do but not on the x-axis (since I'm doing it in 3d my spaceship moves on the y and z axis and I can't figure out how to make it x and y). I'm trying to get it to like turn towards where I right click without rotating any other way. How do I do that?

teal viper
nimble scaffold
#

Ok

nimble scaffold
teal viper
#

Do you expect me to google for you?🤔

robust ledge
#

@nimble scaffold what is your goal? you're very early on this journey

nimble scaffold
#

I wanna make a web gl based fps game

#

But I don't know animation

robust ledge
#

like a single player first person shooter?

nimble scaffold
#

Aeon Valor is the name

nimble scaffold
#

But fusion isn't working

#

At all

teal viper
robust ledge
#

however you need a lot of sophistication to use it

slender depot
#

is there an easy way to depict a 3 dimensional graph in 2d like this?

eternal needle
slender depot
#

oh, to clarify, im making a game for my thesis that's essentially a practice tool for engineering students early on in their course. this is specifically for adding cartesian vectors so as part of the question i need to be able to depict a pair of 3d vectors. i need a way to show the 3d graph basically

eternal needle
slender depot
#

oh right, well i just meant im using unity2d. my problem is like, accurately showing the angles in "3d space"

#

ive tried messing with this arrow renderer i have and trying editing the rotation of the vectors as if it was on 3d

nimble scaffold
eternal needle
strong harness
#

I have implemented a pool system for my particles. The pool system has been implemented correctly but the particles do not play. They are play on awake and to play them, I disable and enable using setActive(). Also, delay some frames between disabling and enabling but it does not differ.
If I disable and enable them through the inspector, afterwards, they start playing!

                    ripplePSInstance.Clear();
                    ripplePSInstance.SetParticles(_ripples, rippleCount);
                    ripplePSInstance.gameObject.SetActive(false);
                    await UniTask.Yield();
                    await UniTask.Yield();
                    ripplePSInstance.gameObject.SetActive(true);
                    await UniTask.Yield();
                    ripplePSInstance.Play();

The combinations of it have been tested

slender depot
eternal needle
north kiln
#

It 100% should just be 3D and then rendered orthographically

slender depot
nimble scaffold
north kiln
#

That package is for an ECS character controller; I doubt it's what you want

nimble scaffold
#

Yeah I want it

north kiln
#

pangloss giving lazy suggestions again 💀

north kiln
nimble scaffold
#

Idk

north kiln
#

Then you probably won't find any use for that example

teal viper
#

Start simpler

nimble scaffold
#

Pls tell how

#

I downloaded it

north kiln
#

You should not be doing this, and nobody is going to entertain this. Multiplayer as a first project is silly enough, let alone multiplayer ECS. It ain't happening.

nimble scaffold
#

Kk

woven crater
#

whats does the curve do?

teal viper
#

From the name, changes start size.

woven crater
#

during it life time?

queen adder
#

Hey all!

#

Is there a way to simply "do something once only when a variable's value is x" without having to use a bool?

#

so like if I have a variable, lets call it amountOfStuffInRange

#

and I want something to happen only once, any time amountOfStuffInRange's value goes to 0

#

and I know I can accomplish it with a simple bool check, but is there another way? thats maybe less cluttery?

gaunt ice
#

check it only after it was modified

queen adder
#

Oh but I need to use it in update

#

Sorry for not writibg that it

gaunt ice
#

then just use it

teal viper
#

Avoid modifying it after that event occurred.🤷‍♂️

gaunt ice
#

no need to check it in update loop

queen adder
#

But itd continuously keep checking it tho? I might be misunderstanding something a lot here haha its a bit early here

distant mesa
#

is it possible to align GameObjects on the position of an Arduino?
If you move the Arduino that the GameObjects move aswell?

Im using the HoloLens so the gameobjects are "holograms" that need to be set to the Arduino device. If yes, what Arduino compononent would fit best for this case?

eternal needle
teal viper
#

There are 2 states you have: the state(value) of the checked variable, and wether it had the desired value once or not.
If you have 2 different states you can't possibly keep track of them without 2 variables.

queen adder
#

Hold on let me see if that works

eternal needle
distant mesa
#

ah okay ill do that instead

queen adder
woven crater
#

how do i fix this?

teal viper
woven crater
#

not really sure i move my project file to my laptop and and it got this error

#

but its good now i moved the plastic4 from my pc to my laptop now its fixed

prime oar
#

Hello, I used some Textmeshpro Text elements in my game, and it resulted in showing these giant blue text symbols while playing. Any idea what is up?

fossil drum
# prime oar

It's the gizmo for TextMeshPro texts. You can disable it in your gizmos menu if you want.

prime oar
fossil drum
rich adder
ocean wolf
#

Hello, I'm wondering if there would be a better way to tackle my problem.

Basically I have an array, each element in the array has a partner and I need to specify a point between those 2 specific partners, the way I'm doing this seems inefficient, would it be better to use a dictionary for example?

#

This is the way each element is partnered, you can see the intervals are irregular so I used for loops with 2 iterators to achieve this

eternal needle
eternal falconBOT
gaunt ice
#

in window, you can use window icon key+print scene to screenshot

patent compass
#

Hello, doesnt awake only run once and at the start of play mode?
_playerInputActions.Player.Interact.performed
Will this code run when the button has been pressed at any time of the game?

#

or should i keep it in update

teal viper
ocean wolf
patent compass
teal viper
patent compass
teal viper
#

Make sure to provide some more context with your question and preferably some code too(not just one disconnected line)

teal viper
gaunt ice
#

create a mapping so that you can get the partner by directly accessing the mapping

ocean wolf
#

i think this is my mapping

eternal needle
# ocean wolf i think this is my mapping

honestly its really hard to understand what the code is doing at a quick glance, you might want to cache some of these values for readability first. A dictionary or class could help you pair values together, so you dont need to calculate or lookup what the index of the other object is.
Whats the use case of this?

ocean wolf
#

@eternal needle to create a "Mesh Cube" or frame at runtime that has specific points which dictate the shape of the frame/cube

#

sec ill grab screenshots

gaunt ice
#
switch((index&0x4)==0x4){
  case true:{
    return index-4;
  }
  case false:{
    return index+4;
  }
}
```this is much easier to understand, or
```cs
return index-(((index&0x4)>>1)-1)<<2);
```branchless version (just for fun version), i wont suggest you use this even if you understand why it works
#

the idea is mapping 0 and 1 to -1 to 1 by 2*x-1

eternal needle
# ocean wolf <@119616167894712320> to create a "Mesh Cube" or frame at runtime that has speci...

i dont really know what array you were talking about for the partner, but these definitely sound like you can throw both of them in a single class then do your calculations. I would really just map these by storing the objects together in the first place.
i dont really see why most of this is being done so its really hard to suggest anything. all of these numbers just seem like pure hardcode. the only other code i see is that you are getting the average between 2 positions (though sometimes you use localPosition).

#

also that screenshot really doesnt help anything here, its just random shapes mirrored

ocean wolf
#

@eternal needle this is the way I'm currently defining the colliders, which also seems inefficient to me

#

everything is currently stored as a prefeb, but I want to be able to add more points at runtime when a specific GameObject is clicked on, then the partners would change because the initial Frame isn't being interacted with anymore

#

idk if I'm even explaining this or if it's just confusing

shrewd swift
#

how do you add a tooltip in visual studio when hovering a variable or enum value for example or a function ?
in VScode i would do this but it doesnt seam to work for me

// description var
public float something;


something += 1; //when hovering "something" it should show "description var"


eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

rich adder
#

oh you mean regular visualstudio

shrewd swift
#

i mean in unity i am having troubles

rich adder
#

what

shrewd swift
#

when i code in something else my example works

#

except if there is something special in VS 2019 with unity

rich adder
#

yes you need to install unity workload

shrewd swift
shrewd swift
rich adder
#

!vs

eternal falconBOT
#
Visual Studio guide

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

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

rich adder
eternal needle
shrewd swift
rich adder
shrewd swift
#

evrything is fine except this tooltip thing

shrewd swift
eternal needle
rich adder
#

ohhh

#

that

eternal needle
#

if you just type ///, at least in visual studio, it should autogenerate the whole summary part. for methods it adds whatever params you have as well

shrewd swift
#

regular // works in VScode but i didnt know the equivalent in VS

rich adder
teal viper
patent compass
teal viper
patent compass
delicate pewter
#
        public float qTimer = 0.0f;
        public float qTime = 3.0f;
        void Update()
        {
            if (inQueue.Count > 0){
                if (qTimeCheck()){
                    Debug.Log("Agent: " + inQueue.Peek() + " has been in Queue for 3 seconds");
                }
            }
        }

        private bool qTimeCheck(){
            qTimer += Time.deltaTime;
            Debug.Log("time in Queue: " + qTimer + " Max Time: " + qTime);
            if (qTimer > qTime){
                qTimer = 0;
                return true;
            }
            return false;
        }

Does anyone have any idea how on EARTH qTime can be 0?

#

I've looked through the document with Ctrl + F for it and nowhere else do I mention qTime

#

Yet somehow when I print it, it's set at 0 even tho I initialize it as 3

autumn tusk
#

wondering for a mechanic im implementing

#

is is possible to turn a sprite fully white using only scripts in unity 2d

gaunt ice
#

what is the value of qTime in your inspector

high roost
#

Any ideas? bullet is not accurate on 60 degrees camera. It's all good when camera is 90 degrees. But my game is on 60 degrees

the projectile launches from rangedAttackPoint and the direction is changing based on mouse cursor

this is my RangedAttackScript:

using UnityEngine;

public class RangedAttackScript : MonoBehaviour {
    private Rigidbody _rigidbody;
    public int damageAmount = 0;
    public GameObject rangedAttackPrefab;
    public Transform rangedAttackPoint;
    public float bulletVelocity = 30f;
    public float bulletPrefabLifeTime = 3f;

    public void InitializeRangedAttack() {
        GameObject rangedAttack = Instantiate(
            rangedAttackPrefab,
            rangedAttackPoint.position,
            Quaternion.identity
        );

        rangedAttack
            .GetComponent<Rigidbody>()
            .AddForce(rangedAttackPoint.forward.normalized * bulletVelocity, ForceMode.Impulse);
        Destroy(rangedAttack.gameObject, bulletPrefabLifeTime);
    }
}```

the codelet that handles player facing rotation:

```cs
private void HandleRotation() {
        float rayHit;
        Vector2 mousePosition = _inputActions.PlayerActions.MousePosition.ReadValue<Vector2>();
        Plane playerPlane = new Plane(Vector3.up, transform.position);
        Ray ray = Camera
            .main
            .ScreenPointToRay(mousePosition);

        if(playerPlane.Raycast(ray, out rayHit)) {
            Vector3 targetPoint = ray.GetPoint(rayHit);
            Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
            transform.rotation = Quaternion.Slerp(
                transform.rotation,
                targetRotation,
                100 * Time.deltaTime
            );
        }
    }
languid spire
#

Check the setting in the Inspector. That takes precedence over what is in code @delicate pewter

rare basin
#

if you can't properly ask for help we can't help you

shrewd swift
#

i am getting a VS warning when adding _ in a enum var, but not with other regular types
i am curious, why ?

#

is there a tech explanation

rare basin
eternal falconBOT
keen dew
shrewd swift
#
 private enum _Elements {
        None,
        eFloorBox
       }

just in case : i dont have any problem when running the code

keen dew
#

It's just a styling rule, you don't start enum definitions with an underscore, the same way that you don't start class or struct names with it either

#

Note that that's not a variable

shrewd swift
#

ah okay, i just wanted to use a underscore because all my private vars starts with it

shrewd swift
keen dew
#

variable types are also not variables

shrewd swift
#

ik im just saying i foget that enums arent like other "classic" vars

slender nymph
golden otter
delicate pewter
#
inQueue.Enqueue(new KeyValuePair<int, GameObject>(i, RVOAgents[i]));
#

I dont understand this error, how on earth is it saying that im flipping them

#

its clearly Int, GameObject in both

#

i is an int

#

RVOAgents[] is a list of GameObjects

languid spire
#

show declaration of inQueue

delicate pewter
#

Yep im an idiot

#

As usual

shrewd swift
#

regarding interfaces, where should i declare them ?

golden otter
shrewd swift
#

okay ty

#

also, i never see anything like this, could someone explain what this means (i took a random example)

        get {return m_maxHealth; }
        set {m_maxHealth = value; }
shrewd swift
#

what are "properties" in Unity ?

young warren
#

that specifically are the custom getters and setters of the property

raven kindle
#

for some reason under my platforms i have these dotted lines
but i get stuck on them
how can i fix this?
i only get stuck on them for a second before falling through it

young warren
#

it's a C# thing, not specifically Unity. Look "C# Properties" @shrewd swift

fossil drum
shrewd swift
young warren
#

you can think of them as variables, but you can customise the behaviour of what happens when you get or set them

#

yeah, something like that. I recommend you read up or learn up on them

#

they're pretty useful

young warren
#

no worries

#

you can do stuff like this for example

get {return m_maxHealth; }

set 
{m_maxHealth = value; 
UpdateHealthUI(value);
}
shrewd swift
#

what does { get; } do ? a default set with no editing ?

young warren
shrewd swift
#

shortcut ig

young warren
#

yes

shrewd swift
#

its cool working with c# after being "forced" to use visual scripting

#

you got more possibilities and you truly understand the tech and technical limitations

shrewd swift
#

im quite confused around this, should i create 1 script file per custom class ?

young warren
shrewd swift
#

thats why i am asking those questions

young warren
#

I would usually declare classes in their own file, unless it's a plain C# class that's used as a data container that's to be used in a particular script

#

but no harm in just declaring classes in their own file

shrewd swift
#

okay

shrewd swift
#

or does the interface is "declared" everywhere by its own

young warren
#

doesnt that tutorial teach you how to implement interfaces

shrewd swift
#

no

young warren
#

it does

shrewd swift
#

the only mention is:
You can declare an interface as you would declare class or struct, but using the interface keyword.

wintry quarry
shrewd swift
shrewd swift
slender nymph
young warren
#

i'm thinking you'd benefit from a video
https://www.youtube.com/watch?v=MZOrGXk4XFI

📝 C# Basics to Advanced Playlist https://www.youtube.com/playlist?list=PLzDRvYVwl53t2GGC4rV_AmH7vSvSqjVmz
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses​
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

✅ Let's learn all about Interfaces in C# and how ...

▶ Play video
shrewd swift
#

so i declare the interface a a seperate file script, and implement by just adding the name with the class?

young warren
#

you dont seem to understand the text. having a demonstration might help

shrewd swift
young warren
#

after you watch that, compare it to the Unity Learn examples

#

might help it click

shrewd swift
young warren
shrewd swift
#

okay so i dont add it as a script component, but i have to declare it somewhere

young warren
#

please just watch the video first

shrewd swift
#

👍

shrewd swift
#

now i understand why my questions were weird

#

the only annoying thing i can see is that you have to implement all interfaces methods

swift crag
#

an interface is a contract

#

you promise you can do X, Y, and Z

#

If you find that you're implementing methods that make no sense for your class, your interface needs to be broken up

#

as an extreme example

#
public interface IWhat {
  public void Hit(float damage);
  public string GetFavoriteColor();
}
#

This interface is bogus. It's describing two concepts that don't belong together.

static cedar
young warren
#

if you dont want all, then you wouldn't use an interface

polar acorn
# shrewd swift the only annoying thing i can see is that you *have* to implement all interfaces...

The entire point of the interface is that the compiler can guarantee that no matter what the object does or what type it is or what it's a subclass of, you can be 100% certain that it has these specific functions with these parameters and return types.

If you didn't need to put them all then an interface is pointless. How would the compiler know if your class implemented that specific function when it doesn't even know what class it is

queen adder
#

Any idea why Related keeps getting reset to 0 items?

#
public class RelatedRuleTile : RuleTile 
{
    public List<TileBase> Related;
    public override bool RuleMatch(int neighbor, TileBase tile)
    {
        switch (neighbor)
        {
            case TilingRule.Neighbor.This: 
                return tile != null && Related.Contains(tile);
            case TilingRule.Neighbor.NotThis:
                return tile == null || !Related.Contains(tile);
        }
        return true;
    }```
static cedar
#

I don't see .Clear here.

#

And why is it a switch case? o.o

queen adder
#

bothers me too...

#

all of it's usage

static cedar
#

Try encapsulating the Related field and set up a break point on the getter. UnityChanThink

#

lol

#

Do u have a custom editor for it?

swift crag
#

in what context is it getting reset?

#

every time you enter play mode? instantly?

polar acorn
# queen adder all of it's usage

If that's everything then I don't think the problem is that it's getting reset I think it's just always empty. You're likely calling that function on a different instance than one that I assume you've populated in the inspector

queen adder
#

I add something in the list, I click outside the object

#

click again and it's bvack to 0

swift crag
#

why is this necessary?

queen adder
polar acorn
queen adder
#

hmm ig Imma just duplicate the entire RuleTile class

#

it used to work when I was working that

#

I just separated it and this version dont work anymore

#

(realized i also have to make its own editor script as well UnityChanOops )

#

actually, it's the editor script messing it up

#

a 400 line editor script 😭

spiral narwhal
#
 private IEnumerator SmoothChangeCoroutine(int amountOfXPAfterCalculation, int amountOfLevelUps)
        {
            float elapsedTime;
            var sliderValue = _experienceSlider.value;

            while (amountOfLevelUps > 0)
            {
                elapsedTime = 0f;

                while (elapsedTime < SLIDER_MOVEMENT_DURATION)
                {
                    _experienceSlider.value = Mathf.Lerp(sliderValue, _experienceSlider.maxValue,
                        elapsedTime / SLIDER_MOVEMENT_DURATION);
                    elapsedTime += Time.deltaTime;
                    yield return null;
                }

                amountOfLevelUps--;
                _experienceSlider.value = 0f;
                sliderValue = 0f;
            }

            _experienceSlider.maxValue = ExperienceService.Instance.RequiredXPForNextLevelUp;
            elapsedTime = 0f;

            while (elapsedTime < SLIDER_MOVEMENT_DURATION)
            {
                _experienceSlider.value = Mathf.Lerp(sliderValue, amountOfXPAfterCalculation,
                    elapsedTime / SLIDER_MOVEMENT_DURATION);
                elapsedTime += Time.deltaTime;
                yield return null;
            }

            // Sometimes, precision issues of 1-2
            Assert.AreEqual((int)_experienceSlider.value, amountOfXPAfterCalculation);
        }

I have an issue where I'm using sliders (set to whole numbers) that are using floats in Unity. My ExperienceService uses ints, resulting in precision issues. Is there a better a way to handle this, or should I just accept that there should be a 1-2 difference tolerance in the assertion?

oak imp
#

Hey, I'm having trouble trying to build my game in unity. I keep getting an error saying "cannot build player while editor is importing assets or compiling scripts" I saw one solution was to eliminate any "Using UnityEditor" from my scripts, i did that but it didn't fix the issue. Anyone know what I can do to fix this?

ivory bobcat
spiral narwhal
#

Is that some kind of clamp?

autumn tusk
#

i'm currently changing my gun from semi auto to auto

#

only issue is this code doesnt work for whatever reason to add a delay between shots

#
    {
        ammoui.SetText(ammo.ToString());
        if (Input.GetButton("Fire1"))
        {
            Shoot();
        }
    }
    IEnumerator Shoot()
    {
        
        PlayerShoot();
        yield return new WaitForSeconds(0.4f);

    }
    void PlayerShoot()
    {
        if (ammo > 0)
        {
            float spreadvalue = (Random.Range(-7.5f, 7.5f));
            Quaternion bulletRotation = Quaternion.Euler(0f, 0f, transform.rotation.eulerAngles.z + spreadvalue);
            GameObject playerbullet = Instantiate(playerbulletPrefab, firePoint.position, bulletRotation);
            Rigidbody2D rb = playerbullet.GetComponent<Rigidbody2D>();
            rb.AddForce(playerbullet.transform.right * bulletForce, ForceMode2D.Impulse);
            audiosource.PlayOneShot(shootclip, 0.2f);
            Destroy(playerbullet, 5f);
            
            ammo = ammo - 1;
        }
        else if (ammo == 0)
        {
            audiosource.PlayOneShot(emptyclip, 0.4f);
        }
    }
}
hollow zenith
#
    public int Health { get { return Health; } internal set { Health = value; } }

Does this work or do I need to create a backing field manually?

autumn tusk
gaunt ice
#

work
and you will get stackoverflow

hollow zenith
gaunt ice
#

just like this:

public void SetA(int a){
  SetA(a);
}
public int GetA(){
  return GetA();
}
```property is shorthand of method, but they are still function call
hollow zenith
#

Alright, thanks

slender bridge
polar acorn
sullen zealot
#

hello!

#

does anyone know how can i check if transform.rotation.y is set to 90 degrees?

wintry quarry
#

a better option is to check if the object is facing "right" for example

#

which is probably what you really want to know

sullen zealot
#

yes

#

how do i do that?

wintry quarry
#

Something like:

if (Vector3.Angle(transform.forward, Vector3.right) < 10) {
  // it's facing right
}```
#

10 being an arbitrary threshold value

#

this checks if you're within 10 degrees of facing purely to the right

sullen zealot
#

i ll try this

#

thanks

polar acorn
# sullen zealot does anyone know how can i check if transform.rotation.y is set to 90 degrees?

.rotation is a Quaternion, a normalized 4D value. It'll never have any components at 90 because it's components have to add up to 1.
You could check if the .eulerAngles.y is a certain value, but considering that something being 90 on y is identical to being 270 on y and you have no idea how that is going to be calculated, you can't rely on it.

You should use the method Praetor is sending, or use Vector3.dot between your facing angle and the angle you want to check. If the dot product of those directions is near 1, it means they're facing the same way. 0 means they're perpendicular, and -1 means they're opposite

waxen wyvern
#

hi I need help

sullen zealot
#

i was also thinking about using this
if (transform.rotation == Quaternion.Euler(new Vector3(0, 90, 0))) ;

#

would this work?

waxen wyvern
#

my camera zooms in to the feet of my character when i move it around

sullen zealot
#

i am sure the x and z are always 0

waxen wyvern
#

anyone hlelp 😄 ❤️

wintry quarry
#

better to go with a threshold

timber tide
sullen zealot
waxen wyvern
#

I started unity in today what do you mean by inscpetor lik the game mode?

sullen zealot
#

click on maincamera then screenshot again

waxen wyvern
#

ok

sullen zealot
#

click on thirdperson chinemachine

#

and screenshot

waxen wyvern
polar acorn
# waxen wyvern

And what is the position of the Player object your camera is looking at?

waxen wyvern
#

hold on

#

Vector3(458.631012,27.1529999,154.957611)

#

very close to the one in the screen

sullen zealot
#

try creating an empty gameobject as a child for the player gameobject and place it in the head of the player.
then change the "look at" in cinemachine to the new gameobject created

slender bridge
#

2 things to look at, i see 2 cinemachine camera named objects for player, is it switching to another one that is at the feet using priority. you could also have some suspect values in body or aim module

wintry quarry
#

your player object's pivot is probably at its feet

waxen wyvern
#

the camera starts in the right position but when i move it sometimes it zoom in

waxen wyvern
wintry quarry
waxen wyvern
sullen zealot
#

move it by the arrows so that it is "inside" the head

#

but make sure it is a child of the player

waxen wyvern
#

wow it works

#

:DD but how

sullen zealot
#

idk

#

im kinda new to this too

polar acorn
summer stump
sullen zealot
#

i think he meant why does it now zoom on the feet anymore

polar acorn
#

and that object is not at the player's feet

waxen wyvern
#

i am looking at a tutorial and it should not zoom in even before this

summer stump
sullen zealot
waxen wyvern
#

This is tutorial#08. In this course you will learn 3d game development step by step using unity game engine by developing Third Person Shooter TPS zombie apocalypse and zombie survival horror game.

Follow us on our Instagram: https://www.instagram.com/wits.gaming/

Complete Course YouTube Playlist: https://youtu.be/tSkKIqvDTEM?list=PLA-xaldQ72r...

▶ Play video
sullen zealot
#

this seems kinda complicated for a beginner

#

i think you should try to make a simpler game

#

idk tho

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
#

If not, do it first

waxen wyvern
#

thanks

queen adder
#

Hey, I wanna create 2d Teleportation. Basic idea is: stand on top of tele entrance, animation plays and player teleports to the exit. Exit has no teleport function, just acts as a waypoint. These will be created by the player so I wanna be able to grab the entrance and exit as prefabs

sullen zealot
#
  1. create gameobject that has the animation
  2. on player script make 1 serializefiled Transform and in unity assign the exit gameobject to it
  3. instantiate the animation gameobject
  4. hide the player
  5. waitforsecond(you choose)
  6. transform.position = transform(from 2).position
#

if (gameObject.name.Contains("Fast"))

#

does anyone know why this doesnt work?

#

i also tried with ToString()

wintry quarry
sullen zealot
#

it doesnt return true

#

even if the gameobject name contains "Fast"

wintry quarry
sullen zealot
#

ok

autumn tusk
#

how would i set this text function to display with two variables that are in tostring functions

summer stump
eager elm
# sullen zealot it doesnt return true

Checking like that is pretty bad practice and can cause problems as you are seeing now. One way where you are not relying on typing the correct string is adding a new empty class to your gameObject named 'FastUnit'.
Then you can use:

if (gameObject.TryGetComponent(out FastUnit)
{
    //Some code in here
}```
wintry quarry
#
ammoui.SetText($"{ammo}/{totalAmmo}");``` for example
autumn tusk
#

so like 12/60

eager elm
wintry quarry
summer stump
eager elm
sullen zealot
wintry quarry
#

There always is. This is why we debug

sullen zealot
#

ty for making me see that 🙂

wintry quarry
#

the problem is never going to be "basic operations in C# don't work"

safe root
#

I'm trying to get my VS code to work again but It ain't and I don't know if this is the problem

rich adder
safe root
rich adder
safe root
rich adder
#

oh cool at least its working lol

safe root
#

True

safe root
#
public class Grapple : MonoBehaviour
{
    private RaycastHit lastRaycastHit;
    [SerializeField] private float maxDistance = 2f;
    private bool PullSurface = false;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 origin = Camera.main.transform.position;
        Vector3 direction = Camera.main.transform.forward;
        RaycastHit raycastHit = new RaycastHit();
        

        if (Physics.Raycast(origin, direction, out raycastHit, maxDistance))
        {
           if (raycastHit.collider.gameObject.CompareTag("GrappleAble"))
           {
                print ("Can grapple to!");
                transform.position = lastRaycastHit.point + lastRaycastHit.normal * 2;
           }
            
        }

    }
#

Why does my character not teleport when it looks at a object?

rich adder
safe root
rich adder
safe root
#

Ah, got it

rich adder
#

components can be disabled with .enabled =

safe root
#

Now my character goes below the ground for some reason

rich adder
safe root
safe root
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Grapple : MonoBehaviour
{
    private RaycastHit lastRaycastHit;
    [SerializeField] private float maxDistance = 2f;
    private bool PullSurface = false;

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

    // Update is called once per frame
    void Update()
    {
        Vector3 origin = Camera.main.transform.position;
        Vector3 direction = Camera.main.transform.forward;
        RaycastHit raycastHit = new RaycastHit();
        

        if (Physics.Raycast(origin, direction, out raycastHit, maxDistance))
        {
           if (raycastHit.collider.gameObject.CompareTag("GrappleAble"))
           {
                print ("Can grapple to!");
                if (Input.GetMouseButtonDown(0))
                {
                    GrapplePull();
                }
           }
            
        }

    }

    public void GrapplePull()
    {
        characterController.enabled = false;
        transform.position = lastRaycastHit.point + lastRaycastHit.normal * 2;
        characterController.enabled = true;
    }
}
#

I'm thinking of changing this line cs transform.position = lastRaycastHit.point + lastRaycastHit.normal * 2; for now to have it at the game object a certain amount above the object looked at

slender nymph
#

you don't appear to be assigning to lastRaycastHit anywhere

safe root
#

Wait

rich adder
#

rip

safe root
rich adder
#

the new one is out raycastHit

safe root
#

private RaycastHit lastRaycastHit;

short hazel
#

I'd just pass the RaycastHit as a parameter to GrapplePull, it's easier

#

No need for a class variable

slender nymph
safe root
slender nymph
#

how could it be the last thing you hit if you never assign to it?

short hazel
#

Your code editor is probably graying out that lastRaycastHit field, telling you it's not used and can be removed

#

That's a hint you're not putting a value into it ever

short hazel
#

Never assigned to then, it'll ask you to make it readonly

slender nymph
#

what would this print?

string myName;
string name = "Boxfriend";
Debug.Log(myName);
safe root
#

Nothing

slender nymph
#

exactly.

#

so now how is lastRaycastHit anything other than nothing (or rather it's default value which is basically the same thing)?

safe root
short hazel
#

Nope

slender nymph
#

you do know what it means to assign to something, right?

safe root
#

Yes! it's assign a vaule but i just seen that raycastHit is not being used for some reason

#

So the raycastHit is not assiging lastRaycastHit

slender nymph
#

why would it? on what line are you expecting lastRaycastHit to be assigned the value of your raycastHit local variable?

safe root
#

private RaycastHit lastRaycastHit;

summer stump
polar acorn
slender nymph
slender nymph
summer stump
short hazel
#

Misunderstanding between local variables and fields. Your Physics.Raycast assigns to the local variable, declared 3 lines above

#

The local does not exist outside of Update

queen adder
#

ugh.. did ms just made vsc valid for unity again? anyone seen this before?

short hazel
#

Assign to the field, not the local variable (you don't need the local, technically)

slender nymph
#

vs is still better though

tranquil glacier
#

this animation does not seem to exit, I have a trigger that fires once you enter the box trigger, then it continuously loops the prayer animation.Does someone know what I am doing wrong?

#

do triggers fire once or do they continuosly fire?

polar acorn
#

Triggers are one-time use. Once read, they reset

safe root
short hazel
#

Are you getting an error message?

#

NullReferenceException?

tranquil glacier
polar acorn
tranquil glacier
#

I was trying to get it to turn off

polar acorn
#

Triggers turn off once read

#

What is your condition to leave the Prayer animation

tranquil glacier
#

its nothing, I just want it to go back to default state and stay

polar acorn
tranquil glacier
#

correct

polar acorn
#

which appears to be about 20 seconds long? Unless that timeline is in frames

tranquil glacier
#

yes I animated the prayer to be long and cinematic

polar acorn
#

And if during that animation you spend any frames with the F key pressed, it'll queue another one

#

Chances are when you hit the button, you've held it for at least one extra frame

#

so it's going to be praying for 40 seconds

tranquil glacier
#

ok, can I just use "getkeydown"?

polar acorn
#

and only set the trigger once

tranquil glacier
#

alr then

autumn tusk
#

how would i destroy all instances of an enemy with a specific tag if theyre inside a collision box

slender nymph
#

what part of that are you struggling to figure out?

polar acorn
#

Is it the destroying, the detecting, or the tag-checking

autumn tusk
#

if theyre inside the collision box or not

polar acorn
slender nymph
#

so detecting them. there's a few options for that, you can rely on physics messages like OnCollisionEnter/OnTriggerEnter or you can use physics queries like OverlapBox

autumn tusk
#

all these enemies have the enemydead tag, and what i want to code is that only the enemies inside the collision box get removed

#

while all the enemies outside stay where they are

autumn tusk
#

my game is in 2d

polar acorn
autumn tusk
#

ok im thinking

#

i create a new tag called "enemydeletable" and inside the radius all dead enemies get assigned that

#

only thing is i have to reassign enemies with the enemydead tag when the enemy leaves the radius

merry spade
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class PlayerMove : MonoBehaviour
{
    [SerializeField] GameObject camera;

    private Rigidbody rb;

    private float speed;
    private float xAxis;
    private float zAxis;

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

    // Update is called once per frame
    void Update()
    {
        camera.transform.position = new Vector3(camera.transform.position.x, camera.transform.position.y, transform.position.z - 6);

        xAxis = Input.GetAxis("Horizontal");
        zAxis = Input.GetAxis("Vertical");

        

        Vector3 movementDirection = new Vector3(xAxis, 0, zAxis);


        transform.Translate(movementDirection * speed * Time.deltaTime, Space.Self);
        Quaternion rotationQuat = transform.rotation.normalized;
        print(rotationQuat);
        if (rotationQuat.x > 0.37)
        {
            transform.rotation = Quaternion.Euler(0.37f, 0, transform.rotation.normalized.z);
            print("stop1");
        }
        else if(rotationQuat.x < -0.37)
        {
            transform.rotation = Quaternion.Euler(-0.37f, 0, transform.rotation.normalized.z);
            print("stop2");

        }
            
        if (rotationQuat.z > 0.37)
        {
            transform.rotation = Quaternion.Euler(transform.rotation.normalized.x, 0, 0.37f);
            print("stop3");
        }
        else if (rotationQuat.z < -0.37)
        {
            transform.rotation = Quaternion.Euler(transform.rotation.normalized.x, 0, -0.37f);
            print("stop4");

        }
    }
}

I want to stop the cube from falling over when it approaches a slope, but the cube is rotating weirldy and stuff here is a video:

The weird thing is, that it keeps rotating the y axis. However I freezed the y rotation in the rigidbody

slender nymph
#

that's not rotating around the Y axis. looks more like either X or Z oh my bad, thought you meant the rolling

merry spade
#

of course it is look into the inspector at the end

polar acorn
merry spade
polar acorn
#

Also, why are you checking individual values of a quaternion? Those values are going to be basically nonsense to any human

#

What are you trying to achieve by checking if the x component of a quaternion is greater than 0.37?

merry spade
merry spade
slender nymph
#

why do people insist on showing 20 seconds of unrelated stuff for the issue to only be the last 2 or 3 seconds of a video

polar acorn
merry spade
merry spade
#

ok i will look into that

polar acorn
#

A quaternion is a four-dimensional normalized expression of an orientation and is basically incomprehensible to people. The X, Y, Z, and W values have nothing to do with the X, Y, and Z axes of euclidian space

summer stump
#

From my barest understanding, w is the amount of twist along the colinear composite of axes of xyz in a quaternion. It doesn't really work well when trying to use it directly

polar acorn
#

It's best to just consider them "Wizard math" and do everything in your power to never operate on them directly

merry spade
#

how can I get transform.rotation.x to the numbers that are shown in the inspector?

slender nymph
#

you don't because transform.rotation is a quaternion

#

even transform.eulerAngles which are in degrees may not be the same as what you see in the inspector because they are interpreted from the quaternion at the time you access them

quick ruin
#

Does anyone know how to access this page? "Netcode -> general ->"

merry spade
slender nymph
slender nymph
summer stump
# merry spade but there has to be a way

Why even try? Why do you require them to match? Just work with your own numbers internally

But I have never seen a satisfactory way to make it match the inspector

merry spade
summer stump
merry spade
# slender nymph https://unity.huh.how/programming/quaternions/members
        Vector3 cubeRotation = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.rotation.z);
        print(cubeRotation);
        if (cubeRotation.x > 45)
        {
            transform.localEulerAngles = new Vector3(45, 0, transform.rotation.z);
            print("stop1");
        }
        else if(cubeRotation.x < -45)
        {
            transform.localEulerAngles = new Vector3(-45, 0, transform.rotation.z);
            print("stop2");

        }
            
        if (cubeRotation.z > 45)
        {
            transform.localEulerAngles = new Vector3(transform.rotation.x, 0, 45);
            print("stop3");
        }
        else if (cubeRotation.z < -45)
        {
            transform.localEulerAngles = new Vector3(transform.rotation.x, 0, -45);
            print("stop4");

        }

like this?

polar acorn
# merry spade but there has to be a way

Not to make transform.rotation match. The inspector shows a value for transform.localEulerAngles. There are an infinite number of euler angles that express the same orientation so it might not match the numbers but as a whole will match to orientation

autumn tusk
#

i dont understand why this code is red, i pulled it off the unity documentation

#

nvm i forgot to assign values

slender nymph
summer stump
#

That is the default in the declaration

Oh yeah, there is more wrong than just that...

sullen zealot
#

i have this piece of code which uses 1d axis values
public void OnMove(InputValue value)
{
Debug.Log(value);
}
how can i log the actual value of "value"

nimble tartan
#

I have 2 elements (player and enemy) in the same position when the game is running (enemy is with isTrigger true), but the transform value of X and Y is so much different for close positions.

Anyone knows what possibilities to this happens?

sullen zealot
#

it only logs this

placid siren
#

What is the best tutorials I should learn from???

slender nymph
slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

fossil tree
#

hi everyone i dont uderstand why my coroutine dont work that dont wait 5 second this is my code (first time i use coroutine) :

using System.Collections.Generic;
using UnityEngine;

public class timer : MonoBehaviour
{
    public int temp = 30;
    // Start is called before the first frame update
    void Start()
    {
        while(temp > -1)
        {
            StartCoroutine(Timer());
            temp--;
        }
    }

    // Update is called once per frame
    IEnumerator Timer()
    {
        print(temp);
        yield return new WaitForSeconds(5);      
    }
}
slender nymph
sullen zealot
#

and what type of value is that

#

i tried using float

#

.Get<float>

slender nymph
#

and what happened?

sullen zealot
#

it shows an error

patent compass
sullen zealot
slender nymph
slender nymph
sullen zealot
#

ok

#

()

#

ahaha

slender nymph
#

make sure that your !IDE is configured so you don't make silly syntax errors like that