#💻┃code-beginner

1 messages · Page 815 of 1

ionic mirage
#

i sned you a private message so i can screen share

grand snow
#

checking if an if statement did anything is pretty basic

#

Debug Logs, visual indication or a debugger will let you know

#

hell input system even has an debugger thing for this

vapid egret
#

Hey, guys. I've been trying to get a question answered in the animation channel for the last week with no response. It seems like I'm on at the wrong time or something. May I post the question here to see if anyone can help?

queen vale
vapid egret
#

Any advice would be appreciated. This is a root motion setup, where the character's speed and direction are driven by the animation. My character seems to be playing jump rope between the back run and diagonal back run on both sides. I managed to somewhat solve the problem at certain coordinates previously by just duplicating animations in the coordinates in question, but I'm not sure if it's an acceptable solution since I'm new. I've made all of the animations start when the left foot hits the ground using offset. IK is on, and the layer has IK passing. if I turn either of them off, it all goes haywire.

floral garden
#

!code

radiant voidBOT
queen vale
#

^
If it's bouncing between states I'd start with the code controlling the animator, then the conditions for the transitions between states.

swift crag
#

I am also doing humanoid root motion, and I mirrored all of my animations to get left-movement. All of those animations have a cycle offset of 0.5

#

If one animation tries to lead with the left foot and one lead with the right foot, they'll cancel out and give you a weird hovering effect

#

goofy walk

vapid egret
vapid egret
#

I'm not sure if the dampening is really making much of a difference though

swift crag
#

it's an issue with the blend-tree itself, yeah

vapid egret
#

Fen, when you offset your animations are you setting them when your character makes contact with the ground on the same foot or when they pick up the same foor?

swift crag
#

<@&502884371011731486> scam

swift crag
#

(i.e. if you go from some other state to the state that contains the blendtree)

swift crag
vapid egret
swift crag
#

whatever was being previewed in the video you sent!

wintry quarry
#

The code is never running

#

The default value isn't relevant

queen vale
white zinc
swift crag
#

so it's causing problems when it blends between:

  • Run_Loop_B_180
  • Run_Loop_B_R_45
vapid egret
#

yes and Run_Loop_B_L45

swift crag
#

That really sounds like a problem with your cycle offset. What happens if you adjust the cycle offset of one of the two animations by 0.5?

queen vale
vapid egret
swift crag
#

nice (:

white zinc
swift crag
#

Make sure the walk and run animations are consistent, too

#

otherewise you will get the same "hopping" behavior as you blend between them

#

note that blend trees will adjust the lengths of the animations to make them all sync up

#

This can cause some really weird behaviors if the animations have dramatically different lengths

vapid egret
#

Yeah I'm starting to understand why many people choose to move their characters with code, but I have to go this route for the combat I'm trying.

#

Thanks again. I'm going to get right on this.

swift crag
#

I use blend trees excessively...in VRChat, where everything happens in the animator

#

so i've been forced to learn about them, haha

verbal dome
#

Like game logic too?

swift crag
#

For avatars, it's all you really get

#

(Worlds can use Udon, which is slow enough that it's often faster to use animators for things like spinning objects)

swift sedge
#

I've heard nothing but bad things about the performance of Udon

swift crag
#

It's a very basic assembly language

#

it has like six instructions

#

almost everything is an extern call into a C# function

#

interestingly, this means you're incentivized to use existing Unity functions as much as possible

#

the actual C# is fast

supple flume
#

YES
I MADE AN ABILITY SYSTEM USING SCRIPTABLE OBJECTS RAHH

#

can i ask a question

#

how do i pause everything in scene

supple flume
#

to the one who did Google emoji

solar hill
#

im seeing plenty of good answers here in the first few results... looking it up myself

grand snow
#

Setting timescale to 0 is babys first pause

solar hill
#

its also the first answer you see when you actually google it

#

what a coincidence 🤯

supple flume
#

as i understood it doesnt

grand snow
#

Yes but it will "freeze" physics
If you have logic that runs over time that uses delta time then that is affected too

supple flume
grand snow
#

UI animation can use unscaled time to work as normal

analog cypress
#

is this somewhere i can go for questions on coding for scripts?

#

or a different text chat?

slender nymph
#

did you perhaps read the description for the channel you are posting in?

analog cypress
#

lol

#

im just trying to write a script for like any tag i put on set entities to be lockable. ill figure out the camera placement after wards i just wanted to make sure if i am writing this correctly so far idk anyone could take a look at it for me.

#

also not sure if i should use other.CompareTag(nameoftag) when checking for a tag

slender nymph
#

you absolutely should use the CompareTag method when checking a tag, unlike string equality it won't just silently fail if you try to compare against a tag that doesn't exist, it's also slightly faster

verbal dome
#

Theres even that new faster overload that takes a TagHandle instead of a string, never seen anyone use it though

analog cypress
#

ok thats good and since im using this as a camera lock on should i use the same main camera thats on my current character to put it in the folder the lockable entity? or should i make a different camera for it?

frigid lark
verbal dome
#

Set its position to the center of the points (a + b) * 0.5f

frigid lark
#

its the scale im talking about

verbal dome
#

Then set its scale to fit the difference of those points

frigid lark
#

ohh righto

verbal dome
frigid lark
#

its really annoying isnt it lol

verbal dome
#

Idk, it became pretty intuitive for me after dealing with vectors a bunch

frigid lark
#

yeah fr

verbal dome
#

What I suggested does not take rotation into account btw

frigid lark
#

yeha i know

verbal dome
#

But seems like things are axis aligned?

frigid lark
#

uhh kind of

#

ive made it so that it doesnt require rotation

#

all the textures are tiled based on world pos

#

and everything scales nicely

#

so when it comes time to make a bunch of rooms for the game I'll have a system that can let me pump out one room every 30 minutes 🔥

verbal dome
#

So it's like, procedural but pre generated?

frigid lark
#

in a sense

#

the skirting is all instantiated in editor

#

but the script i have uses custom editor ui, and it lets me do all sorts of fun shit

#

so essentially i have one room prefab, i can scale it on all axis to whatever size i want, have an entrance on any side i want

#

have skirting automatically done for my

#

everything is already grid aligned

#

its awesome

verbal dome
#

Cool

#

Yeah grid aligned is what sane people do

#

Everything else is just asking for trouble lol

frigid lark
#

exactly

#

well

#

idkhow to explain it

#

are there vcs in this server

verbal dome
#

Nope

frigid lark
#

oof

#

my brain hurts

#

what would i do to scale it

#

i know the difference of the two points but

#

planes are like 5x5units

boreal ibex
#

wouldn't you just measure the gap, move it to the center, align it, then scale it and that would do effectively what u want

frigid lark
#

yeah ig so

verbal dome
#

Would be the scale

#

Division by 5 because of the plane size

frigid lark
#

im a certified professional dumbass

verbal dome
#

Isnt it 10x10 though

frigid lark
#

wdym

verbal dome
#

The plane

frigid lark
#

oh probbly

verbal dome
#

Idk i dont have unity open

frigid lark
#

actually nah the approach i was doing before is the better one imo

#

because you need to scale either side of the doorway IF theres a door, but if not, scale the full wall

#

actually nvm

#

OKAY

#

RIGHT

#

SO THE MAGIC NUMBER WAS 12

#

WTF

boreal ibex
#

if the mesh is 12 world units long yeah

frigid lark
#

the stupid thing is

#

is that i based it on the skirting

#

each skirting unit is 1.2 units in unity

#

omg what

#

ok

#

@verbal dome wanna call

#

my brain is melted

verbal dome
#

Nah im good

frigid lark
#

aight

verbal dome
#

Just ask here

#

Someone/I will help if we can

frigid lark
#

i have a wall prefab right

#

thats what handles all the wall shit

#

but when i have multiple walls

verbal dome
#

One coherent message please

frigid lark
#

it specifically never works for the north or south walls

frigid lark
#

SO:

My wall prefab contains the empty gameobjects recognised as the points to scale with.

Example: Border of Door Arch, Room Corner, etc.

I then run those through scripting to scale. It works great. thanks for that. However, my room consists of:

A floor
A ceiling
4x Wall Prefabs (copy and paste, im trying to make it so that you dont need to manually adjust references etc)
And a skirting parent, the object that containts all of the skirting, just for tidyness sake

#

its not:

Incorrect scaling, im scaling locally so it cant be that

I dont believe its in scripting, Ive tried changing the wall reference in the master Room script from north to east.

prisma shard
#

Is there a generally agreed upon coding IDE to use for Unity. I am getting suggested a particular one often and im wondering what u guys are using

frigid lark
#

i use visual studio 2022

#

2022 not 2019, sorry

boreal ibex
boreal ibex
#

vscode and rider being the other 2 main ones

frigid lark
#

notepad if im feeling cocky

verbal dome
#

I don't have much experience with VS but VS Code is the most lightweight, Rider has a good feature set

#

VS probably sits somewhere in between

#

Rider is free for non-commercial projects only

boreal ibex
#

visual studios the best option featurewise/pricewise, but its also the slowest

verbal dome
boreal ibex
#

cant really tell much more than that

prisma shard
boreal ibex
hardy wing
hardy wing
verbal dome
#

It was chugging like crazy on my machine so it was unusable sadly

hardy wing
verbal dome
#

Yeah, but at least it is usable for me

hardy wing
#

Fair

verbal dome
#

I still fire up VS Code if i need to quickly look at some code in another project though

hardy wing
#

Time to start learning vim for minimum resources 🤝

verbal dome
#

1 sec vs 10+ sec bootup

hardy wing
#

I genuinely don't know why VS Code takes so long at time to start

#

Gladfully only use that piece of software for web stuff

verbal dome
#

Hmm I mean it starts up fast for me

#

In 2-3 seconds

hardy wing
#

Yeah I just tested it again on my linux system and it's quite fast

#

Maybe I started comparing it to NPP early on and then the idea of "slower start" stuck

verbal dome
#

Just tested and Rider took ~20 seconds before I saw any of the code in my project lol

#

But I just never close it so it's not an issue (unless i run outta ram)

hardy wing
#

Low specs huh? Rider is not fast for me but not that slow.

verbal dome
#

3700X CPU

#

@4.2GHz

#

I don't know what people call "low specs" these days

hardy wing
#

Me neither KEKW

verbal dome
#

Under 10 seconds

hardy wing
#

Yeah sounds about what I have too

verbal dome
#

But it's a bit choppy until it has properly warmed up

hardy wing
#

Yeah it needs to re-index the entire file structure every time you open it, it's a bit annoying

timber nacelle
#

i just made an xr game, how do i play it on my headset now?

queen vale
timber nacelle
#

ok, but how do i connect it?

#

i mean the game to the vr because just pressing start with airlink wont do it

queen vale
queen vale
lunar axle
#

is garbage collection a thing to keep in mind for optimize?

timber nacelle
#

i dont get, why the hell is this so complicated. i just went to that airlink hub or whatever it it is, then went to desktop and monitor 1 and presses play on unity. i dont get what to do different

frail hawk
#

there are more inportant things you could optimize your game instead of taking care of manual garbage collection

queen vale
#

Waxy you're killing me

lunar axle
verbal dome
#

Yeah stop that emote spam

verbal dome
#

But if you are a beginner I would not stress about it too much

queen vale
lunar axle
verbal dome
tranquil forge
#

when should i use material property block instead of .material and changing it

verbal dome
#

Struct vs class is a concept you should learn before even thinking about this

#

Or stack vs heap memory

frail hawk
#

could it be that you are coming from some programing language where you´d have to do the garbage collecting on your own?

lunar axle
soft iris
#

Hi everyone, I'm having trouble assigning my character prefabs to the NetworkPrefabs list in the NetworkManager. Even though I try to drag and drop them, the list doesn't seem to accept the prefabs.

frail hawk
#

because in c# there is the garbage collector doing this job for you

lunar axle
#

and whenever i run this everytime the gc just kept spiking up, and lags my game

queen vale
verbal dome
#

Need context

lunar axle
#

cuz if every frame it lags af

soft iris
verbal dome
#

Nothing is allocated on the heap in the code you showed

#

(Heap = gets garbage collected)

#

In short: You should just reuse the same List instance

#

The List (class) being stored inside a struct might be a code smell. Show how you actually use it

lunar axle
verbal dome
#

Well I also don't understand because you aren't giving any context 😅

#

How are you using this struct

#

Show code

queen vale
sour fulcrum
#

they are not the ones defining the list

queen vale
#

I'm no expert, what'd I say that's wrong

sour fulcrum
#

networkprefabs list is a ngo thing

verbal dome
queen vale
# sour fulcrum networkprefabs list is a ngo thing

I'm trying to lookup that term 'ngo', but they did mention "assigning my character prefabs to the NetworkPrefabs list" so they're trying to place a GameObject within a list. Thus the list must be made for GameObjects ( List<GameObject> things = new List<GameObject>();) right?

sour fulcrum
#

sure

#

but they dont get to make the list

#

they need to add a NetworkPrefab to the list, as that is its type

celest abyss
#

Is there any general chat in this server?

frail hawk
#

no

queen vale
lunar axle
tender mirage
#

I'm having abit of a problem when it comes to using linq for a dictionary. i'm trying to reorder my dictionary by name. But order by seemingly is doing nothing here.


    //Assign to debug list
    this.storedDataTiles = storedDataTiles;

    //Update debug ui
    debugUI.UpdateStoredTilesText();



    //Sort keys by name
    storedDataTiles.Keys.OrderBy(key => key.name);

    //Return stored data tiles
    return storedDataTiles;


}
verbal dome
#

OrderBy returns a new IEnumerable, it does not modify an existing one

#

Keys are read only anyway

grand snow
#

And dictionaries dont care about order or try to keep an order so this is a dumb idea

#

If order matters you need a new collection like a List with the keys in some order you want

#

@tender mirage ^

verbal dome
#

(Man that site is annoying on mobile, popups, ads, and it opens the keyboard when i try to scroll)

lunar axle
tender mirage
#

Thanks for the reminder.

grand snow
verbal dome
#

So you can reuse it instead by replacing that with .Clear instead

#

Also do you know how structs vs. classes work?

grand snow
#

Creating lists with a good initial size and clearing them will improve things a lot

verbal dome
#

Structs are copied when you pass them around

#

Classes are passed by reference (not copy)

lunar axle
grand snow
verbal dome
#

And yeah rob's advice about pre-allocating it with an initial capacity is good

#

Otherwise the list starts with a capacity of like 4 (or 0?) and then every time you add more and the capacity is exceeded, it will allocate a new internal array double the size of the original

#

4 -> 8 -> 16 -> 32 -> 64... Lots of allocations so if you know you will have for example ~1000 elements then create the list with that capacity: new List<MyType>(1000)

#

If that went over your head then just focus on the value vs. reference type for now

lunar axle
#

But is it ok if we dont use all the space?

verbal dome
#

Better than constant pressure on thet garbage collector

grand snow
#

Allocation and deallocation has cost so its usually better to use a tad more memory instead

#

If you know you may need to add up to 16 elements but it could be only 8? Make the list be 16 to start.

lunar axle
verbal dome
#

I was cooking up some analogy about apartment sizes, moving to different apartments and getting new family members but i gave up

grand snow
verbal dome
sour fulcrum
grand snow
#

Just know that when a list needs to resize all data has to be copied to the new internal array

lunar axle
#

well then i think either i make the recording duration constant or just set to like 1000

grand snow
# lunar axle alr

And as you maybe just learnt, an array of a struct has a lot more data to copy.
Anyway you should use the profiler to check if such things are actually an issue before trying to over optimise.

verbal dome
lunar axle
lunar axle
grand snow
#

I dont want to get too deep here and confuse you. Stick with a struct.

lunar axle
grand snow
grand snow
lunar axle
# grand snow

Cant believe ppl do this for free u could start a course (lowkey) xd

gaunt atlas
#

can someone lmk like the best way to learn how to make a third person game with a camera kinda like how roblox's looks (without the zooming in and out), like I just need to know what exactly Im meant to use in the script. I believe I should probably put a camera as a child of a parent object which I will have as my player, and then I make the parent object rotate according to my keyboard input, right? but how do I do that whats the logic

#

Ive been trynna find a way to actually learn things but Ive never really found an actual useful video or anything, theyre all about copy what I just did

swift sedge
#

look into Cinemachine

gaunt atlas
#

Ive seen that pop up but isnt that just something to make things easier

#

I wanna be good at the fundamentals

timber tide
#

third person camera are just generally hard

#

there's a lot of ways you can configure one with that being said

#

control relativity is up to preference

gaunt atlas
#

my issue is mostly: lets say I want the camera to be always at a specific radius from a certain position

#

and I want it to not rotate looking up or down past x angle

#

I dont know how to achieve that

frail hawk
#

with clamping the rotation

swift sedge
#

float newAngle = Mathf.Clamp(currentAngle, min, max)

gaunt atlas
gaunt atlas
dense basin
#

Friends, I need help with setting up a sleep system and logging system, including shelf and product registration. Please write to me.

frail hawk
#

no one will dm you, just aks here

timber tide
#

It's actually not ideal to child the camera to your object, but in many cases it will work fine. It's just that you're more likely to run into desync issues if your character updates in a different timestep than the update of the camera.

#

Which is why cinemachine is a good option too as it handles a lot of that complexity

gaunt atlas
timber tide
#

More that character controllers update in a fixed update but smooth out their translation in update, but this can somewhat conflict with how the camera captures it all. Usually just keeping the camera movement in late update works fine, but it's not unlikely you run into some frame inconsistencies.

#

But you're also correct about it being a bit more complicated to manage camera collision when it is child to the object... which cinemachine also does pretty well lol.

dense basin
#

How can I create a sleeping system and a shelving and product storage system? Can you help me?

gaunt atlas
#

so use cinemachine

#

😭

#

bet

timber tide
#

it's probably one of unity's best tools that's for sure

celest abyss
#

Cinemachine

floral garden
#

use cinemachine men haha i try to make a system of camera and it is hard asf for nothing xD

swift sedge
#

camera systems are the last thing you want to spend time and procrastinate on in game development

#

good for learning, but for production I would just use cinemachine UnityChanThumbsUp

floral garden
#

even for learning,if you don't have a solid base, you will just get lose or get a bad system

#

(I talk by experience hahaha)

frail hawk
dense basin
frail hawk
#

so post the relevant code

dense basin
frail hawk
#

!code

radiant voidBOT
tranquil forge
#

did i get it right fr

verbal dome
#

Something like that yeah

#

Main point being that SRP batcher (urp/hdrp) only cares about shader variants, not materials

#

MaterialPropertyBlock was more useful when we wanted to avoid creating new material instances, to avoid breaking batching in the older GPU instancing/batching system

errant breach
#

Hey, so im struggling to understand list despite watching tutorials. But basically, i have multiple list inside one list. How can i make so that the first element in the list can be a gameObject ? Thanks !

#

By the way, i would like to thank you for the support ! I was very busy to say it but you really took time to help me and this is very kind of you :)

ivory bobcat
errant breach
#

Of "colorList" ! Ah, i see...

ivory bobcat
#

What exactly were you trying to do? If you can explain, we may be able to give you further suggestions.

rough granite
errant breach
#

By the way i dont exactly understand how to ask for "floats" instead of colors ! Sorry if this this code is disgusting 😅

errant breach
# ivory bobcat What exactly were you trying to do? If you can explain, we may be able to give y...

Sooo im working on a gameEngine for a SpaceShooter, i want to allow my classmate to easily create various enemies.
I want them to be able to create multiple attacks using list. One list is a attack, and the list containt :
1 - The GameObject to summon
2 - The time before the attack start
3 - The duration of the attack
4 - The duration of the cooldown

But i dont think i have the knowledge to make it easily 😅

floral garden
#

wut? your ColorsList take a float but then after you try to access a list from a float

rough granite
errant breach
#

Ah, i understand my mistake now.. So i should use public float GetColor() to avoid this error ? (Or a int)

rough granite
#

no a float is not anything close to a color

errant breach
#

I think I'm confusing the name (of the classes/functions) with the types 🤔

#

Because i no longer wants any colors, only float

tender mirage
#

What type would you use to return a Color?

errant breach
#

Sorry if i look dumb 😅

rough granite
#

then the question of would this work is yes but you should change the name of the function to match.
also this only ever returns the first element meaning there is no point to it being a list in a list

errant breach
rough granite
ivory bobcat
#

You should probably change the name. colors imply it's a list of color(s).

errant breach
#

Thanks for your suggestions. I changed the function's name and type, and added "valA" and "valB" to go through the entire list.
Now, im being hit with the error :

'float' does not contain a definition for 'value' and no accessible extension method 'value' accepting a first argument of type 'float' could be found (are you missing a using directive or an assembly reference?)

I do understand that i'm using the wrong type, but i dont understand what else should i use..

rough granite
#

the two underlined parts should match

#

you just currently have two completely seperate lists in different classes with no reference between them

ivory bobcat
errant breach
rough granite
#

no i underlined the error, or well what'd make it

errant breach
#

like "Values" and "ValueList" should match but doesn't...

ivory bobcat
#

public List<Values> colorList

errant breach
#

OOH

#

The error is now fixed...

ivory bobcat
#

What's this float value for?

#

Value isn't really self explanatory

errant breach
#

Guys, thanks for the help. Now it's time for me to walk outside as i did like 40h of unity in one week and i think im starting to become like.. Crazy or smth.. 😅

errant breach
#

this is how it should appear

#

so i think "Values" should be renamed "attack"

ivory bobcat
#

Yeah and value would be cooldowns

river imp
#

Hlo

#

Here Anyone can teach me c # ?

vital barn
#

!lern

radiant voidBOT
# vital barn !lern
<:error:1413114584763596884> Command not found

There's no command called lern.

ivory bobcat
#

!learn

radiant voidBOT
errant breach
#

Herreee we go

#

Now it's time for me to WALK OUTSIDE or sleep idk 😅

#

Thanks guys !!!

errant breach
undone pier
#

does unity have any data type that allow assignment of logic? I have been using SerializedReference but these get erased as i change the class' name

#

other than that there is reflection but i doubt its any faster

timber tide
#

composition and usage of scriptable objects

undone pier
#

ye but is there any data type that accepts a delegate?

#

that can be selected in the inspector

timber tide
#

You can serialize unity listeners /events with the editor but otherwise need to write some extra boilerplate to bind stuff like that

undone pier
#

I see. Thanks

timber tide
#

Usually those have limited data types too. I think it's usually just like int/floats/strings

#

and usually you don't expect return values anyway

#

Like the Button class for instance

undone pier
#

ye i guess serializedReference is the best option rn

timber tide
#

Godot's signals a bit more versatile because the typing isn't always specific

#

The problem isn't so much that you couldn't serialize it all, it's just that Unity's editor doesn't really have that support.

#

Much like interface serialization, it's a bit ambiguous without a bit more of that boilerplate

somber granite
#

having an issue with no global 2d lights showing up in my build: i have a main menu level select scene and levels, and scene transitions are done with SceneManagement.LoadScene(). When i dragged all my levels into the hierarchy to test the level transitions in the editor, i initially got a “more than one global light on layer…” error that went away after unloading the level scenes and leaving only the main menu. after building, it appears as if all of the lights are gone, the scenes all look super dark, except for the canvas UI. i had one global light 2d in each scene, set to light “everything” in the layer select

granite elk
#

hello, i have a problem, i have an object that orbits in my player(the object rotates in the mouse position), but when the player and the object are in a wall and i move my mouse opposite the player the object will push my player but i dont want that, i even deactivated the collision between the two in the physic collider matrix

frail hawk
#

do you need the collider on the orbiter object

mystic lantern
#

I can do a simple job for 5-10 euros. I have some experience writing code in Unity. If you need anything, please let me know.

radiant voidBOT
# solar hill !collab

: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**

grand snow
granite elk
timber nacelle
#

guys how do i play a unity game on an ocolus? 1. im in the engine 2. i pressed on start 3. when i press a button on the joystick the fingers move but i cant look around and move.

frail hawk
granite elk
frail hawk
#

you could manually correct the position of the incoming object

timber nacelle
#

can my question please not get ignored?

frail hawk
granite elk
#

no that cant work because it will trapass walls

twin pivot
timber nacelle
solar hill
#

Dont crosspost

#

you also spammed your question multiple times and ignored every response you got.....

timber nacelle
solar hill
#

now you're lying

timber nacelle
#

yes, i did got an answer, but it didnt really work, and my questionw was "how to play on ocolus" and the only answer i got was something with dev settings or smth and it dosent really work

fickle plume
timber nacelle
#

i did ask a full question and sorry that i dont want to wait 3 hours for an answer

fickle plume
solar hill
#

but you didnt ask a full question, at least not one thats clear

fickle plume
#

@timber nacelle Use appropriate channel and stop bickering

timber nacelle
#

i asked the question on the virtual channel but after 2 hours not even a single answer

fickle plume
fickle plume
frail hawk
fickle plume
#

Preferably, yes ^^

granite elk
#

okay

bronze fable
#

Can someone give me a basic explanation as to why the Add Score function in the second picture isn't working, I'm working with guides and have 0 experience coding otherwise

#

Says I'm having a CS1061 issue

solar hill
#

that also has a script called "TriggerScript"

bronze fable
solar hill
#

attached to a what

bronze fable
#

Attached to this

solar hill
#

theres no triggerscript there....

#

you have scorecounter... not triggerscript

#

youre searching for a triggerscript component in your code

bronze fable
#

Oh wait nevermind I have it attached here mb

#

Thats where my trigger script is

#

It's just named 'trigger script', but it's a custom script

#

I barely know what I'm doing I am sorry I'm a day one learner

solar hill
#

right, but the game object needs the tag "Logic"

#

i think youre missing some very basic fundamentals here

#

!learn

radiant voidBOT
solar hill
#

i suggest you start learning with the unity pathways

bronze fable
#

Unless you mean both need it

solar hill
#

I Realllyyyyyy think you should go through those learning pathways

#

because you are writing code that you have no clue how it functions

#

thats not good, and its not a good way to learn

bronze fable
#

yeahhh you're probably right

grand snow
#

day 1: use tag to find script
day 2: stop using tags they are shit

bronze fable
# grand snow day 1: use tag to find script day 2: stop using tags they are shit

🔴 Get bonus content by supporting Game Maker’s Toolkit - https://gamemakerstoolkit.com/support/ 🔴

Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and...

▶ Play video
#

I'm just following this guide

#

from 3 years ago

solar hill
#

Never trust those who sell shovels in a goldrush

#

use the pathways, much better tutorials

grand snow
bronze fable
#

I'm just gonna finish this tutorial and then move on to newer ones

#

If I give up now I ain't ever learning lmao

grand snow
bronze fable
grand snow
elder hearth
#

So I'm either really dumb or over looking smth obvious(i am quite tired), but my isGrounded is working

cs
using UnityEngine;

public class GroundedCheck : MonoBehaviour
{
public bool isGrounded = true;

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.collider.tag == "Player")
        {
            return;
        }
        isGrounded = true;
    }
    private void OnCollisionExit(Collision collision)
    {
        if (collision.collider.tag == "Player")
        {
            return;
        }
        isGrounded = false;
    }
}

It is retuning false, it is being called in my movement script

elder hearth
dusky marsh
#

hi all, I am just starting off and going through tutorial on Unity website. aI have got this far but Unity is saying there is an error with this and I cannot see where. I triple checked the tutorial to see but I cant spot the mistake. Can anyone see it ? thanks

solar hill
#

show us the error

ivory bobcat
solar hill
#

also your ide needs to be set up

#

!ide

radiant voidBOT
elder hearth
elder hearth
dusky marsh
ivory bobcat
solar hill
#

inside the collision methods

elder hearth
elder hearth
dusky marsh
# solar hill show us the error
Unity Learn

In this tutorial, you’ll write your first Unity script to control how each obstacle behaves. By assigning random properties — like size, direction, and speed — you’ll make your game world feel unpredictable and alive. Along the way, you’ll learn key C# scripting concepts, how to edit prefabs directly, and how to test and tune behaviors...

elder hearth
#

I only get true in the console

dusky marsh
rough granite
# elder hearth

does the object this groundcheck class is one have a rigidbody?

#

Just checking for reasons why it wouldn't run

#

What about the collider type that this class is using?

elder hearth
rough granite
rough granite
#

Thats the game scene not inspector ~_~

#

I suspect you are using a trigger collider and which if you are you should be using OnTriggerEnter not OnCollisionEnter (same with the exist function)

Edit: nvm you arent

elder hearth
rough granite
#

All good

elder hearth
elder hearth
raw veldt
#

!code

radiant voidBOT
ivory bobcat
elder hearth
#

Thought my tired dumbass over looked smth 😭

rough granite
elder hearth
#

Wait but the parent has one?

elder hearth
rough granite
ivory bobcat
raw veldt
elder hearth
raw veldt
#

like where you add callback context to make your input handler work

#

all that used to be in my character controller

rough granite
# elder hearth It works!

Nice i would still recommend making the circle for ground checks a trigger as this adds an extra height lifting the character off the ground when not

elder hearth
elder hearth
rough granite
raw veldt
#

i made that script before there were manuals to the new input system... should i keep it how it is or change it like the guy is doing in the tutorial/screenshot

elder hearth
rough granite
#

Yeah

rough granite
elder hearth
elder hearth
spring hamlet
#

does anyone know a good way to keep NavMeshAgents/enemies following a path from forming "conga lines" when they're trying to get somewhere as a group? can I get away with making the characters themselves NavMeshObstacles or is there some particular way I have to manipulate the path's corners?

raw veldt
#

would you just make them ignore eachothers physics colliders

spring hamlet
#

because then they'd just stack onto each other and pile up at corners or intersections

raw veldt
#

usually they give some them ranged abilities

#

some of them

spring hamlet
#

that's totally besides the point

solar hill
raw veldt
#

theres like a spacing thing around the player i was looking at on linkedin earlier

spring hamlet
raw veldt
#

make them select spots around the player and go there instead of to the player

#

force them to pick different spots

solar hill
#

that alone makes them less likely to form a conga line, but its a subtle fix in the end, all it does it makes them all yield differently so they stop following the exact same paths, with leads to more lateral separation

spring hamlet
#

does this also affect the paths NavMeshAgents themselves generate? (that's how they get their paths)

solar hill
#

im not exactly sure

#

youl have to test it out

#

Another thing i personally did was have different agent "personalities" inspired by pacmans ghosts, certain personalities behave slightly differently, and the randomized avoidancePriority was built into that

spring hamlet
#

if it doesn't work where can I start for calculating avoidance myself

analog cypress
#

Im not sure if anyone can help me with my script that im having trouble with. To walk through the point of my script i wanted to set a tag that i can give to entities that i wish to be "Lockable" and if that said entity has that tag and you use the middle mouse button on it, it would start to lock on to that entity. In order words i am trying to create a target camera lock on system like something from elden ring or zelda. It is giving me a couple of issues being: Monobehavior not being found, Locking.Locking() must declare a body. And that it needs a return type and im just at a loss right now.

sour fulcrum
#

!ide

radiant voidBOT
analog cypress
#

I'm confused on the purpose of this command? Should I send/show or specify something?

sour fulcrum
#

your visual studio is not working correctly

#

and is not showing you the problem

analog cypress
#

oh ok thank you

stuck cedar
#

Can anyone teach me unity

#

And c#

twin pivot
radiant voidBOT
stuck cedar
frosty hound
#

Nobody here (or anyone for that matter) is going to be your free personal tutor. Unity has plenty of resources for getting you started.

queen vale
# stuck cedar Help me to learn

Create, create more, create again, learn from mistakes, don't fret over making an entire game at first, make projects for the sake of learning, read, watch tutorials but actually look into what they're saying don't just copy-paste.

brave token
#

is there any way i can learn unity if i already know c#

#

every tutorials i watch just say "copy paste this complicated code" without explaining

queen vale
brave token
#

i want to make a fps game and every time the tutorial types code it confuses me and he never explains what each variable, arguments or methods do and how they get information from the engine.

#

and since the tutorial is kinda outdated, i come across errors that he doesn't

queen vale
# brave token and since the tutorial is kinda outdated, i come across errors that he doesn't

That's quite the umbrella, whenever you come across something you don't yet understand I'd recommend Unity Docs. so you can see an example / usage / related properties.
Yea, some old tutorials can use some deprecated functions. But there should be new ones, might use some extra variables or whatnot but serve the same/similar purpose.
There's also the forum where you might find someone else with the same question and hopefully an answer to it.

wraith hornet
#

How can i call "Unity_SampleGradient_float" in a custom function in hlsl ?

queen vale
# brave token thanks bro

No worries. If you have a specific example / error, someone in here can probably help if they see it.

ornate cosmos
brave token
#

yeah i learned them from bro code. i watched the entire c# playlist

ornate cosmos
#

the public member variables of a class will be displayed in the Inspector of the editor, so if you create a new code file, write a class that inherits MonoBehavior, and then write something like this: public Transform A; Then you go to the editor, add an empty game object, and add the class you wrote. Then you can see this A variable, and you can drag other game objects into this variable. This operation is equivalent to assigning values in the code

#

if the member is private, then u cant see it

#

and u can write some methods that unity will call them in ur class

#

Update, or FixedUpdate

#

so basicly u just code some members, drag something into it in editor, then code something in Update method, unity will call it

queen vale
#

Unless being referenced by another script, I don't think public variables is advised. If anything [SerializeField] if you REALLY want to drag them in the editor.

ornate cosmos
#

yeah, thats another way to make it, u set a member to private, then give it a [SerializeField]

#

if u know wuts it

#

its a "attribute"

#

since u just started it, not need to know how it works, just use it, if u learn fps, i can give u some words then u can search the tutorials as a study path

#

u need to learn: ray, collider, rigidbody, new input system

brave token
#

im learning from the essentials pathway rn and i just completed mission 1

queen vale
#

Can be hard to break habits, start with good ones.

ornate cosmos
#

since u used to use C, u need to know: if some methods(function u can think it is) wont used in another class, set it to private, or u dont want it to be used in another class

#

and also private members wont be seen in the Inspector

ornate cosmos
#

nice

#

u can also use Field

brave token
#

just need to learn how to use c# with unity

#

whats that

ornate cosmos
#

public int A {get; set;}

queen vale
ornate cosmos
#

u can set the read and assign setting(public or private) for this field separately

#

and "get;" means nothing diff

gloomy charm
#

Hi im coming from c++

ornate cosmos
#

but u can also say

#

{get {return 1;}}

brave token
#

the get set part was a bit confusing

ornate cosmos
#

or return another private value cuz u just dont want another class get that value directly

brave token
ornate cosmos
#

also like : set{_value = something;}

ornate cosmos
#

well its like something in java

#

u made a private value, lets say HP

#

others should change the value, thats cheating. but u also wanna get the value

#

so u write "public int GetHP()" method to get it

#

but Field just for more ez to make it

gloomy charm
#

How hard is it to learn c#?

brave token
#

well can you explain with this example? and what's value?

ornate cosmos
#

i learn C++ before, then i just quickly use C# without learning

ornate cosmos
brave token
gloomy charm
queen vale
#

SerializeField makes a variable accessible within the editor.
As a better standard though when working with scripts, you should look into UnityEvents and Public functions that 'return x' the value in question.
Making a variable public creates opportunities for cheats, etc. Not bad when learning, but not good long term.

brave token
gloomy charm
#

Essential what?

sour fulcrum
ornate cosmos
#

and value means...let me make a example

queen vale
frail hawk
#

i agree, what does cheating have to do with a public modifier

sour fulcrum
#

you can access whatever you want at runtime

brave token
gloomy charm
queen vale
brave token
sour fulcrum
#

access modifiers do not exist in compiled games really, it's just something to help devs

ornate cosmos
#

here, "value" is the "1" in "Speed = 1;"

brave token
sour fulcrum
gloomy charm
brave token
gloomy charm
#

I got time to kill anyway might as well

ornate cosmos
queen vale
#

more better

brave token
#

fun fact: the # in C# means C++++

gloomy charm
ornate cosmos
#

when i use C++, i was using UE4, but i changed my mind into unity, so i just ask my friend wuts the diff, so my friend just tell me the default things(public or private when u didnt write it) is diff sometimes, and C# is more ez, and u need to know C# method can be: public void Hi() => ...; for one statement, so i just use C# without any learning

ornate cosmos
#

but diff

#

its just diff, once u met it u'll see, but tbh i didnt trigger it for a long time in C#

#

the last time i met this problem is about maybe 3 years ago

#

if u use unity, i think its not a problem, cuz u just wont write codes like that if ur good at it

grand snow
#

C++ is the outlier with how its compiled as modern languages all take multiple passes

gloomy charm
grand snow
#

there is no concept of "including"

gloomy charm
#

Oh

gloomy charm
#

This will make life so much easier then

ornate cosmos
#

u will see it after u write

ornate cosmos
gloomy charm
#

Debugging that problem in c++ was so difficult 😭

ornate cosmos
#

cuz C# just is more ez and simple

brave token
ornate cosmos
#

so... yeah, u wont see the problem

#

after i use C#

#

my brain just smaller 70%

grand snow
#

Anyway im sure you know in cpp we can use defines or #pragma once to overtime this issue

ornate cosmos
#

than when i use C++

gloomy charm
ornate cosmos
grand snow
gloomy charm
#

That's probably the first time I actually had that problem anyway

grand snow
#

Unity has a very stable api too

ornate cosmos
#

so u dont need to worry about it in unity

#

wont met it in 99% time

gloomy charm
#

I like those chances

ornate cosmos
#

at least i never met it in Unity

#

i just met once or twice in winform

#

its a... QT like thing u can say

gloomy charm
#

Now there's only one problem left. Finding out how to embed lua🫠

grand snow
#

people have already made that work in c# and for unity

ornate cosmos
#

u mean XLua or SLua?

grand snow
gloomy charm
#

What are those?

ornate cosmos
#

nvm, just found its all chinese

#

skip the link i send

gloomy charm
#

I can't read chinese💀(yet)

grand snow
#

They have english docs it seems

#

and it appears as the lib is english too so its valid so id say either option is good

#

Its very common for libraries to be in english regardless of the creators home language

gloomy charm
#

I'd run the dotnet command outside of unity right?

grand snow
#

you cant use that to manage a "project" because unity doesnt use that

gloomy charm
#

Oh

#

Whoops didn't see the unity section

grand snow
#

The "slap random files in your project" solution is outdated and a bit shit

gloomy charm
#

It's possible to use c++ in unity?

ornate cosmos
#

u can compile C++ code as a dll then use it at runtime

gloomy charm
#

Im not gonna use it im just asking because I see il2cpp in a few games I play which are unity games

ornate cosmos
#

i tried to do it before cuz i already have a small compiler C++ dll so i put it in

ornate cosmos
grand snow
#

yea il2cpp is not something we can use at will. you can use native code but it cannot interact with unity apis

ornate cosmos
#

if u mean this, u can just turn it on

gloomy charm
#

And it'll behave like c++ even if written with c#?

ornate cosmos
#

if u mean write C++ code in unity, u need a dll

ornate cosmos
#

then IL will compile to C++

sour fulcrum
ornate cosmos
#

so yeah, u can say that

gloomy charm
#

Why does that exist?

grand snow
#

haha it very much does NOT behave like cpp

frail hawk
#

why dont you just learn c# and do it the normal way

ornate cosmos
gloomy charm
ornate cosmos
#

its just a build way, u can build by IL2CPP way

grand snow
#

cool then lets end the discussion

gloomy charm
#

Ok

frail hawk
#

people usually ask how to use c# in unreal engine but you asked the opposite question, kind of funny though

gloomy charm
#

It's because I see il2cpp.dll pop up sometimes

ornate cosmos
sour fulcrum
#

in the context of the question of "can i use c++ in unity"

ornate cosmos
#

cool

gloomy charm
#

Ok I probably asked that wrong

sour fulcrum
#

no your question is fine

brave token
grand snow
#

They went with mono as it was the only way back then to run c# on platforms other than Windows

ornate cosmos
# brave token what's mono

u can just think its one of these build backend, and it can run c# in diff platform cuz its cross-platform

brave token
#

wait il2cpp isn't cross platform?

ornate cosmos
#

well its also

#

but its diff by the way it made it

gloomy charm
#

Who doesn't love mono

ornate cosmos
#

il2cpp can cross cuz it compile by diff compilers

#

its a...AOT thing

#

compile these C# codes to machine code so it can run in diff platforms

#

but mono is a runtime way to make it, it just run IL at runtime

#

like java use JIT

gloomy charm
#

I was gonna use c# for scripting one time

brave token
#

from what i know, il2cpp is also faster

grand snow
#

Unity used to support JS and boo but as well for scripting but ditched them

ornate cosmos
#

thats too old things, il2cpp already here maybe after 2014

grand snow
#

In relation to the engine existing it is recent

ornate cosmos
grand snow
#

anyway there is plenty of information online about mono and il2cpp

#

so go check that out instead of half baked explanations here

sour fulcrum
subtle mulch
gloomy charm
subtle mulch
brave token
#

unity physics are the best

lilac pulsar
subtle mulch
errant breach
#

Hello ! I've created a projectile that every enemies shoot. But how can i pass parameter to the projectile (Speed, damage, lifespan) so that every enemies can shoot a different one ? Thanks.
(im using the instantiate's function but if you have better suggestion, i'll take !)

subtle mulch
#

when you instantiate it, you get back a reference to the gameobject

#

use that reference to get the projectile class component

errant breach
#

Oh really ? It's that simple ? :0 ?
So i do something like...
"instantiate(projectile) projectile.speed = 12 projectile.damage = 16"

subtle mulch
#

no

#

var projectile = Instantiate(projectilePrefab);
var projComp = projectile.GetComponent<ProjectileClass>();
projComp .speed = 12;
projComp .damage = 6;

#

like this

errant breach
#

ahah omg it's that simple thanks !!

#

and if the player get hit, to access the projectileDamage value, i do like
collider.GetComponent<ProjectileClass>(); too ?

subtle mulch
#

if collider is the object that hit the player yes

#

but, use TryGetComponent

#

not GetComponent

errant breach
#

Ah i see to avoid crashes 😅

#

Alright thank you Diamond Master !

subtle mulch
#

to prevent null references in case it was not a bullet that hit the player

lilac pulsar
lilac pulsar
errant breach
#

By the way...

var projectile = Instantiate(projectilePrefab);

Whats the point of creating the "var projectile" value is it's not used later ? Im trying to understand unity's logic 😅

subtle mulch
#

wdym

#

it's used locally

#

and you might prob need it to set the position and stuff

#

(and it makes the code look cleaner) lol

errant breach
#

Okkkayy, i guess i'll have time to better understand everything 😅

#

Thanks <3

subtle mulch
#

var is to just auto assign the value type btw

#

it makes the code look somewhat cleaner

errant breach
#

OOOH okay now i understand better 😅 thx :>

gloomy charm
#

Opened unity and now i am ready to learn

#

And appearntly the editor i have installed have a security issue

subtle mulch
#

why didn't you download the latest?

#

6000.3.10f1

gloomy charm
#

I downloaded it a while ago and it was just sitting on my computer

subtle mulch
#

ah, lol

#

well, get the newest one

gloomy charm
#

Yea i am just updated the hub

swift sedge
#

what version is it?

gloomy charm
#

6000.2.5f1

subtle mulch
#

yeah it's old

rich adder
#

6.0 or 6.3 LTS
though 6.0 is much better and mature

subtle mulch
#

6.3 works just fine tbh

gloomy charm
#

I can't update from the editor menu? I have to do a full install on the new version?

rich adder
#

eh considering everyone who comes with problems is always with 6.3 bugs

subtle mulch
#

i never had tbh

gloomy charm
#

So im seeing windows support il2cpp does that mean if i wanted to export to windows i would have to have il2cpp enabled?

subtle mulch
#

nah

#

but it does help with performance

rich adder
#

IL2CPP is just different backend type instead of Mono.
there are pros n cons

gloomy charm
#

22gb for my basic needs is wild

subtle mulch
#

(it's pretty good tbh) XD

rich adder
#

laughs in Unreal

subtle mulch
#

unreal is 50gb+ alone

gloomy charm
#

Ok bruh lol

#

I might as well add mac too right?

rich adder
#

no

#

it won't work

gloomy charm
#

Really?

subtle mulch
#

you might wanna add linux

gloomy charm
#

Already added

subtle mulch
rich adder
#

never seen someone successfully build to mac from windows who knows if they ever fixed it

#

You need a mac to build to mac proper

gloomy charm
#

So i would need to run all this on a vm

subtle mulch
subtle mulch
gloomy charm
subtle mulch
#

yes afaik

#

i saw an action that did that

gloomy charm
rich adder
#

I would worry about this stuff later..

subtle mulch
#

yep

rich adder
#

learn the editor first lol

subtle mulch
#

and i will prob get rid of Unreal now that i saw the full size XD

gloomy charm
#

Relearn you mean

subtle mulch
#

136Gb on disk

gloomy charm
#

Didn't really have the chance to learn unity too much because my old laptop is bad

gloomy charm
subtle mulch
gloomy charm
#

How big is it??

subtle mulch
#

tho unreal build alone is 50gb+

#

(it's bloated AF)

gloomy charm
#

Well that explains where a big chunk of my storage went

rich adder
gloomy charm
#

Ok

#

I'll just add it anyway

#

The only things i really need atm is android and ios build support

chrome storm
#

Hello! I need big help with my code. I made it that when a player is near a ledge the off balance animation plays but since I could still move around and stuff the player could move a bit while still playing the animations I tried snapping the player when its not moving to the corner but couldnt get it to work. can someone help! :(

#

I can send the code if u want the one with the snap and without

rich adder
#

every system is specific

naive pawn
#

you're probably using a ground check that doesn't make sense for your character

#

what's the intended behavior anyways

chrome storm
#
private RaycastHit2D GetIsGrounded()
    {
        return Physics2D.Raycast(transform.position, Vector2.down, PlayerHalfHeight + 0.2f, LayerMask.GetMask("Ground"));
    }

    private void CheckGroundAndEdges()
    {
        Vector2 basePosition = (Vector2)transform.position + Vector2.down * PlayerHalfHeight;

        Vector2 center = basePosition;
        float facing = facingRight ? 1f : -1f;
        
        Vector2 front = basePosition + Vector2.right * facing * edgeOffset;
        Vector2 back  = basePosition - Vector2.right * facing * edgeOffset;
        
        bool centerHit = Physics2D.Raycast(center, Vector2.down, groundRayLength, LayerMask.GetMask("Ground"));
        bool frontHit  = Physics2D.Raycast(front, Vector2.down, groundRayLength, LayerMask.GetMask("Ground"));
        bool backHit   = Physics2D.Raycast(back, Vector2.down, groundRayLength, LayerMask.GetMask("Ground"));

        Debug.DrawRay(center, Vector2.down * groundRayLength, centerHit ? Color.green : Color.red);
        Debug.DrawRay(front, Vector2.down * groundRayLength, frontHit ? Color.green : Color.red);
        Debug.DrawRay(back, Vector2.down * groundRayLength, backHit ? Color.green : Color.red);

        isGrounded = centerHit;

        isNearEdgeFront = centerHit && !frontHit;
        isNearEdgeBack  = centerHit && !backHit;

        anim.SetBool("isGrounded", isGrounded);
        anim.SetBool("isNearEdgeFront", isNearEdgeFront);
        anim.SetBool("isNearEdgeBack", isNearEdgeBack);
    }

    void HandleFlip()
    {
        if (rb.linearVelocity.x > 0.1f && !facingRight)
        {
            Flip();
        }
        else if (rb.linearVelocity.x < -0.1f && facingRight)
        {
            Flip();
        }
    }
rich adder
#

so you want to just interrupt the nearEdge animation thing when moving away from ledge ?

midnight tree
#

Implementations of Func and generics

chrome storm
#

yeah! Its just so that when the player is near the ledge it snaps there so that the foor is on the corner

#

Then I can just walk off the ledge if I want to

rich adder
chrome storm
#

I tried making a code that does that but it didn't work I even asked chatgpt for help but that was no use XD I'll send it over

#
    private void HandleEdgeSnap()
    {
        if (!isGrounded || rb.linearVelocity.y > 0f) return;

        float snapAmount = 0.05f;
        float moveDir = moveInput;

        if (isNearEdgeFront)
        {
            if ((facingRight && moveDir <= 0) || (!facingRight && moveDir >= 0))
            {
                transform.position += new Vector3(facingRight ? -snapAmount : snapAmount, 0f, 0f);
            }
        }

        if (isNearEdgeBack)
        {
            if ((facingRight && moveDir >= 0) || (!facingRight && moveDir <= 0))
            {
                transform.position += new Vector3(facingRight ? snapAmount : -snapAmount, 0f, 0f);
            }
        }
    }
rich adder
chrome storm
#

Mk Ill do that rq

#

Yeah your right didn't really solve anything

rich adder
#

yeah , what exact behavior you want? why did you want to snap it?

chrome storm
#

so that the foot is always on the edge and not offset

#

I need it to snap under the foot but not that much that the left raycast touches the floor

#

Since there a gap between them if I move a little I want it to snap back to the ledge but still have the ability to walk off the edge

rich adder
chrome storm
#

Yeah i can try that

#

No I tried keeps sliding back to the platform

rich adder
# chrome storm

hmm the games I seen only add the behavior to the animation but it breaks the animation when you move, the snapping thing idk that might mess with gameplay too much no?

chrome storm
#

Yeah i understand

subtle mulch
#

yeah snapping will def mess with gameplay

#

and looks pretty bad

chrome storm
#

Leaving the feature out might make the game smoother

chrome storm
#

I wanted to do something like in rayman origins

subtle mulch
chrome storm
#

Yes I'm recording it rq

subtle mulch
granite elk
#

hello, im having a problem with my magnet object, everytime i attract an object it doesent stay in the magnet and floats around, how do i fix that?

subtle mulch
#

add more force the closer an object gets

#

it's like real life

granite elk
#

i use joints

subtle mulch
#

huh

#

where

#

and which joint

granite elk
#

when i attract an object, i create a joint

granite elk
subtle mulch
#

i would not use a joint

#

but move the object as a child of the magnet

#

and disable the object rigidbody

#

and then enable the rigidbody again later when detaching

granite elk
subtle mulch
granite elk
#

no it doesent

subtle mulch
granite elk
#

it doesent trapass walls

subtle mulch
#

yep, it basically is

subtle mulch
#

and it won't trespass walls

#

if you code the magnet correctly

granite elk
chrome storm
#

Alright I'll see what I can do then. Thanks for the help guys!

subtle mulch
#

by just setting its rotation?

granite elk
#

do you want me to share the code? But idk how to

subtle mulch
#

well, that would help

#

send it via pastebin

#

so i can see how you assign to the joint

granite elk
#

whats that

subtle mulch
#

also, show the joint settings

granite elk
subtle mulch
#

why did you send a .txt...

granite elk
#

i did paste in pastebin and download

subtle mulch
#

yeah that's so wrong...

#

you had to publish the pastebin and send the link

#

why all of these here tho..

#

just set them to public

granite elk
#

no its better to be private

subtle mulch
#

not really

#

if you are Serializing them, just set them to public

slender nymph
# subtle mulch not really

yes it is. there's no reason to make something public unless other objects need access to them. serializing them just exposes them to the inspector to be editable, making them public exposes them to anything with a reference to the object and can therefore be changed any time at runtime

subtle mulch
#

one thing, did you check if the target RB is actually getting set in the joint?

subtle mulch
#

did you actually check if there is a joint and if the joint has the correct values set?

granite elk
#

there is no joint in the object i want to attract, since i build it in code

subtle mulch
#

i meant during runtime...

#

after you click play

granite elk
#

yes there isnt

subtle mulch
#

in the magnet

#

not in the object

granite elk
#

the magnet has a target joint

subtle mulch
#

that script is assigned to the magnet i think

#

also, you are just creating a new joint in the magnet

#

for each object

#

so don't look at the one you already have

#

but check if a second one gets added to the magnet

#

with the right values

granite elk
subtle mulch
chrome storm
#

Nvm I'm back. I'm going to have to change colliders and ground checks because using raycast really isn't working :P

subtle mulch
#

also, you are never setting grabJoint to null (tho i think Destroy might do that)

#

add a check if the first if is actually running

#

like a Debug.Log

granite elk
#

it runs

subtle mulch
#

but it never creates a second joint, hmm

#

do you use the joint you already have in the magnet btw?

granite elk
#

sorry i meant to say it doesent run

subtle mulch
#

oh

#

then check why

#

and

#

it is buggy

#

the second else will always run after the first run

#

causing some problems

#

!code

radiant voidBOT
granite elk
#

how do i find out the problem tho

subtle mulch
#
if (distance < distanceToBlock)
            {
              if (grabJoint == null) {
                              grabJoint = gameObject.AddComponent<FixedJoint2D>();
                  
                              grabJoint.connectedBody = attractedObject;
                  
                              grabJoint.breakForce = Mathf.Infinity;
              }
            }
            else
            {
                attractedObject.AddForce(direction * attractForce);
            }
#

edit the if to this first of all