#💻┃code-beginner

1 messages · Page 707 of 1

grand snow
#

is this at runtime? changing a prefab asset wont affect spawned copies

#

also using player prefs for this is a bad idea

grand snow
#

at runtime its just a copy made with the prefab data and thats it

subtle sedge
#

are you able to use strings?

solid oyster
#

oh

subtle sedge
#

i assume it has to be Keycode.D

solid oyster
#

if i complied it would it work?

grand snow
#

no

solid oyster
#

what should i do then

grand snow
#

You need to take a different approach where you inform all spawned copies of this change or they listen to an event to respond to a change

#

e.g. keep all spawned copies in a List and when you change this "glow level" you refresh them all

solid oyster
#

ok

#

thanks for the help

patent wedge
#

if i wanted to check if"transform.GetChild(number) == null" how would i do that without transform out of bound errors?

cosmic dagger
solid oyster
grand snow
solid oyster
grand snow
#

those are child game objects

solid oyster
#

ah

grand snow
#

you can use a serialized list to reference them

[SerializeField]
List<MyScript> glowObjects;
solid oyster
#

how do i reference them

#

quite new to unity srry

polar acorn
#

Like that.

#

Make a list of a type you want and drag em in

grand snow
#

^ yep. You will see the list in the inspector and you can drag in your child game objects to assign them

#

very beginner stuff

solid oyster
#

wont let me drag the light object to the element in the list

polar acorn
#

And what type is that list

solid oyster
#

are these not the same light?

polar acorn
# solid oyster

Okay, which object has the variable on it? These glowX objects are in a prefab, is that script also on the same prefab?

solid oyster
#

its also attached to a canvas to access a togglebox

grand snow
# solid oyster

that should work 🤔
unless there is another type in your project named "Light"

polar acorn
solid oyster
#

ok

polar acorn
#

Scene objects can't directly access children of a prefab, only the root-level prefab object

solid oyster
#

wont let me drag the light object into the list even tho its attached to the prefab

#

im doing this from the project window

#

coudl that be why?

slender nymph
#

are you trying to drag scene objects into the slots on the prefab?

grand snow
#

If the script with the list is on "target" and everything is within the same prefab it should work

solid oyster
#

object from a prefab folder i made

rich adder
#

isLight from UnityEngine ?

solid oyster
#

yes

slender nymph
#

if they are part of the same prefab then most likely you are just using the wrong Light type in your code

solid oyster
#

do i have to speficy if its spot light or smth?

rich adder
#

no

polar acorn
#

Do you have a script in your project named Light?

rich adder
#

Right click on Light Go to Definition on Light see where it takes you

slender nymph
polar acorn
#

Can you show a screenshot of your unity window with this inspector visible? In the prefab edit mode?

slender nymph
#

okay, now click the little lightbulb (?) button on the Light component and see what namespace that one is in

solid oyster
#

it says light is from Unity.Engine

rich adder
#

still think you're probably dragging scene components onto a prefab or somethin

slender nymph
#

then you are doing something wrong when trying to assign the objects.

solid oyster
#

can i not do that?

grand snow
solid oyster
rich adder
slender nymph
# solid oyster can i not do that?

you can drag prefabs into scene objects. you cannot drag scene objects into prefabs. which is why i specifically asked you if that was what you were doing before and you said you were not

slender nymph
solid oyster
#

im trying to drag these into a scene object

#

thats not allowed?

#

if the object is not on the scene

polar acorn
slender nymph
#

you can drag the root object of a prefab into any other object. child objects can only be referenced within the prefab itself

polar acorn
#

As I said, it should be on the target object

solid oyster
#

im tryna make a toggle box that enables the target to glow when checked

polar acorn
solid oyster
#

it didnt really work

grand snow
#

this is possible reference wise

#

no one here understands what you are describing

rich adder
#

can you like show a vid what you did maybe ?

solid oyster
#

so i can add a gameobject constructor, then reference the child objects from there?

native flame
#

when using a spherecast for groundcheck, should the starting point be the player origin, or the origin + (vector3.up * spherecast) radius?

Gemini is insisting it's more reliable to have it be a radius above the origin, but the reasoning provided is contradictory

grand snow
polar acorn
#

You would make a script on target that holds a reference to all of its Lights. Then you would keep around the reference to that target you spawn in, and use that to access its Lights

rich adder
native flame
#

yeah yeah yeah

solid oyster
rich adder
# native flame yeah yeah yeah

depends on the usecase, there is no set way to do this, but its common to either make a separate transform for the origin of cast or use an Offset (origin + offset)

the origin being in the middle it means you have the make the cast longer , not much changes. As long as you put the Layers to ignore its own player caster, should be fine

solid oyster
#

got it thx

#

have to document all ts as well

rich adder
native flame
#

huh alright

timber tide
native flame
rich adder
timber tide
#

oh yeah true

native flame
rich adder
timber tide
#

think you can still get some point of intersection

native flame
#

but yeah a raycasthit would be useful for determining the floor type

rich adder
#

most cases Overlap is fine, if you need the hitInfo like slope angles and shite, use casts

timber tide
#

you can also do overlap + ray

#

overlap for the collider then ray to it

native flame
rich adder
#

It just makes sense to me to put it at the feet if its a ground check etc.

#

especially if you make the ground check slightly bigger than the player capsule you don't want his "hips" to count as grounded if the check spills outside

native flame
#

ok yeah that makes sense

rich adder
#

for rays normally that doesnt matter cause they are a line, no radius

native flame
#

isnt it recommended to make the radius slightly lower than player width tho?

rich adder
#

sometimes the capsule has its corners hit a ledge, if check is smaller than the radius of capusle, its like stuck in place while the grounded check says "not grounded"

#

I usually make the groundcheck sphere like 1-2 cm bigger than quarter half of the capsule

#

@native flame

sharp mirage
west garnet
#

i got in the new input system the event that when you click on attack, i also have when you get close to an npc you can press Z and gamble, opens a canvas with some gambling UI things, but when you press Z to gamble and then try to click in one of the things it attacks and disables back again the canvas, how can i fix this

rich adder
west garnet
native flame
rich adder
#

not a reliable way to do it tbh

native flame
west garnet
native flame
#

then i guess it would be better to do a MenuActive bool that disables actions

eternal needle
# west garnet ill check it out ty

You dont need to, you already have some design where the canvas will open up. Just toggle the correct input action maps at the same time

rich adder
solid oyster
#

it says in the code the intensity changes but the prefab does not change at all

naive pawn
#

you probably wouldn't want to modify the prefab?

#

you'd be modifying a copy/clone/instance of the prefab instead

#

sidenotes:

  • not sure you should be using PlayerPrefs for this - or at all, since it's not really being utilized as anything other than a variable
  • this is a "set" method, not a toggle
solid oyster
#

the toggle is in another scene

naive pawn
#

no, this just functionally isn't a toggle

#

a toggle would be like this:

bool state;
void Toggle() {
  state = !state;
}
```what you have is more like this```cs
bool state;
void SetState(bool x) {
  state = x;
}
solid oyster
#

i see

#

didnt realize how much toggle boxes would kill me in this

naive pawn
#

to be clear - the note about the toggle is just a naming thing, it's not really a logical issue

solid oyster
#

i see

solid oyster
polar acorn
solid oyster
#

im studying a level computer science so my knowledge is somewhat limited

vast matrix
#

I know this sounds dumb, but ive been struggling to get unity to recognize if the player is pressing R for the past 20 minutes. Im current using Input.GetKeyDown(KeyCode.R). I am so confused on why it isnt working

polar acorn
#

Remember - the prefab itself is simply a template. You copy the template and create a whole new thing. That thing has no connection back to the prefab, and the prefab has no connection to the things it makes. You'll want your toggle box to know which target you want to modify

polar acorn
rich adder
solid oyster
vast matrix
solid oyster
#

does that mean for every target in my scene i would have to alter those?

rich adder
vast matrix
vast matrix
rich adder
vast matrix
#

But none relating to what im trying to do now

solid oyster
#

i think im gonna forget the whole toggle thing for now, it was kind of a last minute addition to my program i thought would be fun and simple to implement

rich adder
solid oyster
#

maybe after a few prototypes ill come back to this

naive pawn
rich adder
#

true true, any use of Input class would error

#

especially polled in Update

vast matrix
rich adder
vast matrix
# rich adder so what was it...

Kinda embarrassing, but basically I was using the invoke method after I detect R, and basically I messed up the Invoke method

#

I put Invoke("Reload()") instead of Invoke("Reload")

rich adder
#

strings are ugly and error prone anyway

vast matrix
#

yeah

rich adder
#

you should learn Coroutines if you want to make delayed functions, they offer more benefits

vast matrix
#

Invoke works for the simpler stuff such as reloading a gun

naive pawn
#

but is very fragile and not very maintainable

#

coroutines are way easier to work with and keep track of tbh

rich adder
#

if(reloading) return
StartCoroutine(Reload())

IEnumerator Reload(){
reloading = true
yield return new WaitForSeconds(reloadTime);
//Reload weapon()
reloading = false```
whats so difficult about that
naive pawn
#

even with Invoke, you'd need all the same pieces, just arranged differently

polar acorn
#

So, Invoke is kind of a "noob trap"

#

It's more intuitive, but also more incorrect, so while it feels simpler to learn it's going to clip your wings in the long run. (similar to the old Input Manager vs new Input System but that one's mostly because decades of Unity tutorials were written for it and there's not enough new stuff to override that yet)

vast matrix
#

Ok Ill keep that in mind for the future

rich adder
#

very true.
ontop of everything else

  • you cannot pass arguments to Invoke
  • you cannot stop specific Invokes , especially ones that repeat
silver fern
#

I added a Box Collider 2D to an object, but I can't see the collider in the editor so I can't change it. Is there any way to move it or draw a new one?

rich adder
#

also not really a coding question

silver fern
silver fern
#

ok ty

vast matrix
#

How would I be able to use a variable in a different script than the one it's declared in

polar acorn
grand maple
#

does anyone know how to run the debugger through unity? i have breakpoints but when i run my code, it doesn't stop at the breakpoint

blissful crag
#

im not sure if this is what you mean but theres a small debug button on the bottom right of the unity project screen usually

#

this icon

west garnet
#

does anyone know how could i make the npc freeze or at least not move once they die?

west garnet
rich adder
west garnet
rich adder
west garnet
#

he doesnt explain much

#

anything tbh

strong wren
#

Presumably you would create a dead state and figure out how to transition to it.

rich adder
#

well you have to make the script that moves it, not do that

blissful crag
#

i have no idea what im talking about and this should probably be disregarded because its inefficient but what if you save the location of the enemy at death and jsut keep it there

rich adder
#

tossing them into FSM without any explanations how the system works or how to extend it , is just oversight of this "professor"

west garnet
#

also a radar script that he did and didnt explain it to us

#

i made my own with youtube but this class its mostly the prof telling us what to do giving us code and we doing a different version yourself

rich adder
#

so is the "Freezing" it into place part of the curriculum or , what is the objective

west garnet
#

i made the health system with an observer pattern and once the health is 0 they play the dying animation but they still follow the waypoints that i made for them to follow

#

so i got no clue just to make them freeze

rich adder
#

make a new state to transition into when that event occurs or disable whatever the movement into waypoints script is

west garnet
rich adder
#

You could potentially destroy the entire object and then create a death copy at the position.. but thats pretty cumbersome even if its easier on the surface

vale lintel
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

solid oyster
#

anybody know why this code doesnt work when the program is complied

rich adder
solid oyster
#

runtime

rich adder
#

also next time post code with links not screenshots

polar acorn
solid oyster
#

changed colour to cyan and all my targets were cyan

solid oyster
polar acorn
solid oyster
polar acorn
rich adder
#

so then whats "not working"

solid oyster
#

because

#

when i build it

#

and run it

#

it doesnt work

naive pawn
#

this is such a roundabout way to map values

rich adder
naive pawn
solid oyster
#

during runtime, it works perfectly fine

#

but after i build & run it doesnt change the colour

#

the actual dropdown stays constant

rich adder
#

Debug it

rich adder
solid oyster
#

do i need to sned avideo explaining the situation

#

ok

#

fine

rich adder
#

okay but really you should be learning debugging it, starting with logs in changeColor to see if thats even running in build

solid oyster
#

ill send a vid rq

#

here

#

i dont get why this happens

#

done some googling and will i have to use a different render pipeline?

rich adder
#

no

solid oyster
#

whats the issue then

rich adder
solid oyster
#

ok you want me to debug.log and see what the output colour is?

rich adder
#

log everything you can, narrow down to issue

#

check the Player logs / Devbuild console to see it specific to a build

solid oyster
rich adder
eternal falconBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

rich adder
#

check the "Development Build" checkbox in Build page

#

editor and build don't share the same value/location *onwindows

calm wedge
#

Hey there,
How do I paint a terrain at runtime?
I generate a Maze for my Project on Start. This Maze has different Biomes. In order to detect what Biome is where I have a render texture that is generated after the maze by a orthographic camera. It outputs a 256x256 RGB Texture that is colored differently for each biome.
Now I want my terrain to use a Sand texture wherever the Sand Biome is (color red on render texture), a grass texture where the grass biome (color green on render texture) is and so on. How do I do that in a way that doesnt break my performance? I dont need it to change after the generation as the maze doesnt change after that

rich adder
glacial cobalt
#

Hello iam trying to detect when object hits wall, tried using raycast acording to unity documentations but it doesnt want to work

#

thats from unity documents

polar acorn
#

Debug.Log = "touched wall"
This is nonsense

#

Configure your !ide so you don't make these mistakes in the future

rich adder
#

you scoped hit inside a if statement

eternal falconBOT
rich adder
#

yes use an ide compatible with unity out of the box like VS

glacial cobalt
polar acorn
glacial cobalt
polar acorn
rich adder
glacial cobalt
rich adder
#

hit is scoped inside the entire FixedUpdate method

#

yours is not

#

yours is inside the if statement block you did

#

hit only exists in if(right) block

glacial cobalt
#

okay

#

yeah stupid mistake

rich adder
#

just basic c# mistake, make sure you do beginners c# course before doing unity

#

doesnt help that you're using vim rn

#

your formatting is all over the place

glacial cobalt
rich adder
#

make sure the IDE is properly configred to work with unity so you also get proper syntax error highlight and intellisense

polar acorn
floral garden
balmy vortex
#

hey does anyone have an updated guide on how to grab inputs and move 3d stuff in unity?

#

cuz like I figured out how to take 2d inputs but 3d stuff seems to be more complicated?

rich adder
rancid tinsel
#

!code

eternal falconBOT
rancid tinsel
#

https://paste.mod.gg/lwqumanhlpjj/0 I'm making a block breaker kind of game, and I've ran into the issue that when the ball moves too slow, it starts hugging the wall upon collision instead of actually bouncing off. This seems to be an issue only when the speed is too low - the obvious fix is to increase the ball speed, but that's a bad solution design-wise so I'm wondering if anyone knows of a better method?

timber tide
#

You're not using forces though

#

probably worthwhile to find a tutorial for it

rancid tinsel
#

oh yeah you're right

timber tide
#

your chatbot is making you do custom physics while also applying physics materials that wont do squat

rich adder
rancid tinsel
rancid tinsel
rich adder
wintry quarry
unkempt garnet
#

i have a dumb question, HOW do u guys test your online game? Every other engine i used just opens 2 windows. How do i join myself?

#

-no laptop

final trellis
#

so i have a class called CC_Spell, which contains an instance of the class CC_Spell_Range, which can either contain the normal CC_Spell_Range class or the CC_Spell_Range_AOE class ( which inherits CC_Spell_Range )

when i utilize JsonUtility.ToJson(CC_SPELL_INSTANCE); to turn it into a JSON string, will that disambiguation of which class it is be represented? if not, how would i? or is this type of data structure not supported by JSON

polar acorn
rich adder
balmy vortex
vagrant mist
#

Is [Min(0)] public float MinIdleTime; essentially saying that whatever the value MinIdleTime is, it wont ever be lower than 0?

If so, why not use this instead of creating a separate static variable to compare MinIdleTime to?

balmy vortex
#

it's not what I used for my 2d demo which is the main thing that confuses me

rocky canyon
#

that for example wouldn't affect a runtime set variable

#

for runtime safe-guards u'd probably still wnat to use a property or clamping logic

rocky canyon
# balmy vortex oh well what's with the character controller thing that a lot of tutorials use?

for a chacter controller ur still usually only using 2 axis of inputs
WS-AD , arrow keys, joysticks etc
Horizontal and Vertical.. (for a 3d space w/ a cc normally the Horizontal controls the Y movement (left right) Vertical controls the X movement (forward and backwards)
and then for the third axis Z its normally controlled with a mix of gravity logic and for example the spacebar key (for adding force on the Z axis (up and down)

#
            float horizontalInput = Input.GetAxisRaw("Horizontal");
            float verticalInput = Input.GetAxisRaw("Vertical");

            Vector3 input = new Vector3(horizontalInput, 0, verticalInput);

            moveDirection = input * moveSpeed;
            controller.Move(moveDirection * Time.deltaTime);```
super simple example ^ without normalization or local -> world conversions
warm palm
#

Does anyone have any clue as to why my EnemyBody is avoiding the player in my "Roll a ball" project? I was wondering if it was the code but I even went as far as to copy and paste the entire code from the tutorial page into my PlayerController.cs script and it still happens and there's no mention of this issue on the tutorial page...

#

from "Step 7: Set the win and lose conditions"

rocky canyon
#

first glance it looks like an offset problem

#

like the EnemyBody is offset from teh actual object thats rotating
and the Enemy gameobject appears to be rotating relative to the player
but since the enemybody is offset looks like that

wintry quarry
#

there's nothing stopping you from making a controller similar to your 2D one

warm palm
# rocky canyon first glance it looks like an offset problem

It was, thank you! I moved the EnemyBody so the game wouldn't start with the enemy on top of the player and instantly lose from colliding on game start but I didn't realise I had to move the Enemy gameobject too, I just reset both their positions and then moved them both together to the side so the game could start and now it's working

rocky canyon
#

to see where the actual transform is

rocky canyon
#

i made that mistake 100s of times when i first started.. and sometimes still do 😬 lol

rocky canyon
hazy dagger
#

hello, i´m making a 2D puzzle game where the player slides around the map, i´m using addForce to move them around, i´d like for the player to snap in the middle of tiles when it stops moving but i can´t make it work, i´m using the code below, also "rb.velocity = Vector2.zero;" isn´t stopping the player

private void FixedUpdate()
{
if (rb.velocity.magnitude < 0.05f)
{
transform.position = new Vector2(Mathf.Round(pos.x - 0.5f) + 0.5f, Mathf.Round(pos.y - 0.5f) + 0.5f);
rb.velocity = Vector2.zero;
}
}

polar acorn
#

If you're planning on doing movement by snapping to a grid you probably don't want to be using forces or velocity

#

You probably wouldn't even be using Rigidbodies, but if you do it'll probably be Rigidbody.MovePosition

hazy dagger
#

aren´t rigidbodies important to make stuff collide?

polar acorn
#

If everything is grid-based you probably don't even need to detect collisions, you just need to know what object is in the space you're trying to move to

#

But even if you do want physics-based collisions you probably don't need velocity or forces

#

Those are important for making a realistic movement system but you're already not being realistic if you're doing grid-based movement

hazy dagger
#

just a playtest level

#

also i noticed a long while back that the player triggers scripts when the spites touch and not when the colliders though, the player is supposed to be slightly inside the portal (though i´d prefer it if was completely inside) but it gets teleported as soon as the sprites touch instead, same goes for a switch i made, the scripts work but visually it´s annoying

#

is this because of the rigidbodies?

floral garden
#

do someone has experience in visual novel game ? (creating)

subtle sedge
#

Nope

#

but i assume it would be super easy to make

floral garden
subtle sedge
#

i never made one tho so i cant say im 100% sure

#

but it sounds like you can just use unity and inky to make that type of game

floral garden
subtle sedge
rocky canyon
floral garden
floral garden
daring heath
#

i have something i want to happen only once a state has changed: for example while a player might get a new quest while in dialogue, i don't want the "new quest" notification to play until the player is out of dialogue; how do i store the notification to make it wait until dialogue is over and then play?

rich ice
#

maybe you could store the notification in a queue. once the dialogue is finished you could set a bool, something like "NotificationDisplayable" or something, to true after an event which could be invoked after the dialogue finishes

Represents a first-in, first-out collection of objects.

rocky canyon
#

most simple would be boolean imo
canShowQuest = false;
once dialog finished set true;
once true -> show quest -> set back to false (awaiting next time)

#

but yea not jordan is onto something

daring heath
#

will look into queues thank youu

hazy dagger
#

had some code that looped the addforce

rocky canyon
#

storing it would be the simple part.. store it however u wish.. (in a variable i suppose)

#
public class Quest
{
    public string title;
    public string description;
    public int rewardXP;
    public bool isCompleted;
}
``` as an example
then its just a variable
`Quest pendingQuest = questGivenByDialogPossibly;`
#

i've not made a quest system just yet.. but i would think something like that naturally.. now i need to make one 😅

#

imo the harder part of quest systems is checking when the quest isCompleted

grand snow
#

Ah yes the logic for quest conditions

#

I did something recently to let me have semi configurable conditions based on value comparisons

rocky canyon
#

was it fun? sounds really fun lol

#

simple value comparisons would be about the only quest validation i'd like to even attempt..
"did you collect enough chickens?"

floral garden
#

is better to overload an function or use different name ?

wintry quarry
#

If it's doing the same thing just using some optional parameter(s), then it makes sense to overload. If it's doing something different, then you make a different method.

floral garden
#

I have 2 function loadAsset from my addressable manager, one return void and other Task<T>

wintry quarry
#

I would probably make the one that returns Task LoadAssetAsync or something

floral garden
#

both do the same

wintry quarry
#

presumably they have different argument lists?

floral garden
#

no

#

all same

wintry quarry
#

that's not possible

floral garden
#

just one return nothing and other a Task<T>

wintry quarry
#

you can't make two functions with the same name with two different return types but the same parameter list

#

it's a compile error

floral garden
#

I need to launch then ?

#

i don't have any error show in vs

wintry quarry
#

Think about it

floral garden
wintry quarry
#

those have two different parameter lists

#

as I said

floral garden
#

oh yeah I hasn't see the action

wintry quarry
#

No I wouldn't name them differently

floral garden
#

my bad

#

so the same name MCSenkoThinking

#

thanks

hazy dagger
#

why does the "OnTriggerEnter2D" trigger when the rigid bodies touch and not the colliders touch?

north kiln
#

Also, rigidbodies logically combine child colliders for collision callbacks

hazy dagger
#

i solved my problem with "yield return new WaitForSeconds"

#

wanted the player and other objects to teleport when in the middle of the portal, instead of the edge

rancid tinsel
#

how can line 34 throw a null reference?

rich adder
rancid tinsel
#

but weirdly I entered playmode again and it disappeared so maybe something else broke and it freaked out here randomly

teal viper
unreal dock
#

!bug

eternal falconBOT
#

🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!

💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

vagrant mist
#
 void FixedUpdate()
 {
     if (IsDodging)
     {
         rb.linearVelocity = new Vector2(moveInput.x * dodgingPower, moveInput.y * dodgingPower);
         return;
     }
     else
     {
         rb.linearVelocity = new Vector2(moveInput.x * moveSpeed, moveInput.y * moveSpeed);
     }
 }

I'm currently using this as a way of moving my character across the screen. If I wanted to make my character slightly jerk forward when it's attacking by using ForceMode.Impulse2D, would I need to change the way I handle the movement here? I mean like instead of setting the rb.linearVelocity how I have here, is there a more appropriate way to handle character movement if I want my character to be affected by forces on top of simply moving it

#

I tried

public class PlayerController : MonoBehaviour
{
Vector2 moveInput;

  public void OnAttack(InputAction.CallbackContext context)
{
    if (playerAttacks != null)
    {
        if (context.started)
        {
            playerAttacks.MeleeAttack();
            rb.AddForce(moveInput.right * 5f, ForceMode.Impulse);
        }
    }
}
}

but whenever I try to attack, everything else but the AddForce() seems to work fine

wintry quarry
#

A common approach is to temporarily disable the normal movement code during a dash.

#

Another option is to switch over fully to controlling things via forces

vagrant mist
#

I'm thinking about doing the latter. Im testing it now and its moving but I still need to configure the force value and a way to add some friction

vagrant mist
wintry quarry
#

It's simpler to control the object with

#

A purely force based controller will be much more complex

vagrant mist
#

ah, so maybe mix and matching controls with force and directly overriding the velocity

crisp fiber
eternal needle
rare basin
#

why everytime i fill my dictionary (using GenericDictionary from github for many years, no issues), then going out of the prefab and entering the prefab mode again, it's all nulls

#

why are the references being deleted...

sour fulcrum
#

Initial assumption is it's the plugin/asset/package

#

Hard to say without specific infos

hexed terrace
#

first thought is - that's not code!
second is - possibly trying to save references to objects not in the prefab

grand snow
#

Oo yea it may not account for this

fresh kestrel
#

aight thanks

#

perhaps 🤔

#

Wait a minuite.

#

I never let disrespect slide

#

bro why cant i post gifs

#

4 years and this server is still ahh

north kiln
patent wedge
#

hey for some reason in the editor the character controller.isGrounded is fine but in build its constantly jittering?

native flame
#

I've read that when using a rigidbody character controller, you should read inputs in Update() and do AddForce() in FixedUpdate(). Does that apply to just WASD inputs or also jumping, sprinting, and crouching?

grand snow
#

For intermittent things like jumping it best to in case the input is missed
you can just add the jump force in Update() because it gets stored and applied next fixed update anyway

wintry quarry
#

Recommended to use your own grounded check

frosty hound
#

It's a capsule cast, making your own check would be a capsule cast?

#

The only issue I've seen with isGrounded not being consistent has been a misunderstanding how to use the CC properly (applying downward force constantly vs. assuming that it's a one time automatic check)

foggy yoke
#

i'm trying to get the velocity of the player, but rb.linearVelocity returns the velocity in world-units, and I need the local velocity. Thank you

wintry quarry
#

E.g. InverseTransformDirection

foggy yoke
#

does that work in 2d?

wintry quarry
#

Why not

foggy yoke
#

okay

#

lemme try that

native flame
#

Why does TransformDirection seemingly do the exact opposite of what the docs state? If I don't convert moveDir to localDir, all my movements are in world space and don't respond to the rotation of the player object. But according to the docs, the method only converts from local space to world space, even though I am using it for the opposite

#

I assume I am somehow misunderstanding world v local space but I'm not sure where

rich ice
#

so, you have world space movement and you're using a method that converts from local to world space movement. you already have world space movement though so it does nothing.

#

anyway im pretty sure you can just do transform.rotation * moreDir to get localDir.
neat tip if you didn't know, you can multiply quaternions and vectors to rotate vectors (gotta make sure they're the right way around though)

timber tide
#

where you seeing this

#

Inverse is world to local

rich ice
#

oh right, i completely forgot the inverse exists aswell

slender nymph
#

also note that your raw input would be considered the local direction because presumably you are pressing the input based on the direction you want to travel relative to the camera's rotation so that would need to be converted to world space

#

so while the comments and understanding are wrong, the logic would be correct

native flame
native flame
zealous talon
#

ok i'm posting the code for the game-does-not-start problem

slender nymph
#

please read what i said then read the documentation for the method you are using to convert from local to world space.

native flame
#

i read what you said

#

which is how i responded to what you said

zealous talon
slender nymph
#

so then surely you understand that your movement is in world space because of the TransformDirection method and not because you converted from a Vector2 to a Vector3

#

!code

eternal falconBOT
native flame
#

if i dont use TransformDirection, movement occurs in world space

#

which is why I use it, so movement responds to player rotation

slender nymph
#

so you are still misunderstanding the difference between local and world space

#

the way you move expects a World Space direction. your input is in Local Space. if you do not convert the input from Local Space to World Space then the movement will be wrong because your input is still in local space. as in, it is a direction that if applied locally to the object would move it relative to its rotation

#

For example, let's say you have an object at 0,0,0 facing backwards (its forward direction is (0,0,-1)
If you move that object forward along its forward direction, that is a local translation of 0,0,1. But because it faces backwards it's world space translation would be 0,0,-1 because that is the direction it moved relative to the world

keen dew
scarlet skiff
#

what could i possibly be missing here...

slender nymph
#

look at the previous line

scarlet skiff
#

oh i deleted the ; somehow

#

cheers

zealous talon
keen dew
#

right

zealous talon
#

thanks you saved me

native flame
#

Thanks for the explanation

zealous talon
#

btw i think i still miss something essential about coroutines, any guide or video i can follow in order to understand them better?

native flame
zealous talon
#

thx

patent wedge
#

does anyone know how to manually set the rotation of a bone with animations i've tried setting the rotation in lateupdate but that didn't work.

rich adder
eternal flicker
#

sorry, not sure if this is the right place to ask this but i am brand new to makeing games at all and when I tried to build my game to send it to a friend this poped up. anyone know how to fix this?

vapid ledge
#

are properties generally used for unity projects or do people just use public fields

#

they are a pain to serialize so i'm just wondering if they're worth it or not

rich ice
#

main thing i use them for is changing them through UnityEvents

vapid ledge
#

huh okay

#

i have not used unity events at all before

slender nymph
rich ice
vapid ledge
#

alright ty

vast matrix
#

How would I be able to replace a placeholder model with the actual model I want to use?

grand snow
#

copy over the existing model so the guid is kept (external to unity editor)

rigid drum
#

Guys, someone knows if Cloud Code Logs have a limit? It seems that the logs of my C# modules stopped appearing there :p

boreal plinth
#

Yall how do I get interact to work when I press E? I watched a tutorial, but "Interact" doesn't show up on the second image

rich adder
boreal plinth
#

I just get:
"ArgumentException: Input Button Interact is not setup.
To change the input settings use: Edit -> Project Settings... -> Input Manager
UnityEngine.Internal.InputUnsafeUtility.GetButtonDown (System.String buttonName) (at <8464a637132d4cf7b07958f4016932b9>:0)
UnityEngine.Input.GetButtonDown (System.String buttonName) (at <8464a637132d4cf7b07958f4016932b9>:0)
NPC_Talk.Update () (at Assets/GAME/NPCs/Scripts/NPC States/NPC_Talk.cs:30)"

rich adder
#

one way to use would be putting a PlayerInput component with that action asset, then you just put a method in scrip on same object,
void OnInteract(InputValue val){ Debug.Log("InteractPresed"); }

boreal plinth
#

I know. I'm just posting the error message

rich adder
#

You cannot do Input.GetButtonDown("Interact") if its not added to list on right

boreal plinth
#

I know. But the guy I was following a tutorial on had an "Interact" tab on that one

rich adder
#

"Interact" tab on that one ?
what one?

boreal plinth
#

My second image

rich adder
#

oh they did not show how to add a new entry

boreal plinth
#

Nope

rich adder
#

make the 30 to 31 , then the new entry at the bottom can be modified as needed

boreal plinth
#

Ah thank you

rigid drum
#

It seems that sometimes the logs just stop appearing, it's really strange

rich adder
rigid drum
#

yep, its weird because sometimes shows part of the logs and "lost" the rest.

high wagon
#

im trying to change an object's material when a button is pressed, and earlier it was working fine, but now it keeps outputting this error. does anyone know why?

high wagon
#

alr

high wagon
rare basin
#

is there a way to check if given game object is a instance or a prefab?

#
public void AddItemToBox(Item item)
{
    //if prefab, then make instance and add to list
    itemsInside.Add(item);
}
#

if(!item.gameObject.scene.IsValid()) will work?

calm wedge
#

How do I make my NavMesh generation more performant?
I can't really pre-bake it as I generate a maze at runtime. Whenever I try to either _navmeshSurface.BuildNavMesh(); or UpdateNavMesh(_navMeshData); the entire scene freezes and doesnt recover (even after 5+ minutes).
I've tried lowering the NavMesh quality significantly by reducing the tile size from 256 to 64 and increasing the voxel size from 1.667 to 3. This still froze the scene.
What should I do? I use a default terrain with no changes to the size. My Maze uses prefabs (basically just 4 wall) were walls are being deleted for the randomness.

wintry quarry
rich adder
rare basin
#

so i can drag&drop the item prefab to the scene and using odin inspector's Button via inspector

#

add the item to the chest

#

tldr just to add items to the chests in playmode via editor to test stuff

sour ruin
#

how do you detect mouse clicks from a script that extends editor when the user is clicking at any point on the screen. The OnInspectorGUI method is only invoked as far as im aware when Event.current != null but clicking anywhere other than on a gui element doesnt trigger EventType.MouseDown. I cant tap into the EditorApplication.update because Event.current is always null.

#

the hierarchy window is able to do it and you can validate that it does by selecting a scene object and then clicking somewhere on another window to deselect the gameobject

rich adder
azure token
#

im trying to figure out how to start a host from a lobby

#

new to this anyone have an idea? lobby works fine

rich adder
azure token
#

my b forgot they switched servers

azure token
rich adder
azure token
#

i understand that netcode is different from lobby code im just trying to understand how to get those players into the game

#

yes

rich adder
#

there lots of resources on this topic. Anyway that channel linked is the place for those Qs

calm wedge
rich adder
calm wedge
# rich adder wdym "only task manager can help there? " also don't get the last part

I cant stop the game from running by using the stop button or the windows close button. I have to use the windows task manager to forcefully kill the unity project.
About the last part:
In the documentation it says that I have to call the UpdateNavMeshDataAsync() function in order to update it asynchronously while the game is running - this shouldnt effect performance too much and could easiely be hidden by a small 5-10 second loading screen - or at least should be. Sadly there is no UpdateNavMeshDataAsync() function to call from the NavMeshSurface script. When checking out the NavMeshSurface's functions in their code I've seen the UpdateNavMesh() function. In its description it is marked as asynchronously:

/// <remarks> This operation is executed asynchronously. </remarks>
...
public AsyncOperation UpdateNavMesh(NavMeshData data)

But it still freezes even if using this. I cant imagine that the baking operation - that takes less than a second in editor - would take more than 5 minutes in play mode on a standard unity terrain

sharp mirage
#

im making a script for my player to be able to ledge jump across buildings using a raycast and everythings functional, the idea is for their horizontal velocity to gain like a massive speed boost so they can close the gap quickly but it didnt rly function well as i multiplied my linear velocity X by some multiplier, what could work better with the code?

#

wait forgot to comment it

delicate condor
#

what do i do i try make a project and try opening it and it says "failed to decompress" how do i fix

wintry quarry
#

(multiplied by the sign of the current x velocity of course)

sharp mirage
sharp mirage
#

but it didnt clamp back and my players velocity was just constantly multiplied by 5

rich adder
mystic flume
#

i finished vector3 and raycasting what should i do now

wintry quarry
foggy spade
#

is it bad to rely on ai for debugging?? i generally cant find the issue without it but it feels shameful

sour fulcrum
#

Yes it is

#

Ideally you should be more than capable to troubleshoot and debug directly via google and other resources

#

But debugging and troubleshooting in itself is a skill that is crucial to develop

cosmic dagger
foggy spade
#

okay, ill try fixing some errors without it thank you!

sour fulcrum
#

If you get stuck feel free to ask. If your trying people here will be more than happy to help, whether that be directly helping that specific issue or supporting you in how you could potentially have found the solution yourself

cosmic dagger
#

Especially, if the error has a stack trace to follow . . .

foggy spade
foggy spade
#

tysm!

rich adder
cosmic dagger
past sentinel
#

Im having an issue making my player controller. is it okay if i ask about it here?

cosmic dagger
#

If it pertains to code, sure . . .

past sentinel
#

so im having an issue where my player is sticking to walls when i jump into them. This is the script my player uses

wintry quarry
#

you're esserntially pushing your player against the wall

#

so it sticks due to friction

past sentinel
#

my player amteral has no friction

wintry quarry
#

in real life people cannot push against a wall in midair, hence no pushing and no friction

wintry quarry
past sentinel
wintry quarry
wintry quarry
#

Don't ignore Friction Combine

#

it's very important

past sentinel
#

oh minimum fixes it

#

also what can i do to limtie player air movment?

wintry quarry
#

write code that limits it

#

using raycasts and the like to detect when you are going into a wall, for example

foggy spade
#


public class GrappleScript : MonoBehaviour


{
    public GameObject[] Grapple;
    float Distance;
    private GameObject NearestObject;
    private LineRenderer lr;
    private SpringJoint joint;
    private float NearestDis;

    void Awake()
    {

        joint = GetComponent<SpringJoint>();
        lr = GetComponent<LineRenderer>();
        joint.autoConfigureConnectedAnchor = false;

    }

    // Update is called once per frame
    void Update()
    {
        Grapple = GameObject.FindGameObjectsWithTag("Grapple");

    }

    void StartGrapple()
    {
        if (Input.GetMouseButtonDown(0))
        {
            joint.connectedBody = NearestObject.GetComponent<Rigidbody>();
            joint.spring = 5;
            joint.damper = 0.5f;
            
            
        }
        



    }


    void StopGrapple()
    {

    }

    void DrawLine()

    {
    }

    void NearestObj()
    {

        for (int i = 0; i < Grapple.Length; i++)
        {
            Distance = Vector3.Distance(Grapple[i].transform.position, transform.position);



            if (Distance < NearestDis)
            {
                NearestDis = Distance;
                NearestObject = Grapple[i];
            }
        }

    }

} 


```  i havent finish this yet but for some reason the object is connected to the air
#

it just bounces around

wintry quarry
#

Aren't you seeing an error in your console window?

foggy spade
#

no i havent gotten any

wintry quarry
#

You're also not even calling StartGrapple either

foggy spade
wintry quarry
#

so yeah your joint is just going to be connected to nothing

foggy spade
wintry quarry
#

hence - connected to the air

foggy spade
#

let me go do all of that and ill be back if its still not working

wintry quarry
#

what are you expecting it to do

#

there's a lot of fishy stuff in this script - like the FindWithTag in Update etc

foggy spade
# wintry quarry what are you expecting it to do

i wasnt expecting it to do anything currently i just thought it was weird it was hanging from the air, but im trying to make a grapple that connects u to the nearest object that has a grapple tag

past sentinel
#

how can i see what number something is the closest to? im dealing with floats as well. Im scaling stuff but sometimes it comes out at a number it should. it should be at 2, 1, 0,5, or 0,25.

wintry quarry
wintry quarry
#

do you mean the nearest integer?

#

or maybe the nearest increment of 0.25 or something?

past sentinel
foggy spade
past sentinel
#

i supoose to put it simply

wintry quarry
#

e.g. log base 2 of 0.32 gets you -1.64, which rounds to -2, and 2^-2 gives you 0.25

digital haven
#

Trying to transfer over my files from another pc but it won’t load for some reason. I’m sure I did everything right any thoughts?

past sentinel
wintry quarry
digital haven
#

My first attempt I downloaded a copied folder of the game from my OG pc and brought it over from a usb.

Second what I did tonight, I copied all 13 of those files, put them on drive and downloaded them from gdrive.

#

I tried using GitHub but it says the files were too big so I didn’t go that way. Around 14 gb big

wintry quarry
wintry quarry
digital haven
#

So the other stuff I delete it and it’ll work?

wintry quarry
#

yes

#

well, maybe.

#

but yes you should not copy the other stuff

#

it is not useful and certainly may be causing the crash

#

especially Library, Temp, and obj

naive pawn
wintry quarry
#

instead of manually copying anything

digital haven
#

It should be the same version as the one on my main Pc

#

Oh what’s version control?

wintry quarry
#

version control is softwre, such as Git, which is used to manage software project files

#

and to allow easily cloning it, tracking changes, collaborating with people, etc

digital haven
#

Is there a size limit for projects?

wintry quarry
#

that's a vague question

#

there are many different types of version control

#

and many different providers

digital haven
#

I see, I don’t really know much about version control.

But it sounds like it be easier to manage the game I’m working on

wintry quarry
#

It will be easier for managing any game than manually copying files around, yes.

naive pawn
#

there's lfs (large file storage) though

digital haven
#

Is there a guide or tutorial I could walk through to set it up?

naive pawn
#

there are plenty online

#

this is the code channel

foggy spade
#


public class GrappleScript : MonoBehaviour


{
    public GameObject[] Grapple;
    float Distance;
    public GameObject NearestObject;
    public LineRenderer lr;
    public SpringJoint joint;
    private float NearestDis;
    public Transform GrappleTip;

    void Awake()
    {

        
        lr = GetComponent<LineRenderer>();
        

    }

    // Update is called once per frame
    void Update()
    {
        Grapple = GameObject.FindGameObjectsWithTag("Grapple");
        NearestObj();
        StartGrapple();
        StopGrapple();

        DrawLine();
        Debug.Log(NearestObject);

    }

    void StartGrapple()
    {
        if (Input.GetMouseButtonDown(0))
        {
            joint = GetComponent<SpringJoint>();
            joint.autoConfigureConnectedAnchor = false;
            joint.connectedBody = NearestObject.GetComponent<Rigidbody>();
            joint.spring = 5;
            joint.damper = 0.5f;

            
            
        }
        



    }


    void StopGrapple()
    {
        if (Input.GetMouseButtonUp(0))
        {
           
            joint.connectedBody = null;

            NearestDis = 0;
        }
    }

    void DrawLine()

    {
        if( joint.connectedBody != null)
        {
            lr.enabled = true;
            lr.SetPosition(0, GrappleTip.transform.position);
            lr.SetPosition(1, NearestObject.transform.position);
        }
        else
        {
            lr.enabled = false;
        }
    }

    void NearestObj()
    {
        NearestDis = Mathf.Infinity;
        for (int i = 0; i < Grapple.Length; i++)
        {
            Distance = Vector3.Distance(Grapple[i].transform.position, transform.position);



            if (Distance < NearestDis)
            {
                NearestDis = Distance;
                NearestObject = Grapple[i];
            }
        }

    }

} 
#

my script is to grapple and swing to the nearest object and it works fine but when i let go it goes back to the middle of the game

wintry quarry
#

right because you're disconnecting the joint

#

As I was saying before you shouldn't really have the joint created at all until you're grappling

#

create it when you grapple, destroy it when you stop

foggy spade
#

okay!! thank you

mystic flume
#

why is my game zoomed in like this and how do i fix it

north kiln
#

Also, don't cross-post.

mystic flume
neon glade
#

i wanna do this game mechanic where there is a wall that appears and they can pass through if they press a key. does anyone know how i can make this work?

wintry quarry
lofty mirage
#

Hey guys, hope you're having a good day!

#

Keep it up champs!!

sour fulcrum
#

Being a dumbass and would love a pair of eyes rq,

I have this old code

        Vector3 returnValue = Vector3.zero;

        if (Physics.Raycast(UIManager.TrackingCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, layerMask: lookMask, maxDistance: Mathf.Infinity, queryTriggerInteraction: QueryTriggerInteraction.Ignore))
            returnValue = hit.point;

        if (returnValue != Vector3.zero)
            prevMousPos = returnValue;
        else
            returnValue = prevMousPos;

        return (returnValue);

that i'm attempting to simplify to just

        if (Physics.Raycast(UIManager.TrackingCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, layerMask: lookMask, maxDistance: Mathf.Infinity, queryTriggerInteraction: QueryTriggerInteraction.Ignore))
            prevMousPos = hit.point;

        return (prevMousPos);

But my refactor is not working and I cannot tell what I am logically doing different here

fiery veldt
#

Hey, I'm having trouble using Unity playworks plugin. According to Playworks documentation: Unity Playworks Plugin supports DoTween up to version 1.2.705 but for some reason it isn't being recognized

Unity Engine:2022.3.47f1
Unity Playworks Plugin version: 6.3.0
DOTween version: Tried both 1.2.705 and 1.2.690

neon glade
#

its hard to explain i think i know what i would make as the concept but im not sure how to actually do it in code

wintry quarry
#

Which seems like a bug in the first one

wintry quarry
neon glade
#

yes ill be back tonight 🫡

past sentinel
#

for soem reason my camrea is speeding up in rotation between 0 and 90 degrees

naive pawn
eternal falconBOT
naive pawn
#

don't use deltaTime with mouse delta

#

it's already per-frame

sour fulcrum
#
    private IEnumerator Unload()
    {
        Debug.Log("Unloading Global Scene");
        yield return SceneManager.UnloadSceneAsync("GlobalScene");
        Debug.Log("Unloaded Global Scene, Status: " + SceneManager.GetSceneByName("GlobalScene").isLoaded);
    }
#

am i stupid

#

seems to be due to timing, not sure why

naive pawn
#

what if you add a yield return null;

sour fulcrum
eternal needle
# sour fulcrum ```cs private IEnumerator Unload() { Debug.Log("Unloading Global...

is it by chance the only active scene? not sure if unity gives you a warning in that case but cant unload a scene if its the only active one
otherwise you could check the values like isDone or progress to maybe get more insight.
https://docs.unity3d.com/ScriptReference/AsyncOperation.html for some reason they also have an extra yield return null. Maybe the actual unloading and loading of a scene happen on the next frame.
Could also try while !isDone yield return null

sour fulcrum
#

fuck sake

#

that will be it

#

docs are wrong

#

Note: It is not possible to UnloadSceneAsync if there are no scenes to load. For example, a project that has a single scene cannot use this static member.

eternal needle
#

whats wrong about that?

sour fulcrum
#

I have another scene

#

its just not active

#

thank you

eternal needle
#

i dont think the statement is wrong, it just doesn't specifically say "you can't unload a scene if there are no other active scenes" as well

#

they do word it weirdly

sour fulcrum
#

I think it's wrong in the sense it fails to convey the point

eternal needle
#

apparently it returns null when it cant unload the scene, so it was essentially just waiting a frame before telling you the scene is still loaded. Maybe its by design incase people actually want to try unloading scenes while its the only active one, rather than spitting out an error or warning

worn peak
#

I have a button object with a text as the child. I made the size of the button the whole scene, but it only reads the input, when I click on the text object inside the button

silk night
noble cedar
#

hello could I ask is there way to slowly rotate turrets like the heads of it with code so the turret wouldnt instantly look at the enemy that its suppost to shoot but like line up?

noble cedar
#

exactly what I was looking for 😄

grand snow
#

rotate towards will be more reactive to a moving target

silk night
grand snow
#

both are linear

silk night
grand snow
#

yea the ol lerp abuse

#

move towards is better still as you can specify the max rotation amount

silk night
#

Thats why I said with more code it behaves the same, as in I also recommend rotatetowards

noble cedar
#

ok so Ill use rotatetowards

brisk fossil
#

question how do i fix the pink on the water prefab? I already have the universal rp and tried to render pipeline converter but the water is still pink

#

im using the simple low poly nature asset

polar acorn
#

You will need to switch that material to a shader compatible with your render pipeline. The automatic converter will only work on built in shaders, if it's custom you'll need to do it manually

silk night
brisk fossil
silk night
#

oh wait, i thought you switched rendering backends, sorry

Yeah for the water there is most likely a more complicated shader that cant be converted, so what digiholic says applies

#

either get a free water shader from the asset store or watch a tutorial to make one

brisk fossil
#

Alright, thank you!

grand snow
#

all the converter does is change materials over to a URP/HDRP equivilent shader
e.g. Standard -> URP Lit

#

so any other custom shader doesn't work in this case

grand snow
#

also that project does NOT look like a good fit for hdrp 😐

silk night
#

oh wait, hdrp assets in the project 😄

grand snow
#

Yea i saw hdrp assets making me think its hdrp
Unless they are just trying anything and fucking it up more

silk night
#

yeah, but you can also see the shaderfile for the water, its a shaderscript

#

converting is possible but not for anyone at that level 😄

grand snow
brisk fossil
#

I see so that's why

grand snow
# brisk fossil yep im just trying anything

First change to URP, second try to see if using a URP lit shader on a material will be enough.
This shader is not compatible with anything other than the old built in renderer.

grand snow
#

Oo these are nice.

silk night
#

HDRP brings a default water system, but that is way overkill here

brisk fossil
grand snow
brisk fossil
#

thank you appreciate you two for giving time to reply

rare bison
#

can someone help me? the cooldown for the coroutine doesn't seem to be working. it's teleporting the player every frame instead of every 1 second

grand snow
#

!code

eternal falconBOT
rare bison
# rare bison can someone help me? the cooldown for the coroutine doesn't seem to be working. ...
using UnityEngine;
using System.Collections;

public class UpDownTeleporter : MonoBehaviour
{

    private StateHandler stateHandler;
    public LayerMask teleporterPad;

    public float cooldownDuration = 1f;
    private bool isOnCooldown = false;

    IEnumerator TeleportDown(Collider other)
    {
        Transform otherRoot = other.transform.root;

        if (Physics.Raycast(otherRoot.transform.position - new Vector3(0, 2f, 0), Vector3.down, out RaycastHit hit, 30f, teleporterPad))
        {
            otherRoot.transform.position = hit.point + new Vector3(0, 0.8f, 0);
        }
        yield return new WaitForSeconds(cooldownDuration);
        isOnCooldown = false;
    }
    
    IEnumerator TeleportUp(Collider other)
    {
        Transform otherRoot = other.transform.root;

        if (Physics.Raycast(otherRoot.transform.position + new Vector3(0, 2f, 0), Vector3.up, out RaycastHit hit, 30f, teleporterPad))
        {
            otherRoot.transform.position = hit.point + new Vector3(0, 0.8f, 0);
        }
        yield return new WaitForSeconds(cooldownDuration);
        isOnCooldown = false;
    }

    private void OnTriggerEnter(Collider other)
    {
        Transform otherRoot = other.transform.root;
        if (otherRoot.CompareTag("Player"))
        {
            stateHandler = otherRoot.GetComponent<StateHandler>();
        }
    }

    private void OnTriggerStay(Collider other)
    {
        if (stateHandler != null && !isOnCooldown)
        {
            if (Input.GetKey(stateHandler.crouchKey))
            {
                isOnCooldown = true;
                StartCoroutine(TeleportDown(other));
            }

            if (Input.GetKey(stateHandler.jumpKey))
            {
                isOnCooldown = true;
                StartCoroutine(TeleportUp(other));
            }
        }
    }
}
sour fulcrum
#

stress intensifies

north kiln
#

no idea, but if you crouched and jumped at the same time it would run both

silk night
#

which would explain the cooldown not working...

naive pawn
silk night
#

oh oops

rare bison
#

i tried moving it but it still doesn't work

north kiln
#

is cooldown duration set correctly in the Inspector?

rare bison
#

it is

rough granite
rare bison
rare bison
rough granite
rough granite
#

Also i would recommend using async / await over a coroutine

#

But that partly a preference thing

rough granite
#

Well having the same check in an if statement after its checked seems silly, but i doubt that would be the problem

raven pilot
#

Need to be checking for Key press instead of hold.

red igloo
#

I am using a character controller and I want to add a crouch feature. when I crouch I want it to smoothly change to both standing & crouching height. Should I use lerp? if so what type? or move towards? I heard people use different things but what would be the best for this?

rough granite
# rare bison

Make the isOnCooldown a public and watch (in the inspector) if it stays false until the cooldown is done or not if not than its the way you handle the cooldown

silk night
#

dont crosspost

rare bison
#

ok so i figured out the problem
i used one script for each teleporter instead of one script to handle all the teleporters, so the cooldown doesn't carry over to the next teleporter and it just starts another coroutine immediately
if that makes sense

rough granite
silk night
rough granite
rough granite
rare bison
#

that's a good idea i'm gonna do that now

raven pilot
rare bison
#

anyway thanks everyone for all the replies

patent wedge
#

for a basic inventory system how should i have multiple item types with icons should i have each object in the scene have some sort of tag etc.

elfin fulcrum
#

even the "beginner" code people post here is confusing 💔

wintry quarry
patent wedge
silk night
#

normal programming feels like climbing stairs
game programming feels like running into a brick wall with the intention to climb it 😄

grand snow
sour fulcrum
#

all the code is neat and tidy until some nerd ass designer wants juice

patent wedge
silk night
sour fulcrum
grand snow
wintry quarry
# patent wedge so i.e a scene with a bunch of objects that get parented to the player for picki...

You really need to break down the whole inventory system into different parts:

  • ScriptableObjects holding the item descriptions and assets (icons, names, descriptions, stats, etc)
  • An inventory script for managing what's actually in the player's inventory at any given time
  • UI prefab for representing the item in an inventory UI
  • A prefab/script for a representation of the object in the game world, if relevant (e.g. the version of a minecraft object as it's pickupable in the world)
#

depending on how your game works you need to handle all this stuff separately

#

Having a good separation of concerns here is critical

rotund root
#

the purpose of this code is to play a sound effect once when colliding with a pickup
AI recommended me to add the highlighted part, I tried run without it and everything seems normal to me
what's the point of the highlighted part
in what situation do i want that?

silk night
#

(can also just do pickUpSound?.Play()

rotund root
#

thanks!

cerulean badger
#

how do I find an inactive game object by tag?

rich adder
silk night
cerulean badger
# sour fulcrum why?

I want a npc to move from inside a door, and when the door's closed there's a collider that stops the player from passing through. I want to keep the npc inactive in the position inside the door so it not collides with the door and glitches yk

#

like this, the npc comes from there

floral garden
#

the stop play of unity is so brutal

#

!code

eternal falconBOT
floral garden
#

anyone has experience with dialogue system ? i am dying , i do it 3 days already and still can't make it work

cerulean badger
# floral garden anyone has experience with dialogue system ? i am dying , i do it 3 days already...

Introduction to dialogue editor with graph view tutorial series.

➤ Play List
https://www.youtube.com/playlist?list=PLOZ3CbLbuxPwQvkDMBiIe4v1pTwAE380z

➤ Tutorial Description
This tutorial will be focusing on how you can make a dialogue editor with the use of graph view.
You will also be learning how to make your own nodes so you can custom...

▶ Play video
cerulean badger
#

it's long as heck but I recommend watching his explanation so u can improve the system and stuff

floral garden
rich adder
floral garden
#

i don't know why but when I load the prefabs, it can't play or set the sprite

rich adder
#

"cant make it work" is pretty vague

floral garden
#

I load a prefabs characterFrame (gameobject) that contain Image and animator from the addressable
then I load a sprite and a clip from the addressable before applying it on the characterFrame that I loaded previously
but the clip can't be played on a inactif gameobject.
The prefabs is actif in default and the parent is actived before I place it as childen

sour fulcrum
#

(starting off with that kinda info is a big help)

floral garden
#

Yeah sorry

patent wedge
#

Get component in children returns itself?!

floral garden
#

hmmm ???

#

no

floral garden
#

rlly ?

rich adder
#

indeed

#

it starts recursive from itself

#

You would think unity would put a flag to ignore self but alas here we are..

patent wedge
# rich adder yes

i've never had this issue before thankfully i do have a solution in my situation thats still clean. but i would rather figure out a better way.

rich adder
floral garden
#

who is this arudoyu... ? (japanese name)

#

Btw, i still can’t figure out where my problem, maybe because it is in async ?

rich adder
floral garden
#

Wait i send you all the log i get (placed)

patent wedge
floral garden
#

Couroutine error is normal

#

It is used to check if the clip is played

rich adder
#

how so ?

floral garden
rich adder
#

no error should be normal lol This one is simple just dont start a coroutine on an inactive gameobject / Monobehaviour script

#

place logs through your Dialogue chain and see where its going

grand snow
#

"help my coroutine doesnt work and i cant read!"

floral garden
grand snow
rich adder
floral garden
floral garden
grand snow
#

I use addressables a lot and i dont really get what this script does

#

abstracting addressable stuff like this seems pointless

rich adder
naive pawn
ember arrow
#

I have zero experience and im trying to make a game and chatgpt is doing all my code 😭 does anyone wanna help

eternal falconBOT
#

:teacher: Unity Learn ↗

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

ember arrow
#

im not tryong to be a coder tho i just wanted to play this game and realized it didn;t exist so im trying to mke it really quick

naive pawn
#

!collab

eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

rich adder
#

" mke it really quick" UnityChanLOL

ember arrow
#

lol trust

#

bro it's not a serious collab lol

rich adder
#

trust someone with no experience to tell me a game is "real quick"

ember arrow
#

this is the least serious thing possible

#

ill explain it for yall

rich adder
ember arrow
#

balright

#

nav shut up bro im just tryna learn something

#

mb bro

rich adder
#

never too late to start learning how to post in the proper section UnityChanLOL

ember arrow
#

balright im not a discord no life bro

#

im just tryna get some input

#

aren;t i in code beginner right now

rich adder
#

for code questions for someone working on code, you're not asking a code question.

naive pawn
ember arrow
#

alright so where do I go for advice

#

im not posting a job tho

rich adder
#

advice on what ?

ember arrow
#

im in high school and im doing this cause im bored

#

my project thing

#

is this discord like for people who do this for work

rich adder
#

one doesnt make a game out of boredom, quite the opposite

ember arrow
#

or just like a cimmunity

#

i just wanna know what template to use on unity

naive pawn
rich adder
#

its a community for all different stages , only thing is you don't request work

ember arrow
#

where do i ask my question

naive pawn
#

we are here to help you make your own thing, not make stuff for you

ember arrow
#

i know bro

#

i have a question

rich adder
#

so ask it

ember arrow
#

what template should I use for a madden ultimate team type game but only pack opening so it's basically slots

naive pawn
#

what do you mean by "template" exactly? you're not gonna get a functioning game just out of a template

ember arrow
#

oh

naive pawn
#

all that is stuff you have to make

ember arrow
#

like 2d or 3d

floral garden
naive pawn
#

well, do you want to make it in 2d or 3d

naive pawn
rich adder
#

there are templates on asset store but very unlikely its specific to what you want

ember arrow
#

whats the render pipeline thing tho

ember arrow
#

nah yall are annoying wtf

naive pawn
#

literally in the rules

rich adder
#

just leave then

#

if you don't like to adhere to community rules, find another place to spam

ember arrow
#

who cares just stop making me feel dumb and answer the question

naive pawn
#

was going to.. and then you insulted me...

ember arrow
#

yall are sad bro this is genune no life discord rules yall nt even mods lighten up

floral garden
#

if you ask help, being kind is the first thing you should know

rich adder
#

"how not to get help 101 "

naive pawn
#

this is hilarious

ember arrow
#

ive been nice but yall keep being rude

naive pawn
#

yeah...

#

aight im out

rich adder
#

You took everything as negative so you are the only one escalating to hostile

ember arrow
naive pawn
#

yeah, and that person actually took it well too lmao

ember arrow
rich adder
#

oh please..if this is being rude, don't be on the internet..

naive pawn
#

...that was a joke...?

#

how is that seen as rude

frosty hound
#

@ember arrow Enough already, you're burying your own question.

ember arrow
#

alright can i ask it again and get an asnwer so i can leave the server

#

should i use a 2d thing or the built in render pipeline

frosty hound
#

The answer is, no template.

ember arrow
#

idk wat the redner thing is

frosty hound
#

Use URP.

ember arrow
#

how do i not choose a template

rich adder
frosty hound
#

Choose Universal 3D in your case

ember arrow
#

i dont know what core means im new to this like i just downloaded

rich adder
#

I just said what it means lol its literally a blank template (no assets or example files)

ember arrow
#

wakt why not 2d

#

im ajust use 2d

#

sorry for being rude

#

thanks for helpung me

naive pawn
#

if you want a 2d project you can use one of the 2d templates

frosty hound
#

You can choose either 2D or 3D and you're not locked into your decision. Behind the scenes, it's really just the same thing with different settings that can be modified anyway.

#

If you're trying to replicate a game, look at what they do, if it's 2D/3D.

timber tide
#

3D is just cooler 2D

floral garden
#

depend but yeah also, it is harder to code

naive pawn
#

it's not really harder, it's just different

#

there are different skills and mindsets involved

rich adder
#

all you're doing is considering Y is usually gravity , and ZX is your movespace by default (ofc depends on game style)

timber tide
#

(easier)

#

you get depth in 3D

#

so you dont have to do a custom sorting axis

rich adder
#

Unity "2D" is just 3D with sprites on a "stage"

floral garden
#

Btw if i modify sprite deph, will it affect the sprite ? (I think yes but to be sure)

rich adder
#

sprite deph?

floral garden
#

Y or Z

#

Forget

#

But the 3 dimensions

rich adder
#

Z yes

naive pawn
#

Z is typically distance to camera

#

but the effect depends on the sorting axis, iirc

rich adder
#

but Order in Layer takes precedence

naive pawn
#

layer, then order in layer, then sort axis

rich adder
#

Z depth works if both are on the same order in layer

#

the 2D physics components are "stuck" they can't move on Z

#

I think box2D is probably the only true 2D part of the Unity2D part